diff options
author | Richard MacGregor <rmacgregor@cyngn.com> | 2015-08-13 17:09:06 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2016-11-02 22:09:23 -0700 |
commit | 85b6e6d9452a95a2d9f9ae73f9e9a8ad176a62a7 (patch) | |
tree | 2762b2b4354dfebcde6830542cc8715e42ce25a7 | |
parent | e0f0adeb9e438eb63561fd5e1e294a6021e57886 (diff) | |
download | android_packages_apps_CMFileManager-85b6e6d9452a95a2d9f9ae73f9e9a8ad176a62a7.tar.gz android_packages_apps_CMFileManager-85b6e6d9452a95a2d9f9ae73f9e9a8ad176a62a7.tar.bz2 android_packages_apps_CMFileManager-85b6e6d9452a95a2d9f9ae73f9e9a8ad176a62a7.zip |
Picker Updates
- Roots directory no longer uses navigation view
- Roots directory uses different item layouts than navigation
- Dialog header for roots view now correct
- Dialog header now changes layout for roots vs browsing lists
- Dialog header now reflects volume color
- ***NEW: CREATE NEW FOLDERS RIGHT FROM THE PICKER***
CLOUD-180
Change-Id: I2789d11f2315c441b02f4b38218e31d7eacb6efa
18 files changed, 694 insertions, 153 deletions
diff --git a/res/drawable/ic_folder_new.xml b/res/drawable/ic_folder_new.xml new file mode 100644 index 00000000..6caaec4c --- /dev/null +++ b/res/drawable/ic_folder_new.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (c) 2015 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + + <path + android:fillColor="#FFFFFF" + android:pathData="M20,6h-8l-2-2H4C2.9,4,2,4.9,2,6l0,12c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2V8C22,6.9,21.1,6,20,6z +M19,14h-3 v3h-2v-3h-3v-2h3V9h2v3h3V14z" /> +</vector>
\ No newline at end of file diff --git a/res/layout/navigation_view_details.xml b/res/layout/navigation_view.xml index cf137c3d..cf137c3d 100644 --- a/res/layout/navigation_view_details.xml +++ b/res/layout/navigation_view.xml diff --git a/res/layout/navigation_view_simple_item.xml b/res/layout/navigation_view_simple_item.xml index f53dc1e6..9b3797c9 100644 --- a/res/layout/navigation_view_simple_item.xml +++ b/res/layout/navigation_view_simple_item.xml @@ -17,14 +17,14 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/navigation_view_details_item" android:layout_width="match_parent" - android:layout_height="@dimen/default_row_height" + android:layout_height="@dimen/navigation_view_simple_item_height" android:orientation="horizontal" android:background="@drawable/navigation_item_background"> <com.cyanogenmod.filemanager.ui.widgets.FixedSizeImageView android:id="@+id/navigation_view_item_icon" - android:layout_marginStart="@dimen/easy_mode_type_icon_margin_lr" - android:layout_marginEnd="@dimen/easy_mode_type_icon_margin_lr" + android:layout_marginStart="@dimen/navigation_view_simple_item_icon_margin" + android:layout_marginEnd="@dimen/navigation_view_simple_item_icon_margin" android:layout_width="@dimen/circle_icon_wh" android:layout_height="@dimen/circle_icon_wh" android:layout_gravity="center_vertical" @@ -37,18 +37,9 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" - android:layout_marginStart="@dimen/default_margin" - android:layout_marginTop="@dimen/extra_margin" android:gravity="start|center_vertical" android:singleLine="true" android:ellipsize="middle" android:textAppearance="@style/primary_text_appearance" /> - <com.cyanogenmod.filemanager.ui.widgets.TransparentNonFocusableButtonItem - android:id="@+id/navigation_view_item_info" - android:layout_width="@dimen/item_menu_row_button_width" - android:layout_height="match_parent" - android:contentDescription="@null" - android:src="@drawable/ic_details" /> - </LinearLayout> diff --git a/res/layout/navigation_view_simple_item_small.xml b/res/layout/navigation_view_simple_item_small.xml new file mode 100644 index 00000000..4a5403c4 --- /dev/null +++ b/res/layout/navigation_view_simple_item_small.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2015 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/navigation_view_details_item" + android:layout_width="match_parent" + android:layout_height="@dimen/navigation_view_simple_item_small_height" + android:orientation="horizontal" + android:background="@drawable/navigation_item_background"> + + <com.cyanogenmod.filemanager.ui.widgets.FixedSizeImageView + android:id="@+id/navigation_view_item_icon" + android:layout_marginStart="@dimen/navigation_view_simple_item_small_icon_margin" + android:layout_marginEnd="@dimen/navigation_view_simple_item_small_icon_margin" + android:layout_width="@dimen/circle_icon_wh" + android:layout_height="@dimen/circle_icon_wh" + android:layout_gravity="center_vertical" + android:scaleType="center" + android:contentDescription="@null" + android:src="@null" /> + + <TextView + android:id="@+id/navigation_view_item_name" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:gravity="start|center_vertical" + android:singleLine="true" + android:ellipsize="middle" + android:textAppearance="@style/primary_text_appearance" /> + +</LinearLayout> diff --git a/res/layout/picker.xml b/res/layout/picker.xml index 65a21acc..72053ca1 100644 --- a/res/layout/picker.xml +++ b/res/layout/picker.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2012 The CyanogenMod Project +<!-- Copyright (C) 2015 The CyanogenMod Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,32 +15,40 @@ --> <LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:filemanager="http://schemas.android.com/apk/res/com.cyanogenmod.filemanager" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@color/default_background" - android:orientation="vertical"> - - <!-- Breadcrumb --> - <com.cyanogenmod.filemanager.ui.widgets.DialogBreadcrumbView - android:id="@+id/breadcrumb_view" + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:filemanager="http://schemas.android.com/apk/res/com.cyanogenmod.filemanager" android:layout_width="match_parent" - android:layout_height="@dimen/default_row_height" - android:layout_marginStart="@dimen/extra_large_margin" - android:layout_marginEnd="@dimen/extra_large_margin" - android:visibility="gone"/> - - <include layout="@layout/vertical_divider" /> - - <!-- Picker Navigation View --> - <com.cyanogenmod.filemanager.ui.widgets.NavigationView - android:id="@+id/navigation_view" - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="1" - android:layout_marginStart="@dimen/extra_margin" - android:layout_marginEnd="@dimen/extra_margin" - filemanager:navigation="pickable" /> + android:layout_height="match_parent" + android:background="@color/default_background" + android:orientation="vertical"> + + <com.cyanogenmod.filemanager.ui.widgets.PickerHeaderView + android:id="@+id/picker_header" + android:layout_width="match_parent" + android:layout_height="@dimen/picker_header_height" + android:background="@color/picker_header_color" /> + + <com.cyanogenmod.filemanager.ui.widgets.ToggleSwipeViewPager + android:id="@+id/picker_viewpager" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/default_background"> + + <!-- Roots View --> + <ListView + android:id="@+id/roots_listview" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/default_background" + android:divider="@null" /> + + <!-- Picker Navigation View --> + <com.cyanogenmod.filemanager.ui.widgets.NavigationView + android:id="@+id/navigation_view" + android:layout_width="match_parent" + android:layout_height="0dp" + filemanager:navigation="pickable" /> + + </com.cyanogenmod.filemanager.ui.widgets.ToggleSwipeViewPager> </LinearLayout> diff --git a/res/layout/picker_header_browse.xml b/res/layout/picker_header_browse.xml new file mode 100644 index 00000000..381c7248 --- /dev/null +++ b/res/layout/picker_header_browse.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2015 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/picker_header_scene_container" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="horizontal"> + + <LinearLayout + android:orientation="vertical" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/picker_default_margin" + android:layout_alignParentLeft="true" + android:layout_centerVertical="true" + android:layout_toLeftOf="@+id/header_new_folder" > + + <TextView + android:id="@+id/header_text_action" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="start|center_vertical" + android:singleLine="true" + android:fontFamily="sans-serif" + android:textColor="@color/white_54" + android:textSize="14sp" + android:text="@null" /> + + <TextView + android:id="@+id/header_text_location" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="start|center_vertical" + android:layout_below="@id/header_text_action" + android:singleLine="true" + android:ellipsize="end" + android:fontFamily="sans-serif-medium" + android:textColor="@color/white_87" + android:textSize="16sp" + android:text="@null" /> + + </LinearLayout> + + <ImageView android:id="@+id/header_new_folder" + android:layout_width="@dimen/small_icon_size" + android:layout_height="@dimen/small_icon_size" + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:layout_margin="@dimen/picker_default_margin" + android:src="@drawable/ic_folder_new" /> + +</RelativeLayout>
\ No newline at end of file diff --git a/res/layout/picker_header_root.xml b/res/layout/picker_header_root.xml new file mode 100644 index 00000000..29217254 --- /dev/null +++ b/res/layout/picker_header_root.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2015 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/picker_header_scene_container" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="horizontal" > + + <LinearLayout + android:orientation="vertical" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/picker_default_margin" + android:layout_alignParentLeft="true" + android:layout_centerVertical="true" > + + <TextView + android:id="@+id/header_text_action" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="start|center_vertical" + android:singleLine="true" + android:fontFamily="sans-serif-medium" + android:textColor="@color/white_87" + android:textSize="20sp" + android:text="@null" /> + + </LinearLayout> + +</RelativeLayout>
\ No newline at end of file diff --git a/res/layout/navigation_view_simple.xml b/res/layout/picker_header_view.xml index cf137c3d..1730ff0c 100644 --- a/res/layout/navigation_view_simple.xml +++ b/res/layout/picker_header_view.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2012 The CyanogenMod Project +<!-- Copyright (C) 2015 The CyanogenMod Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,10 +14,19 @@ limitations under the License. --> -<com.cyanogenmod.filemanager.ui.widgets.FlingerListView - xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/navigation_view_layout" +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/navigation_view_item_default_fill" - android:divider="@null" /> + android:orientation="vertical" > + + <FrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/picker_header_title_scene_root" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <include layout="@layout/picker_header_root" /> + + </FrameLayout> + +</RelativeLayout>
\ No newline at end of file diff --git a/res/values/colors.xml b/res/values/colors.xml index f85ad947..fc6d8bf6 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -62,11 +62,15 @@ <color name="default_background_disabled">#f2f2f2</color> <color name="white">#ffffff</color> - <color name="off_white">#efefef</color> + <color name="white_54">#8bffffff</color> + <color name="white_87">#deffffff</color> <!-- A black color with some transparency --> <color name="black_transparent">#8a000000</color> + <color name="black_87">#de000000</color> + <color name="black_60">#96000000</color> + <color name="black_54">#8b000000</color> <color name="black_46">#75000000</color> <color name="black_26">#42000000</color> <color name="black_11">#1C000000</color> @@ -86,6 +90,9 @@ <color name="action_bar_title_text_color">#deffffff</color> <color name="action_bar_subtitle_text_color">#8bffffff</color> + <!-- Picker header color --> + <color name="picker_header_color">#607d8b</color> + <!-- Breadcrumb text color --> <color name="breadcrumb_text_color">#deffffff</color> <!-- Navigation Drawer Background Color --> diff --git a/res/values/dimen.xml b/res/values/dimen.xml index 67278575..eecd314a 100644 --- a/res/values/dimen.xml +++ b/res/values/dimen.xml @@ -19,9 +19,9 @@ <!-- The primary text size --> <dimen name="title_text_size">16sp</dimen> <!-- The primary text size --> - <dimen name="primary_text_size">14sp</dimen> + <dimen name="primary_text_size">16sp</dimen> <!-- The secondary text size --> - <dimen name="secondary_text_size">12sp</dimen> + <dimen name="secondary_text_size">14sp</dimen> <!-- The dialog_title text size --> <dimen name="dialog_title_text_size">16sp</dimen> <!-- The note text size --> @@ -75,11 +75,23 @@ <!-- The default vertical grid spacing --> <dimen name="default_vertical_grid_spacing">8dp</dimen> - <!-- The navigation view details item row height --> + <!-- The navigation view details item icon margin --> <dimen name="navigation_view_details_item_icon_margin">16dp</dimen> <!-- The navigation view details item row height --> <dimen name="navigation_view_details_item_height">72dp</dimen> + <!-- The navigation view simple item icon margint --> + <dimen name="navigation_view_simple_item_icon_margin">24dp</dimen> + <!-- The navigation view simple view item height --> + <dimen name="navigation_view_simple_item_height">72dp</dimen> + <!-- The navigation view simple item small icon margint --> + <dimen name="navigation_view_simple_item_small_icon_margin">16dp</dimen> + <!-- The navigation view simple view (small) item height --> + <dimen name="navigation_view_simple_item_small_height">56dp</dimen> + <!-- The navigation view simple view (small) icon size --> + <dimen name="navigation_view_simple_item_small_icon_size">24dp</dimen> + <dimen name="small_icon_size">24dp</dimen> + <!-- The navigation grid width --> <dimen name="navigation_grid_width">85dp</dimen> <!-- The navigation grid height --> @@ -164,6 +176,11 @@ <!-- Drawer header background (image) height --> <dimen name="drawer_header_backgound_height">172dp</dimen> + <!-- Picker header height --> + <dimen name="picker_header_height">72dp</dimen> + <!-- Picker left margin --> + <dimen name="picker_default_margin">24dp</dimen> + <!-- usage graph stuff --> <dimen name="legend_title_textSize">9sp</dimen> <dimen name="legend_title_paddingStart">3dp</dimen> diff --git a/res/values/strings.xml b/res/values/strings.xml index f7eee320..67bd2a75 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -355,8 +355,8 @@ <!-- Picker Activity --> <string name="picker" translatable="false">@string/app_name</string> <!-- Picker Activity - Dialog title --> - <string name="picker_title">Pick a file</string> - <string name="directory_picker_title">Pick a directory</string> + <string name="picker_title">Open from</string> + <string name="directory_picker_title">Open from</string> <string name="picker_copy_title">Copy to</string> <string name="picker_move_title">Move to</string> @@ -929,7 +929,7 @@ <string name="snackbar_unable_to_complete">Unable to complete action</string> <string name="snackbar_retry">RETRY</string> <string name="snackbar_upgrade">UPGRADE</string> - + <!-- File System info --> <string name="file_system_info_unavailable">Unable to fetch file system info for this path</string> diff --git a/res/values/styles.xml b/res/values/styles.xml index 5260addc..70b75bbd 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -165,8 +165,8 @@ <!-- The text appearance for principal information (text that need to be highlighted) --> <style name="primary_text_appearance"> <item name="android:textSize">@dimen/primary_text_size</item> - <item name="android:textColor">@color/black_transparent</item> - <item name="android:textStyle">bold</item> + <item name="android:textColor">@color/black_87</item> + <item name="android:fontFamily">sans-serif</item> </style> <!-- The text appearance for principal information (important but not highlight) --> @@ -177,8 +177,8 @@ <!-- The text appearance for secondary information (text with a lower importance) --> <style name="secondary_text_appearance"> <item name="android:textSize">@dimen/secondary_text_size</item> - <item name="android:textColor">@color/black_transparent</item> - <item name="android:textStyle">normal</item> + <item name="android:textColor">@color/black_54</item> + <item name="android:fontFamily">sans-serif</item> </style> <!-- The text appearance for hexeditor --> diff --git a/src/com/cyanogenmod/filemanager/activities/PickerActivity.java b/src/com/cyanogenmod/filemanager/activities/PickerActivity.java index 5dcdfae1..c28544d1 100644 --- a/src/com/cyanogenmod/filemanager/activities/PickerActivity.java +++ b/src/com/cyanogenmod/filemanager/activities/PickerActivity.java @@ -19,48 +19,51 @@ package com.cyanogenmod.filemanager.activities; import android.app.Activity; import android.app.AlertDialog; import android.content.ActivityNotFoundException; -import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnDismissListener; import android.content.Intent; -import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; -import android.os.Handler; import android.os.storage.StorageVolume; import android.support.v4.content.FileProvider; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.FrameLayout; import android.widget.ListPopupWindow; +import android.widget.ListView; import android.widget.Toast; import com.cyanogenmod.filemanager.R; import com.cyanogenmod.filemanager.adapters.CheckableListAdapter; import com.cyanogenmod.filemanager.adapters.CheckableListAdapter.CheckableItem; +import com.cyanogenmod.filemanager.adapters.FileSystemObjectAdapter; +import com.cyanogenmod.filemanager.adapters.PickerAdapter; import com.cyanogenmod.filemanager.console.ConsoleBuilder; +import com.cyanogenmod.filemanager.listeners.OnRequestRefreshListener; import com.cyanogenmod.filemanager.model.FileSystemObject; +import com.cyanogenmod.filemanager.model.RootDirectory; import com.cyanogenmod.filemanager.preferences.DisplayRestrictions; -import com.cyanogenmod.filemanager.preferences.FileManagerSettings; -import com.cyanogenmod.filemanager.preferences.Preferences; import com.cyanogenmod.filemanager.ui.ThemeManager; import com.cyanogenmod.filemanager.ui.ThemeManager.Theme; -import com.cyanogenmod.filemanager.ui.widgets.Breadcrumb; -import com.cyanogenmod.filemanager.ui.widgets.ButtonItem; +import com.cyanogenmod.filemanager.ui.dialogs.ActionsDialog; import com.cyanogenmod.filemanager.ui.widgets.NavigationView; import com.cyanogenmod.filemanager.ui.widgets.NavigationView.OnDirectoryChangedListener; import com.cyanogenmod.filemanager.ui.widgets.NavigationView.OnFilePickedListener; +import com.cyanogenmod.filemanager.ui.widgets.PickerHeaderView; +import com.cyanogenmod.filemanager.ui.widgets.ToggleSwipeViewPager; import com.cyanogenmod.filemanager.util.DialogHelper; import com.cyanogenmod.filemanager.util.ExceptionUtil; import com.cyanogenmod.filemanager.util.FileHelper; @@ -69,17 +72,20 @@ import com.cyanogenmod.filemanager.util.MimeTypeHelper; import com.cyanogenmod.filemanager.util.StorageHelper; import java.io.File; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static com.cyanogenmod.filemanager.adapters.PickerAdapter.ListType; + /** * The activity for allow to use a {@link NavigationView} like, to pick a file from other * application. */ -public class PickerActivity extends Activity - implements OnCancelListener, OnDismissListener, OnFilePickedListener, OnDirectoryChangedListener { +public class PickerActivity extends Activity implements OnCancelListener, OnDismissListener, + OnFilePickedListener, OnDirectoryChangedListener, OnRequestRefreshListener { private static final String TAG = "PickerActivity"; //$NON-NLS-1$ @@ -137,12 +143,19 @@ public class PickerActivity extends Activity FileSystemObject mFso; // The picked item FileSystemObject mCurrentDirectory; private AlertDialog mDialog; - private Handler mHandler; /** * @hide */ NavigationView mNavigationView; + /** + * @hide + */ + ListView mRootListView; private View mRootView; + private PickerHeaderView mHeaderView; + private ToggleSwipeViewPager mViewPager; + + private int mPrimaryColor; /** * {@inheritDoc} @@ -298,6 +311,8 @@ public class PickerActivity extends Activity return; } + this.mPrimaryColor = getResources().getColor(R.color.picker_header_color); + // Create the root file this.mRootView = getLayoutInflater().inflate(R.layout.picker, null, false); this.mRootView.post(new Runnable() { @@ -307,21 +322,35 @@ public class PickerActivity extends Activity } }); - // Breadcrumb - Breadcrumb breadcrumb = (Breadcrumb)this.mRootView.findViewById(R.id.breadcrumb_view); - // Set the free disk space warning level of the breadcrumb widget - String fds = Preferences.getSharedPreferences().getString( - FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getId(), - (String)FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getDefaultValue()); - breadcrumb.setFreeDiskSpaceWarningLevel(Integer.parseInt(fds)); + // Get the viewPager + this.mViewPager = (ToggleSwipeViewPager)this.mRootView.findViewById(R.id.picker_viewpager); + this.mViewPager.setAdapter(new PickerAdapter()); + this.mViewPager.setSwipeEnabled(false); + + // Roots listview + mRootListView = (ListView)this.mRootView.findViewById(R.id.roots_listview); + mRootListView.setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(final AdapterView<?> parent, View view, final int position, + long id) { + // Navigate to new directory + final FileSystemObject fso = + ((FileSystemObjectAdapter)parent.getAdapter()).getItem(position); + final RootDirectory rootDir = (RootDirectory)fso; + PickerActivity.this.mNavigationView.setPrimaryColor(rootDir.getPrimaryColor()); + PickerActivity.this.mNavigationView.changeCurrentDir(rootDir.getRootPath()); + PickerActivity.this.mPrimaryColor = rootDir.getPrimaryColor(); + } + }); + GetStorageVolumesTask task = + new GetStorageVolumesTask(this.getApplicationContext(), mRootListView); + task.execute(); // Navigation view - this.mNavigationView = - (NavigationView)this.mRootView.findViewById(R.id.navigation_view); + this.mNavigationView = (NavigationView)this.mRootView.findViewById(R.id.navigation_view); this.mNavigationView.setRestrictions(restrictions); this.mNavigationView.setOnFilePickedListener(this); this.mNavigationView.setOnDirectoryChangedListener(this); - this.mNavigationView.setBreadcrumb(breadcrumb); // Get dialog title and positive button, default to picker_title and select respectively ACTION_MODE pickerMode = ACTION_MODE.SELECT; @@ -346,10 +375,23 @@ public class PickerActivity extends Activity break; } - // Create the dialog - this.mDialog = DialogHelper.createDialog( - this, R.mipmap.ic_launcher_filemanager, titleId, this.mRootView); + mHeaderView = + (PickerHeaderView) this.mRootView.findViewById(R.id.picker_header); + mHeaderView.setActionText(titleId); + mHeaderView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + // Create new directory + ActionsDialog.showInputNameDialog(PickerActivity.this, + getString(R.string.actions_menu_new_directory), + R.id.mnu_actions_new_directory, mNavigationView.getFiles(), + mNavigationView, PickerActivity.this); + } + }); + // Create the dialog + this.mDialog = DialogHelper.createDialog(this, 0, null, this.mRootView); + this.mDialog.setCustomTitle(null); this.mDialog.setButton( DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), @@ -376,27 +418,17 @@ public class PickerActivity extends Activity this.mDialog.setOnDismissListener(this); DialogHelper.delegateDialogShow(this, this.mDialog); - // Set content description of storage volume button - ButtonItem fs = (ButtonItem)this.mRootView.findViewById(R.id.ab_filesystem_info); - fs.setContentDescription(getString(R.string.actionbar_button_storage_cd)); - final File initialDir = getInitialDirectoryFromIntent(getIntent()); final String rootDirectory; - if (initialDir != null) { - rootDirectory = initialDir.getAbsolutePath(); + if (initialDir == null) { + mViewPager.setCurrentItem(ListType.ROOTS_LISTVIEW.ordinal(), false); } else { - rootDirectory = FileHelper.ROOTS_LIST; - } + rootDirectory = initialDir.getAbsolutePath(); - this.mHandler = new Handler(); - this.mHandler.post(new Runnable() { - @Override - public void run() { - // Navigate to. The navigation view will redirect to the appropriate directory - PickerActivity.this.mNavigationView.changeCurrentDir(rootDirectory); - } - }); + // Navigate to. The navigation view will redirect to the appropriate directory + PickerActivity.this.mNavigationView.changeCurrentDir(rootDirectory); + } } @@ -626,19 +658,19 @@ public class PickerActivity extends Activity */ @Override public void onDirectoryChanged(FileSystemObject item) { - int visibility = View.VISIBLE; this.mCurrentDirectory = item; if (TextUtils.equals(mCurrentDirectory.getName(), FileHelper.ROOTS_LIST) && mCurrentDirectory.getParent() == null) { mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); - visibility = View.GONE; + // show roots list + changeListView(ListType.ROOTS_LISTVIEW); + mPrimaryColor = getResources().getColor(R.color.picker_header_color); } else { + changeListView(ListType.NAVIGATION_VIEW); mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true); } - View breadView = mRootView.findViewById(R.id.breadcrumb_view); - if (breadView != null && breadView.getVisibility() != visibility) { - breadView.setVisibility(visibility); - } + mHeaderView.setDirectory(mCurrentDirectory.getName()); + mHeaderView.setPrimaryColor(mPrimaryColor); } /** @@ -669,6 +701,12 @@ public class PickerActivity extends Activity finish(); } + private void changeListView(ListType type) { + if (mViewPager.getCurrentItem() != type.ordinal()) { + mViewPager.setCurrentItem(type.ordinal(), false); + } + } + /** * Method that shows a popup with the storage volumes * @@ -710,10 +748,72 @@ public class PickerActivity extends Activity popup.dismiss(); if (volumes != null) { PickerActivity.this. - mNavigationView.changeCurrentDir(volumes[position].getPath()); + mNavigationView.changeCurrentDir(volumes[position].getPath()); } } }); popup.show(); } + + private static class GetStorageVolumesTask + extends AsyncTask<Void, String, List<FileSystemObject>> { + private Context mContext; + private WeakReference<ListView> mView; + + public GetStorageVolumesTask(final Context context, final ListView view) { + mContext = context.getApplicationContext(); + mView = new WeakReference<ListView>(view); + } + + @Override + protected List<FileSystemObject> doInBackground(Void... params) { + List<FileSystemObject> volumes = + StorageHelper.getStorageVolumesFileSystemObjectList(mContext); + return volumes; + } + + @Override + protected void onPostExecute(List<FileSystemObject> volumes) { + FileSystemObjectAdapter fsoAdapter = new FileSystemObjectAdapter(mContext, volumes, + R.layout.navigation_view_simple_item, true); + if (mView != null && mView.get() != null) { + mView.get().setAdapter(fsoAdapter); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void onRequestRefresh(Object o, boolean clearSelection) { + if (o instanceof FileSystemObject) { + // Refresh only the item + mNavigationView.refresh((FileSystemObject) o); + } else if (o == null) { + // Refresh all + mNavigationView.refresh(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void onRequestRemove(Object o, boolean clearSelection) { + // Ignored + } + + /** + * {@inheritDoc} + */ + @Override + public void onNavigateTo(Object o) { + // Ignored + } + + @Override + public void onCancel(){ + // nop + } } diff --git a/src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java b/src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java index e655fce1..f1311906 100644 --- a/src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java +++ b/src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java @@ -227,8 +227,12 @@ public class FileSystemObjectAdapter viewHolder.mTvSummary = (TextView)v.findViewById(RESOURCE_ITEM_SUMMARY); viewHolder.mBtInfo = (ImageButton) v.findViewById(RESOURCE_ITEM_INFO); if (!mPickable) { - viewHolder.mIvIcon.setOnClickListener(this); - viewHolder.mBtInfo.setOnClickListener(this); + if (viewHolder.mIvIcon != null) { + viewHolder.mIvIcon.setOnClickListener(this); + } + if (viewHolder.mBtInfo != null) { + viewHolder.mBtInfo.setOnClickListener(this); + } } v.setTag(viewHolder); } @@ -513,9 +517,9 @@ public class FileSystemObjectAdapter mRequests.put(view, task); task.execute(); } else if (FileHelper.isDirectory(fso)) { - setFolderIcon(view, mimeTypeIconId); + setFolderIcon(view, mimeTypeIconId, !mPickable); } else { - setFileIcon(view, mimeTypeIconId, fso); + setFileIcon(view, mimeTypeIconId, fso, !mPickable); } } @@ -527,18 +531,22 @@ public class FileSystemObjectAdapter } // TODO: change folder colors depending on current volume (root, local, sdcard, usb, etc.) - private void setFolderIcon(ImageView view, int iconId) { - float opacity = mRes.getFloat(R.float_type.navigation_view_icon_circle_opacity); - int transparentColor = Color.argb( - Math.round(((float) 0xFF) * opacity), - Color.red(mPrimaryColor), - Color.green(mPrimaryColor), - Color.blue(mPrimaryColor)); + private void setFolderIcon(ImageView view, int iconId, boolean colorCircle) { + int transparentColor = mRes.getColor(R.color.white); + if (colorCircle) { + float opacity = mRes.getFloat(R.float_type.navigation_view_icon_circle_opacity); + transparentColor = Color.argb( + Math.round(((float) 0xFF) * opacity), + Color.red(mPrimaryColor), + Color.green(mPrimaryColor), + Color.blue(mPrimaryColor)); + } setIcon(mRes, view, mRes.getDrawable(iconId), mPrimaryColor, R.drawable.ic_icon_background, transparentColor); } - private void setFileIcon(ImageView view, final int iconId, FileSystemObject fso) { + private void setFileIcon(ImageView view, final int iconId, FileSystemObject fso, + final boolean colorCircle) { // Use iconholder to check for thumbnail final ICallback callback = new ICallback() { @@ -551,11 +559,16 @@ public class FileSystemObjectAdapter public void onLoaded(ImageView imageView, Drawable icon) { if (icon == null) { // Icon holder didn't have anything at the moment, set default. + Drawable iconDrawable = mRes.getDrawable(iconId, null); + int backgroundId = R.drawable.ic_icon_background; int colorId = MimeTypeHelper.getIconColorFromIconId(getContext(), iconId); - setIcon(mRes, imageView, mRes.getDrawable(iconId, null), - mRes.getColor(R.color.navigation_view_icon_unselected), - R.drawable.ic_icon_background, - mRes.getColor(colorId)); + int color = mRes.getColor(colorId); + int secondaryColor = mRes.getColor(R.color.navigation_view_icon_unselected); + if (colorCircle) { + setIcon(mRes, imageView, iconDrawable, secondaryColor, backgroundId, color); + } else { + setIcon(mRes, imageView, iconDrawable, color, backgroundId, secondaryColor); + } } else { // Thumbnail present, set the background to rectangle to match better. setIconThumbnail(mRes, imageView, icon); diff --git a/src/com/cyanogenmod/filemanager/adapters/PickerAdapter.java b/src/com/cyanogenmod/filemanager/adapters/PickerAdapter.java new file mode 100644 index 00000000..2b402548 --- /dev/null +++ b/src/com/cyanogenmod/filemanager/adapters/PickerAdapter.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cyanogenmod.filemanager.adapters; + +import android.support.v4.view.PagerAdapter; +import android.view.View; +import com.cyanogenmod.filemanager.R; +import android.view.ViewGroup; + +public class PickerAdapter extends PagerAdapter { + + public static enum ListType { + ROOTS_LISTVIEW, + NAVIGATION_VIEW, + } + + public Object instantiateItem(ViewGroup collection, int position) { + + int resId = 0; + ListType type = ListType.values()[position]; + switch (type) { + case ROOTS_LISTVIEW: + resId = R.id.roots_listview; + break; + case NAVIGATION_VIEW: + resId = R.id.navigation_view; + break; + } + return collection.findViewById(resId); + } + + @Override + public int getCount() { + return ListType.values().length; + } + + @Override + public boolean isViewFromObject(View view, Object o) { + return view == ((View) o); + } +} diff --git a/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java b/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java index e84c2c52..22b709cf 100644 --- a/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java +++ b/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java @@ -49,7 +49,6 @@ import com.cyanogenmod.filemanager.listeners.OnSelectionListener; import com.cyanogenmod.filemanager.model.Directory; import com.cyanogenmod.filemanager.model.FileSystemObject; import com.cyanogenmod.filemanager.model.ParentDirectory; -import com.cyanogenmod.filemanager.model.RootDirectory; import com.cyanogenmod.filemanager.model.Symlink; import com.cyanogenmod.filemanager.mstaru.IMostStarUsedFilesManager; import com.cyanogenmod.filemanager.parcelables.NavigationViewInfoParcelable; @@ -239,15 +238,9 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe */ @Override protected List<FileSystemObject> doInBackground(String... params) { - - if (TextUtils.equals(params[0], FileHelper.ROOTS_LIST)) { - // If new directory is "Roots list" don't check ChRooted evnironment - mNewDirChecked = params[0]; - } else { - // Check navigation security (don't allow to go outside the ChRooted environment if one - // is created) - mNewDirChecked = checkChRootedNavigation(params[0]); - } + // Check navigation security (don't allow to go outside the ChRooted environment if one + // is created) + mNewDirChecked = checkChRootedNavigation(params[0]); mHasChanged = !(NavigationView.this.mPreviousDir != null && NavigationView.this.mPreviousDir.compareTo(mNewDirChecked) == 0); @@ -263,17 +256,11 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe } } - List<FileSystemObject> files; - if (TextUtils.equals(mNewDirChecked, FileHelper.ROOTS_LIST)) { - files = StorageHelper.getStorageVolumesFileSystemObjectList(getContext()); - } else { - //Get the files, resolve links and apply configuration - //(sort, hidden, ...) - files = NavigationView.this.mFiles; - if (!mUseCurrent) { - files = CommandHelper.listFiles(getContext(), mNewDirChecked, null); - mNewDirFSO = CommandHelper.getFileInfo(getContext(), mNewDirChecked, null); - } + List<FileSystemObject> files = null; + files = NavigationView.this.mFiles; + if (!mUseCurrent) { + files = CommandHelper.listFiles(getContext(), mNewDirChecked, null); + mNewDirFSO = CommandHelper.getFileInfo(getContext(), mNewDirChecked, null); } //Apply user preferences @@ -573,14 +560,11 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe private IMostStarUsedFilesManager mMStarUManager; - //The layout for icons mode - private static final int RESOURCE_MODE_ICONS_LAYOUT = R.layout.navigation_view_icons; - private static final int RESOURCE_MODE_ICONS_ITEM = R.layout.navigation_view_icons_item; //The layout for simple mode - private static final int RESOURCE_MODE_SIMPLE_LAYOUT = R.layout.navigation_view_simple; - private static final int RESOURCE_MODE_SIMPLE_ITEM = R.layout.navigation_view_simple_item; + private static final int RESOURCE_MODE_LAYOUT = R.layout.navigation_view; + private static final int RESOURCE_MODE_SIMPLE_ITEM_SMALL = + R.layout.navigation_view_simple_item_small; //The layout for details mode - private static final int RESOURCE_MODE_DETAILS_LAYOUT = R.layout.navigation_view_details; private static final int RESOURCE_MODE_DETAILS_ITEM = R.layout.navigation_view_details_item; //The current layout identifier (is shared for all the mode layout) @@ -994,12 +978,12 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe } else */if (newMode.compareTo(NavigationLayoutMode.SIMPLE) == 0) { newView = (AdapterView<ListAdapter>)LayoutInflater.from(getContext()).inflate( - RESOURCE_MODE_SIMPLE_LAYOUT, this, false); - itemResourceId = RESOURCE_MODE_SIMPLE_ITEM; + RESOURCE_MODE_LAYOUT, this, false); + itemResourceId = RESOURCE_MODE_SIMPLE_ITEM_SMALL; } else if (newMode.compareTo(NavigationLayoutMode.DETAILS) == 0) { newView = (AdapterView<ListAdapter>)LayoutInflater.from(getContext()).inflate( - RESOURCE_MODE_DETAILS_LAYOUT, this, false); + RESOURCE_MODE_LAYOUT, this, false); itemResourceId = RESOURCE_MODE_DETAILS_ITEM; } @@ -1287,7 +1271,15 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe if (!((FileSystemObjectAdapter) parent.getAdapter()).isSelected(position)) { try { if (fso instanceof ParentDirectory) { - changeCurrentDir(fso.getParent(), true, false, false, null, null); + if (TextUtils.equals(fso.getParent(), FileHelper.ROOTS_LIST)) { + if (this.mOnDirectoryChangedListener != null) { + FileSystemObject dir = FileHelper.createFileSystemObject( + new File(FileHelper.ROOTS_LIST)); + this.mOnDirectoryChangedListener.onDirectoryChanged(dir); + } + } else { + changeCurrentDir(fso.getParent(), true, false, false, null, null); + } return; } else if (fso instanceof Directory) { changeCurrentDir(fso.getFullPath(), true, false, false, null, null); @@ -1302,10 +1294,6 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe // Open the link ref fso = symlink.getLinkRef(); - } else if (fso instanceof RootDirectory) { - RootDirectory rootDirectory = (RootDirectory) fso; - changeCurrentDir(rootDirectory.getRootPath(), true); - return; } // Open the file (edit or pick) diff --git a/src/com/cyanogenmod/filemanager/ui/widgets/PickerHeaderView.java b/src/com/cyanogenmod/filemanager/ui/widgets/PickerHeaderView.java new file mode 100644 index 00000000..b8167217 --- /dev/null +++ b/src/com/cyanogenmod/filemanager/ui/widgets/PickerHeaderView.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.cyanogenmod.filemanager.ui.widgets; + +import android.content.Context; +import android.support.v7.widget.Toolbar; +import android.text.TextUtils; +import android.transition.Scene; +import android.transition.Transition; +import android.transition.TransitionInflater; +import android.transition.TransitionManager; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.cyanogenmod.filemanager.R; +import com.cyanogenmod.filemanager.util.FileHelper; + +public class PickerHeaderView extends LinearLayout implements OnClickListener { + private ViewGroup mSceneRoot; + private Scene mRootTitleScene; + private View mRootTitleLayout; + private Scene mBrowseTitleScene; + private View mBrowseTitleLayout; + private Scene mCurrentScene; + + private OnClickListener mOnClickListener; + + public PickerHeaderView(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public PickerHeaderView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + /** + * Method that initializes the view. This method loads all the necessary + * information and create an appropriate layout for the view + */ + private void init() { + View content = inflate(getContext(), R.layout.picker_header_view, null); + content.setLayoutParams(new LinearLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + + mSceneRoot = (ViewGroup) content.findViewById(R.id.picker_header_title_scene_root); + mRootTitleLayout = inflate(getContext(), R.layout.picker_header_root, null); + mRootTitleScene = new Scene(mSceneRoot, mRootTitleLayout); + mBrowseTitleLayout = inflate(getContext(), R.layout.picker_header_browse, null); + mBrowseTitleScene = new Scene(mSceneRoot, mBrowseTitleLayout); + ImageView imageView = (ImageView) mBrowseTitleLayout.findViewById(R.id.header_new_folder); + imageView.setOnClickListener(this); + + mCurrentScene = mRootTitleScene; + TransitionManager.go(mCurrentScene); + + addView(content); + } + + public void setActionText(int stringId) { + TextView textView = (TextView) mRootTitleLayout.findViewById(R.id.header_text_action); + textView.setText(stringId); + textView = (TextView) mBrowseTitleLayout.findViewById(R.id.header_text_action); + textView.setText(stringId); + TransitionManager.go(mCurrentScene); + } + + public void setDirectory(String directory) { + TextView textView = (TextView) mBrowseTitleLayout.findViewById(R.id.header_text_location); + if (TextUtils.equals(directory, FileHelper.ROOTS_LIST)) { + textView.setText(null); + mCurrentScene = mRootTitleScene; + } else { + textView.setText(directory); + mCurrentScene = mBrowseTitleScene; + } + TransitionManager.go(mCurrentScene); + } + + public void setPrimaryColor(int color) { + mBrowseTitleLayout.setBackgroundColor(color); + TransitionManager.go(mCurrentScene); + } + + public void setOnClickListener(OnClickListener onClickListener) { + mOnClickListener = onClickListener; + } + + /** + * Called when a view has been clicked. + * + * @param v The view that was clicked. + */ + @Override + public void onClick(View v) { + if (mOnClickListener != null) { + mOnClickListener.onClick(v); + } + } +}
\ No newline at end of file diff --git a/src/com/cyanogenmod/filemanager/ui/widgets/ToggleSwipeViewPager.java b/src/com/cyanogenmod/filemanager/ui/widgets/ToggleSwipeViewPager.java new file mode 100644 index 00000000..786fc9f4 --- /dev/null +++ b/src/com/cyanogenmod/filemanager/ui/widgets/ToggleSwipeViewPager.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cyanogenmod.filemanager.ui.widgets; + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; +import android.view.MotionEvent; + +public class ToggleSwipeViewPager extends ViewPager { + private boolean mSwipeEnabled; + + public ToggleSwipeViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + this.mSwipeEnabled = true; + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + if (this.mSwipeEnabled) { + return super.onTouchEvent(ev); + } + return false; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + if (this.mSwipeEnabled) { + return super.onInterceptTouchEvent(ev); + } + return false; + } + + public void setSwipeEnabled(boolean swipeEnabled) { + this.mSwipeEnabled = swipeEnabled; + } +} |