何これ?
Java SEのFileDialogに相当するものがAndroid SDKにはないので(ないよね?),簡単なものでもあれば便利かなと思ってを作ってみました.好きに使ってください.
何ができるの?
ざっくり言って4つのことができます
1. ファイルの選択
2. 新しいファイル名の指定
3. ディレクトの選択
4. 新しいディレクトリ名の指定
1と3はファイル・システム上に存在するファイルないしはディレクトリをユーザーに選ばせます.Figure 1に示すようにリスト・ビューでディレクトリを移動し,目的のファイルを選択します.3の場合は<Here>を押せば,現在のディレクトリが選択されます.
2と4はファイル・システム内に新しいファイルないしディレクトリの名前を指定します.任意のディレクトリで<Here>を押すと,ファイル名を指定するためのテキスト・ボックスが現れます(Figure 2, Figure 3).2の場合は,既存のファイルを指定することでもファイル名の指定ができます(選択されたファイル名があらかじめテキスト・ボックスに挿入されています).
使い方
ダウンロード・パッケージには次のようなサンプル・プログラムが入っています.
onCreate()内のコードが上記4つの使い方の例になっています.最初の引数で開始位置のディレクトリを指定します.2番目と3番目で使い方を指定します.4番目と5番目でContextとFileDialogue.Listenerを指定します.結果を受け取るためにはFileDialogue.Listenerを実装する必要があります.
fd.showDialogue()でファイル・ダイアログが表示されます.結果はonSelected()の引数に渡されます(ディレクトリ指定の場合はfilenameには""が入っています).ユーザーがBackボタンを押した場合はonCanceled()が呼び出されます.
です.
public class FdExample extends Activity implements FileDialogue.Listener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// (1) Select file, starting direcotry is /sdcard/
FileDialogue fd = new FileDialogue(null, FileDialogue.FILE, FileDialogue.SELECT, this, this);
// (2) Create file, starting direcotry is /sdcard/, user will be requested to enter filename
// FileDialogue fd = new FileDialogue("/sdcard/picture/", FileDialogue.FILE, FileDialogue.CREATE, this, this);
// (3) Select directory, starting direcotry is /sdcard
// FileDialogue fd = new FileDialogue(null, FileDialogue.DIRECTORY, FileDialogue.SELECT, this, this);
// (4) Create directory, starting direcotry is /sdcard/, user will be requested to enter direcotry name
// FileDialogue fd = new FileDialogue(null, FileDialogue.DIRECTORY, FileDialogue.CREATE, this, this);
fd.showDialogue();
}
public void onSelected(String directory, String filename) {
// filename will be "" when target is the FileDialogue.DIRECOTRY
Log.v("FdExample", "Directory = " + directory + ", File = " + filename);
}
public void onCanceled() {
// this is when "back" button is pressed
Log.v("FdExample", "Canceled");
}
}
これが限界かい?
個人的にはファイル・ダイアログが苦手です.今どこにいるのか,どうやって目的地に達するのか,疲れるしつまんないです.人間が苦手な処理の塊のようなUIだと思います.
なので,もうちょっと別のやり方があるんじゃないかと思って今いろいろ考えてます.人間の得意とする画像の並列処理や位置や色の記憶をつかってスパっと目的地へ到達できるようにできるんじゃないかと思ってます.出来上がったらまたこのWikiで.
最終更新:2010年06月28日 23:18