packages/apps/FileManager
Révision | 9471f21e6896254fa67c70dce957ef5f8bafbdfe (tree) |
---|---|
l'heure | 2011-07-03 03:08:18 |
Auteur | Joe Berria <nexesdevelopment@gmai...> |
Commiter | Joe Berria |
added ability to changed bookmark names
@@ -27,11 +27,9 @@ import android.content.DialogInterface; | ||
27 | 27 | import android.preference.PreferenceManager; |
28 | 28 | import android.app.ListFragment; |
29 | 29 | import android.app.AlertDialog; |
30 | -import android.view.ContextMenu; | |
31 | 30 | import android.view.View; |
32 | 31 | import android.view.ViewGroup; |
33 | 32 | import android.view.LayoutInflater; |
34 | -import android.view.ContextMenu.ContextMenuInfo; | |
35 | 33 | import android.widget.AdapterView; |
36 | 34 | import android.widget.AdapterView.OnItemLongClickListener; |
37 | 35 | import android.widget.ListView; |
@@ -39,7 +37,6 @@ import android.widget.ImageView; | ||
39 | 37 | import android.widget.TextView; |
40 | 38 | import android.widget.EditText; |
41 | 39 | import android.widget.ArrayAdapter; |
42 | -import android.widget.AdapterView.AdapterContextMenuInfo; | |
43 | 40 | import android.widget.Toast; |
44 | 41 | |
45 | 42 | import java.util.ArrayList; |
@@ -47,15 +44,16 @@ import java.io.File; | ||
47 | 44 | |
48 | 45 | public class DirListActivity extends ListFragment implements OnBookMarkAddListener, |
49 | 46 | OnItemLongClickListener{ |
50 | - private static final String PREF_LIST_KEY = "pref_dirlist"; | |
51 | 47 | private static final int BOOKMARK_POS = 6; |
52 | 48 | |
53 | 49 | private static OnChangeLocationListener mChangeLocList; |
54 | 50 | private ArrayList<String> mDirList; |
51 | + private ArrayList<String> mBookmarkNames; | |
55 | 52 | private Context mContext; |
56 | 53 | private ImageView mLastIndicater = null; |
57 | 54 | private DirListAdapter mDelegate; |
58 | 55 | private String mDirListString; |
56 | + private String mBookmarkString; | |
59 | 57 | |
60 | 58 | |
61 | 59 | public interface OnChangeLocationListener { |
@@ -69,10 +67,14 @@ public class DirListActivity extends ListFragment implements OnBookMarkAddListen | ||
69 | 67 | String storage = "/" + Environment.getExternalStorageDirectory().getName(); |
70 | 68 | mContext = getActivity(); |
71 | 69 | mDirList = new ArrayList<String>(); |
70 | + mBookmarkNames = new ArrayList<String>(); | |
72 | 71 | mDirListString = (PreferenceManager.getDefaultSharedPreferences(mContext)) |
73 | - .getString(PREF_LIST_KEY, ""); | |
72 | + .getString(SettingsActivity.PREF_LIST_KEY, ""); | |
74 | 73 | |
75 | - if(mDirListString.length() > 0) { | |
74 | + mBookmarkString = (PreferenceManager.getDefaultSharedPreferences(mContext)) | |
75 | + .getString(SettingsActivity.PREF_BOOKNAME_KEY, ""); | |
76 | + | |
77 | + if (mDirListString.length() > 0) { | |
76 | 78 | String[] l = mDirListString.split(":"); |
77 | 79 | |
78 | 80 | for(String string : l) |
@@ -87,12 +89,18 @@ public class DirListActivity extends ListFragment implements OnBookMarkAddListen | ||
87 | 89 | mDirList.add(storage + "/" + "Pictures"); |
88 | 90 | mDirList.add("Bookmarks"); |
89 | 91 | } |
92 | + | |
93 | + if (mBookmarkString.length() > 0) { | |
94 | + String[] l = mBookmarkString.split(":"); | |
95 | + | |
96 | + for(String string : l) | |
97 | + mBookmarkNames.add(string); | |
98 | + } | |
90 | 99 | } |
91 | 100 | |
92 | 101 | @Override |
93 | 102 | public void onActivityCreated(Bundle savedInstanceState) { |
94 | 103 | super.onActivityCreated(savedInstanceState); |
95 | - getView().setBackgroundResource(R.color.gray); | |
96 | 104 | |
97 | 105 | ListView lv = getListView(); |
98 | 106 | lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); |
@@ -129,18 +137,19 @@ public class DirListActivity extends ListFragment implements OnBookMarkAddListen | ||
129 | 137 | |
130 | 138 | @Override |
131 | 139 | public boolean onItemLongClick(AdapterView<?> list, View view, int pos, long id) { |
140 | + AlertDialog.Builder builder = new AlertDialog.Builder(mContext); | |
141 | + LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
142 | + | |
143 | + View v = inflater.inflate(R.layout.input_dialog_layout, null); | |
144 | + final EditText text = (EditText)v.findViewById(R.id.dialog_input); | |
145 | + | |
132 | 146 | |
133 | 147 | /* the first two items in our dir list is / and scdard. |
134 | 148 | * the user should not be able to change the location |
135 | 149 | * of these two entries. Everything else is fair game */ |
136 | 150 | if (pos > 1 && pos < BOOKMARK_POS) { |
137 | - AlertDialog.Builder builder = new AlertDialog.Builder(mContext); | |
138 | - LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
139 | - | |
140 | - View v = inflater.inflate(R.layout.input_dialog_layout, null); | |
141 | 151 | final int position = pos; |
142 | - final EditText text = (EditText)v.findViewById(R.id.dialog_input); | |
143 | - | |
152 | + | |
144 | 153 | ((TextView)v.findViewById(R.id.dialog_message)) |
145 | 154 | .setText("Change the location of this directory."); |
146 | 155 |
@@ -186,41 +195,55 @@ public class DirListActivity extends ListFragment implements OnBookMarkAddListen | ||
186 | 195 | |
187 | 196 | builder.create().show(); |
188 | 197 | return true; |
189 | - } | |
190 | 198 | |
191 | - return false; | |
192 | - } | |
193 | - | |
194 | - @Override | |
195 | - public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { | |
196 | - final int pos = ((AdapterContextMenuInfo)menuInfo).position; | |
197 | - | |
198 | - if(pos <= BOOKMARK_POS) | |
199 | - return; | |
200 | - | |
201 | - new AlertDialog.Builder(mContext) | |
202 | - .setTitle("Remove Bookmark " + mDirList.get(pos)) | |
203 | - .setMessage("Are you sure you want to remove this as a bookmark?") | |
204 | - .setPositiveButton("Remove", new DialogInterface.OnClickListener() { | |
199 | + /*manage the users bookmarks, delete or rename*/ | |
200 | + } else if (pos > BOOKMARK_POS) { | |
201 | + final int p = pos; | |
202 | + final String bookmark = mBookmarkNames.get(p - (BOOKMARK_POS + 1)); | |
203 | + | |
204 | + builder.setTitle("Manage bookmark " + bookmark); | |
205 | + builder.setIcon(R.drawable.folder_md); | |
206 | + builder.setView(v); | |
207 | + | |
208 | + ((TextView)v.findViewById(R.id.dialog_message)) | |
209 | + .setText("Would you like to delete or rename this bookmark?"); | |
210 | + | |
211 | + text.setText(bookmark); | |
212 | + builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() { | |
213 | + | |
205 | 214 | @Override |
206 | 215 | public void onClick(DialogInterface dialog, int which) { |
207 | - mDirList.remove(pos); | |
216 | + mDirList.remove(p); | |
217 | + mBookmarkNames.remove(p - (BOOKMARK_POS + 1)); | |
218 | + | |
208 | 219 | buildDirString(); |
209 | 220 | mDelegate.notifyDataSetChanged(); |
210 | 221 | } |
211 | - }) | |
212 | - .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { | |
222 | + }); | |
223 | + builder.setNegativeButton("Rename", new DialogInterface.OnClickListener() { | |
224 | + | |
213 | 225 | @Override |
214 | 226 | public void onClick(DialogInterface dialog, int which) { |
215 | - dialog.dismiss(); | |
227 | + mBookmarkNames.remove(p - (BOOKMARK_POS + 1)); | |
228 | + mBookmarkNames.add(p - (BOOKMARK_POS + 1), text.getText().toString()); | |
229 | + | |
230 | + buildDirString(); | |
231 | + mDelegate.notifyDataSetChanged(); | |
216 | 232 | } |
217 | - | |
218 | - }).create().show(); | |
233 | + }); | |
234 | + | |
235 | + builder.create().show(); | |
236 | + return true; | |
237 | + | |
238 | + } | |
239 | + return false; | |
219 | 240 | } |
220 | - | |
241 | + | |
221 | 242 | @Override |
222 | 243 | public void onBookMarkAdd(String path) { |
223 | 244 | mDirList.add(path); |
245 | + mBookmarkNames.add(path.substring(path.lastIndexOf("/") + 1)); | |
246 | + | |
224 | 247 | buildDirString(); |
225 | 248 | mDelegate.notifyDataSetChanged(); |
226 | 249 | } |
@@ -229,25 +252,37 @@ public class DirListActivity extends ListFragment implements OnBookMarkAddListen | ||
229 | 252 | mChangeLocList = l; |
230 | 253 | } |
231 | 254 | |
232 | - public void setDirListString(String list) { | |
233 | - mDirListString = list; | |
234 | - } | |
255 | +// public void setDirListString(String list) { | |
256 | +// mDirListString = list; | |
257 | +// } | |
235 | 258 | |
236 | 259 | public String getDirListString() { |
237 | 260 | return mDirListString; |
238 | 261 | } |
239 | 262 | |
263 | + | |
264 | + public String getBookMarkNameString() { | |
265 | + return mBookmarkString; | |
266 | + } | |
267 | + | |
240 | 268 | /* |
241 | 269 | * Builds a string from mDirList to easily save and recall |
242 | 270 | * from preferences. |
243 | 271 | */ |
244 | 272 | private void buildDirString() { |
273 | + int len = mDirList.size(); | |
245 | 274 | |
246 | - if(mDirListString != null && mDirListString.length() > 0) | |
275 | + if(mDirListString != null && mDirListString.length() > 0) { | |
247 | 276 | mDirListString = ""; |
277 | + mBookmarkString = ""; | |
278 | + } | |
248 | 279 | |
249 | - for(String l : mDirList) | |
250 | - mDirListString += l + ":"; | |
280 | + for (int i = 0; i <len; i++) { | |
281 | + mDirListString += mDirList.get(i) + ":"; | |
282 | + | |
283 | + if (i > BOOKMARK_POS && mBookmarkNames.size() > 0) | |
284 | + mBookmarkString += mBookmarkNames.get(i - (BOOKMARK_POS + 1)) + ":"; | |
285 | + } | |
251 | 286 | } |
252 | 287 | |
253 | 288 |
@@ -263,9 +298,7 @@ public class DirListActivity extends ListFragment implements OnBookMarkAddListen | ||
263 | 298 | } |
264 | 299 | |
265 | 300 | @Override |
266 | - public View getView(int position, View view, ViewGroup parent) { | |
267 | - String name = mDirList.get(position); | |
268 | - | |
301 | + public View getView(int position, View view, ViewGroup parent) { | |
269 | 302 | if(view == null) { |
270 | 303 | LayoutInflater in = (LayoutInflater)mContext. |
271 | 304 | getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
@@ -321,8 +354,7 @@ public class DirListActivity extends ListFragment implements OnBookMarkAddListen | ||
321 | 354 | break; |
322 | 355 | |
323 | 356 | default: |
324 | - mHolder.mMainText.setText(name.substring(name.lastIndexOf("/") + 1, | |
325 | - name.length())); | |
357 | + mHolder.mMainText.setText(mBookmarkNames.get(position - (BOOKMARK_POS + 1))); | |
326 | 358 | mHolder.mIcon.setImageResource(R.drawable.folder_md); |
327 | 359 | break; |
328 | 360 | } |
@@ -206,7 +206,7 @@ public class MainActivity extends Activity { | ||
206 | 206 | |
207 | 207 | /* read and display the users preferences */ |
208 | 208 | mSettingsListener.onHiddenFilesChanged(mPreferences.getBoolean(SettingsActivity.PREF_HIDDEN_KEY, false)); |
209 | - mSettingsListener.onThumbnailChanged(mPreferences.getBoolean(SettingsActivity.PREF_THUMB_KEY, false)); | |
209 | + mSettingsListener.onThumbnailChanged(mPreferences.getBoolean(SettingsActivity.PREF_THUMB_KEY, true)); | |
210 | 210 | mSettingsListener.onViewChanged(mPreferences.getString(SettingsActivity.PREF_VIEW_KEY, "grid")); |
211 | 211 | mSettingsListener.onSortingChanged(mPreferences.getString(SettingsActivity.PREF_SORT_KEY, "type")); |
212 | 212 | } |
@@ -314,12 +314,22 @@ public class MainActivity extends Activity { | ||
314 | 314 | super.onPause(); |
315 | 315 | String list = ((DirListActivity)getFragmentManager() |
316 | 316 | .findFragmentById(R.id.list_frag)).getDirListString(); |
317 | + String bookmark = ((DirListActivity)getFragmentManager() | |
318 | + .findFragmentById(R.id.list_frag)).getBookMarkNameString(); | |
319 | + | |
317 | 320 | String saved = mPreferences.getString(SettingsActivity.PREF_LIST_KEY, ""); |
321 | + String saved_book = mPreferences.getString(SettingsActivity.PREF_BOOKNAME_KEY, ""); | |
318 | 322 | |
319 | - if(!list.equals(saved)) { | |
323 | + if (!list.equals(saved)) { | |
320 | 324 | SharedPreferences.Editor e = mPreferences.edit(); |
321 | 325 | e.putString(SettingsActivity.PREF_LIST_KEY, list); |
322 | - e.commit(); | |
326 | + e.commit(); | |
327 | + } | |
328 | + | |
329 | + if (!bookmark.equals(saved_book)) { | |
330 | + SharedPreferences.Editor e = mPreferences.edit(); | |
331 | + e.putString(SettingsActivity.PREF_BOOKNAME_KEY, bookmark); | |
332 | + e.commit(); | |
323 | 333 | } |
324 | 334 | } |
325 | 335 | } |
@@ -24,6 +24,7 @@ import android.preference.PreferenceActivity; | ||
24 | 24 | public class SettingsActivity extends PreferenceActivity { |
25 | 25 | //keys used for preference file |
26 | 26 | public static final String PREF_LIST_KEY = "pref_dirlist"; |
27 | + public static final String PREF_BOOKNAME_KEY = "pref_bookmarks"; | |
27 | 28 | public static final String PREF_HIDDEN_KEY = "pref_hiddenFiles"; |
28 | 29 | public static final String PREF_THUMB_KEY = "pref_thumbnail"; |
29 | 30 | public static final String PREF_VIEW_KEY = "pref_view"; |