OSDN Git Service

CMFM: Implement initial landing view for "External Storage Bookmarks"
authorMartin Brabham <optedoblivion@cyngn.com>
Wed, 7 Jan 2015 22:00:48 +0000 (14:00 -0800)
committerMatt Garnes <matt@cyngn.com>
Thu, 8 Jan 2015 22:38:07 +0000 (22:38 +0000)
Change-Id: Ic542043190ccf18dff106a8b358ef94aa2ebbe96

25 files changed:
res/drawable-hdpi/ic_em_all.png [new file with mode: 0644]
res/drawable-hdpi/ic_em_document.png [new file with mode: 0644]
res/drawable-hdpi/ic_em_image.png [new file with mode: 0644]
res/drawable-hdpi/ic_em_music.png [new file with mode: 0644]
res/drawable-hdpi/ic_em_video.png [new file with mode: 0644]
res/drawable-mdpi/ic_em_all.png [new file with mode: 0644]
res/drawable-mdpi/ic_em_document.png [new file with mode: 0644]
res/drawable-mdpi/ic_em_image.png [new file with mode: 0644]
res/drawable-mdpi/ic_em_music.png [new file with mode: 0644]
res/drawable-mdpi/ic_em_video.png [new file with mode: 0644]
res/drawable-xhdpi/ic_em_all.png [new file with mode: 0644]
res/drawable-xhdpi/ic_em_document.png [new file with mode: 0644]
res/drawable-xhdpi/ic_em_image.png [new file with mode: 0644]
res/drawable-xhdpi/ic_em_music.png [new file with mode: 0644]
res/drawable-xhdpi/ic_em_video.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_em_all.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_em_document.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_em_image.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_em_music.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_em_video.png [new file with mode: 0644]
res/layout/navigation.xml
res/values/dimen.xml
res/values/strings.xml
src/com/cyanogenmod/filemanager/activities/NavigationActivity.java
src/com/cyanogenmod/filemanager/activities/SearchActivity.java

