summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/Folder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/Folder.java')
-rw-r--r--src/com/android/launcher3/Folder.java103
1 files changed, 100 insertions, 3 deletions
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 1e0827e54..ccb12b62a 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -23,7 +23,9 @@ import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Point;
@@ -39,6 +41,7 @@ import android.text.Selection;
import android.text.Spannable;
import android.util.AttributeSet;
import android.util.Log;
+import android.util.Pair;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.Menu;
@@ -54,6 +57,7 @@ import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -67,9 +71,15 @@ import com.android.launcher3.settings.SettingsProvider;
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;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.List;
/**
* Represents a set of icons chosen by the user or generated by the system.
@@ -161,6 +171,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
@Thunk float mFolderIconPivotY;
private boolean mIsEditingName = false;
+ ImageView mFolderLock;
+ private int mFolderLockHeight;
+
private boolean mDestroyed;
@Thunk Runnable mDeferredAction;
@@ -170,6 +183,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
// Folder scrolling
private int mScrollAreaOffset;
+ private boolean mHiddenFolder = false;
+
@Thunk int mScrollHintDir = DragController.SCROLL_NONE;
@Thunk int mCurrentScrollDir = DragController.SCROLL_NONE;
@@ -212,6 +227,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mContent = (FolderPagedView) findViewById(R.id.folder_content);
mContent.setFolder(this);
+ // We find out how tall footer wants to be (it is set to wrap_content), so that
+ // we can allocate the appropriate amount of space for it.
+ int measureSpec = MeasureSpec.UNSPECIFIED;
+
mFolderName = (ExtendedEditText) findViewById(R.id.folder_name);
mFolderName.setOnBackKeyListener(new ExtendedEditText.OnBackKeyListener() {
@Override
@@ -236,12 +255,13 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
if (hideLabels) {
mFolderName.setVisibility(View.GONE);
}
+ mFolderLock = (ImageView) findViewById(R.id.folder_lock);
+ mFolderLock.measure(measureSpec, measureSpec);
+ mFolderLock.setOnClickListener(this);
+ mFolderLockHeight = mFolderLock.getMeasuredHeight();
mFooter = findViewById(R.id.folder_footer);
- // We find out how tall footer wants to be (it is set to wrap_content), so that
- // we can allocate the appropriate amount of space for it.
- int measureSpec = MeasureSpec.UNSPECIFIED;
mFooter.measure(measureSpec, measureSpec);
mFooterHeight = mFooter.getMeasuredHeight();
}
@@ -268,6 +288,49 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
if (tag instanceof ShortcutInfo) {
mLauncher.onClick(v);
}
+
+ if (v.getId() == R.id.folder_lock) {
+ startHiddenFolderManager();
+ }
+ }
+
+ public void startHiddenFolderManager() {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(HiddenFolderFragment.HIDDEN_FOLDER_STATUS, mInfo.hidden);
+ mLauncher.validateLockForHiddenFolders(bundle, mFolderIcon);
+ }
+
+ public List<Pair<ComponentName, CharSequence>> getComponents() {
+ int size = mItemsInReadingOrder.size();
+ List<Pair<ComponentName, CharSequence>> components =
+ new ArrayList<Pair<ComponentName, CharSequence>>();
+
+ for (int i = 0; i < size; i++) {
+ View v = mItemsInReadingOrder.get(i);
+ Object tag = v.getTag();
+ if (tag instanceof ShortcutInfo) {
+ ShortcutInfo shortcut = (ShortcutInfo) tag;
+ components.add(Pair.create(shortcut.getIntent().getComponent(), shortcut.title));
+ }
+ }
+
+ return components;
+ }
+
+ public void modifyProtectedApps(boolean protect) {
+ ArrayList<ComponentName> components = new ArrayList<ComponentName>();
+ for (Pair<ComponentName, CharSequence> item : getComponents()) {
+ if (item.first != null) {
+ components.add(item.first);
+ }
+ }
+
+ Intent intent = new Intent();
+ intent.setAction(ACTION_PROTECTED);
+ intent.putExtra(EXTRA_PROTECTED_STATE, protect);
+ intent.putExtra(EXTRA_PROTECTED_COMPONENTS, components);
+
+ mLauncher.sendBroadcast(intent);
}
public boolean onLongClick(View v) {
@@ -422,6 +485,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
updateTextViewFocus();
mInfo.addListener(this);
+ setFolderName();
+ }
+
+ public void setFolderName() {
if (!sDefaultFolderName.contentEquals(mInfo.title)) {
mFolderName.setText(mInfo.title);
} else {
@@ -1496,6 +1563,32 @@ 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);
}
@@ -1513,6 +1606,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
outRect.right += mScrollAreaOffset;
}
+ public View getViewFromPosition(int position) {
+ return mItemsInReadingOrder.get(position);
+ }
+
@Override
public void fillInLaunchSourceData(Bundle sourceData) {
// Fill in from the folder icon's launch source provider first