[Arakhnę-Dev] [429] * Add icon selector for the embodied file chooser.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 429
Author:   galland
Date:     2013-04-27 14:58:20 +0200 (Sat, 27 Apr 2013)
Log Message:
-----------
* Add icon selector for the embodied file chooser.

Modified Paths:
--------------
    trunk/ui/ui-android/src/main/java/org/arakhne/afc/ui/android/filechooser/FileChooser.java
    trunk/ui/ui-android/src/main/java/org/arakhne/afc/ui/android/filechooser/FileChooserActivity.java

Modified: trunk/ui/ui-android/src/main/java/org/arakhne/afc/ui/android/filechooser/FileChooser.java
===================================================================
--- trunk/ui/ui-android/src/main/java/org/arakhne/afc/ui/android/filechooser/FileChooser.java	2013-04-27 12:57:42 UTC (rev 428)
+++ trunk/ui/ui-android/src/main/java/org/arakhne/afc/ui/android/filechooser/FileChooser.java	2013-04-27 12:58:20 UTC (rev 429)
@@ -119,25 +119,29 @@
 	 * @param chooserTitle is the identifier for the chooser's title.
 	 * @param directory is the directory to explore.
 	 * @param fileFilter is the file filter to use.
+	 * @param iconSelector is the selector of icon to use; or <code>null</code> for none.
 	 */
 	public static void showOpenChooser(Activity context, 
 			int activityResultRequestCode, 
 			int chooserTitle,
 			File directory,
-			Class<? extends FileFilter> fileFilter) {
+			Class<? extends FileFilter> fileFilter,
+			Class<? extends FileChooserIconSelector> iconSelector) {
 		showOpenChooser(context, activityResultRequestCode, chooserTitle,
-				createOptions(directory, fileFilter));
+				createOptions(directory, fileFilter, iconSelector));
 	}
 	
 	/** Create options that may be passed to a chooser.
 	 * 
 	 * @param directory is the directory to explore.
 	 * @param fileFilter is the file filter to use.
+	 * @param iconSelector is the selector of icon to use; or <code>null</code> for none.
 	 * @return the options.
 	 */
 	public static Bundle createOptions(
 			File directory,
-			Class<? extends FileFilter> fileFilter) {
+			Class<? extends FileFilter> fileFilter,
+			Class<? extends FileChooserIconSelector> iconSelector) {
 		Bundle bundle = new Bundle();
 		if (directory!=null) {
 			bundle.putString(FileChooserActivity.SAVED_PATH_NAME, directory.getAbsolutePath());
@@ -145,9 +149,12 @@
 		if (fileFilter!=null) {
 			bundle.putString(FileChooserActivity.SAVED_FILE_FILTER, fileFilter.getName());
 		}
+		if (iconSelector!=null) {
+			bundle.putString(FileChooserActivity.SAVED_ICON_SELECTOR, iconSelector.getName());
+		}
 		return bundle;
 	}
-
+	
 	/** Show the file chooser for opening a file.
 	 * <p>
 	 * Mime type is "file/*".
@@ -155,28 +162,9 @@
 	 * @param context is the execution context.
 	 * @param activityResultRequestCode is the code that may be used to retreive the result of the activity.
 	 * @param chooserTitle is the identifier for the chooser's title.
-	 * @param directory is the directory to explore.
-	 * @param fileFilter is the file filter to use.
 	 */
 	public static void showOpenChooser(Activity context, 
 			int activityResultRequestCode, 
-			int chooserTitle,
-			File directory,
-			FileFilter fileFilter) {
-		showOpenChooser(context, activityResultRequestCode, chooserTitle,
-				createOptions(directory, fileFilter!=null ? fileFilter.getClass() : null));
-	}
-
-	/** Show the file chooser for opening a file.
-	 * <p>
-	 * Mime type is "file/*".
-	 * 
-	 * @param context is the execution context.
-	 * @param activityResultRequestCode is the code that may be used to retreive the result of the activity.
-	 * @param chooserTitle is the identifier for the chooser's title.
-	 */
-	public static void showOpenChooser(Activity context, 
-			int activityResultRequestCode, 
 			int chooserTitle) {
 		showOpenChooser(context, activityResultRequestCode, chooserTitle, null);
 	}
@@ -259,14 +247,16 @@
 	 * @param chooserTitle is the identifier for the chooser's title.
 	 * @param file is the filename to use for the saving file.
 	 * @param fileFilter is the file filter to use.
+	 * @param iconSelector is the selector of icon to use; or <code>null</code> for none.
 	 */
 	public static void showSaveChooser(Activity context, 
 			int activityResultRequestCode, 
 			int chooserTitle,
 			File file,
-			Class<? extends FileFilter> fileFilter) {
+			Class<? extends FileFilter> fileFilter,
+			Class<? extends FileChooserIconSelector> iconSelector) {
 		showSaveChooser(context, activityResultRequestCode, chooserTitle,
-				createOptions(file, fileFilter));
+				createOptions(file, fileFilter, iconSelector));
 	}
 
 	/** Show the file chooser for saving a file.
@@ -276,28 +266,9 @@
 	 * @param context is the execution context.
 	 * @param activityResultRequestCode is the code that may be used to retreive the result of the activity.
 	 * @param chooserTitle is the identifier for the chooser's title.
-	 * @param file is the filename to use for the saving file.
-	 * @param fileFilter is the file filter to use.
 	 */
 	public static void showSaveChooser(Activity context, 
 			int activityResultRequestCode, 
-			int chooserTitle,
-			File file,
-			FileFilter fileFilter) {
-		showSaveChooser(context, activityResultRequestCode, chooserTitle,
-				createOptions(file, fileFilter!=null ? fileFilter.getClass() : null));
-	}
-
-	/** Show the file chooser for saving a file.
-	 * <p>
-	 * Mime type is "file/*".
-	 * 
-	 * @param context is the execution context.
-	 * @param activityResultRequestCode is the code that may be used to retreive the result of the activity.
-	 * @param chooserTitle is the identifier for the chooser's title.
-	 */
-	public static void showSaveChooser(Activity context, 
-			int activityResultRequestCode, 
 			int chooserTitle) {
 		showSaveChooser(context, activityResultRequestCode, chooserTitle, null);
 	}