diff --git a/res/drawable-hdpi/ic_em_all.png b/res/drawable-hdpi/ic_em_all.png
new file mode 100644 (file)
index 0000000..ff4b9e6
Binary files /dev/null and b/res/drawable-hdpi/ic_em_all.png differ
diff --git a/res/drawable-hdpi/ic_em_document.png b/res/drawable-hdpi/ic_em_document.png
new file mode 100644 (file)
index 0000000..bc2f379
Binary files /dev/null and b/res/drawable-hdpi/ic_em_document.png differ
diff --git a/res/drawable-hdpi/ic_em_image.png b/res/drawable-hdpi/ic_em_image.png
new file mode 100644 (file)
index 0000000..8ed5a96
Binary files /dev/null and b/res/drawable-hdpi/ic_em_image.png differ
diff --git a/res/drawable-hdpi/ic_em_music.png b/res/drawable-hdpi/ic_em_music.png
new file mode 100644 (file)
index 0000000..433e917
Binary files /dev/null and b/res/drawable-hdpi/ic_em_music.png differ
diff --git a/res/drawable-hdpi/ic_em_video.png b/res/drawable-hdpi/ic_em_video.png
new file mode 100644 (file)
index 0000000..33e643e
Binary files /dev/null and b/res/drawable-hdpi/ic_em_video.png differ
diff --git a/res/drawable-mdpi/ic_em_all.png b/res/drawable-mdpi/ic_em_all.png
new file mode 100644 (file)
index 0000000..029b7b6
Binary files /dev/null and b/res/drawable-mdpi/ic_em_all.png differ
diff --git a/res/drawable-mdpi/ic_em_document.png b/res/drawable-mdpi/ic_em_document.png
new file mode 100644 (file)
index 0000000..7fbf597
Binary files /dev/null and b/res/drawable-mdpi/ic_em_document.png differ
diff --git a/res/drawable-mdpi/ic_em_image.png b/res/drawable-mdpi/ic_em_image.png
new file mode 100644 (file)
index 0000000..980ca1e
Binary files /dev/null and b/res/drawable-mdpi/ic_em_image.png differ
diff --git a/res/drawable-mdpi/ic_em_music.png b/res/drawable-mdpi/ic_em_music.png
new file mode 100644 (file)
index 0000000..f097e53
Binary files /dev/null and b/res/drawable-mdpi/ic_em_music.png differ
diff --git a/res/drawable-mdpi/ic_em_video.png b/res/drawable-mdpi/ic_em_video.png
new file mode 100644 (file)
index 0000000..363842b
Binary files /dev/null and b/res/drawable-mdpi/ic_em_video.png differ
diff --git a/res/drawable-xhdpi/ic_em_all.png b/res/drawable-xhdpi/ic_em_all.png
new file mode 100644 (file)
index 0000000..62fb95b
Binary files /dev/null and b/res/drawable-xhdpi/ic_em_all.png differ
diff --git a/res/drawable-xhdpi/ic_em_document.png b/res/drawable-xhdpi/ic_em_document.png
new file mode 100644 (file)
index 0000000..69f231b
Binary files /dev/null and b/res/drawable-xhdpi/ic_em_document.png differ
diff --git a/res/drawable-xhdpi/ic_em_image.png b/res/drawable-xhdpi/ic_em_image.png
new file mode 100644 (file)
index 0000000..94df1c3
Binary files /dev/null and b/res/drawable-xhdpi/ic_em_image.png differ
diff --git a/res/drawable-xhdpi/ic_em_music.png b/res/drawable-xhdpi/ic_em_music.png
new file mode 100644 (file)
index 0000000..d45579c
Binary files /dev/null and b/res/drawable-xhdpi/ic_em_music.png differ
diff --git a/res/drawable-xhdpi/ic_em_video.png b/res/drawable-xhdpi/ic_em_video.png
new file mode 100644 (file)
index 0000000..edf281d
Binary files /dev/null and b/res/drawable-xhdpi/ic_em_video.png differ
diff --git a/res/drawable-xxhdpi/ic_em_all.png b/res/drawable-xxhdpi/ic_em_all.png
new file mode 100644 (file)
index 0000000..e1b4c2e
Binary files /dev/null and b/res/drawable-xxhdpi/ic_em_all.png differ
diff --git a/res/drawable-xxhdpi/ic_em_document.png b/res/drawable-xxhdpi/ic_em_document.png
new file mode 100644 (file)
index 0000000..41f47cc
Binary files /dev/null and b/res/drawable-xxhdpi/ic_em_document.png differ
diff --git a/res/drawable-xxhdpi/ic_em_image.png b/res/drawable-xxhdpi/ic_em_image.png
new file mode 100644 (file)
index 0000000..783e35f
Binary files /dev/null and b/res/drawable-xxhdpi/ic_em_image.png differ
diff --git a/res/drawable-xxhdpi/ic_em_music.png b/res/drawable-xxhdpi/ic_em_music.png
new file mode 100644 (file)
index 0000000..79ee9bd
Binary files /dev/null and b/res/drawable-xxhdpi/ic_em_music.png differ
diff --git a/res/drawable-xxhdpi/ic_em_video.png b/res/drawable-xxhdpi/ic_em_video.png
new file mode 100644 (file)
index 0000000..e865391
Binary files /dev/null and b/res/drawable-xxhdpi/ic_em_video.png differ
index 2416282..e457d1b 100644 (file)
                     android:layout_weight="1"
                     filemanager:navigation="browsable"/>
 
+            <ListView
+                android:background="@android:color/white"
+                android:id="@+id/lv_easy_mode"
+                android:layout_width="match_parent"
+                android:layout_height="0dp"
+                android:layout_weight="1"
+                android:visibility="gone"/>
+
             <!-- SelectionBar -->
             <com.cyanogenmod.filemanager.ui.widgets.SelectionView
                     android:id="@+id/navigation_selectionbar"
@@ -72,4 +80,4 @@
     <!-- The navigation drawer -->
     <include layout="@layout/navigation_drawer" />
 
-</android.support.v4.widget.DrawerLayout>
\ No newline at end of file
+</android.support.v4.widget.DrawerLayout>
index 58307cb..f3feef5 100644 (file)
     <dimen name="legend_title_paddingLeft">3dp</dimen>
     <dimen name="legend_padding">10dp</dimen>
 
