summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/FastBitmapDrawable.java2
-rw-r--r--src/com/android/launcher3/LauncherProvider.java92
-rw-r--r--src/com/android/launcher3/compat/AppWidgetManagerCompatVO.java16
-rw-r--r--src/com/android/launcher3/notification/NotificationHeaderView.java59
-rw-r--r--src/com/android/launcher3/notification/NotificationInfo.java16
-rw-r--r--src/com/android/launcher3/notification/NotificationItemView.java21
-rw-r--r--src/com/android/launcher3/popup/PopupContainerWithArrow.java27
-rw-r--r--src/com/android/launcher3/popup/PopupPopulator.java23
-rw-r--r--src/com/android/launcher3/popup/SystemShortcut.java17
-rw-r--r--src/com/android/launcher3/shortcuts/DeepShortcutTextView.java2
-rw-r--r--src/com/android/launcher3/shortcuts/ShortcutsItemView.java13
-rw-r--r--src/com/android/launcher3/widget/WidgetsAndMore.java64
12 files changed, 149 insertions, 203 deletions
diff --git a/src/com/android/launcher3/FastBitmapDrawable.java b/src/com/android/launcher3/FastBitmapDrawable.java
index 5a44f7504..be3ba9014 100644
--- a/src/com/android/launcher3/FastBitmapDrawable.java
+++ b/src/com/android/launcher3/FastBitmapDrawable.java
@@ -167,7 +167,7 @@ public class FastBitmapDrawable extends Drawable {
}
}
- protected IconPalette getIconPalette() {
+ public IconPalette getIconPalette() {
if (mIconPalette == null) {
mIconPalette = IconPalette.fromDominantColor(Utilities
.findDominantColorByHue(mBitmap, 20));
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 65d76728d..630274469 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -76,7 +76,18 @@ public class LauncherProvider extends ContentProvider {
private static final String TAG = "LauncherProvider";
private static final boolean LOGD = false;
- private static final int DATABASE_VERSION = 28;
+ /**
+ * Represents the schema of the database. Changes in scheme need not be backwards compatible.
+ */
+ private static final int SCHEMA_VERSION = 27;
+ /**
+ * Represents the actual data. It could include additional validations and normalizations added
+ * overtime. These must be backwards compatible, else we risk breaking old devices during
+ * restore or binary version downgrade.
+ */
+ private static final int DATA_VERSION = 2;
+
+ private static final String PREF_KEY_DATA_VERISON = "provider_data_version";
public static final String AUTHORITY = ProviderConfig.AUTHORITY;
@@ -599,7 +610,7 @@ public class LauncherProvider extends ContentProvider {
*/
public DatabaseHelper(
Context context, Handler widgetHostResetHandler, String tableName) {
- super(new NoLocaleSqliteContext(context), tableName, null, DATABASE_VERSION);
+ super(new NoLocaleSqliteContext(context), tableName, null, SCHEMA_VERSION);
mContext = context;
mWidgetHostResetHandler = widgetHostResetHandler;
}
@@ -711,6 +722,55 @@ public class LauncherProvider extends ContentProvider {
}
@Override
+ public void onOpen(SQLiteDatabase db) {
+ super.onOpen(db);
+ SharedPreferences prefs = mContext
+ .getSharedPreferences(LauncherFiles.DEVICE_PREFERENCES_KEY, 0);
+ int oldVersion = prefs.getInt(PREF_KEY_DATA_VERISON, 0);
+ if (oldVersion != DATA_VERSION) {
+ // Only run the data upgrade path for an existing db.
+ if (!Utilities.getPrefs(mContext).getBoolean(EMPTY_DATABASE_CREATED, false)) {
+ db.beginTransaction();
+ try {
+ onDataUpgrade(db, oldVersion);
+ db.setTransactionSuccessful();
+ } catch (Exception e) {
+ Log.d(TAG, "Error updating data version, ignoring", e);
+ return;
+ } finally {
+ db.endTransaction();
+ }
+ }
+ prefs.edit().putInt(PREF_KEY_DATA_VERISON, DATA_VERSION).apply();
+ }
+ }
+
+ /**
+ * Called when the data is updated as part of app update. It can be called multiple times
+ * with old version, even though it had been run before. The changes made here must be
+ * backwards compatible, else we risk breaking old devices during restore or binary
+ * version downgrade.
+ */
+ protected void onDataUpgrade(SQLiteDatabase db, int oldVersion) {
+ switch (oldVersion) {
+ case 0:
+ case 1: {
+ // Remove "profile extra"
+ UserManagerCompat um = UserManagerCompat.getInstance(mContext);
+ for (UserHandle user : um.getUserProfiles()) {
+ long serial = um.getSerialNumberForUser(user);
+ String sql = "update favorites set intent = replace(intent, "
+ + "';l.profile=" + serial + ";', ';') where itemType = 0;";
+ db.execSQL(sql);
+ }
+ }
+ case 2:
+ // data updated
+ return;
+ }
+ }
+
+ @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (LOGD) Log.d(TAG, "onUpgrade triggered: " + oldVersion);
switch (oldVersion) {
@@ -807,30 +867,9 @@ public class LauncherProvider extends ContentProvider {
!LauncherDbUtils.prepareScreenZeroToHostQsb(mContext, db)) {
break;
}
- case 27: {
- // Remove "profile extra"
- db.beginTransaction();
- try {
- UserManagerCompat um = UserManagerCompat.getInstance(mContext);
- for (UserHandle user : um.getUserProfiles()) {
- long serial = um.getSerialNumberForUser(user);
- String sql = "update favorites set intent = replace(intent, "
- + "';l.profile=" + serial + ";', ';') where itemType = 0;";
- db.execSQL(sql);
- }
- db.setTransactionSuccessful();
- } catch (SQLException ex) {
- Log.e(TAG, ex.getMessage(), ex);
- // Old version remains, which means we wipe old data
- break;
- } finally {
- db.endTransaction();
- }
- }
- case 28: {
+ case 27:
// DB Upgraded successfully
return;
- }
}
// DB was not upgraded
@@ -840,6 +879,11 @@ public class LauncherProvider extends ContentProvider {
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ if (oldVersion == 28 && newVersion == 27) {
+ // TODO: remove this check. This is only applicable for internal development/testing
+ // and for any released version of Launcher.
+ return;
+ }
// This shouldn't happen -- throw our hands up in the air and start over.
Log.w(TAG, "Database version downgrade from: " + oldVersion + " to " + newVersion +
". Wiping databse.");
diff --git a/src/com/android/launcher3/compat/AppWidgetManagerCompatVO.java b/src/com/android/launcher3/compat/AppWidgetManagerCompatVO.java
index bde8b7801..1c48a13bd 100644
--- a/src/com/android/launcher3/compat/AppWidgetManagerCompatVO.java
+++ b/src/com/android/launcher3/compat/AppWidgetManagerCompatVO.java
@@ -16,17 +16,12 @@
package com.android.launcher3.compat;
-import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
-import android.os.UserHandle;
-import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import android.util.Log;
import com.android.launcher3.util.PackageUserKey;
-import java.lang.reflect.InvocationTargetException;
import java.util.List;
class AppWidgetManagerCompatVO extends AppWidgetManagerCompatVL {
@@ -40,14 +35,7 @@ class AppWidgetManagerCompatVO extends AppWidgetManagerCompatVL {
if (packageUser == null) {
return super.getAllProviders(null);
}
- // TODO: don't use reflection once API and sdk are ready.
- try {
- return (List<AppWidgetProviderInfo>) AppWidgetManager.class.getMethod(
- "getInstalledProvidersForPackage", String.class, UserHandle.class)
- .invoke(mAppWidgetManager, packageUser.mPackageName, packageUser.mUser);
- } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
- Log.e("AppWidgetManagerCompat", "Failed to call new API", e);
- }
- return super.getAllProviders(packageUser);
+ return mAppWidgetManager.getInstalledProvidersForPackage(packageUser.mPackageName,
+ packageUser.mUser);
}
}
diff --git a/src/com/android/launcher3/notification/NotificationHeaderView.java b/src/com/android/launcher3/notification/NotificationHeaderView.java
deleted file mode 100644
index e70b48949..000000000
--- a/src/com/android/launcher3/notification/NotificationHeaderView.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2017 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.notification;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import com.android.launcher3.R;
-
-/**
- * A {@link LinearLayout} that contains two text views: one for the notification count
- * and one just to say "Notification" or "Notifications"
- */
-public class NotificationHeaderView extends LinearLayout {
-
- private TextView mNotificationCount;
- private TextView mNotificationText;
-
- public NotificationHeaderView(Context context) {
- this(context, null, 0);
- }
-
- public NotificationHeaderView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public NotificationHeaderView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- mNotificationCount = (TextView) findViewById(R.id.notification_count);
- mNotificationText = (TextView) findViewById(R.id.notification_text);
- }
-
- public void update(int notificationCount) {
- mNotificationCount.setText(String.valueOf(notificationCount));
- mNotificationText.setText(getResources().getQuantityString(
- R.plurals.notifications_header, notificationCount));
- }
-}
diff --git a/src/com/android/launcher3/notification/NotificationInfo.java b/src/com/android/launcher3/notification/NotificationInfo.java
index 0b41743b9..1a93e1155 100644
--- a/src/com/android/launcher3/notification/NotificationInfo.java
+++ b/src/com/android/launcher3/notification/NotificationInfo.java
@@ -25,7 +25,6 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.service.notification.StatusBarNotification;
-import android.util.Log;
import android.view.View;
import com.android.launcher3.Launcher;
@@ -66,20 +65,7 @@ public class NotificationInfo implements View.OnClickListener {
title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
- // TODO(b/36855196): use getBadgeIconType() without reflection
- int badgeIcon = Notification.BADGE_ICON_NONE;
- try {
- badgeIcon = (int) Notification.class.getMethod("getBadgeIconType").invoke(notification);
- } catch (Exception e) {
- Log.w("NotificationInfo", "getBadgeIconType() failed", e);
- // Try the old name, getBadgeIcon(), instead.
- try {
- badgeIcon = (int) Notification.class.getMethod("getBadgeIcon").invoke(notification);
- } catch (Exception e1) {
- Log.e("NotificationInfo", "getBadgeIcon() failed", e);
- }
- }
- mBadgeIcon = badgeIcon;
+ mBadgeIcon = notification.getBadgeIconType();
// Load the icon. Since it is backed by ashmem, we won't copy the entire bitmap
// into our process as long as we don't touch it and it exists in systemui.
Icon icon = mBadgeIcon == Notification.BADGE_ICON_SMALL ? null : notification.getLargeIcon();
diff --git a/src/com/android/launcher3/notification/NotificationItemView.java b/src/com/android/launcher3/notification/NotificationItemView.java
index 37b8325ea..5e8e2c768 100644
--- a/src/com/android/launcher3/notification/NotificationItemView.java
+++ b/src/com/android/launcher3/notification/NotificationItemView.java
@@ -17,16 +17,20 @@
package com.android.launcher3.notification;
import android.animation.Animator;
+import android.app.Notification;
import android.content.Context;
import android.graphics.Rect;
+import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
+import android.widget.TextView;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.anim.PillHeightRevealOutlineProvider;
+import com.android.launcher3.graphics.IconPalette;
import com.android.launcher3.logging.UserEventDispatcher.LogContainerProvider;
import com.android.launcher3.popup.PopupItemView;
import com.android.launcher3.userevent.nano.LauncherLogProto;
@@ -43,11 +47,12 @@ public class NotificationItemView extends PopupItemView implements LogContainerP
private static final Rect sTempRect = new Rect();
- private NotificationHeaderView mHeader;
+ private TextView mHeaderCount;
private NotificationMainView mMainView;
private NotificationFooterLayout mFooter;
private SwipeHelper mSwipeHelper;
private boolean mAnimatingNextIcon;
+ private int mNotificationHeaderTextColor = Notification.COLOR_DEFAULT;
public NotificationItemView(Context context) {
this(context, null, 0);
@@ -64,7 +69,7 @@ public class NotificationItemView extends PopupItemView implements LogContainerP
@Override
protected void onFinishInflate() {
super.onFinishInflate();
- mHeader = (NotificationHeaderView) findViewById(R.id.header);
+ mHeaderCount = (TextView) findViewById(R.id.notification_count);
mMainView = (NotificationMainView) findViewById(R.id.main_view);
mFooter = (NotificationFooterLayout) findViewById(R.id.footer);
mSwipeHelper = new SwipeHelper(SwipeHelper.X, mMainView, getContext());
@@ -77,8 +82,16 @@ public class NotificationItemView extends PopupItemView implements LogContainerP
getBackgroundRadius(), newHeight).createRevealAnimator(this, true /* isReversed */);
}
- public void updateHeader(int notificationCount) {
- mHeader.update(notificationCount);
+ public void updateHeader(int notificationCount, @Nullable IconPalette palette) {
+ mHeaderCount.setText(notificationCount <= 1 ? "" : String.valueOf(notificationCount));
+ if (palette != null) {
+ if (mNotificationHeaderTextColor == Notification.COLOR_DEFAULT) {
+ mNotificationHeaderTextColor =
+ IconPalette.resolveContrastColor(getContext(), palette.dominantColor,
+ getResources().getColor(R.color.notification_header_background_color));
+ }
+ mHeaderCount.setTextColor(mNotificationHeaderTextColor);
+ }
}
@Override
diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
index b92814fab..d2512def5 100644
--- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java
+++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
@@ -46,6 +46,7 @@ import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
+import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
@@ -62,6 +63,7 @@ import com.android.launcher3.badge.BadgeInfo;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
+import com.android.launcher3.graphics.IconPalette;
import com.android.launcher3.graphics.TriangleShape;
import com.android.launcher3.notification.NotificationItemView;
import com.android.launcher3.notification.NotificationKeyData;
@@ -158,12 +160,12 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
public void populateAndShow(final BubbleTextView originalIcon, final List<String> shortcutIds,
final List<NotificationKeyData> notificationKeys) {
final Resources resources = getResources();
- final int arrowWidth = resources.getDimensionPixelSize(R.dimen.deep_shortcuts_arrow_width);
- final int arrowHeight = resources.getDimensionPixelSize(R.dimen.deep_shortcuts_arrow_height);
+ final int arrowWidth = resources.getDimensionPixelSize(R.dimen.popup_arrow_width);
+ final int arrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height);
final int arrowHorizontalOffset = resources.getDimensionPixelSize(
- R.dimen.deep_shortcuts_arrow_horizontal_offset);
+ R.dimen.popup_arrow_horizontal_offset);
final int arrowVerticalOffset = resources.getDimensionPixelSize(
- R.dimen.deep_shortcuts_arrow_vertical_offset);
+ R.dimen.popup_arrow_vertical_offset);
// Add dummy views first, and populate with real info when ready.
PopupPopulator.Item[] itemsToPopulate = PopupPopulator
@@ -195,7 +197,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
if (mNotificationItemView != null) {
BadgeInfo badgeInfo = mLauncher.getPopupDataProvider()
.getBadgeInfoForItem(originalItemInfo);
- updateNotificationHeader(badgeInfo);
+ updateNotificationHeader(badgeInfo, originalIcon);
}
// Add the arrow.
@@ -247,7 +249,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
R.layout.shortcuts_item, this, false);
addView(mShortcutsItemView);
}
- mShortcutsItemView.addShortcutView(item, itemTypeToPopulate, mIsAboveIcon);
+ mShortcutsItemView.addShortcutView(item, itemTypeToPopulate);
if (shouldAddBottomMargin) {
((LayoutParams) mShortcutsItemView.getLayoutParams()).bottomMargin = spacing;
}
@@ -384,14 +386,14 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
// Aligning with the shortcut icon.
int shortcutIconWidth = resources.getDimensionPixelSize(R.dimen.deep_shortcut_icon_size);
int shortcutPaddingStart = resources.getDimensionPixelSize(
- R.dimen.deep_shortcut_padding_start);
+ R.dimen.popup_padding_start);
xOffset = iconWidth / 2 - shortcutIconWidth / 2 - shortcutPaddingStart;
} else {
// Aligning with the drag handle.
int shortcutDragHandleWidth = resources.getDimensionPixelSize(
R.dimen.deep_shortcut_drag_handle_size);
int shortcutPaddingEnd = resources.getDimensionPixelSize(
- R.dimen.deep_shortcut_padding_end);
+ R.dimen.popup_padding_end);
xOffset = iconWidth / 2 - shortcutDragHandleWidth / 2 - shortcutPaddingEnd;
}
x += mIsLeftAligned ? xOffset : -xOffset;
@@ -548,12 +550,15 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
if (originalItemInfo != mOriginalIcon.getTag()) {
return;
}
- updateNotificationHeader(badgeInfo);
+ updateNotificationHeader(badgeInfo, mOriginalIcon);
}
- private void updateNotificationHeader(BadgeInfo badgeInfo) {
+ private void updateNotificationHeader(BadgeInfo badgeInfo, BubbleTextView originalIcon) {
if (mNotificationItemView != null && badgeInfo != null) {
- mNotificationItemView.updateHeader(badgeInfo.getNotificationCount());
+ IconPalette palette = originalIcon.getIcon() instanceof FastBitmapDrawable
+ ? ((FastBitmapDrawable) originalIcon.getIcon()).getIconPalette()
+ : null;
+ mNotificationItemView.updateHeader(badgeInfo.getNotificationCount(), palette);
}
}
diff --git a/src/com/android/launcher3/popup/PopupPopulator.java b/src/com/android/launcher3/popup/PopupPopulator.java
index d26d3062b..112889474 100644
--- a/src/com/android/launcher3/popup/PopupPopulator.java
+++ b/src/com/android/launcher3/popup/PopupPopulator.java
@@ -17,7 +17,7 @@
package com.android.launcher3.popup;
import android.content.ComponentName;
-import android.content.res.Resources;
+import android.content.Context;
import android.os.Handler;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
@@ -54,6 +54,7 @@ public class PopupPopulator {
public static final int MAX_ITEMS = 4;
@VisibleForTesting static final int NUM_DYNAMIC = 2;
+ private static final int MAX_SHORTCUTS_IF_NOTIFICATIONS = 2;
public enum Item {
SHORTCUT(R.layout.deep_shortcut, true),
@@ -74,7 +75,11 @@ public class PopupPopulator {
@NonNull List<NotificationKeyData> notificationKeys) {
boolean hasNotifications = notificationKeys.size() > 0;
int numNotificationItems = hasNotifications ? 1 : 0;
- int numItems = Math.min(MAX_ITEMS, shortcutIds.size() + numNotificationItems)
+ int numShortcuts = shortcutIds.size();
+ if (hasNotifications && numShortcuts > MAX_SHORTCUTS_IF_NOTIFICATIONS) {
+ numShortcuts = MAX_SHORTCUTS_IF_NOTIFICATIONS;
+ }
+ int numItems = Math.min(MAX_ITEMS, numShortcuts + numNotificationItems)
+ PopupDataProvider.SYSTEM_SHORTCUTS.length;
Item[] items = new Item[numItems];
for (int i = 0; i < numItems; i++) {
@@ -288,15 +293,19 @@ public class PopupPopulator {
@Override
public void run() {
- final Resources res = mSystemShortcutChild.getResources();
+ final Context context = mSystemShortcutChild.getContext();
if (mSystemShortcutChild instanceof DeepShortcutView) {
+ // Expanded system shortcut, with both icon and text shown on white background.
final DeepShortcutView shortcutView = (DeepShortcutView) mSystemShortcutChild;
- shortcutView.getIconView().setBackground(mSystemShortcutInfo.getIcon(res));
- shortcutView.getBubbleText().setText(mSystemShortcutInfo.getLabel(res));
+ shortcutView.getIconView().setBackground(mSystemShortcutInfo.getIcon(context,
+ android.R.attr.textColorTertiary));
+ shortcutView.getBubbleText().setText(mSystemShortcutInfo.getLabel(context));
} else if (mSystemShortcutChild instanceof ImageView) {
+ // Only the system shortcut icon shows on a gray background header.
final ImageView shortcutIcon = (ImageView) mSystemShortcutChild;
- shortcutIcon.setImageDrawable(mSystemShortcutInfo.getIcon(res));
- shortcutIcon.setContentDescription(mSystemShortcutInfo.getLabel(res));
+ shortcutIcon.setImageDrawable(mSystemShortcutInfo.getIcon(context,
+ android.R.attr.textColorHint));
+ shortcutIcon.setContentDescription(mSystemShortcutInfo.getLabel(context));
}
if (!(mSystemShortcutInfo instanceof SystemShortcut.Widgets)) {
mSystemShortcutChild.setOnClickListener(mSystemShortcutInfo
diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java
index d94db43b8..fa70de911 100644
--- a/src/com/android/launcher3/popup/SystemShortcut.java
+++ b/src/com/android/launcher3/popup/SystemShortcut.java
@@ -1,6 +1,6 @@
package com.android.launcher3.popup;
-import android.content.res.Resources;
+import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
@@ -10,6 +10,7 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.PackageUserKey;
+import com.android.launcher3.util.Themes;
import com.android.launcher3.widget.WidgetsAndMore;
import java.util.List;
@@ -29,14 +30,14 @@ public abstract class SystemShortcut {
mLabelResId = labelResId;
}
- public Drawable getIcon(Resources resources) {
- Drawable icon = resources.getDrawable(mIconResId);
- icon.setTint(resources.getColor(R.color.system_shortcuts_icon_color));
+ public Drawable getIcon(Context context, int colorAttr) {
+ Drawable icon = context.getResources().getDrawable(mIconResId);
+ icon.setTint(Themes.getAttrColor(context, colorAttr));
return icon;
}
- public String getLabel(Resources resources) {
- return resources.getString(mLabelResId);
+ public String getLabel(Context context) {
+ return context.getString(mLabelResId);
}
public abstract View.OnClickListener getOnClickListener(final Launcher launcher,
@@ -46,7 +47,7 @@ public abstract class SystemShortcut {
public static class Widgets extends SystemShortcut {
public Widgets() {
- super(R.drawable.ic_widget, R.string.widgets_and_more);
+ super(R.drawable.ic_widget, R.string.widget_button_text);
}
@Override
@@ -72,7 +73,7 @@ public abstract class SystemShortcut {
public static class AppInfo extends SystemShortcut {
public AppInfo() {
- super(R.drawable.ic_info_launcher, R.string.app_info_drop_target_label);
+ super(R.drawable.ic_info_no_shadow, R.string.app_info_drop_target_label);
}
@Override
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
index 42086fcb5..1a5297dc7 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
@@ -47,7 +47,7 @@ public class DeepShortcutTextView extends BubbleTextView {
super(context, attrs, defStyle);
Resources resources = getResources();
- mDragHandleWidth = resources.getDimensionPixelSize(R.dimen.deep_shortcut_padding_end)
+ mDragHandleWidth = resources.getDimensionPixelSize(R.dimen.popup_padding_end)
+ resources.getDimensionPixelSize(R.dimen.deep_shortcut_drag_handle_size)
+ resources.getDimensionPixelSize(R.dimen.deep_shortcut_drawable_padding) / 2;
}
diff --git a/src/com/android/launcher3/shortcuts/ShortcutsItemView.java b/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
index 2255007d3..1f90bb023 100644
--- a/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
+++ b/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
@@ -118,8 +118,7 @@ public class ShortcutsItemView extends PopupItemView implements View.OnLongClick
return false;
}
- public void addShortcutView(View shortcutView, PopupPopulator.Item shortcutType,
- boolean isAboveIcon) {
+ public void addShortcutView(View shortcutView, PopupPopulator.Item shortcutType) {
if (shortcutType == PopupPopulator.Item.SHORTCUT) {
mDeepShortcutViews.add((DeepShortcutView) shortcutView);
} else {
@@ -130,11 +129,7 @@ public class ShortcutsItemView extends PopupItemView implements View.OnLongClick
if (mSystemShortcutIcons == null) {
mSystemShortcutIcons = (LinearLayout) mLauncher.getLayoutInflater().inflate(
R.layout.system_shortcut_icons, mShortcutsLayout, false);
- if (isAboveIcon) {
- mShortcutsLayout.addView(mSystemShortcutIcons, 0);
- } else {
- mShortcutsLayout.addView(mSystemShortcutIcons);
- }
+ mShortcutsLayout.addView(mSystemShortcutIcons, 0);
}
mSystemShortcutIcons.addView(shortcutView);
} else {
@@ -156,7 +151,9 @@ public class ShortcutsItemView extends PopupItemView implements View.OnLongClick
}
public List<View> getSystemShortcutViews(boolean reverseOrder) {
- if (reverseOrder) {
+ // Always reverse system shortcut icons (in the header)
+ // so they are in priority order from right to left.
+ if (reverseOrder || mSystemShortcutIcons != null) {
Collections.reverse(mSystemShortcutViews);
}
return mSystemShortcutViews;
diff --git a/src/com/android/launcher3/widget/WidgetsAndMore.java b/src/com/android/launcher3/widget/WidgetsAndMore.java
index 1aea534fd..401337b16 100644
--- a/src/com/android/launcher3/widget/WidgetsAndMore.java
+++ b/src/com/android/launcher3/widget/WidgetsAndMore.java
@@ -24,6 +24,7 @@ import android.graphics.Rect;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -49,12 +50,8 @@ import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.TouchController;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import static android.R.attr.bottom;
-
/**
* Bottom sheet for the "Widgets & more" long-press option.
*/
@@ -101,7 +98,8 @@ public class WidgetsAndMore extends AbstractFloatingView implements Insettable,
public void populateAndShow(ItemInfo itemInfo) {
mOriginalItemInfo = itemInfo;
- ((TextView) findViewById(R.id.title)).setText(mOriginalItemInfo.title);
+ ((TextView) findViewById(R.id.title)).setText(getContext().getString(
+ R.string.widgets_bottom_sheet_title, mOriginalItemInfo.title));
onWidgetsBound();
@@ -118,70 +116,33 @@ public class WidgetsAndMore extends AbstractFloatingView implements Insettable,
protected void onWidgetsBound() {
List<WidgetItem> widgets = mLauncher.getWidgetsForPackageUser(new PackageUserKey(
mOriginalItemInfo.getTargetComponent().getPackageName(), mOriginalItemInfo.user));
- List<WidgetItem> shortcuts = new ArrayList<>();
- // Transfer configurable widgets to shortcuts
- Iterator<WidgetItem> widgetsIter = widgets.iterator();
- WidgetItem nextWidget;
- while (widgetsIter.hasNext()) {
- nextWidget = widgetsIter.next();
- if (nextWidget.activityInfo != null) {
- shortcuts.add(nextWidget);
- widgetsIter.remove();
- }
- }
ViewGroup widgetRow = (ViewGroup) findViewById(R.id.widgets);
ViewGroup widgetCells = (ViewGroup) widgetRow.findViewById(R.id.widgets_cell_list);
- ViewGroup shortcutRow = (ViewGroup) findViewById(R.id.shortcuts);
- ViewGroup shortcutCells = (ViewGroup) shortcutRow.findViewById(R.id.widgets_cell_list);
-
widgetCells.removeAllViews();
- shortcutCells.removeAllViews();
for (int i = 0; i < widgets.size(); i++) {
- addItemCell(widgetCells);
+ WidgetCell widget = addItemCell(widgetCells);
+ widget.applyFromCellItem(widgets.get(i), LauncherAppState.getInstance(mLauncher)
+ .getWidgetCache());
+ widget.ensurePreview();
+ widget.setVisibility(View.VISIBLE);
if (i < widgets.size() - 1) {
addDivider(widgetCells);
}
}
- for (int i = 0; i < shortcuts.size(); i++) {
- addItemCell(shortcutCells);
- if (i < shortcuts.size() - 1) {
- addDivider(shortcutCells);
- }
- }
- // Bind the views in the horizontal tray regions.
- if (widgetCells.getChildCount() > 0) {
- for (int i = 0; i < widgets.size(); i++) {
- WidgetCell widget = (WidgetCell) widgetCells.getChildAt(i*2); // skip dividers
- widget.applyFromCellItem(widgets.get(i), LauncherAppState.getInstance(mLauncher)
- .getWidgetCache());
- widget.ensurePreview();
- widget.setVisibility(View.VISIBLE);
- }
- } else {
- removeView(findViewById(R.id.widgets_header));
- }
- if (shortcutCells.getChildCount() > 0) {
- for (int i = 0; i < shortcuts.size(); i++) {
- WidgetCell shortcut = (WidgetCell) shortcutCells.getChildAt(i*2); // skip dividers
- shortcut.applyFromCellItem(shortcuts.get(i), LauncherAppState.getInstance(mLauncher)
- .getWidgetCache());
- shortcut.ensurePreview();
- shortcut.setVisibility(View.VISIBLE);
- }
- } else {
- removeView(findViewById(R.id.shortcuts_header));
- }
+ // If there is only one widget, we want to center it instead of left-align.
+ WidgetsAndMore.LayoutParams params = (WidgetsAndMore.LayoutParams) widgetRow.getLayoutParams();
+ params.gravity = widgets.size() == 1 ? Gravity.CENTER_HORIZONTAL : Gravity.START;
}
private void addDivider(ViewGroup parent) {
LayoutInflater.from(getContext()).inflate(R.layout.widget_list_divider, parent, true);
}
- private void addItemCell(ViewGroup parent) {
+ private WidgetCell addItemCell(ViewGroup parent) {
WidgetCell widget = (WidgetCell) LayoutInflater.from(getContext()).inflate(
R.layout.widget_cell, parent, false);
@@ -190,6 +151,7 @@ public class WidgetsAndMore extends AbstractFloatingView implements Insettable,
widget.setAnimatePreview(false);
parent.addView(widget);
+ return widget;
}
@Override