Revisão | 6 (tree) |
---|---|
Hora | 2010-10-24 07:23:54 |
Autor | tamanegisoul |
ダウンロード機能開発中
@@ -8,7 +8,7 @@ | ||
8 | 8 | <application |
9 | 9 | android:icon="@drawable/icon" |
10 | 10 | android:label="@string/app_name" |
11 | - > | |
11 | + android:debuggable="true"> | |
12 | 12 | <activity |
13 | 13 | android:name=".Main" |
14 | 14 | android:label="@string/app_name" |
@@ -6,6 +6,7 @@ | ||
6 | 6 | import java.io.InputStream; |
7 | 7 | import java.io.InputStreamReader; |
8 | 8 | import java.util.ArrayList; |
9 | +import java.util.List; | |
9 | 10 | |
10 | 11 | import org.apache.http.HttpResponse; |
11 | 12 | import org.apache.http.client.ClientProtocolException; |
@@ -121,7 +122,7 @@ | ||
121 | 122 | |
122 | 123 | return new BufferedHttpEntity(response.getEntity()).getContent(); |
123 | 124 | } |
124 | - | |
125 | + | |
125 | 126 | public void cache(AlbumInfo albumInfo) { |
126 | 127 | try { |
127 | 128 | String url = albumInfo.link + "&fields=entry(title,media:group(media:content))"; |
@@ -0,0 +1,92 @@ | ||
1 | +package tamanegisoul.pl.widget; | |
2 | + | |
3 | +import tamanegisoul.pl.AppContext; | |
4 | +import tamanegisoul.pl.R; | |
5 | +import tamanegisoul.pl.data.AlbumInfo; | |
6 | +import android.app.AlertDialog; | |
7 | +import android.app.ProgressDialog; | |
8 | +import android.content.Context; | |
9 | +import android.content.DialogInterface; | |
10 | +import android.content.res.Resources; | |
11 | + | |
12 | +public class CacheMenuDialogBuilder implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, Runnable { | |
13 | + | |
14 | + private Context mContext; | |
15 | + private AlbumInfo mInfo; | |
16 | + private ProgressDialog mProgressDialog; | |
17 | + private int mButtonClicked = AlertDialog.BUTTON_NEUTRAL; | |
18 | + | |
19 | + public CacheMenuDialogBuilder(Context context, AlbumInfo info) { | |
20 | + super(); | |
21 | + mContext = context; | |
22 | + mInfo = info; | |
23 | + } | |
24 | + | |
25 | + public void show() { | |
26 | + Resources r = mContext.getResources(); | |
27 | + AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); | |
28 | + alertDialog.setIcon(android.R.drawable.ic_dialog_alert); | |
29 | + alertDialog.setTitle(r.getString(R.string.cache_menu)); | |
30 | + alertDialog.setMessage(r.getString(R.string.cache_menu_text)); | |
31 | + alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, r.getString(R.string.update), this); | |
32 | + alertDialog.setOnDismissListener(this); | |
33 | + alertDialog.show(); | |
34 | + } | |
35 | + | |
36 | + @Override | |
37 | + public void onClick(DialogInterface dialog, int which) { | |
38 | + mButtonClicked = which; | |
39 | + } | |
40 | + | |
41 | + @Override | |
42 | + public void onDismiss(DialogInterface dialog) { | |
43 | + switch (mButtonClicked) { | |
44 | + case DialogInterface.BUTTON_POSITIVE: | |
45 | + mProgressDialog = new ProgressDialog(mContext); | |
46 | + mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); | |
47 | + mProgressDialog.setMessage("処理を実行中です..."); | |
48 | + mProgressDialog.setCancelable(true); | |
49 | + mProgressDialog.show(); | |
50 | + new Thread(this).start(); | |
51 | + break; | |
52 | + case DialogInterface.BUTTON_NEGATIVE: | |
53 | + | |
54 | + break; | |
55 | + default: | |
56 | + break; | |
57 | + } | |
58 | + } | |
59 | + | |
60 | + @Override | |
61 | + public void run() { | |
62 | + AppContext.instance.getPicasa().cache(mInfo); | |
63 | + /* | |
64 | + * このRunnableから↓のコメントアウト行のように直接UIを書き換えようとすると、 | |
65 | + * CalledFromWrongThreadException: Only the original thread that created | |
66 | + * a view hierarchy can touch its views. | |
67 | + * で落ちる。(=このRunnableはUIスレッドとは別スレッドで立ち上がっているため) | |
68 | + */ | |
69 | + // ((TextView)findViewById(R.id.textProgressDialog)).setText("このUI操作はできません!"); | |
70 | + | |
71 | + /* | |
72 | + * 3.UIのテキストを変更 UIを書き換える場合はHandlerに処理を渡す (ダイアログ表示してるからあまり必要ない気もする) | |
73 | + * | |
74 | + * 実際に行う処理の結果(ループカウンタ等)を動的にUI側へ渡したい場合 | |
75 | + * Handler#sendMessage()にBundleをセットして渡す UIに動的変数(引数)を渡す必要が無い場合 | |
76 | + * Handler#post(Runnable r)でも可(今回は省略) | |
77 | + * | |
78 | + * 今回は 上記sleepの間はUIテキストが「これはProgressDialogのテストです」 ダイアログが消えると「HOGEHOGE」 | |
79 | + * に書き換わる Message message = new Message(); Bundle bundle = new Bundle(); | |
80 | + * bundle.putString("hoge", "HOGEHOGE"); message.setData(bundle); | |
81 | + * handler.sendMessage(message); | |
82 | + */ | |
83 | + | |
84 | + /* | |
85 | + * 4.実際に行いたい処理が終わったらダイアログを消去 onCreateDialog()を使う場合 | |
86 | + * dismissDialog(ID_PROGRESS_DIALOG) progressDialog.show()を使う場合 | |
87 | + * progressDialog.dismiss() | |
88 | + */ | |
89 | + // dismissDialog(ID_PROGRESS_DIALOG); | |
90 | + mProgressDialog.dismiss(); | |
91 | + } | |
92 | +} |
@@ -1,9 +1,7 @@ | ||
1 | 1 | package tamanegisoul.pl; |
2 | 2 | |
3 | -import java.io.BufferedInputStream; | |
4 | 3 | import java.io.BufferedOutputStream; |
5 | 4 | import java.io.File; |
6 | -import java.io.FileNotFoundException; | |
7 | 5 | import java.io.FileOutputStream; |
8 | 6 | import java.io.IOException; |
9 | 7 | import java.io.InputStream; |
@@ -24,8 +22,8 @@ | ||
24 | 22 | File f = new File(CACHE, albumTitle); |
25 | 23 | return getSize(f); |
26 | 24 | } |
27 | - | |
28 | - public static void cache(String albumTitle, String title, InputStream in) throws IOException{ | |
25 | + | |
26 | + public static void cache(String albumTitle, String title, InputStream in) throws IOException { | |
29 | 27 | Bitmap bm = BitmapFactory.decodeStream(in); |
30 | 28 | |
31 | 29 | Matrix matrix = new Matrix(); |
@@ -40,10 +38,21 @@ | ||
40 | 38 | bm.compress(CompressFormat.JPEG, 100, out); |
41 | 39 | out.flush(); |
42 | 40 | out.close(); |
43 | - | |
44 | - new MediaScannerConnection(AppContext.instance.getContext(), null).scanFile(f.getAbsolutePath(), "image/jpeg"); | |
41 | + | |
42 | + // ContentValues values = new ContentValues(); | |
43 | + // ContentResolver contentResolver = | |
44 | + // AppContext.instance.getContext().getContentResolver(); | |
45 | + // values.put(Images.Media.MIME_TYPE, "image/jpeg"); | |
46 | + // values.put(Images.Media.TITLE, title); | |
47 | + // values.put("_data", f.getAbsolutePath()); | |
48 | + // contentResolver.insert(Media.EXTERNAL_CONTENT_URI, values); | |
49 | + MediaScannerConnection.scanFile(AppContext.instance.getContext(), new String[] { f.getAbsolutePath() }, null, null); | |
45 | 50 | } |
46 | 51 | |
52 | + public static void clearCache(String albumTitle) { | |
53 | + deleteFile(new File(CACHE, albumTitle)); | |
54 | + } | |
55 | + | |
47 | 56 | private static long getSize(File file) { |
48 | 57 | if (!file.exists()) { |
49 | 58 | return 0; |
@@ -58,4 +67,14 @@ | ||
58 | 67 | } |
59 | 68 | } |
60 | 69 | |
70 | + private static void deleteFile(File file) { | |
71 | + if (file.exists()) { | |
72 | + if (file.isDirectory()) { | |
73 | + for (File f : file.listFiles()) { | |
74 | + deleteFile(f); | |
75 | + } | |
76 | + } | |
77 | + file.delete(); | |
78 | + } | |
79 | + } | |
61 | 80 | } |
@@ -16,7 +16,7 @@ | ||
16 | 16 | } |
17 | 17 | |
18 | 18 | public void init(Context context) { |
19 | - Log.d(NAME, "AppContext.init"); | |
19 | + Log.d(NAME, String.format("AppContext.init(%s)", context)); | |
20 | 20 | this.mContext = context; |
21 | 21 | } |
22 | 22 |
@@ -7,14 +7,12 @@ | ||
7 | 7 | import tamanegisoul.pl.R; |
8 | 8 | import tamanegisoul.pl.data.AlbumInfo; |
9 | 9 | import tamanegisoul.pl.widget.AlbumInfoAdapter; |
10 | -import android.app.AlertDialog; | |
10 | +import tamanegisoul.pl.widget.CacheMenuDialogBuilder; | |
11 | 11 | import android.app.ListActivity; |
12 | -import android.content.DialogInterface; | |
13 | 12 | import android.os.Bundle; |
14 | 13 | import android.util.Log; |
15 | 14 | import android.view.View; |
16 | 15 | import android.widget.AdapterView; |
17 | -import android.widget.AdapterView.OnItemSelectedListener; | |
18 | 16 | |
19 | 17 | public class SynchronizeActivity extends ListActivity { |
20 | 18 |
@@ -50,26 +48,9 @@ | ||
50 | 48 | getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { |
51 | 49 | @Override |
52 | 50 | public void onItemClick(final AdapterView<?> arg0, View arg1, final int arg2, long arg3) { |
53 | - new AlertDialog.Builder(arg0.getContext()) | |
54 | - .setIcon(android.R.drawable.ic_dialog_alert) | |
55 | - .setTitle("YES/NO Dialog") | |
56 | - .setMessage("キャッシュを更新 or 削除しますか?") | |
57 | - .setPositiveButton("更新", new DialogInterface.OnClickListener() { | |
58 | - public void onClick(DialogInterface dialog, int whichButton) { | |
59 | - AlbumInfo info = ((AlbumInfoAdapter)arg0.getAdapter()).getItem(arg2); | |
60 | - Log.d(AppContext.NAME, String.format("selectedItem: %s", info)); | |
61 | - AppContext.instance.getPicasa().cache(info); | |
62 | - } | |
63 | - }) | |
64 | - .setNeutralButton("削除", new DialogInterface.OnClickListener() { | |
65 | - public void onClick(DialogInterface dialog, int whichButton) { | |
66 | - } | |
67 | - }) | |
68 | - .setNegativeButton("キャンセル", new DialogInterface.OnClickListener() { | |
69 | - public void onClick(DialogInterface dialog, int whichButton) { | |
70 | - } | |
71 | - }) | |
72 | - .show(); | |
51 | + AlbumInfo info = ((AlbumInfoAdapter) arg0.getAdapter()).getItem(arg2); | |
52 | + Log.d(AppContext.NAME, String.format("(%s) item clicked: %s", SynchronizeActivity.class, info)); | |
53 | + new CacheMenuDialogBuilder(arg0.getContext(), info).show(); | |
73 | 54 | } |
74 | 55 | }); |
75 | 56 | } |
@@ -7,4 +7,9 @@ | ||
7 | 7 | <string name="preference_account">アカウント</string> |
8 | 8 | <string name="not_selected">未選択</string> |
9 | 9 | <string name="nodata">データなし</string> |
10 | + <string name="cache_menu">キャッシュ操作</string> | |
11 | + <string name="cache_menu_text">キャッシュを更新または削除する</string> | |
12 | + <string name="update">更新</string> | |
13 | + <string name="delete">削除</string> | |
14 | + <string name="cancel">キャンセル</string> | |
10 | 15 | </resources> |