+    <dimen name="easy_mode_type_icon_wh">48dp</dimen>
+
 </resources>
index aef1e5b..fd8b1dd 100644 (file)
     <string name="welcome_title">Welcome</string>
     <!-- Welcome Dialog - Message -->
     <string name="welcome_msg">Welcome to the CyanogenMod file manager.\n\nThis app allows you to explore the file system and do operations that could break your device. To prevent damage, the app will start in a safe, low-privileged mode.\n\nYou can access the advanced, full-privileged mode via Settings. It\'s your responsibility to ensure that an operation doesn\'t break your system.\n\nThe CyanogenMod Team</string>
+
+    <string name="easy_mode_type_icon">Icon for mime type</string>
+    <string name="easy_mode_type_none">All Files</string>
+    <string name="easy_mode_type_images">Images</string>
+    <string name="easy_mode_type_videos">Videos</string>
+    <string name="easy_mode_type_music">Music</string>
+    <string name="easy_mode_type_documents">Documents</string>
+
 </resources>
index c676692..2d7473c 100644 (file)
@@ -56,6 +56,7 @@ import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.ListPopupWindow;
+import android.widget.ListView;
 import android.widget.PopupWindow;
 import android.widget.ScrollView;
 import android.widget.SearchView;
@@ -63,6 +64,7 @@ import android.widget.TextView;
 import android.widget.Toast;
 
 import android.widget.Toolbar;
+import android.widget.ArrayAdapter;
 import com.android.internal.util.XmlUtils;
 import com.cyanogenmod.filemanager.FileManagerApplication;
 import com.cyanogenmod.filemanager.R;
@@ -116,14 +118,19 @@ import com.cyanogenmod.filemanager.util.DialogHelper;
 import com.cyanogenmod.filemanager.util.ExceptionUtil;
 import com.cyanogenmod.filemanager.util.ExceptionUtil.OnRelaunchCommandResult;
 import com.cyanogenmod.filemanager.util.FileHelper;
+import com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory;
 import com.cyanogenmod.filemanager.util.StorageHelper;
 
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
+
+import static com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory.*;
 
 /**
  * The main navigation activity. This activity is the center of the application.
@@ -395,12 +402,42 @@ public class NavigationActivity extends Activity
         }
     };
 
+    static String MIME_TYPE_LOCALIZED_NAMES[];
+    /**
+     * @hide
+     */
+    static Map<MimeTypeCategory, Drawable> EASY_MODE_ICONS = new
+            HashMap<MimeTypeCategory, Drawable>();
+
     /**
      * @hide
      */
     NavigationView[] mNavigationViews;
+    /**
+     * @hide
+     */
+    ListView mEasyModeListView;
     private List<History> mHistory;
 
+    private static final List<MimeTypeCategory> EASY_MODE_LIST = new ArrayList<MimeTypeCategory>() {
+        {
+            add(NONE);
+            add(IMAGE);
+            add(VIDEO);
+            add(AUDIO);
+            add(DOCUMENT);
+        }
+    };
+
+    private ArrayAdapter<MimeTypeCategory> mEasyModeAdapter;
+    private View.OnClickListener mEasyModeItemClickListener = new View.OnClickListener() {
+        @Override
+        public void onClick(View view) {
+            Integer position = (Integer) view.getTag();
+            onClicked(position);
+        }
+    };
+
     private int mCurrentNavigationView;
 
     private ViewGroup mActionBar;
@@ -421,6 +458,7 @@ public class NavigationActivity extends Activity
     private ButtonItem mClearHistory;
 
     private List<Bookmark> mBookmarks;
+    private List<Bookmark> mSdBookmarks;
     private LinearLayout mDrawerBookmarks;
 
     private boolean mExitFlag = false;
@@ -544,6 +582,20 @@ public class NavigationActivity extends Activity
             }
         });
 
