summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2014-08-12 15:58:36 -0700
committerSunny Goyal <sunnygoyal@google.com>2014-08-18 13:51:51 -0700
commitdcbcc86353e9ed52daac87f292aece667cd0ac71 (patch)
treea0e1c4ca2ba2e9863a2168cbc4299b136cea2f30
parent0fc1be164e982433e619bcbb16aa67e28ff681ef (diff)
downloadandroid_packages_apps_Trebuchet-dcbcc86353e9ed52daac87f292aece667cd0ac71.zip
android_packages_apps_Trebuchet-dcbcc86353e9ed52daac87f292aece667cd0ac71.tar.gz
android_packages_apps_Trebuchet-dcbcc86353e9ed52daac87f292aece667cd0ac71.tar.bz2
Updating the UI for focused state of an icon/folder.
issue: 16352129 Change-Id: If2e154dba06a0648f933f9aea38898642db9fd85
-rw-r--r--res/drawable-hdpi/focused_bg.9.pngbin188 -> 0 bytes
-rw-r--r--res/drawable-mdpi/focused_bg.9.pngbin180 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/focused_bg.9.pngbin194 -> 0 bytes
-rw-r--r--res/drawable-xxhdpi/focused_bg.9.pngbin2884 -> 0 bytes
-rw-r--r--res/drawable/focusable_view_bg.xml13
-rw-r--r--res/layout-land/launcher.xml5
-rw-r--r--res/layout-port/launcher.xml5
-rw-r--r--res/layout-sw720dp/launcher.xml5
-rw-r--r--res/layout/all_apps_button.xml3
-rw-r--r--res/layout/application.xml3
-rw-r--r--res/layout/apps_customize_application.xml3
-rw-r--r--res/layout/folder_application.xml3
-rw-r--r--res/layout/folder_icon.xml3
-rw-r--r--res/values/colors.xml1
-rw-r--r--src/com/android/launcher3/AppsCustomizeCellLayout.java8
-rw-r--r--src/com/android/launcher3/AppsCustomizePagedView.java1
-rw-r--r--src/com/android/launcher3/CellLayout.java5
-rw-r--r--src/com/android/launcher3/FocusIndicatorView.java146
-rw-r--r--src/com/android/launcher3/Folder.java8
-rw-r--r--src/com/android/launcher3/FolderIcon.java1
-rw-r--r--src/com/android/launcher3/Hotseat.java1
-rw-r--r--src/com/android/launcher3/Launcher.java4
22 files changed, 201 insertions, 17 deletions
diff --git a/res/drawable-hdpi/focused_bg.9.png b/res/drawable-hdpi/focused_bg.9.png
deleted file mode 100644
index 2925ae8..0000000
--- a/res/drawable-hdpi/focused_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/focused_bg.9.png b/res/drawable-mdpi/focused_bg.9.png
deleted file mode 100644
index 89c29ac..0000000
--- a/res/drawable-mdpi/focused_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/focused_bg.9.png b/res/drawable-xhdpi/focused_bg.9.png
deleted file mode 100644
index 197a269..0000000
--- a/res/drawable-xhdpi/focused_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/focused_bg.9.png b/res/drawable-xxhdpi/focused_bg.9.png
deleted file mode 100644
index 84d3062..0000000
--- a/res/drawable-xxhdpi/focused_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/focusable_view_bg.xml b/res/drawable/focusable_view_bg.xml
index 66661e2..e156513 100644
--- a/res/drawable/focusable_view_bg.xml
+++ b/res/drawable/focusable_view_bg.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 The Android Open Source Project
+<!--
+ Copyright (C) 2011 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.
@@ -15,5 +16,11 @@
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_focused="true" android:drawable="@drawable/focused_bg" />
-</selector>
+
+ <item android:state_focused="true">
+ <shape android:shape="rectangle">
+ <solid android:color="@color/focused_background" />
+ </shape>
+ </item>
+
+</selector> \ No newline at end of file
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
index 7791609..0af9e59 100644
--- a/res/layout-land/launcher.xml
+++ b/res/layout-land/launcher.xml
@@ -30,6 +30,11 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">
+ <com.android.launcher3.FocusIndicatorView
+ android:id="@+id/focus_indicator"
+ android:layout_width="52dp"
+ android:layout_height="52dp" />
+
<!-- The workspace contains 5 screens of cells -->
<com.android.launcher3.Workspace
android:id="@+id/workspace"
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml
index 574b73e..46e0c0f 100644
--- a/res/layout-port/launcher.xml
+++ b/res/layout-port/launcher.xml
@@ -29,6 +29,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
+ <com.android.launcher3.FocusIndicatorView
+ android:id="@+id/focus_indicator"
+ android:layout_width="52dp"
+ android:layout_height="52dp" />
+
<!-- The workspace contains 5 screens of cells -->
<com.android.launcher3.Workspace
android:id="@+id/workspace"
diff --git a/res/layout-sw720dp/launcher.xml b/res/layout-sw720dp/launcher.xml
index 685d03c..f8b8437 100644
--- a/res/layout-sw720dp/launcher.xml
+++ b/res/layout-sw720dp/launcher.xml
@@ -30,6 +30,11 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">
+ <com.android.launcher3.FocusIndicatorView
+ android:id="@+id/focus_indicator"
+ android:layout_width="52dp"
+ android:layout_height="52dp" />
+
<!-- The workspace contains 5 screens of cells -->
<com.android.launcher3.Workspace
android:id="@+id/workspace"
diff --git a/res/layout/all_apps_button.xml b/res/layout/all_apps_button.xml
index 1b9ea08..9d6d82b 100644
--- a/res/layout/all_apps_button.xml
+++ b/res/layout/all_apps_button.xml
@@ -16,5 +16,4 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/WorkspaceIcon"
- android:focusable="true"
- android:background="@drawable/focusable_view_bg" />
+ android:focusable="true" />
diff --git a/res/layout/application.xml b/res/layout/application.xml
index e4909dd..c21dea0 100644
--- a/res/layout/application.xml
+++ b/res/layout/application.xml
@@ -16,5 +16,4 @@
<com.android.launcher3.BubbleTextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/WorkspaceIcon"
- android:focusable="true"
- android:background="@drawable/focusable_view_bg" />
+ android:focusable="true" />
diff --git a/res/layout/apps_customize_application.xml b/res/layout/apps_customize_application.xml
index b48b9b7..17f4a8e 100644
--- a/res/layout/apps_customize_application.xml
+++ b/res/layout/apps_customize_application.xml
@@ -20,5 +20,4 @@
style="@style/WorkspaceIcon.AppsCustomize"
android:id="@+id/application_icon"
- android:focusable="true"
- android:background="@drawable/focusable_view_bg" />
+ android:focusable="true" />
diff --git a/res/layout/folder_application.xml b/res/layout/folder_application.xml
index 37dd79d..b48b613 100644
--- a/res/layout/folder_application.xml
+++ b/res/layout/folder_application.xml
@@ -16,5 +16,4 @@
<com.android.launcher3.BubbleTextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/WorkspaceIcon.Folder"
- android:focusable="true"
- android:background="@drawable/focusable_view_bg" />
+ android:focusable="true" />
diff --git a/res/layout/folder_icon.xml b/res/layout/folder_icon.xml
index 5147f99..fd45d76 100644
--- a/res/layout/folder_icon.xml
+++ b/res/layout/folder_icon.xml
@@ -19,8 +19,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- android:focusable="true"
- android:background="@drawable/focusable_view_bg">
+ android:focusable="true" >
<ImageView
android:id="@+id/preview_background"
android:layout_gravity="center_horizontal"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 4e64d41..5e9c6ec 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -24,6 +24,7 @@
<color name="info_target_hover_tint">#DA0099CC</color>
<color name="bubble_dark_background">#20000000</color>
+ <color name="focused_background">#80c6c5c5</color>
<color name="appwidget_error_color">#FCCC</color>
diff --git a/src/com/android/launcher3/AppsCustomizeCellLayout.java b/src/com/android/launcher3/AppsCustomizeCellLayout.java
index 3c8bda9..76b81d2 100644
--- a/src/com/android/launcher3/AppsCustomizeCellLayout.java
+++ b/src/com/android/launcher3/AppsCustomizeCellLayout.java
@@ -20,8 +20,16 @@ import android.content.Context;
import android.view.View;
public class AppsCustomizeCellLayout extends CellLayout implements Page {
+
+ final FocusIndicatorView mFocusHandlerView;
+
public AppsCustomizeCellLayout(Context context) {
super(context);
+
+ mFocusHandlerView = new FocusIndicatorView(context);
+ addView(mFocusHandlerView, 0);
+ mFocusHandlerView.getLayoutParams().width = FocusIndicatorView.DEFAULT_LAYOUT_SIZE;
+ mFocusHandlerView.getLayoutParams().height = FocusIndicatorView.DEFAULT_LAYOUT_SIZE;
}
@Override
diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java
index e0543ce..f78cff0 100644
--- a/src/com/android/launcher3/AppsCustomizePagedView.java
+++ b/src/com/android/launcher3/AppsCustomizePagedView.java
@@ -1041,6 +1041,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
icon.setOnLongClickListener(this);
icon.setOnTouchListener(this);
icon.setOnKeyListener(this);
+ icon.setOnFocusChangeListener(layout.mFocusHandlerView);
int index = i - startIndex;
int x = index % mCellCountX;
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 1073764..07120c5 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -989,10 +989,7 @@ public class CellLayout extends ViewGroup {
}
public ShortcutAndWidgetContainer getShortcutsAndWidgets() {
- if (getChildCount() > 0) {
- return (ShortcutAndWidgetContainer) getChildAt(0);
- }
- return null;
+ return mShortcutsAndWidgets;
}
public View getChildAt(int x, int y) {
diff --git a/src/com/android/launcher3/FocusIndicatorView.java b/src/com/android/launcher3/FocusIndicatorView.java
new file mode 100644
index 0000000..12b7a40
--- /dev/null
+++ b/src/com/android/launcher3/FocusIndicatorView.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2011 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.content.Context;
+import android.graphics.Canvas;
+import android.util.AttributeSet;
+import android.util.Pair;
+import android.view.View;
+import android.view.ViewParent;
+
+public class FocusIndicatorView extends View implements View.OnFocusChangeListener {
+
+ // It can be any number >0. The view is resized using scaleX and scaleY.
+ static final int DEFAULT_LAYOUT_SIZE = 100;
+ private static final float MIN_VISIBLE_ALPHA = 0.2f;
+
+ private static final int[] sTempPos = new int[2];
+ private static final int[] sTempShift = new int[2];
+
+ private final int[] mIndicatorPos = new int[2];
+ private final int[] mTargetViewPos = new int[2];
+
+ private View mLastFocusedView;
+ private boolean mInitiated;
+
+ private Pair<View, Boolean> mPendingCall;
+
+ public FocusIndicatorView(Context context) {
+ this(context, null);
+ }
+
+ public FocusIndicatorView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setAlpha(0);
+ setBackgroundColor(getResources().getColor(R.color.focused_background));
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+
+ // Redraw if it is already showing. This avoids a bug where the height changes by a small
+ // amount on connecting/disconnecting a bluetooth keyboard.
+ if (mLastFocusedView != null) {
+ mPendingCall = Pair.create(mLastFocusedView, Boolean.TRUE);
+ invalidate();
+ }
+ }
+
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ mPendingCall = null;
+ if (!mInitiated && (getWidth() == 0)) {
+ // View not yet laid out. Wait until the view is ready to be drawn, so that be can
+ // get the location on screen.
+ mPendingCall = Pair.create(v, hasFocus);
+ invalidate();
+ return;
+ }
+
+ if (!mInitiated) {
+ getLocationRelativeToParentPagedView(this, mIndicatorPos);
+ mInitiated = true;
+ }
+
+ if (hasFocus) {
+ int indicatorWidth = getWidth();
+ int indicatorHeight = getHeight();
+
+ float scaleX = v.getScaleX() * v.getWidth() / indicatorWidth;
+ float scaleY = v.getScaleY() * v.getHeight() / indicatorHeight;
+
+ getLocationRelativeToParentPagedView(v, mTargetViewPos);
+ float x = mTargetViewPos[0] - mIndicatorPos[0] - (1 - scaleX) * indicatorWidth / 2;
+ float y = mTargetViewPos[1] - mIndicatorPos[1] - (1 - scaleY) * indicatorHeight / 2;
+
+ if (getAlpha() > MIN_VISIBLE_ALPHA) {
+ animate()
+ .translationX(x)
+ .translationY(y)
+ .scaleX(scaleX)
+ .scaleY(scaleY)
+ .alpha(1);
+ } else {
+ setTranslationX(x);
+ setTranslationY(y);
+ setScaleX(scaleX);
+ setScaleY(scaleY);
+ animate().alpha(1);
+ }
+ mLastFocusedView = v;
+ } else {
+ if (mLastFocusedView == v) {
+ mLastFocusedView = null;
+ animate().alpha(0);
+ }
+ }
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (mPendingCall != null) {
+ onFocusChange(mPendingCall.first, mPendingCall.second);
+ }
+ }
+
+ /**
+ * Gets the location of a view relative in the window, off-setting any shift due to
+ * page view scroll
+ */
+ private static void getLocationRelativeToParentPagedView(View v, int[] pos) {
+ getPagedViewScrollShift(v, sTempShift);
+ v.getLocationInWindow(sTempPos);
+ pos[0] = sTempPos[0] + sTempShift[0];
+ pos[1] = sTempPos[1] + sTempShift[1];
+ }
+
+ private static void getPagedViewScrollShift(View child, int[] shift) {
+ ViewParent parent = child.getParent();
+ if (parent instanceof PagedView) {
+ View parentView = (View) parent;
+ child.getLocationInWindow(sTempPos);
+ shift[0] = parentView.getPaddingLeft() - sTempPos[0];
+ shift[1] = -(int) child.getTranslationY();
+ } else if (parent instanceof View) {
+ getPagedViewScrollShift((View) parent, shift);
+ } else {
+ shift[0] = shift[1] = 0;
+ }
+ }
+}
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index fcedaea..4a70771 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -112,6 +112,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
private static String sDefaultFolderName;
private static String sHintText;
+ private FocusIndicatorView mFocusIndicatorHandler;
+
private int DRAG_MODE_NONE = 0;
private int DRAG_MODE_REORDER = 1;
private int mDragMode = DRAG_MODE_NONE;
@@ -178,6 +180,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mScrollView = (ScrollView) findViewById(R.id.scroll_view);
mContent = (CellLayout) findViewById(R.id.folder_content);
+ mFocusIndicatorHandler = new FocusIndicatorView(getContext());
+ mContent.addView(mFocusIndicatorHandler, 0);
+ mFocusIndicatorHandler.getLayoutParams().height = FocusIndicatorView.DEFAULT_LAYOUT_SIZE;
+ mFocusIndicatorHandler.getLayoutParams().width = FocusIndicatorView.DEFAULT_LAYOUT_SIZE;
+
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
@@ -572,6 +579,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
textView.setOnClickListener(this);
textView.setOnLongClickListener(this);
+ textView.setOnFocusChangeListener(mFocusIndicatorHandler);
// We need to check here to verify that the given item's location isn't already occupied
// by another item.
diff --git a/src/com/android/launcher3/FolderIcon.java b/src/com/android/launcher3/FolderIcon.java
index c0b9da7..21efd71 100644
--- a/src/com/android/launcher3/FolderIcon.java
+++ b/src/com/android/launcher3/FolderIcon.java
@@ -178,6 +178,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
icon.mFolderRingAnimator = new FolderRingAnimator(launcher, icon);
folderInfo.addListener(icon);
+ icon.setOnFocusChangeListener(launcher.mFocusHandler);
return icon;
}
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index 79cac8f..3d6befa 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -159,6 +159,7 @@ public class Hotseat extends FrameLayout {
allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
mLauncher.setAllAppsButton(allAppsButton);
allAppsButton.setOnClickListener(mLauncher);
+ allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
}
// Note: We do this to ensure that the hotseat is always laid out in the orientation of
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 062e848..c9d423c 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -384,6 +384,8 @@ public class Launcher extends Activity
private Stats mStats;
+ FocusIndicatorView mFocusHandler;
+
static boolean isPropertyEnabled(String propertyName) {
return Log.isLoggable(propertyName, Log.VERBOSE);
}
@@ -1289,6 +1291,7 @@ public class Launcher extends Activity
final DragController dragController = mDragController;
mLauncherView = findViewById(R.id.launcher);
+ mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
mWorkspace.setPageSwitchListener(this);
@@ -1428,6 +1431,7 @@ public class Launcher extends Activity
BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
favorite.applyFromShortcutInfo(info, mIconCache, true);
favorite.setOnClickListener(this);
+ favorite.setOnFocusChangeListener(mFocusHandler);
return favorite;
}