Modified: trunk/ui/ui-android/src/main/java/org/arakhne/afc/ui/android/filechooser/FileChooserActivity.java
===================================================================
--- trunk/ui/ui-android/src/main/java/org/arakhne/afc/ui/android/filechooser/FileChooserActivity.java	2013-04-27 12:57:42 UTC (rev 428)
+++ trunk/ui/ui-android/src/main/java/org/arakhne/afc/ui/android/filechooser/FileChooserActivity.java	2013-04-27 12:58:20 UTC (rev 429)
@@ -66,6 +66,10 @@
 	 */
 	public static final String SAVED_PATH_NAME = "path"; //$NON-NLS-1$
 
+	/** Name of the attribute that permits to save the icon selector in the activity.
+	 */
+	public static final String SAVED_ICON_SELECTOR = "iconSelector"; //$NON-NLS-1$
+
 	/** Name of the attribute that permits to save the file filter in the activity.
 	 */
 	public static final String SAVED_FILE_FILTER = "fileFilter"; //$NON-NLS-1$
@@ -108,6 +112,26 @@
 		return defaultValue;
 	}
 
+	private static FileChooserIconSelector getIconSelectorParameter(String name, FileChooserIconSelector defaultValue, Bundle... bundles) {
+		for(Bundle b : bundles) {
+			if (b!=null) {
+				String classname = b.getString(name);
+				if (classname!=null) {
+					try {
+						Class<?> type = Class.forName(classname);
+						if (FileChooserIconSelector.class.isAssignableFrom(type)) {
+							return (FileChooserIconSelector)type.newInstance();
+						}
+					}
+					catch(Throwable e) {
+						Log.d("FILE_CHOOSER", e.getLocalizedMessage(), e); //$NON-NLS-1$
+					}
+				}
+			}
+		}
+		return defaultValue;
+	}
+
 	/** Listener on the external storage state.
 	 */
 	private BroadcastReceiver storageListener = new BroadcastReceiver() {
@@ -184,6 +208,11 @@
 				null,
 				this.activityOptions, savedInstanceState);
 
+		this.iconSelector = getIconSelectorParameter(
+				SAVED_ICON_SELECTOR,
+				null,
+				this.activityOptions, savedInstanceState);
+
 		if (this.activityOptions!=null) {
 			this.isOpen = this.activityOptions.getBoolean(SAVED_IS_OPEN,
 					savedInstanceState!=null ?
@@ -366,6 +395,12 @@
 		else {
 			outState.remove(SAVED_FILE_FILTER);
 		}
+		if (this.iconSelector!=null) {
+			outState.putString(SAVED_ICON_SELECTOR, this.iconSelector.getClass().getName());
+		}
+		else {
+			outState.remove(SAVED_ICON_SELECTOR);
+		}
 		outState.putBoolean(SAVED_IS_OPEN, this.isOpen);
 		super.onSaveInstanceState(outState);
 	}
@@ -386,6 +421,18 @@
 				//
 			}
 		}
+		String iconSelectorClassname = savedInstanceState.getString(SAVED_ICON_SELECTOR);
+		if (iconSelectorClassname!=null) {
+			try {
+				Class<?> type = Class.forName(iconSelectorClassname);
+				if (FileChooserIconSelector.class.isAssignableFrom(type)) {
+					this.iconSelector = (FileChooserIconSelector)type.newInstance();
+				}
+			}
+			catch(Throwable _) {
+				//
+			}
+		}
 		String path = savedInstanceState.getString(SAVED_PATH_NAME);
 		if (path!=null) {
 			this.path = new File(path);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/