+        MIME_TYPE_LOCALIZED_NAMES = MimeTypeCategory.getFriendlyLocalizedNames(NavigationActivity
+            .this);
+
+        EASY_MODE_ICONS.put(MimeTypeCategory.NONE, getResources().getDrawable(R.drawable
+                .ic_em_all));
+        EASY_MODE_ICONS.put(MimeTypeCategory.IMAGE, getResources().getDrawable(R.drawable
+                .ic_em_image));
+        EASY_MODE_ICONS.put(MimeTypeCategory.VIDEO, getResources().getDrawable(R.drawable
+                .ic_em_video));
+        EASY_MODE_ICONS.put(MimeTypeCategory.AUDIO, getResources().getDrawable(R.drawable
+                .ic_em_music));
+        EASY_MODE_ICONS.put(MimeTypeCategory.DOCUMENT, getResources().getDrawable(R.drawable
+                .ic_em_document));
+
         //Save state
         super.onCreate(state);
     }
@@ -891,6 +943,22 @@ public class NavigationActivity extends Activity
     }
 
     /**
+     * Show the easy mode view
+     */
+    private void performShowEasyMode() {
+        mEasyModeListView.setVisibility(View.VISIBLE);
+        getCurrentNavigationView().setVisibility(View.GONE);
+    }
+
+    /**
+     * Hide the easy mode view
+     */
+    private void performHideEasyMode() {
+        mEasyModeListView.setVisibility(View.GONE);
+        getCurrentNavigationView().setVisibility(View.VISIBLE);
+    }
+
+    /**
      * Method takes a bookmark as argument and adds it to the bookmark list in
      * the drawer
      */
@@ -983,11 +1051,18 @@ public class NavigationActivity extends Activity
                 final int index = mDrawerBookmarks.indexOfChild(v);
                 final Bookmark bookmark = mBookmarks.get(index);
 
+                boolean showEasyMode = (mSdBookmarks.contains(bookmark));
+
                 // try to navigate to the bookmark path
                 try {
                     FileSystemObject fso = CommandHelper.getFileInfo(
                             getApplicationContext(), bookmark.mPath, null);
                     if (fso != null) {
+                        if (showEasyMode) {
+                            performShowEasyMode();
+                        } else {
+                            performHideEasyMode();
+                        }
                         getCurrentNavigationView().open(fso);
                         mDrawerLayout.closeDrawer(Gravity.START);
                     }
@@ -1106,7 +1181,8 @@ public class NavigationActivity extends Activity
             bookmarks.add(loadHomeBookmarks());
             bookmarks.addAll(loadFilesystemBookmarks());
         }
-        bookmarks.addAll(loadSdStorageBookmarks());
+        mSdBookmarks = loadSdStorageBookmarks();
+        bookmarks.addAll(mSdBookmarks);
         bookmarks.addAll(loadVirtualBookmarks());
         bookmarks.addAll(loadUserBookmarks());
         return bookmarks;
@@ -1320,6 +1396,56 @@ public class NavigationActivity extends Activity
         //- 0
         this.mNavigationViews[0] = (NavigationView)findViewById(R.id.navigation_view);
         this.mNavigationViews[0].setId(0);
