2011年8月29日月曜日

ファイルの拡張子をチェック【java】【file】【チェック処理】

取得したファイルが画像であるかどうかを拡張子から判断します。
画像拡張子リストに宣言されている文字列の中に一致するものがあれば、trueを返します。
このチェック処理ではあくまでファイル名のチェックであり、中身が本当に画像であるか、
または読み取り可能であるか等のチェックは行っておりません。

画像拡張子リストを変更すれば、別の拡張子にも使用できます。

import java.io.File;


public class Check {
protected boolean checkImageFile(File checkedFile){
// チェック結果
boolean checkResultFlag = false;
// 画像拡張子リスト
final String[] IMAGE_EXTENSION_ARRAY = {".bmp",".gif",".jpg",".jpeg",".png"};

// nullチェック
if(checkedFile == null){
return checkResultFlag;
}
// isFileチェック
if(!checkedFile.isFile()){
return checkResultFlag;
}
// ファイル名取得チェック
if(checkedFile.getName() == null || checkedFile.getName().length() == 0){
return checkResultFlag;
}
// ファイルの末尾が画像拡張子リストの中にあるかチェック
for(int i=0;i<IMAGE_EXTENSION_ARRAY.length;i++){
if (checkedFile.getName().endsWith(IMAGE_EXTENSION_ARRAY[i].toLowerCase()) ||
checkedFile.getName().endsWith(IMAGE_EXTENSION_ARRAY[i].toUpperCase())){
checkResultFlag = true;
break;
}
}
return checkResultFlag;
}
}

2011年8月22日月曜日

複数の要素(View)を重ねて表示の続き【android】【FrameLayout】【重ねて表示】

前回の続きです。前回↓
⇒複数の要素(View)を重ねて表示

前回は、1つのImageViewの上に、1つのTextViewを表示していましたが、
今度は、複数のImageViewの上に、1つのTextViewを表示してみます。

気をつけないといけない点は、custom_list_item.xml内のそれぞれの
ImageViewについては重なってはいけない、という点です。

その為、FrameLayoutの中でそれぞれのImageViewを、LinearLayoutで
囲んでいます。
※画像を横並びにする為に、android:orientation="horizontal"を
指定しています。)

結果、下記のように表示されました。


















■custom_list.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
/>

</FrameLayout>




■custom_list_item.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingLeft="2dip"
android:paddingRight="2dip">

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<ImageView
android:id="@+id/imageview"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:padding="2dip"
android:layout_gravity="left"
android:layout_marginRight="2dip"
/>

<ImageView
android:id="@+id/imageview2"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:padding="2dip"
android:layout_gravity="left"
android:layout_marginRight="2dip"
/>

<ImageView
android:id="@+id/imageview3"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:padding="2dip"
android:layout_gravity="left"
android:layout_marginRight="2dip"
/>

<ImageView
android:id="@+id/imageview4"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:padding="2dip"
android:layout_gravity="left"
android:layout_marginRight="2dip"
/>

<ImageView
android:id="@+id/imageview5"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:padding="2dip"
android:layout_gravity="left"
android:layout_marginRight="2dip"
/>

<ImageView
android:id="@+id/imageview6"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:padding="2dip"
android:layout_gravity="left"
android:layout_marginRight="2dip"
/>

</LinearLayout>
<TextView android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="left"
android:layout_marginLeft="2dip"
android:layout_marginTop="2dip"
android:textColor="@color/white"
android:textSize="35dip"
android:textStyle="bold"
/>

</FrameLayout>

2011年8月18日木曜日

複数の要素(View)を重ねて表示【android】【FrameLayout】【重ねて表示】

次回に下記をカスタマイズした記事があります。
⇒複数の要素(View)を重ねて表示の続き

画像に重ねて文字を出力したいときなど、Viewを重ねて表示する場合には、
FrameLayout』を使用します。

SDカードの画像格納ディレクトリ一覧を表示する画面をイメージしたレイアウトが
下記になります。
後から宣言されたViewが上に表示されます。


















■custom_list_item.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
/>

</FrameLayout>
 
 
■custom_list_item.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingLeft="2dip"
android:paddingRight="2dip">

<ImageView
android:id="@+id/imageview"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:padding="2dip"
android:layout_gravity="left"
/>

<TextView android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="left"
android:layout_marginLeft="2dip"
android:layout_marginTop="2dip"
android:textColor="@color/white"
android:textSize="35dip"
android:textStyle="bold"
/>

</FrameLayout>