summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2016-02-08 16:11:19 -0800
committerTom Powell <zifnab@zifnab06.net>2017-03-26 16:15:31 -0700
commitb64e6c03ef041ef6539ed72bc8f7662d7969c173 (patch)
treede26c6ef6d4d5dee4d08dd34d76aee3b4844b62f
parentaa9698dfa1360ade3f7bf347615936da7f267d73 (diff)
downloadandroid_packages_apps_Trebuchet-b64e6c03ef041ef6539ed72bc8f7662d7969c173.zip
android_packages_apps_Trebuchet-b64e6c03ef041ef6539ed72bc8f7662d7969c173.tar.gz
android_packages_apps_Trebuchet-b64e6c03ef041ef6539ed72bc8f7662d7969c173.tar.bz2
Trebuchet: Revise protected app folders UI
Issue-id: CYNGNOS-1881 Change-Id: I5cbc5d9fe9358fdf2708376bfe5d7bf2108a0897
-rw-r--r--res/drawable/ic_remove.xml29
-rw-r--r--res/layout/hidden_folder.xml70
-rw-r--r--res/layout/hidden_folder_apps_list_item.xml48
-rw-r--r--src/com/android/launcher3/Folder.java91
-rw-r--r--src/com/android/launcher3/HiddenFolderFragment.java376
-rw-r--r--src/com/android/launcher3/Launcher.java90
6 files changed, 96 insertions, 608 deletions
diff --git a/res/drawable/ic_remove.xml b/res/drawable/ic_remove.xml
deleted file mode 100644
index e4e550a..0000000
--- a/res/drawable/ic_remove.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2015 The Android Open Source 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="#fafafa"
- android:pathData="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59
-19 19 17.59 13.41 12z" />
- <path
- android:pathData="M0 0h24v24H0z" />
-</vector>
diff --git a/res/layout/hidden_folder.xml b/res/layout/hidden_folder.xml
deleted file mode 100644
index fc336dd..0000000
--- a/res/layout/hidden_folder.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2015 The Android Open Source 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"
- xmlns:insettable="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@color/settings_bg_color"
- android:orientation="vertical"
- android:paddingLeft="@dimen/overview_panel_button_spacing"
- android:paddingRight="@dimen/overview_panel_button_spacing"
- android:paddingTop="@dimen/overview_panel_bottom_padding"
- android:focusable="true"
- android:focusableInTouchMode="true"
- insettable:layout_ignoreInsets="true"
- android:clickable="true" >
-
- <RelativeLayout
- android:id="@+id/folder_title_lock"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal" >
- <ImageView
- android:id="@+id/folder_lock_icon"
- android:layout_width="25dp"
- android:layout_height="25dp"
- android:layout_alignParentRight="true"
- android:layout_centerVertical="true"
- android:src="@drawable/folder_unlocked"
- android:background="@drawable/listitem_bg" />
-
- <EditText
- android:id="@+id/folder_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_toStartOf="@id/folder_lock_icon"
- android:paddingBottom="@dimen/folder_name_padding"
- android:paddingTop="@dimen/folder_name_padding"
- android:hint="@string/folder_hint_text"
- android:textColor="@color/workspace_icon_text_color"
- android:textSize="20sp"
- android:textColorHighlight="@color/folder_name_highlight_text_color"
- android:textColorHint="@color/folder_name_hint_text_color"
- android:textCursorDrawable="@null"
- android:singleLine="true"
- android:background="#00000000" />
- </RelativeLayout>
-
- <ListView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/hidden_apps_list"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp" />
-
-</LinearLayout>
diff --git a/res/layout/hidden_folder_apps_list_item.xml b/res/layout/hidden_folder_apps_list_item.xml
deleted file mode 100644
index 483b463..0000000
--- a/res/layout/hidden_folder_apps_list_item.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2015 The Android Open Source 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:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="48dp"
- android:gravity="center_vertical"
- android:paddingRight="?android:attr/scrollbarSize"
- android:background="?android:attr/selectableItemBackground">
-
- <ImageView android:id="@+id/icon"
- android:layout_width="40dp"
- android:layout_height="40dp"
- android:layout_gravity="center" />
-
- <TextView android:id="@+id/title"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginLeft="15dip"
- android:layout_marginRight="6dip"
- android:layout_marginTop="6dip"
- android:layout_marginBottom="6dip"
- android:layout_weight="1"
- android:singleLine="true"
- android:textAppearance="?android:attr/textAppearanceMediumInverse"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal" />
-
- <ImageView android:id="@+id/remove"
- android:layout_width="40dp"
- android:layout_height="40dp"
- android:layout_gravity="center"
- android:src="@drawable/ic_remove"/>
-</LinearLayout>
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 8c697ee..bf41b8e 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -73,7 +73,6 @@ import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.UiThreadCircularReveal;
import static cyanogenmod.content.Intent.ACTION_PROTECTED;
-import static cyanogenmod.content.Intent.ACTION_PROTECTED_CHANGED;
import static cyanogenmod.content.Intent.EXTRA_PROTECTED_COMPONENTS;
import static cyanogenmod.content.Intent.EXTRA_PROTECTED_STATE;
@@ -152,7 +151,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
ExtendedEditText mFolderName;
private View mFooter;
- private int mFooterHeight;
// Cell ranks used for drag and drop
@Thunk int mTargetRank, mPrevTargetRank, mEmptyCellRank;
@@ -173,7 +171,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
private boolean mIsEditingName = false;
ImageView mFolderLock;
- private int mFolderLockHeight;
private boolean mDestroyed;
@@ -184,8 +181,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
// Folder scrolling
private int mScrollAreaOffset;
- private boolean mHiddenFolder = false;
-
private Handler mHandler;
@Thunk int mScrollHintDir = DragController.SCROLL_NONE;
@@ -294,14 +289,14 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
if (v.getId() == R.id.folder_lock) {
- startHiddenFolderManager();
+ startHiddenFolderManager(mInfo.hidden ?
+ Launcher.REQUEST_UNPROTECT_FOLDER :
+ Launcher.REQUEST_PROTECT_FOLDER);
}
}
- public void startHiddenFolderManager() {
- Bundle bundle = new Bundle();
- bundle.putBoolean(HiddenFolderFragment.HIDDEN_FOLDER_STATUS, mInfo.hidden);
- mLauncher.validateLockForHiddenFolders(bundle, mFolderIcon);
+ public void startHiddenFolderManager(int action) {
+ mLauncher.validateLockForHiddenFolders(mFolderIcon, action);
}
public List<Pair<ComponentName, CharSequence>> getComponents() {
@@ -322,7 +317,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
public void modifyProtectedApps(boolean protect) {
- ArrayList<ComponentName> components = new ArrayList<ComponentName>();
+ ArrayList<ComponentName> components = new ArrayList<>();
for (Pair<ComponentName, CharSequence> item : getComponents()) {
if (item.first != null) {
components.add(item.first);
@@ -331,12 +326,35 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
Intent intent = new Intent();
intent.setAction(ACTION_PROTECTED);
- intent.putExtra(EXTRA_PROTECTED_STATE, protect);
+ // flip the boolean value to accomodate framework
+ // in framework "false" is "protected" and "true" is "visible"
+ intent.putExtra(EXTRA_PROTECTED_STATE, !protect);
+ intent.putExtra(EXTRA_PROTECTED_COMPONENTS, components);
+
+ mLauncher.sendBroadcast(intent);
+ }
+
+ private void removeProtectedApp(ComponentName componentName) {
+ ArrayList<ComponentName> components = new ArrayList<>();
+ components.add(componentName);
+ Intent intent = new Intent();
+ intent.setAction(ACTION_PROTECTED);
+ // flip the boolean value to accomodate framework
+ // in framework "false" is "protected" and "true" is "visible"
+ intent.putExtra(EXTRA_PROTECTED_STATE, true);
intent.putExtra(EXTRA_PROTECTED_COMPONENTS, components);
mLauncher.sendBroadcast(intent);
}
+ public void saveHiddenFolderState(boolean protect) {
+ mInfo.hidden = protect;
+ modifyProtectedApps(protect);
+ LauncherModel.updateItemInDatabase(mLauncher, mInfo);
+ mLauncher.mModel.flushWorkerThread();
+ rebind(mInfo);
+ }
+
public boolean onLongClick(View v) {
// Return if global dragging is not enabled
if (!mLauncher.isDraggingEnabled()) return true;
@@ -418,6 +436,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
mIsEditingName = false;
+ mLauncher.notifyFolderNameChanged();
}
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
@@ -490,6 +509,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mInfo.addListener(this);
setFolderName();
+ updateLock();
+ }
+
+ public void rebind(final FolderInfo info) {
+ bind(info);
}
public void setFolderName() {
@@ -509,6 +533,14 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
});
}
+ private void updateLock() {
+ if (mInfo != null) {
+ mFolderLock.setImageResource(mInfo.hidden ?
+ R.drawable.folder_locked :
+ R.drawable.folder_unlocked);
+ }
+ }
+
/**
* Creates a new UserFolder, inflated from R.layout.user_folder.
*
@@ -1101,6 +1133,13 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
mScrollPauseAlarm.cancelAlarm();
completeDragExit();
+ if (successfulDrop) {
+ ShortcutInfo info = (ShortcutInfo) d.dragInfo;
+ Intent intent = info.getIntent();
+ if (intent != null && mInfo.hidden) {
+ removeProtectedApp(intent.getComponent());
+ }
+ }
}
}
@@ -1369,7 +1408,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
View child = null;
// Move the item from the folder to the workspace, in the position of the folder
- if (getItemCount() == 1) {
+ if (!mInfo.hidden && getItemCount() == 1) {
ShortcutInfo finalItem = mInfo.contents.get(0);
child = mLauncher.createShortcut(cellLayout, finalItem);
LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
@@ -1585,32 +1624,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
return mItemsInReadingOrder;
}
- public ShortcutInfo getShortcutForComponent(ComponentName componentName) {
- for (View v : mItemsInReadingOrder) {
- Object tag = v.getTag();
- if (tag instanceof ShortcutInfo) {
- ComponentName cName = ((ShortcutInfo) tag).getIntent().getComponent();
- if (cName.equals(componentName)) {
- return (ShortcutInfo) tag;
- }
- }
- }
-
- return null;
- }
-
- public ShortcutInfo getShortcutForPosition(int position) {
- if (position < 0 || position >= mItemsInReadingOrder.size()) {
- return null;
- }
- View v = mItemsInReadingOrder.get(position);
- Object tag = v.getTag();
- if (tag instanceof ShortcutInfo) {
- return (ShortcutInfo) tag;
- }
- return null;
- }
-
public void getLocationInDragLayer(int[] loc) {
mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
}
diff --git a/src/com/android/launcher3/HiddenFolderFragment.java b/src/com/android/launcher3/HiddenFolderFragment.java
deleted file mode 100644
index 97c4dfd..0000000
--- a/src/com/android/launcher3/HiddenFolderFragment.java
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source 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.android.launcher3;
-
-import android.app.Fragment;
-import android.app.FragmentTransaction;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.graphics.drawable.Drawable;
-import android.media.Image;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.text.InputType;
-import android.util.Pair;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.ArrayAdapter;
-import android.widget.EditText;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class HiddenFolderFragment extends Fragment {
- public static final String HIDDEN_FOLDER_FRAGMENT = "hiddenFolderFragment";
- public static final String HIDDEN_FOLDER_NAME = "hiddenFolderName";
- public static final String HIDDEN_FOLDER_STATUS = "hiddenFolderStatus";
- public static final String HIDDEN_FOLDER_INFO = "hiddenFolderInfo";
- public static final String HIDDEN_FOLDER_INFO_TITLES = "hiddenFolderInfoTitles";
- public static final String HIDDEN_FOLDER_LAUNCH = "hiddenFolderLaunchPosition";
-
- private static final int REQ_LOCK_PATTERN = 1;
-
- private boolean mHidden;
- private PackageManager mPackageManager;
- private AppsAdapter mAppsAdapter;
- private ArrayList<AppEntry> mAppEntries;
-
- private EditText mFolderName;
- private ListView mListView;
-
- private Launcher mLauncher;
-
- private boolean mAuth = false;
- private boolean mSent = false;
-
- private OnClickListener mClicklistener = new OnClickListener() {
- @Override
- public void onClick(View v) {
- mHidden = !mHidden;
-
- ImageView mLock = (ImageView) v;
- Drawable mLockIcon = mHidden ? getResources().getDrawable(R.drawable.folder_locked)
- : getResources().getDrawable(R.drawable.folder_unlocked);
- mLock.setImageDrawable(mLockIcon);
- }
- };
-
- @Override
- public View onCreateView (LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.hidden_folder, container, false);
-
- mLauncher = (Launcher) getActivity();
- mPackageManager = mLauncher.getPackageManager();
-
- mHidden = getArguments().getBoolean(HIDDEN_FOLDER_STATUS);
- Folder folder = mLauncher.mHiddenFolderIcon.getFolder();
- String title = mLauncher.mHiddenFolderIcon.getFolderInfo().title.toString();
-
- mFolderName = (EditText) v.findViewById(R.id.folder_name);
- mFolderName.setText(title);
- mFolderName.setSelectAllOnFocus(true);
- mFolderName.setInputType(mFolderName.getInputType() |
- InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
- mFolderName.setImeOptions(EditorInfo.IME_ACTION_DONE);
- mFolderName.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == EditorInfo.IME_ACTION_DONE) {
- doneEditingText(v);
- return true;
- }
- return false;
- }
- });
- mFolderName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if (!hasFocus) {
- doneEditingText(v);
- }
- }
- });
-
- ImageView mLock = (ImageView) v.findViewById(R.id.folder_lock_icon);
- Drawable mLockIcon = mHidden ? getResources().getDrawable(R.drawable.folder_locked)
- : getResources().getDrawable(R.drawable.folder_unlocked);
- mLock.setImageDrawable(mLockIcon);
- mLock.setOnClickListener(mClicklistener);
-
- mAppsAdapter = new AppsAdapter(mLauncher, R.layout.hidden_apps_list_item);
- mAppsAdapter.setNotifyOnChange(true);
- mAppEntries = loadApps(folder.getComponents());
- mAppsAdapter.clear();
- mAppsAdapter.addAll(mAppEntries);
-
- mListView = (ListView) v.findViewById(R.id.hidden_apps_list);
- mListView.setAdapter(mAppsAdapter);
-
- // Apply insets
- Launcher launcher = (Launcher) getActivity();
- LinearLayout.LayoutParams llp =
- (LinearLayout.LayoutParams) mListView.getLayoutParams();
- // TODO: Uncomment this once the Settings for Trebuchet are merged
- /*llp.bottomMargin += ((FrameLayout.LayoutParams) launcher.getOverviewPanel()
- .findViewById(R.id.settings_container).getLayoutParams()).bottomMargin;*/
- mListView.setLayoutParams(llp);
-
- return v;
- }
-
- private void doneEditingText(View v) {
- InputMethodManager mInputMethodManager = (InputMethodManager)
- mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE);
- mInputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
-
- mListView.requestFocus();
- }
-
- private ArrayList<AppEntry> loadApps(List<Pair<ComponentName, CharSequence>> items) {
- ArrayList<AppEntry> apps = new ArrayList<AppEntry>();
- int pos = 0;
- for (Pair<ComponentName, CharSequence> item : items) {
- apps.add(new AppEntry(item.first, item.second, pos));
- pos++;
- }
- return apps;
- }
-
- private void removeComponentFromFolder(AppEntry app) {
- ShortcutInfo info;
- if (app.componentName != null) {
- info = mLauncher.mHiddenFolderIcon.getFolder()
- .getShortcutForComponent(app.componentName);
- } else {
- // Shortcut does not have componentName, use position since it maps to
- // reading order position in the folder
- info = mLauncher.mHiddenFolderIcon.getFolder().getShortcutForPosition(app.position);
- }
- mLauncher.mHiddenFolderIcon.getFolderInfo().remove(info);
-
- mAppEntries.remove(app);
- mAppsAdapter.remove(app);
- mAppsAdapter.notifyDataSetInvalidated();
- }
-
- public void saveHiddenFolderStatus(int position) {
- String newTitle = mFolderName.getText().toString();
- if (mLauncher.mHiddenFolderIcon != null) {
- if (position != -1) {
- Folder folder = mLauncher.mHiddenFolderIcon.getFolder();
- View v = folder.getViewFromPosition(position);
- Object tag = v.getTag();
- if (tag instanceof ShortcutInfo) {
- ShortcutInfo shortcut = (ShortcutInfo) tag;
- mLauncher.startActivitySafely(v, shortcut.getIntent(), v.getTag());
- return;
- }
- }
-
- // Folder name
- FolderInfo info = mLauncher.mHiddenFolderIcon.getFolderInfo();
- if (!info.title.equals(newTitle)) {
- info.setTitle(newTitle);
- mLauncher.mHiddenFolderIcon.getFolder().setFolderName();
- LauncherModel.updateItemInDatabase(mLauncher, info);
- }
-
- // Folder hidden status
- if (info.hidden == mHidden) {
- return;
- } else {
- info.hidden = mHidden;
- // flip the boolean value to accomodate framework
- // in framework "false" is "protected" and "true" is "visible"
- mLauncher.mHiddenFolderIcon.getFolder().modifyProtectedApps(!info.hidden);
-
- LauncherModel.updateItemInDatabase(mLauncher, info);
- // We need to make sure this change gets written to the DB before
- // OnResume restarts the process
- mLauncher.mModel.flushWorkerThread();
- }
- }
-
- FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
- fragmentTransaction
- .remove(mLauncher.mHiddenFolderFragment).commit();
- }
-
- public class AppsAdapter extends ArrayAdapter<AppEntry> {
-
- private final LayoutInflater mInflator;
-
- private ConcurrentHashMap<String, Drawable> mIcons;
- private Drawable mDefaultImg;
- private List<AppEntry> mApps;
-
- public AppsAdapter(Context context, int textViewResourceId) {
- super(context, textViewResourceId);
-
- mApps = new ArrayList<AppEntry>();
-
- mInflator = LayoutInflater.from(context);
-
- // set the default icon till the actual app icon is loaded in async
- // task
- mDefaultImg = context.getResources().getDrawable(
- android.R.mipmap.sym_def_app_icon);
- mIcons = new ConcurrentHashMap<String, Drawable>();
- }
-
- @Override
- public View getView(final int position, View convertView,
- ViewGroup parent) {
- final AppViewHolder viewHolder;
-
- if (convertView == null) {
- convertView = mInflator.inflate(
- R.layout.hidden_folder_apps_list_item, parent, false);
- viewHolder = new AppViewHolder(convertView, position);
- convertView.setTag(viewHolder);
- } else {
- viewHolder = (AppViewHolder) convertView.getTag();
- }
-
- final AppEntry app = getItem(position);
-
- viewHolder.title.setText(app.title);
-
- Drawable icon = null;
- if (app.componentName != null) {
- icon = mIcons.get(app.componentName.getPackageName());
- }
- viewHolder.icon.setImageDrawable(icon != null ? icon : mDefaultImg);
- viewHolder.remove.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- removeComponentFromFolder(app);
- }
- });
-
- convertView.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- saveHiddenFolderStatus(position);
- }
- });
-
- return convertView;
- }
-
- @Override
- public boolean hasStableIds() {
- return true;
- }
-
- @Override
- public void notifyDataSetChanged() {
- super.notifyDataSetChanged();
- // If we have new items, we have to load their icons
- // If items were deleted, remove them from our mApps
- List<AppEntry> newApps = new ArrayList<AppEntry>(getCount());
- List<AppEntry> oldApps = new ArrayList<AppEntry>(getCount());
- for (int i = 0; i < getCount(); i++) {
- AppEntry app = getItem(i);
- if (mApps.contains(app)) {
- oldApps.add(app);
- } else {
- newApps.add(app);
- }
- }
-
- if (newApps.size() > 0) {
- new LoadIconsTask().execute(newApps.toArray(new AppEntry[] {}));
- newApps.addAll(oldApps);
- mApps = newApps;
- } else {
- mApps = oldApps;
- }
- }
-
- /**
- * An asynchronous task to load the icons of the installed applications.
- */
- private class LoadIconsTask extends AsyncTask<AppEntry, Void, Void> {
- @Override
- protected Void doInBackground(AppEntry... apps) {
- for (AppEntry app : apps) {
- try {
- // Widget icons do not have a
- if (app.componentName == null ||
- mIcons.containsKey(app.componentName.getPackageName())) {
- continue;
- }
- Drawable icon = mPackageManager
- .getApplicationIcon(app.componentName
- .getPackageName());
- mIcons.put(app.componentName.getPackageName(), icon);
- publishProgress();
- } catch (PackageManager.NameNotFoundException e) {
- // ignored; app will show up with default image
- }
- }
-
- return null;
- }
-
- @Override
- protected void onProgressUpdate(Void... progress) {
- notifyDataSetChanged();
- }
- }
- }
-
- private final class AppEntry {
- public final ComponentName componentName;
- public final CharSequence title;
- public final int position;
-
- public AppEntry(ComponentName component, CharSequence title, int position) {
- this.componentName = component;
- this.title = title;
- this.position = position;
- }
- }
-
- private static class AppViewHolder {
- public final TextView title;
- public final ImageView icon;
- public final ImageView remove;
- public final int position;
-
- public AppViewHolder(View parentView, int position) {
- icon = (ImageView) parentView.findViewById(R.id.icon);
- remove = (ImageView) parentView.findViewById(R.id.remove);
- title = (TextView) parentView.findViewById(R.id.title);
- this.position = position;
- }
- }
-}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 5d3cd27..980badf 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -159,7 +159,9 @@ public class Launcher extends Activity
private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
- private static final int REQUEST_LOCK_PATTERN = 14;
+ public static final int REQUEST_OPEN_PROTECTED_FOLDER = 14;
+ public static final int REQUEST_PROTECT_FOLDER = 15;
+ public static final int REQUEST_UNPROTECT_FOLDER = 16;
private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
@@ -257,7 +259,6 @@ public class Launcher extends Activity
@Thunk DragLayer mDragLayer;
private DragController mDragController;
private View mWeightWatcher;
- protected HiddenFolderFragment mHiddenFolderFragment;
private DynamicGridSizeFragment mDynamicGridSizeFragment;
private AppWidgetManagerCompat mAppWidgetManager;
@@ -826,23 +827,28 @@ public class Launcher extends Activity
showWorkspace(false);
}
return;
- } else if (requestCode == REQUEST_LOCK_PATTERN) {
- mHiddenFolderAuth = true;
- switch (resultCode) {
- case RESULT_OK:
- FragmentManager fragmentManager = getFragmentManager();
- FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
-
- fragmentTransaction.setCustomAnimations(0, 0);
- fragmentTransaction.replace(R.id.launcher, mHiddenFolderFragment,
- HiddenFolderFragment.HIDDEN_FOLDER_FRAGMENT);
- fragmentTransaction.commit();
- break;
- case RESULT_CANCELED:
- // User failed to enter/confirm a lock pattern, back out
- break;
+ } else if (requestCode == REQUEST_OPEN_PROTECTED_FOLDER) {
+ mHiddenFolderAuth = resultCode == RESULT_OK;
+ if (mHiddenFolderIcon != null && mHiddenFolderAuth) {
+ openFolder(mHiddenFolderIcon, null);
+ } else {
+ mHiddenFolderAuth = false;
}
return;
+ } else if (requestCode == REQUEST_PROTECT_FOLDER) {
+ mHiddenFolderAuth = resultCode == RESULT_OK;
+ if (mHiddenFolderIcon != null && mHiddenFolderAuth) {
+ mHiddenFolderIcon.getFolder().saveHiddenFolderState(true);
+ } else {
+ mHiddenFolderAuth = false;
+ }
+ } else if (requestCode == REQUEST_UNPROTECT_FOLDER) {
+ mHiddenFolderAuth = resultCode == RESULT_OK;
+ if (mHiddenFolderIcon != null && mHiddenFolderAuth) {
+ mHiddenFolderIcon.getFolder().saveHiddenFolderState(false);
+ } else {
+ mHiddenFolderAuth = false;
+ }
}
boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
@@ -1185,16 +1191,6 @@ public class Launcher extends Activity
if (gridFragment != null) {
mDynamicGridSizeFragment.setSize();
}
-
- Fragment hiddenFolderFragment = getFragmentManager().findFragmentByTag(
- HiddenFolderFragment.HIDDEN_FOLDER_FRAGMENT);
- if (hiddenFolderFragment != null && !mHiddenFolderAuth) {
- mHiddenFolderFragment.saveHiddenFolderStatus(-1);
- FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
- fragmentTransaction.remove(mHiddenFolderFragment).commit();
- } else {
- mHiddenFolderAuth = false;
- }
}
@Override
@@ -2274,7 +2270,9 @@ public class Launcher extends Activity
outState.putInt(RUNTIME_STATE, mState.ordinal());
// We close any open folder since it will not be re-opened, and we need to make sure
// this state is reflected.
- closeFolder();
+ if (mHiddenFolderIcon == null) {
+ closeFolder();
+ }
if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
mWaitingForResult) {
@@ -2349,18 +2347,21 @@ public class Launcher extends Activity
return mDragController;
}
- public void validateLockForHiddenFolders(Bundle bundle, FolderIcon info) {
+ public void validateLockForHiddenFolders(FolderIcon info, int action) {
+ mHiddenFolderIcon = info;
// Validate Lock Pattern
Intent lockPatternActivity = new Intent();
lockPatternActivity.setClassName(
"com.android.settings",
"com.android.settings.applications.LockPatternActivity");
- startActivityForResult(lockPatternActivity, REQUEST_LOCK_PATTERN);
+ startActivityForResult(lockPatternActivity, action);
mHiddenFolderAuth = false;
+ }
- mHiddenFolderIcon = info;
- mHiddenFolderFragment = new HiddenFolderFragment();
- mHiddenFolderFragment.setArguments(bundle);
+ public void notifyFolderNameChanged() {
+ // Reload
+ mModel.resetLoadedState(true, true);
+ mModel.startLoader(mWorkspace.getCurrentPage(), LauncherModel.LOADER_FLAG_NONE);
}
@Override
@@ -2758,15 +2759,6 @@ public class Launcher extends Activity
return;
}
- Fragment f1 = getFragmentManager().findFragmentByTag(
- HiddenFolderFragment.HIDDEN_FOLDER_FRAGMENT);
- if (f1 != null) {
- mHiddenFolderFragment.saveHiddenFolderStatus(-1);
- FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
- fragmentTransaction
- .remove(mHiddenFolderFragment).commit();
- }
-
if (isAppsViewVisible()) {
showWorkspace(true);
} else if (isWidgetsViewVisible()) {
@@ -2798,6 +2790,7 @@ public class Launcher extends Activity
}
}
+
/**
* Re-listen when widget host is reset.
*/
@@ -3473,7 +3466,7 @@ public class Launcher extends Activity
* is animated relative to the specified View. If the View is null, no animation
* is played.
*
- * @param folderInfo The FolderInfo describing the folder to open.
+ * @param folderIcon The FolderIcon describing the folder to open.
*/
public void openFolder(FolderIcon folderIcon, int[] folderTouch) {
Folder folder = folderIcon.getFolder();
@@ -3490,8 +3483,8 @@ public class Launcher extends Activity
FolderInfo info = folder.mInfo;
- if (info.hidden) {
- folder.startHiddenFolderManager();
+ if (info.hidden && !mHiddenFolderAuth) {
+ folder.startHiddenFolderManager(REQUEST_OPEN_PROTECTED_FOLDER);
return;
}
@@ -3538,7 +3531,12 @@ public class Launcher extends Activity
}
public void closeFolder(Folder folder, boolean animate) {
- folder.getInfo().opened = false;
+ final FolderInfo info = folder.getInfo();
+ info.opened = false;
+ if (info.hidden) {
+ mHiddenFolderAuth = false;
+ mHiddenFolderIcon = null;
+ }
ViewGroup parent = (ViewGroup) folder.getParent().getParent();
if (parent != null) {