+        this.mEasyModeListView = (ListView) findViewById(R.id.lv_easy_mode);
+        mEasyModeAdapter = new ArrayAdapter<MimeTypeCategory>(this, R.layout
+                .navigation_view_simple_item) {
+            @Override
+            public View getView(int position, View convertView, ViewGroup parent) {
+                convertView = (convertView == null) ?getLayoutInflater().inflate(R.layout
+                        .navigation_view_simple_item, null, true) : convertView;
+                MimeTypeCategory item = getItem(position);
+                String typeTitle = MIME_TYPE_LOCALIZED_NAMES[item.ordinal()];
+                TextView typeTitleTV = (TextView) convertView
+                        .findViewById(R.id.navigation_view_item_name);
+                ImageView typeIconIV = (ImageView) convertView
+                        .findViewById(R.id.navigation_view_item_icon);
+                View checkBoxView = convertView.findViewById(R.id.navigation_view_item_check);
+                checkBoxView.setVisibility(View.GONE);
+                typeTitleTV.setText(typeTitle);
+                typeIconIV.setImageDrawable(EASY_MODE_ICONS.get(item));
+                convertView.setOnClickListener(mEasyModeItemClickListener);
+                convertView.setTag(position);
+                return convertView;
+            }
+        };
+        mEasyModeAdapter.addAll(EASY_MODE_LIST);
+        mEasyModeListView.setAdapter(mEasyModeAdapter);
+    }
+
+    private void onClicked(int position) {
+        Intent intent = new Intent(this, SearchActivity.class);
+        intent.setAction(Intent.ACTION_SEARCH);
+        intent.putExtra(SearchActivity.EXTRA_SEARCH_DIRECTORY,
+                getCurrentNavigationView().getCurrentDir());
+        intent.putExtra(SearchManager.QUERY, "*"); // Use wild-card '*'
+        switch (position) {
+            case 0:
+                performHideEasyMode();
+                return;
+            case 1:
+                intent.putExtra(SearchActivity.EXTRA_SEARCH_MIMETYPE, MimeTypeCategory.IMAGE);
+                break;
+            case 2:
+                intent.putExtra(SearchActivity.EXTRA_SEARCH_MIMETYPE, MimeTypeCategory.VIDEO);
+                break;
+            case 3:
+                intent.putExtra(SearchActivity.EXTRA_SEARCH_MIMETYPE, MimeTypeCategory.AUDIO);
+                break;
+            case 4:
+                intent.putExtra(SearchActivity.EXTRA_SEARCH_MIMETYPE, MimeTypeCategory.DOCUMENT);
+                break;
+        }
+        startActivity(intent);
     }
 
     /**
@@ -1473,6 +1599,18 @@ public class NavigationActivity extends Activity
             }
         }
 
+        boolean needsEasyMode = false;
+        for (Bookmark bookmark :mSdBookmarks) {
+            if (bookmark.mPath.equalsIgnoreCase(initialDir)) {
+                needsEasyMode = true;
+                break;
+            }
+        }
+        if (needsEasyMode) {
+            performShowEasyMode();
+        } else {
+            performHideEasyMode();
+        }
         // Change the current directory to the user-defined initial directory
         navigationView.changeCurrentDir(initialDir, addToHistory);
     }
@@ -1547,6 +1685,7 @@ public class NavigationActivity extends Activity
         }
         if (keyCode == KeyEvent.KEYCODE_BACK) {
             if (checkBackAction()) {
+                performHideEasyMode();
                 return true;
             }
 
@@ -1669,6 +1808,7 @@ public class NavigationActivity extends Activity
                             if (fso != null) {
                                 //Goto to new directory
                                 getCurrentNavigationView().open(fso, searchInfo);
+                                performHideEasyMode();
                             }
                         }
                     } else if (resultCode == RESULT_CANCELED) {
index 172f6be..2e5f445 100644 (file)
@@ -86,6 +86,7 @@ import com.cyanogenmod.filemanager.util.ExceptionUtil;
 import com.cyanogenmod.filemanager.util.ExceptionUtil.OnRelaunchCommandResult;
 import com.cyanogenmod.filemanager.util.FileHelper;
 import com.cyanogenmod.filemanager.util.MimeTypeHelper;
+import com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory;
 import com.cyanogenmod.filemanager.util.StorageHelper;
 
 import java.io.FileNotFoundException;
@@ -119,6 +120,10 @@ public class SearchActivity extends Activity
      */
     public static final String EXTRA_SEARCH_RESTORE = "extra_search_restore";  //$NON-NLS-1$
 
+    /**
+     * Intent extra parameter for passing the target mime type information.
+     */
+    public static final String EXTRA_SEARCH_MIMETYPE = "extra_search_mimetype";  //$NON-NLS-1$
 
     //Minimum characters to allow query
     private static final int MIN_CHARS_SEARCH = 3;
@@ -264,9 +269,19 @@ public class SearchActivity extends Activity
         public void onConcurrentPartialResult(final Object partialResults) {
             //Saved in the global result list, for save at the end
             if (partialResults instanceof FileSystemObject) {
-                SearchActivity.this.mResultList.add((FileSystemObject)partialResults);
+                FileSystemObject fso = (FileSystemObject) partialResults;
+                if (mMimeTypeCategory == null || mMimeTypeCategory == MimeTypeHelper
+                        .getCategory(SearchActivity.this, fso)) {
+                    SearchActivity.this.mResultList.add((FileSystemObject) partialResults);
+                }
             } else {
-                SearchActivity.this.mResultList.addAll((List<FileSystemObject>)partialResults);
+                List<FileSystemObject> fsoList = (List<FileSystemObject>) partialResults;
+                for (FileSystemObject fso : fsoList) {
+                    if (mMimeTypeCategory == null || mMimeTypeCategory == MimeTypeHelper
+                            .getCategory(SearchActivity.this, fso)) {
+                        SearchActivity.this.mResultList.add(fso);
+                    }
+                }
             }
 
             //Notify progress
@@ -324,6 +339,11 @@ public class SearchActivity extends Activity
     TextView mSearchTerms;
     private View mEmptyListMsg;
 
+    /**
+     * @hide
+     */
+    Spinner mMimeTypeSpinner;
+
     private String mSearchDirectory;
     /**
      * @hide
@@ -346,6 +366,10 @@ public class SearchActivity extends Activity
      */
     boolean mChRooted;
 
+    /**
+     * @hide
+     */
+    MimeTypeCategory mMimeTypeCategory;
 
     /**
      * {@inheritDoc}
@@ -559,6 +583,7 @@ public class SearchActivity extends Activity
         this.mSearchTerms = (TextView)findViewById(R.id.search_status_query_terms);
         this.mSearchTerms.setText(
                 Html.fromHtml(getString(R.string.search_terms, ""))); //$NON-NLS-1$
+        this.mMimeTypeSpinner = (Spinner) findViewById(R.id.search_status_type_spinner);
     }
 
     /**
@@ -586,6 +611,8 @@ public class SearchActivity extends Activity
      * Method that initializes the titlebar of the activity.
      */
     private void initSearch() {
+        mMimeTypeCategory = (MimeTypeCategory) getIntent()
+                .getSerializableExtra(EXTRA_SEARCH_MIMETYPE);
         //Stop any pending action
         try {
             if (SearchActivity.this.mDrawingSearchResultTask != null
@@ -633,15 +660,22 @@ public class SearchActivity extends Activity
         this.mQuery = new Query().fillSlots(filteredUserQueries);
         List<String> queries = this.mQuery.getQueries();
 
-        //Check if some queries has lower than allowed, in this case
-        //request the user for stop the search
         boolean ask = false;
-        int cc = queries.size();
-        for (int i = 0; i < cc; i++) {
-            if (queries.get(i).trim().length() < MIN_CHARS_SEARCH) {
-                ask = true;
-                break;
+        // Mime type search uses '*' which needs to bypass
+        // length check
+        if (mMimeTypeCategory == null) {
+            //Check if some queries has lower than allowed, in this case
+            //request the user for stop the search
+            int cc = queries.size();
+            for (int i = 0; i < cc; i++) {
+                if (queries.get(i).trim().length() < MIN_CHARS_SEARCH) {
+                    ask = true;
+                    break;
+                }
             }
+            mMimeTypeSpinner.setVisibility(View.VISIBLE);
+        } else {
+            mMimeTypeSpinner.setVisibility(View.INVISIBLE);
         }
         if (ask) {
             askUserBeforeSearch(voiceQuery, this.mQuery, this.mSearchDirectory);
@@ -723,8 +757,15 @@ public class SearchActivity extends Activity
         this.mSearchListView.setAdapter(adapter);
 
         //Set terms
-        this.mSearchTerms.setText(
-                Html.fromHtml(getString(R.string.search_terms, query.getTerms())));
+        if (mMimeTypeCategory == null) {
+            this.mSearchTerms.setText(
+                    Html.fromHtml(getString(R.string.search_terms, query.getTerms())));
+        } else {
+             this.mSearchTerms.setText(
+                     Html.fromHtml(getString(R.string.search_terms,
+                             NavigationActivity.MIME_TYPE_LOCALIZED_NAMES[mMimeTypeCategory
+                                     .ordinal()])));
+        }
 
         //Now, do the search in background
         this.mSearchListView.post(new Runnable() {