Blocking alpha animation if the initial and final state for the animation are both 0
am: 62e7518359
Change-Id: I3ac4f5be0726e2389e31a8fa3b18c5ca7d955c8c
diff --git a/AndroidManifest-common.xml b/AndroidManifest-common.xml
index 3da3535..bbe1f4a 100644
--- a/AndroidManifest-common.xml
+++ b/AndroidManifest-common.xml
@@ -50,7 +50,7 @@
android:fullBackupContent="@xml/backupscheme"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher_home"
- android:label="@string/app_name"
+ android:label="@string/derived_app_name"
android:largeHeap="@bool/config_largeHeap"
android:restoreAnyVersion="true"
android:supportsRtl="true" >
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3a3a28d..6c5990d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -55,7 +55,7 @@
android:fullBackupContent="@xml/backupscheme"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher_home"
- android:label="@string/app_name"
+ android:label="@string/derived_app_name"
android:largeHeap="@bool/config_largeHeap"
android:restoreAnyVersion="true"
android:supportsRtl="true" >
diff --git a/build.gradle b/build.gradle
index ffe4455..e103d79 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,8 +3,8 @@
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.0'
- classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
+ classpath 'com.android.tools.build:gradle:2.1.3'
+ classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
}
}
@@ -16,13 +16,11 @@
buildToolsVersion '24.0.0'
defaultConfig {
- applicationId "com.android.launcher3"
minSdkVersion 21
- targetSdkVersion 'N'
+ targetSdkVersion 25
versionCode 1
versionName "1.0"
- testApplicationId "com.android.launcher3.tests"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -30,11 +28,18 @@
minifyEnabled false
}
}
+
+ productFlavors {
+ aosp {
+ applicationId 'com.android.launcher3'
+ testApplicationId 'com.android.launcher3.tests'
+ }
+ }
sourceSets {
main {
res.srcDirs = ['res']
java.srcDirs = ['src', 'src_config']
- manifest.srcFile 'AndroidManifest.xml'
+ manifest.srcFile 'AndroidManifest-common.xml'
proto.srcDirs 'protos/'
}
@@ -42,6 +47,10 @@
java.srcDirs = ['tests/src']
manifest.srcFile "tests/AndroidManifest.xml"
}
+
+ aosp {
+ manifest.srcFile "AndroidManifest.xml"
+ }
}
}
@@ -65,5 +74,16 @@
// Configure the protoc executable
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0-alpha-3'
+
+ generateProtoTasks {
+ all().each { task ->
+ task.builtins {
+ remove java
+ javanano {
+ option 'ignore_services=false'
+ }
+ }
+ }
+ }
}
}
diff --git a/res/drawable-hdpi/workspace_bg.9.png b/res/drawable-hdpi/workspace_bg.9.png
old mode 100644
new mode 100755
index ff75186..1d82fd4
--- a/res/drawable-hdpi/workspace_bg.9.png
+++ b/res/drawable-hdpi/workspace_bg.9.png
Binary files differ
diff --git a/res/drawable-land-hdpi/workspace_bg.9.png b/res/drawable-land-hdpi/workspace_bg.9.png
deleted file mode 100644
index eecd6de..0000000
--- a/res/drawable-land-hdpi/workspace_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-land-mdpi/workspace_bg.9.png b/res/drawable-land-mdpi/workspace_bg.9.png
deleted file mode 100644
index 626f4a4..0000000
--- a/res/drawable-land-mdpi/workspace_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-land-xhdpi/workspace_bg.9.png b/res/drawable-land-xhdpi/workspace_bg.9.png
deleted file mode 100644
index 60f7d73..0000000
--- a/res/drawable-land-xhdpi/workspace_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-land-xxhdpi/workspace_bg.9.png b/res/drawable-land-xxhdpi/workspace_bg.9.png
deleted file mode 100644
index fc71a0f..0000000
--- a/res/drawable-land-xxhdpi/workspace_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/workspace_bg.9.png b/res/drawable-mdpi/workspace_bg.9.png
old mode 100644
new mode 100755
index c67c432..116ce44
--- a/res/drawable-mdpi/workspace_bg.9.png
+++ b/res/drawable-mdpi/workspace_bg.9.png
Binary files differ
diff --git a/res/drawable-sw720dp-hdpi/workspace_bg.9.png b/res/drawable-sw720dp-hdpi/workspace_bg.9.png
deleted file mode 100644
index ff75186..0000000
--- a/res/drawable-sw720dp-hdpi/workspace_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-sw720dp-mdpi/workspace_bg.9.png b/res/drawable-sw720dp-mdpi/workspace_bg.9.png
deleted file mode 100644
index c67c432..0000000
--- a/res/drawable-sw720dp-mdpi/workspace_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-sw720dp-xhdpi/workspace_bg.9.png b/res/drawable-sw720dp-xhdpi/workspace_bg.9.png
deleted file mode 100644
index 0b80cbf..0000000
--- a/res/drawable-sw720dp-xhdpi/workspace_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-sw720dp-xxhdpi/workspace_bg.9.png b/res/drawable-sw720dp-xxhdpi/workspace_bg.9.png
deleted file mode 100644
index 0d180c2..0000000
--- a/res/drawable-sw720dp-xxhdpi/workspace_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/workspace_bg.9.png b/res/drawable-xhdpi/workspace_bg.9.png
old mode 100644
new mode 100755
index 0b80cbf..b1b3b85
--- a/res/drawable-xhdpi/workspace_bg.9.png
+++ b/res/drawable-xhdpi/workspace_bg.9.png
Binary files differ
diff --git a/res/drawable-xxhdpi/workspace_bg.9.png b/res/drawable-xxhdpi/workspace_bg.9.png
old mode 100644
new mode 100755
index 0d180c2..d47f6b2
--- a/res/drawable-xxhdpi/workspace_bg.9.png
+++ b/res/drawable-xxhdpi/workspace_bg.9.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/workspace_bg.9.png b/res/drawable-xxxhdpi/workspace_bg.9.png
new file mode 100755
index 0000000..3281548
--- /dev/null
+++ b/res/drawable-xxxhdpi/workspace_bg.9.png
Binary files differ
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
index 2e64f6c..ef0dfdc 100644
--- a/res/layout-land/launcher.xml
+++ b/res/layout-land/launcher.xml
@@ -27,6 +27,7 @@
android:id="@+id/drag_layer"
android:clipChildren="false"
android:clipToPadding="false"
+ android:background="@drawable/workspace_bg"
android:importantForAccessibility="no"
android:layout_width="match_parent"
android:layout_height="match_parent">
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml
index d6e2802..49bac3b 100644
--- a/res/layout-port/launcher.xml
+++ b/res/layout-port/launcher.xml
@@ -29,6 +29,7 @@
android:clipChildren="false"
android:importantForAccessibility="no"
android:clipToPadding="false"
+ android:background="@drawable/workspace_bg"
android:layout_width="match_parent"
android:layout_height="match_parent">
diff --git a/res/layout-sw720dp/launcher.xml b/res/layout-sw720dp/launcher.xml
index fef80de..81d2e1b 100644
--- a/res/layout-sw720dp/launcher.xml
+++ b/res/layout-sw720dp/launcher.xml
@@ -28,6 +28,7 @@
android:clipChildren="false"
android:clipToPadding="false"
android:importantForAccessibility="no"
+ android:background="@drawable/workspace_bg"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -77,7 +78,8 @@
android:id="@+id/apps_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:visibility="invisible" />
+ android:visibility="invisible"
+ launcher:layout_ignoreInsets="true" />
</com.android.launcher3.dragndrop.DragLayer>
</com.android.launcher3.LauncherRootView>
diff --git a/res/values/config.xml b/res/values/config.xml
index 94f02f9..2347f66 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -9,6 +9,10 @@
<bool name="is_large_tablet">false</bool>
<bool name="allow_rotation">false</bool>
+ <!-- A string pointer to the original app name string. This allows derived projects to
+ easily override the app name without providing all translations -->
+ <string name="derived_app_name" translatable="false">@string/app_name</string>
+
<!-- DragController -->
<item type="id" name="drag_event_parity" />
diff --git a/src/com/android/launcher3/Alarm.java b/src/com/android/launcher3/Alarm.java
index e9f1fd9..d5b434c 100644
--- a/src/com/android/launcher3/Alarm.java
+++ b/src/com/android/launcher3/Alarm.java
@@ -17,6 +17,7 @@
package com.android.launcher3;
import android.os.Handler;
+import android.os.SystemClock;
public class Alarm implements Runnable{
// if we reach this time and the alarm hasn't been cancelled, call the listener
@@ -41,9 +42,16 @@
// Sets the alarm to go off in a certain number of milliseconds. If the alarm is already set,
// it's overwritten and only the new alarm setting is used
public void setAlarm(long millisecondsInFuture) {
- long currentTime = System.currentTimeMillis();
+ long currentTime = SystemClock.uptimeMillis();
mAlarmPending = true;
+ long oldTriggerTime = mAlarmTriggerTime;
mAlarmTriggerTime = currentTime + millisecondsInFuture;
+
+ // If the previous alarm was set for a longer duration, cancel it.
+ if (mWaitingForCallback && oldTriggerTime > mAlarmTriggerTime) {
+ mHandler.removeCallbacks(this);
+ mWaitingForCallback = false;
+ }
if (!mWaitingForCallback) {
mHandler.postDelayed(this, mAlarmTriggerTime - currentTime);
mWaitingForCallback = true;
@@ -51,15 +59,14 @@
}
public void cancelAlarm() {
- mAlarmTriggerTime = 0;
mAlarmPending = false;
}
// this is called when our timer runs out
public void run() {
mWaitingForCallback = false;
- if (mAlarmTriggerTime != 0) {
- long currentTime = System.currentTimeMillis();
+ if (mAlarmPending) {
+ long currentTime = SystemClock.uptimeMillis();
if (mAlarmTriggerTime > currentTime) {
// We still need to wait some time to trigger spring loaded mode--
// post a new callback
diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java
index e0694f3..604b164 100644
--- a/src/com/android/launcher3/AppInfo.java
+++ b/src/com/android/launcher3/AppInfo.java
@@ -125,11 +125,8 @@
}
@Override
- public String toString() {
- return "ApplicationInfo(title=" + title + " id=" + this.id
- + " type=" + this.itemType + " container=" + this.container
- + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
- + " spanX=" + spanX + " spanY=" + spanY + " user=" + user + ")";
+ protected String dumpProperties() {
+ return super.dumpProperties() + " componentName=" + componentName;
}
/**
diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java
index 0d5043b..d5309b4 100644
--- a/src/com/android/launcher3/AutoInstallsLayout.java
+++ b/src/com/android/launcher3/AutoInstallsLayout.java
@@ -316,7 +316,7 @@
parsers.put(TAG_APP_ICON, new AppShortcutParser());
parsers.put(TAG_AUTO_INSTALL, new AutoInstallParser());
parsers.put(TAG_FOLDER, new FolderParser());
- parsers.put(TAG_APPWIDGET, new AppWidgetParser());
+ parsers.put(TAG_APPWIDGET, new PendingWidgetParser());
parsers.put(TAG_SHORTCUT, new ShortcutParser(mSourceRes));
return parsers;
}
@@ -459,8 +459,12 @@
/**
* AppWidget parser: Required attributes packageName, className, spanX and spanY.
* Options child nodes: <extra key=... value=... />
+ * It adds a pending widget which allows the widget to come later. If there are extras, those
+ * are passed to widget options during bind.
+ * The config activity for the widget (if present) is not shown, so any optional configurations
+ * should be passed as extras and the widget should support reading these widget options.
*/
- protected class AppWidgetParser implements TagParser {
+ protected class PendingWidgetParser implements TagParser {
@Override
public long parseAndAdd(XmlResourceParser parser)
@@ -468,27 +472,13 @@
final String packageName = getAttributeValue(parser, ATTR_PACKAGE_NAME);
final String className = getAttributeValue(parser, ATTR_CLASS_NAME);
if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(className)) {
- if (LOGD) Log.d(TAG, "Skipping invalid <favorite> with no component");
+ if (LOGD) Log.d(TAG, "Skipping invalid <appwidget> with no component");
return -1;
}
- ComponentName cn = new ComponentName(packageName, className);
- try {
- mPackageManager.getReceiverInfo(cn, 0);
- } catch (Exception e) {
- String[] packages = mPackageManager.currentToCanonicalPackageNames(
- new String[] { packageName });
- cn = new ComponentName(packages[0], className);
- try {
- mPackageManager.getReceiverInfo(cn, 0);
- } catch (Exception e1) {
- if (LOGD) Log.d(TAG, "Can't find widget provider: " + className);
- return -1;
- }
- }
-
mValues.put(Favorites.SPANX, getAttributeValue(parser, ATTR_SPAN_X));
mValues.put(Favorites.SPANY, getAttributeValue(parser, ATTR_SPAN_Y));
+ mValues.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET);
// Read the extras
Bundle extras = new Bundle();
@@ -513,38 +503,26 @@
}
}
- final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
- long insertedId = -1;
- try {
- int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
+ return verifyAndInsert(new ComponentName(packageName, className), extras);
+ }
- if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn)) {
- if (LOGD) Log.e(TAG, "Unable to bind app widget id " + cn);
- return -1;
- }
-
- mValues.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET);
- mValues.put(Favorites.APPWIDGET_ID, appWidgetId);
- mValues.put(Favorites.APPWIDGET_PROVIDER, cn.flattenToString());
- mValues.put(Favorites._ID, mCallback.generateNewItemId());
- insertedId = mCallback.insertAndCheck(mDb, mValues);
- if (insertedId < 0) {
- mAppWidgetHost.deleteAppWidgetId(appWidgetId);
- return insertedId;
- }
-
- // Send a broadcast to configure the widget
- if (!extras.isEmpty()) {
- Intent intent = new Intent(ACTION_APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE);
- intent.setComponent(cn);
- intent.putExtras(extras);
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
- mContext.sendBroadcast(intent);
- }
- } catch (RuntimeException ex) {
- if (LOGD) Log.e(TAG, "Problem allocating appWidgetId", ex);
+ protected long verifyAndInsert(ComponentName cn, Bundle extras) {
+ mValues.put(Favorites.APPWIDGET_PROVIDER, cn.flattenToString());
+ mValues.put(Favorites.RESTORED,
+ LauncherAppWidgetInfo.FLAG_ID_NOT_VALID |
+ LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY |
+ LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
+ mValues.put(Favorites._ID, mCallback.generateNewItemId());
+ if (!extras.isEmpty()) {
+ mValues.put(Favorites.INTENT, new Intent().putExtras(extras).toUri(0));
}
- return insertedId;
+
+ long insertedId = mCallback.insertAndCheck(mDb, mValues);
+ if (insertedId < 0) {
+ return -1;
+ } else {
+ return insertedId;
+ }
}
}
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index 5a4ed2f..2dde7ca 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -43,6 +43,7 @@
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.util.Thunk;
@@ -62,6 +63,8 @@
/** Whether this drop target is active for the current drag */
protected boolean mActive;
+ /** Whether an accessible drag is in progress */
+ private boolean mAccessibleDrag;
/** An item must be dragged at least this many pixels before this drop target is enabled. */
private final int mDragDistanceThreshold;
@@ -197,8 +200,8 @@
}
@Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) {
- mActive = supportsDrop(source, info);
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
+ mActive = supportsDrop(dragObject.dragSource, dragObject.dragInfo);
mDrawable.setColorFilter(null);
if (mCurrentColorAnim != null) {
mCurrentColorAnim.cancel();
@@ -207,6 +210,9 @@
setTextColor(mOriginalTextColor);
(mHideParentOnDisable ? ((ViewGroup) getParent()) : this)
.setVisibility(mActive ? View.VISIBLE : View.GONE);
+
+ mAccessibleDrag = options.isAccessibleDrag;
+ setOnClickListener(mAccessibleDrag ? this : null);
}
@Override
@@ -218,13 +224,14 @@
@Override
public boolean isDropEnabled() {
- return mActive
- && mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold;
+ return mActive && (mAccessibleDrag ||
+ mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold);
}
@Override
public void onDragEnd() {
mActive = false;
+ setOnClickListener(null);
}
/**
@@ -306,10 +313,6 @@
return to;
}
- public void enableAccessibleDrag(boolean enable) {
- setOnClickListener(enable ? this : null);
- }
-
@Override
public void onClick(View v) {
mLauncher.getAccessibilityDelegate().handleAccessibleDrop(this, null, null);
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 77f6612..6714d9f 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -54,6 +54,7 @@
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.util.CellAndSpan;
import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.ParcelableSparseArray;
@@ -235,6 +236,7 @@
for (int i = 0; i < mDragOutlines.length; i++) {
mDragOutlines[i] = new Rect(-1, -1, -1, -1);
}
+ mDragOutlinePaint.setColor(getResources().getColor(R.color.outline_color));
// When dragging things around the home screens, we show a green outline of
// where the item will land. The outlines gradually fade out, leaving a trail
@@ -1047,15 +1049,16 @@
return false;
}
- void visualizeDropLocation(View v, Bitmap dragOutline, int cellX, int cellY, int spanX,
- int spanY, boolean resize, DropTarget.DragObject dragObject) {
+ void visualizeDropLocation(View v, DragPreviewProvider outlineProvider, int cellX, int cellY,
+ int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) {
final int oldDragCellX = mDragCell[0];
final int oldDragCellY = mDragCell[1];
- if (dragOutline == null && v == null) {
+ if (outlineProvider == null || outlineProvider.gerenatedDragOutline == null) {
return;
}
+ Bitmap dragOutline = outlineProvider.gerenatedDragOutline;
if (cellX != oldDragCellX || cellY != oldDragCellY) {
Point dragOffset = dragObject.dragView.getDragVisualizeOffset();
Rect dragRegion = dragObject.dragView.getDragRegion();
@@ -1354,12 +1357,9 @@
// and that passed in.
int curDirectionScore = direction[0] * curDirection[0] +
direction[1] * curDirection[1];
- boolean exactDirectionOnly = false;
- boolean directionMatches = direction[0] == curDirection[0] &&
- direction[0] == curDirection[0];
- if ((directionMatches || !exactDirectionOnly) &&
- Float.compare(distance, bestDistance) < 0 || (Float.compare(distance,
- bestDistance) == 0 && curDirectionScore > bestDirectionScore)) {
+ if (Float.compare(distance, bestDistance) < 0 ||
+ (Float.compare(distance, bestDistance) == 0
+ && curDirectionScore > bestDirectionScore)) {
bestDistance = distance;
bestDirectionScore = curDirectionScore;
bestXY[0] = x;
diff --git a/src/com/android/launcher3/DefaultLayoutParser.java b/src/com/android/launcher3/DefaultLayoutParser.java
index e6f34d9..ef28d1e 100644
--- a/src/com/android/launcher3/DefaultLayoutParser.java
+++ b/src/com/android/launcher3/DefaultLayoutParser.java
@@ -1,6 +1,8 @@
package com.android.launcher3;
import android.appwidget.AppWidgetHost;
+import android.appwidget.AppWidgetManager;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -9,6 +11,7 @@
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
+import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
@@ -42,6 +45,10 @@
private static final String ATTR_SCREEN = "screen";
private static final String ATTR_FOLDER_ITEMS = "folderItems";
+ // TODO: Remove support for this broadcast, instead use widget options to send bind time options
+ private static final String ACTION_APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE =
+ "com.android.launcher.action.APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE";
+
public DefaultLayoutParser(Context context, AppWidgetHost appWidgetHost,
LayoutParserCallback callback, Resources sourceRes, int layoutId) {
super(context, appWidgetHost, callback, sourceRes, layoutId, TAG_FAVORITES);
@@ -270,4 +277,61 @@
return super.parseAndAdd(parser);
}
}
+
+
+ /**
+ * AppWidget parser which enforces that the app is already installed when the layout is parsed.
+ */
+ protected class AppWidgetParser extends PendingWidgetParser {
+
+ @Override
+ protected long verifyAndInsert(ComponentName cn, Bundle extras) {
+ try {
+ mPackageManager.getReceiverInfo(cn, 0);
+ } catch (Exception e) {
+ String[] packages = mPackageManager.currentToCanonicalPackageNames(
+ new String[] { cn.getPackageName() });
+ cn = new ComponentName(packages[0], cn.getClassName());
+ try {
+ mPackageManager.getReceiverInfo(cn, 0);
+ } catch (Exception e1) {
+ Log.d(TAG, "Can't find widget provider: " + cn.getClassName());
+ return -1;
+ }
+ }
+
+ final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
+ long insertedId = -1;
+ try {
+ int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
+
+ if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn)) {
+ Log.e(TAG, "Unable to bind app widget id " + cn);
+ mAppWidgetHost.deleteAppWidgetId(appWidgetId);
+ return -1;
+ }
+
+ mValues.put(Favorites.APPWIDGET_ID, appWidgetId);
+ mValues.put(Favorites.APPWIDGET_PROVIDER, cn.flattenToString());
+ mValues.put(Favorites._ID, mCallback.generateNewItemId());
+ insertedId = mCallback.insertAndCheck(mDb, mValues);
+ if (insertedId < 0) {
+ mAppWidgetHost.deleteAppWidgetId(appWidgetId);
+ return insertedId;
+ }
+
+ // Send a broadcast to configure the widget
+ if (!extras.isEmpty()) {
+ Intent intent = new Intent(ACTION_APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE);
+ intent.setComponent(cn);
+ intent.putExtras(extras);
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
+ mContext.sendBroadcast(intent);
+ }
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "Problem allocating appWidgetId", ex);
+ }
+ return insertedId;
+ }
+ }
}
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index f24e00b..705f841 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -25,6 +25,7 @@
import android.view.animation.AnimationUtils;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.util.FlingAnimation;
import com.android.launcher3.util.Thunk;
@@ -49,9 +50,9 @@
}
@Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) {
- super.onDragStart(source, info, dragAction);
- setTextBasedOnDragSource(source);
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
+ super.onDragStart(dragObject, options);
+ setTextBasedOnDragSource(dragObject.dragSource);
}
/** @return true for items that should have a "Remove" action in accessibility. */
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 15f47b4..e6802bd 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -589,9 +589,9 @@
return new int[] {0, 0};
}
- // In landscape, we just match the vertical display width
- int containerWidth = heightPx;
- int padding = (availableWidthPx - containerWidth) / 2;
+ // In landscape, we match the width of the workspace
+ int padding = (pageIndicatorLandGutterRightNavBarPx +
+ hotseatBarHeightPx + hotseatLandGutterPx + mInsets.left) / 2;
return new int[]{ padding, padding };
}
}
diff --git a/src/com/android/launcher3/DragSource.java b/src/com/android/launcher3/DragSource.java
index da32d82..efbb9d7 100644
--- a/src/com/android/launcher3/DragSource.java
+++ b/src/com/android/launcher3/DragSource.java
@@ -19,11 +19,12 @@
import android.view.View;
import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.logging.UserEventDispatcher.LaunchSourceProvider;
/**
* Interface defining an object that can originate a drag.
*/
-public interface DragSource {
+public interface DragSource extends LaunchSourceProvider {
/**
* @return whether items dragged from this source supports
diff --git a/src/com/android/launcher3/DropTarget.java b/src/com/android/launcher3/DropTarget.java
index 90b8f1c..efdeb1f 100644
--- a/src/com/android/launcher3/DropTarget.java
+++ b/src/com/android/launcher3/DropTarget.java
@@ -48,9 +48,12 @@
/** The view that moves around while you drag. */
public DragView dragView = null;
- /** The data associated with the object being dragged */
+ /** The data associated with the object, after item is dropped. */
public ItemInfo dragInfo = null;
+ /** The data associated with the object being dragged */
+ public ItemInfo originalDragInfo = null;
+
/** Where the drag originated */
public DragSource dragSource = null;
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java
index 5966af5..42bab47 100644
--- a/src/com/android/launcher3/DropTargetBar.java
+++ b/src/com/android/launcher3/DropTargetBar.java
@@ -27,6 +27,7 @@
import android.widget.LinearLayout;
import com.android.launcher3.dragndrop.DragController;
+import com.android.launcher3.dragndrop.DragOptions;
/*
* The top bar containing various drop targets: Delete/App Info/Uninstall.
@@ -120,17 +121,11 @@
}
}
- public void enableAccessibleDrag(boolean enable) {
- mDeleteDropTarget.enableAccessibleDrag(enable);
- mAppInfoDropTarget.enableAccessibleDrag(enable);
- mUninstallDropTarget.enableAccessibleDrag(enable);
- }
-
/*
* DragController.DragListener implementation
*/
@Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) {
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
animateToVisibility(true);
}
diff --git a/src/com/android/launcher3/FolderInfo.java b/src/com/android/launcher3/FolderInfo.java
index 9a99852..c0a8caa 100644
--- a/src/com/android/launcher3/FolderInfo.java
+++ b/src/com/android/launcher3/FolderInfo.java
@@ -126,14 +126,6 @@
public void onItemsChanged(boolean animate);
}
- @Override
- public String toString() {
- return "FolderInfo(id=" + this.id + " type=" + this.itemType
- + " container=" + this.container + " screen=" + screenId
- + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX
- + " spanY=" + spanY + ")";
- }
-
public boolean hasOption(int optionFlag) {
return (options & optionFlag) != 0;
}
diff --git a/src/com/android/launcher3/HolographicOutlineHelper.java b/src/com/android/launcher3/HolographicOutlineHelper.java
index 427acea..9dec7d9 100644
--- a/src/com/android/launcher3/HolographicOutlineHelper.java
+++ b/src/com/android/launcher3/HolographicOutlineHelper.java
@@ -29,6 +29,10 @@
import android.graphics.drawable.Drawable;
import android.util.SparseArray;
+import com.android.launcher3.config.ProviderConfig;
+
+import java.nio.ByteBuffer;
+
/**
* Utility class to generate shadow and outline effect, which are used for click feedback
* and drag-n-drop respectively.
@@ -79,50 +83,53 @@
* Applies a more expensive and accurate outline to whatever is currently drawn in a specified
* bitmap.
*/
- public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
- int outlineColor) {
- applyExpensiveOutlineWithBlur(srcDst, srcDstCanvas, color, outlineColor, true);
+ public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas) {
+ applyExpensiveOutlineWithBlur(srcDst, srcDstCanvas, true);
}
- void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
- int outlineColor, boolean clipAlpha) {
+ public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas,
+ boolean clipAlpha) {
+ if (ProviderConfig.IS_DOGFOOD_BUILD && srcDst.getConfig() != Bitmap.Config.ALPHA_8) {
+ throw new RuntimeException("Outline blue is only supported on alpha bitmaps");
+ }
// We start by removing most of the alpha channel so as to ignore shadows, and
// other types of partial transparency when defining the shape of the object
if (clipAlpha) {
- int[] srcBuffer = new int[srcDst.getWidth() * srcDst.getHeight()];
- srcDst.getPixels(srcBuffer,
- 0, srcDst.getWidth(), 0, 0, srcDst.getWidth(), srcDst.getHeight());
- for (int i = 0; i < srcBuffer.length; i++) {
- final int alpha = srcBuffer[i] >>> 24;
- if (alpha < 188) {
- srcBuffer[i] = 0;
+ byte[] pixels = new byte[srcDst.getWidth() * srcDst.getHeight()];
+ ByteBuffer buffer = ByteBuffer.wrap(pixels);
+ buffer.rewind();
+ srcDst.copyPixelsToBuffer(buffer);
+
+ for (int i = 0; i < pixels.length; i++) {
+ if ((pixels[i] & 0xFF) < 188) {
+ pixels[i] = 0;
}
}
- srcDst.setPixels(srcBuffer,
- 0, srcDst.getWidth(), 0, 0, srcDst.getWidth(), srcDst.getHeight());
+
+ buffer.rewind();
+ srcDst.copyPixelsFromBuffer(buffer);
}
- Bitmap glowShape = srcDst.extractAlpha();
// calculate the outer blur first
mBlurPaint.setMaskFilter(mMediumOuterBlurMaskFilter);
int[] outerBlurOffset = new int[2];
- Bitmap thickOuterBlur = glowShape.extractAlpha(mBlurPaint, outerBlurOffset);
+ Bitmap thickOuterBlur = srcDst.extractAlpha(mBlurPaint, outerBlurOffset);
mBlurPaint.setMaskFilter(mThinOuterBlurMaskFilter);
int[] brightOutlineOffset = new int[2];
- Bitmap brightOutline = glowShape.extractAlpha(mBlurPaint, brightOutlineOffset);
+ Bitmap brightOutline = srcDst.extractAlpha(mBlurPaint, brightOutlineOffset);
// calculate the inner blur
- srcDstCanvas.setBitmap(glowShape);
+ srcDstCanvas.setBitmap(srcDst);
srcDstCanvas.drawColor(0xFF000000, PorterDuff.Mode.SRC_OUT);
mBlurPaint.setMaskFilter(mMediumInnerBlurMaskFilter);
int[] thickInnerBlurOffset = new int[2];
- Bitmap thickInnerBlur = glowShape.extractAlpha(mBlurPaint, thickInnerBlurOffset);
+ Bitmap thickInnerBlur = srcDst.extractAlpha(mBlurPaint, thickInnerBlurOffset);
// mask out the inner blur
srcDstCanvas.setBitmap(thickInnerBlur);
- srcDstCanvas.drawBitmap(glowShape, -thickInnerBlurOffset[0],
+ srcDstCanvas.drawBitmap(srcDst, -thickInnerBlurOffset[0],
-thickInnerBlurOffset[1], mErasePaint);
srcDstCanvas.drawRect(0, 0, -thickInnerBlurOffset[0], thickInnerBlur.getHeight(),
mErasePaint);
@@ -132,14 +139,12 @@
// draw the inner and outer blur
srcDstCanvas.setBitmap(srcDst);
srcDstCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
- mDrawPaint.setColor(color);
srcDstCanvas.drawBitmap(thickInnerBlur, thickInnerBlurOffset[0], thickInnerBlurOffset[1],
mDrawPaint);
srcDstCanvas.drawBitmap(thickOuterBlur, outerBlurOffset[0], outerBlurOffset[1],
mDrawPaint);
// draw the bright outline
- mDrawPaint.setColor(outlineColor);
srcDstCanvas.drawBitmap(brightOutline, brightOutlineOffset[0], brightOutlineOffset[1],
mDrawPaint);
@@ -148,7 +153,6 @@
brightOutline.recycle();
thickOuterBlur.recycle();
thickInnerBlur.recycle();
- glowShape.recycle();
}
Bitmap createMediumDropShadow(BubbleTextView view) {
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index 7c0ed10..c738480 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -165,11 +165,9 @@
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// We don't want any clicks to go through to the hotseat unless the workspace is in
- // the normal state.
- if (mLauncher.getWorkspace().workspaceInModalState()) {
- return true;
- }
- return false;
+ // the normal state or an accessible drag is in progress.
+ return mLauncher.getWorkspace().workspaceInModalState() &&
+ !mLauncher.getAccessibilityDelegate().isInAccessibleDrag();
}
@Override
diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java
index 2a94e55..c0c22a3 100644
--- a/src/com/android/launcher3/ItemInfo.java
+++ b/src/com/android/launcher3/ItemInfo.java
@@ -189,10 +189,24 @@
}
@Override
- public String toString() {
- return "Item(id=" + this.id + " type=" + this.itemType + " container=" + this.container
- + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX
- + " spanY=" + spanY + " user=" + user + ")";
+ public final String toString() {
+ return getClass().getSimpleName() + "(" + dumpProperties() + ")";
+ }
+
+ protected String dumpProperties() {
+ return "id=" + id
+ + " type=" + itemType
+ + " container=" + container
+ + " screen=" + screenId
+ + " cellX=" + cellX
+ + " cellY=" + cellY
+ + " spanX=" + spanX
+ + " spanY=" + spanY
+ + " minSpanX=" + minSpanX
+ + " minSpanY=" + minSpanY
+ + " rank=" + rank
+ + " user=" + user
+ + " title=" + title;
}
/**
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 81c95e7..1d5ece2 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -25,7 +25,6 @@
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
-import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.app.SearchManager;
@@ -51,10 +50,8 @@
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.Canvas;
-import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Rect;
-import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
@@ -81,7 +78,6 @@
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
-import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.OvershootInterpolator;
@@ -106,6 +102,7 @@
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.folder.Folder;
@@ -164,10 +161,6 @@
private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
- private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
- private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
- private static final int WORKSPACE_BACKGROUND_BLACK = 2;
-
private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
/**
@@ -198,8 +191,6 @@
// Type: parcelable
private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
- static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
- static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
static final String APPS_VIEW_SHOWN = "launcher.apps_view_shown";
/** The different states that Launcher can be in. */
@@ -316,8 +307,6 @@
// match the sensor state.
private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
- @Thunk Drawable mWorkspaceBackgroundDrawable;
-
private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
@@ -504,12 +493,6 @@
if (mLauncherCallbacks != null) {
mLauncherCallbacks.onCreate(savedInstanceState);
}
-
- if (shouldShowIntroScreen()) {
- showIntroScreen();
- } else {
- showFirstRunActivity();
- }
}
@Override
@@ -883,7 +866,7 @@
} else {
// TODO: Show a snack bar with link to settings
Toast.makeText(this, getString(R.string.msg_no_phone_permission,
- getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
+ getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
}
}
if (mLauncherCallbacks != null) {
@@ -1015,10 +998,6 @@
}
mOnResumeState = State.NONE;
- // Background was set to gradient in onPause(), restore to transparent if in all apps.
- setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
- : WORKSPACE_BACKGROUND_TRANSPARENT);
-
mPaused = false;
if (mRestoring || mOnResumeNeedsLoad) {
setWorkspaceLoading(true);
@@ -1367,10 +1346,8 @@
mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
- mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
// Setup the drag layer
-
mDragLayer.setup(this, mDragController, mAllAppsController);
// Setup the hotseat
@@ -2784,8 +2761,10 @@
*/
public void onClickSettingsButton(View v) {
if (LOGD) Log.d(TAG, "onClickSettingsButton");
- startActivity(new Intent(Utilities.ACTION_APPLICATION_PREFERENCES)
- .setPackage(getPackageName()));
+ Intent intent = new Intent(Intent.ACTION_APPLICATION_PREFERENCES)
+ .setPackage(getPackageName());
+ intent.setSourceBounds(getViewBounds(v));
+ startActivity(intent, getActivityLaunchOptions(v));
}
public View.OnTouchListener getHapticFeedbackTouchListener() {
@@ -2809,7 +2788,7 @@
mDragLayer.onAccessibilityStateChanged(enabled);
}
- public void onDragStarted(View view) {
+ public void onDragStarted() {
if (isOnCustomContent()) {
// Custom content screen doesn't participate in drag and drop. If on custom
// content screen, move to default.
@@ -3172,6 +3151,14 @@
}
}
+ public View getTopFloatingView() {
+ View topView = getOpenShortcutsContainer();
+ if (topView == null) {
+ topView = getWorkspace().getOpenFolder();
+ }
+ return topView;
+ }
+
/**
* @return The open shortcuts container, or null if there is none
*/
@@ -3244,7 +3231,7 @@
longClickCellInfo.cellX, longClickCellInfo.cellY));
if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
// User long pressed on an item
- mWorkspace.startDrag(longClickCellInfo);
+ mWorkspace.startDrag(longClickCellInfo, new DragOptions());
}
}
}
@@ -3286,29 +3273,6 @@
return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
}
- private void setWorkspaceBackground(int background) {
- switch (background) {
- case WORKSPACE_BACKGROUND_TRANSPARENT:
- getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
- break;
- case WORKSPACE_BACKGROUND_BLACK:
- getWindow().setBackgroundDrawable(null);
- break;
- default:
- getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
- }
- }
-
- protected void changeWallpaperVisiblity(boolean visible) {
- int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
- int curflags = getWindow().getAttributes().flags
- & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
- if (wpflags != curflags) {
- getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
- }
- setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
- }
-
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
@@ -3953,14 +3917,30 @@
pendingInfo.minSpanX = item.minSpanX;
pendingInfo.minSpanY = item.minSpanY;
Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
+
+ boolean isDirectConfig =
+ item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
+ if (isDirectConfig && item.bindOptions != null) {
+ Bundle newOptions = item.bindOptions.getExtras();
+ if (options != null) {
+ newOptions.putAll(options);
+ }
+ options = newOptions;
+ }
boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
item.appWidgetId, appWidgetInfo, options);
+ // We tried to bind once. If we were not able to bind, we would need to
+ // go through the permission dialog, which means we cannot skip the config
+ // activity.
+ item.bindOptions = null;
+ item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
+
// Bind succeeded
if (success) {
// If the widget has a configure activity, it is still needs to set it up,
// otherwise the widget is ready to go.
- item.restoreStatus = (appWidgetInfo.configure == null)
+ item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
? LauncherAppWidgetInfo.RESTORE_COMPLETED
: LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
}
@@ -4200,6 +4180,10 @@
return Collections.EMPTY_LIST;
}
ComponentName component = info.getTargetComponent();
+ if (component == null) {
+ return Collections.EMPTY_LIST;
+ }
+
List<String> ids = mDeepShortcutMap.get(new ComponentKey(component, info.user));
return ids == null ? Collections.EMPTY_LIST : ids;
}
@@ -4440,51 +4424,6 @@
}
}
- /**
- * To be overridden by subclasses to indicate that there is an activity to launch
- * before showing the standard launcher experience.
- */
- protected boolean hasFirstRunActivity() {
- if (mLauncherCallbacks != null) {
- return mLauncherCallbacks.hasFirstRunActivity();
- }
- return false;
- }
-
- /**
- * To be overridden by subclasses to launch any first run activity
- */
- protected Intent getFirstRunActivity() {
- if (mLauncherCallbacks != null) {
- return mLauncherCallbacks.getFirstRunActivity();
- }
- return null;
- }
-
- private boolean shouldRunFirstRunActivity() {
- return !ActivityManager.isRunningInTestHarness() &&
- !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
- }
-
- public boolean showFirstRunActivity() {
- if (shouldRunFirstRunActivity() &&
- hasFirstRunActivity()) {
- Intent firstRunIntent = getFirstRunActivity();
- if (firstRunIntent != null) {
- startActivity(firstRunIntent);
- markFirstRunActivityShown();
- return true;
- }
- }
- return false;
- }
-
- private void markFirstRunActivityShown() {
- SharedPreferences.Editor editor = mSharedPrefs.edit();
- editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
- editor.apply();
- }
-
private void markAppsViewShown() {
if (mSharedPrefs.getBoolean(APPS_VIEW_SHOWN, false)) {
return;
@@ -4508,44 +4447,6 @@
return true;
}
- /**
- * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
- * screen that must be displayed and dismissed.
- */
- protected boolean hasDismissableIntroScreen() {
- if (mLauncherCallbacks != null) {
- return mLauncherCallbacks.hasDismissableIntroScreen();
- }
- return false;
- }
-
- /**
- * Full screen intro screen to be shown and dismissed before the launcher can be used.
- */
- protected View getIntroScreen() {
- if (mLauncherCallbacks != null) {
- return mLauncherCallbacks.getIntroScreen();
- }
- return null;
- }
-
- /**
- * To be overriden by subclasses to indicate whether the in-activity intro screen has been
- * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
- */
- private boolean shouldShowIntroScreen() {
- return hasDismissableIntroScreen() &&
- !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
- }
-
- protected void showIntroScreen() {
- View introScreen = getIntroScreen();
- changeWallpaperVisiblity(false);
- if (introScreen != null) {
- mDragLayer.showOverlayView(introScreen);
- }
- }
-
// TODO: These method should be a part of LauncherSearchCallback
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
diff --git a/src/com/android/launcher3/LauncherAppWidgetInfo.java b/src/com/android/launcher3/LauncherAppWidgetInfo.java
index 99210fd..66d8957 100644
--- a/src/com/android/launcher3/LauncherAppWidgetInfo.java
+++ b/src/com/android/launcher3/LauncherAppWidgetInfo.java
@@ -20,6 +20,7 @@
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
+import android.content.Intent;
import com.android.launcher3.compat.UserHandleCompat;
@@ -57,6 +58,12 @@
public static final int FLAG_ID_ALLOCATED = 16;
/**
+ * Indicates that the widget does not need to show config activity, even if it has a
+ * configuration screen. It can also optionally have some extras which are sent during bind.
+ */
+ public static final int FLAG_DIRECT_CONFIG = 32;
+
+ /**
* Indicates that the widget hasn't been instantiated yet.
*/
static final int NO_ID = -1;
@@ -84,6 +91,11 @@
*/
int installProgress = -1;
+ /**
+ * Optional extras sent during widget bind. See {@link #FLAG_DIRECT_CONFIG}.
+ */
+ public Intent bindOptions;
+
private boolean mHasNotifiedInitialWidgetSizeChanged;
LauncherAppWidgetInfo(int appWidgetId, ComponentName providerName) {
@@ -115,6 +127,8 @@
values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
values.put(LauncherSettings.Favorites.APPWIDGET_PROVIDER, providerName.flattenToString());
values.put(LauncherSettings.Favorites.RESTORED, restoreStatus);
+ values.put(LauncherSettings.Favorites.INTENT,
+ bindOptions == null ? null : bindOptions.toUri(0));
}
/**
@@ -129,8 +143,8 @@
}
@Override
- public String toString() {
- return "AppWidget(id=" + Integer.toString(appWidgetId) + ")";
+ protected String dumpProperties() {
+ return super.dumpProperties() + " appWidgetId=" + appWidgetId;
}
public final boolean isWidgetIdAllocated() {
diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java
index 2bbe0fb..4a58e51 100644
--- a/src/com/android/launcher3/LauncherCallbacks.java
+++ b/src/com/android/launcher3/LauncherCallbacks.java
@@ -91,10 +91,6 @@
* Extensions points for adding / replacing some other aspects of the Launcher experience.
*/
public UserEventDispatcher getUserEventDispatcher();
- public Intent getFirstRunActivity();
- public boolean hasFirstRunActivity();
- public boolean hasDismissableIntroScreen();
- public View getIntroScreen();
public boolean shouldMoveToDefaultScreenOnHomeIntent();
public boolean hasSettings();
public AllAppsSearchBarController getAllAppsSearchBarController();
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index c5c52b4..68450e7 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -103,7 +103,6 @@
implements LauncherAppsCompat.OnAppsChangedCallbackCompat {
static final boolean DEBUG_LOADERS = false;
private static final boolean DEBUG_RECEIVER = false;
- private static final boolean REMOVE_UNRESTORED_ICONS = true;
static final String TAG = "Launcher.Model";
@@ -1883,12 +1882,12 @@
restored = false;
itemReplaced = true;
- } else if (REMOVE_UNRESTORED_ICONS) {
+ } else {
FileLog.d(TAG, "Unrestored package removed: " + cn);
itemsToRemove.add(id);
continue;
}
- } else if (REMOVE_UNRESTORED_ICONS) {
+ } else {
FileLog.d(TAG, "Unrestored package removed: " + cn);
itemsToRemove.add(id);
continue;
@@ -2148,7 +2147,7 @@
// Id would be valid only if the widget restore broadcast was received.
if (isIdValid) {
- status = LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
+ status |= LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
} else {
status &= ~LauncherAppWidgetInfo
.FLAG_PROVIDER_NOT_READY;
@@ -2170,7 +2169,7 @@
// App restore has started. Update the flag
appWidgetInfo.restoreStatus |=
LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
- } else if (REMOVE_UNRESTORED_ICONS && !isSafeMode) {
+ } else if (!isSafeMode) {
FileLog.d(TAG, "Unrestored widget removed: " + component);
itemsToRemove.add(id);
continue;
@@ -2179,6 +2178,14 @@
appWidgetInfo.installProgress =
installProgress == null ? 0 : installProgress;
}
+ if (appWidgetInfo.hasRestoreFlag(
+ LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG)) {
+ intentDescription = c.getString(intentIndex);
+ if (!TextUtils.isEmpty(intentDescription)) {
+ appWidgetInfo.bindOptions =
+ Intent.parseUri(intentDescription, 0);
+ }
+ }
appWidgetInfo.id = id;
appWidgetInfo.screenId = c.getInt(screenIndex);
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index eee5627..f3d9493 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -67,6 +67,7 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Locale;
public class LauncherProvider extends ContentProvider {
private static final String TAG = "LauncherProvider";
@@ -313,10 +314,32 @@
SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- int count = db.delete(args.table, args.where, args.args);
- if (count > 0) notifyListeners();
- reloadLauncherIfExternal();
+ if (Binder.getCallingPid() != Process.myPid()
+ && Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) {
+ String widgetSelection = TextUtils.isEmpty(args.where) ? "1=1" : args.where;
+ widgetSelection = String.format(Locale.ENGLISH, "%1$s = %2$d AND ( %3$s )",
+ Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET, widgetSelection);
+ try (Cursor c = db.query(Favorites.TABLE_NAME, new String[] { Favorites.APPWIDGET_ID },
+ widgetSelection, args.args, null, null, null)) {
+ AppWidgetHost host = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID);
+ while (c.moveToNext()) {
+ int widgetId = c.getInt(0);
+ if (widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
+ try {
+ host.deleteAppWidgetId(widgetId);
+ } catch (RuntimeException e) {
+ Log.e(TAG, "Error deleting widget id " + widgetId, e);
+ }
+ }
+ }
+ }
+ }
+ int count = db.delete(args.table, args.where, args.args);
+ if (count > 0) {
+ notifyListeners();
+ reloadLauncherIfExternal();
+ }
return count;
}
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 2758a7c..bea55d2 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -1800,6 +1800,7 @@
case MotionEvent.ACTION_CANCEL:
if (mTouchState == TOUCH_STATE_SCROLLING) {
snapToDestination();
+ onScrollInteractionEnd();
}
resetTouchState();
break;
diff --git a/src/com/android/launcher3/PendingAddItemInfo.java b/src/com/android/launcher3/PendingAddItemInfo.java
index 1aaf85b..31820d7 100644
--- a/src/com/android/launcher3/PendingAddItemInfo.java
+++ b/src/com/android/launcher3/PendingAddItemInfo.java
@@ -29,4 +29,9 @@
* The component that will be created.
*/
public ComponentName componentName;
+
+ @Override
+ protected String dumpProperties() {
+ return super.dumpProperties() + " componentName=" + componentName;
+ }
}
diff --git a/src/com/android/launcher3/PinchToOverviewListener.java b/src/com/android/launcher3/PinchToOverviewListener.java
index 6ee96fc..48a75d1 100644
--- a/src/com/android/launcher3/PinchToOverviewListener.java
+++ b/src/com/android/launcher3/PinchToOverviewListener.java
@@ -102,8 +102,8 @@
// once the state switching animation is complete.
return false;
}
- if (mWorkspace.getOpenFolder() != null) {
- // Don't listen for the pinch gesture if a folder is open.
+ if (mLauncher.getTopFloatingView() != null) {
+ // Don't listen for the pinch gesture if a floating view is open.
return false;
}
diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java
index 21fa8a0..9d7be16 100644
--- a/src/com/android/launcher3/ShortcutInfo.java
+++ b/src/com/android/launcher3/ShortcutInfo.java
@@ -270,14 +270,6 @@
}
}
- @Override
- public String toString() {
- return "ShortcutInfo(title=" + title + "intent=" + intent + "id=" + this.id
- + " type=" + this.itemType + " container=" + this.container + " screen=" + screenId
- + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX + " spanY=" + spanY
- + " user=" + user + ")";
- }
-
public ComponentName getTargetComponent() {
return promisedIntent != null ? promisedIntent.getComponent() : intent.getComponent();
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 50f7156..e34f509 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -58,6 +58,8 @@
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
import android.widget.Toast;
import com.android.launcher3.compat.UserHandleCompat;
@@ -108,6 +110,10 @@
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1;
}
+ public static boolean isNycOrAbove() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
+ }
+
public static final boolean ATLEAST_MARSHMALLOW =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
@@ -156,37 +162,14 @@
if (isNycOrAbove()) {
// If the device was scaled, used the original dimensions to determine if rotation
// is allowed of not.
- try {
- // TODO: Use the actual field when the API is finalized.
- int originalDensity =
- DisplayMetrics.class.getField("DENSITY_DEVICE_STABLE").getInt(null);
- Resources res = context.getResources();
- int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
- * res.getDisplayMetrics().densityDpi / originalDensity;
- return originalSmallestWidth >= 600;
- } catch (Exception e) {
- // Ignore
- }
+ Resources res = context.getResources();
+ int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
+ * res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEVICE_STABLE;
+ return originalSmallestWidth >= 600;
}
return false;
}
- public static boolean isNycOrAbove() {
- // TODO(vadimt): Replace using reflection with looking at the API version once
- // Build.VERSION.SDK_INT gets bumped to 24. b/22942492.
- try {
- View.class.getDeclaredField("DRAG_FLAG_OPAQUE");
- // View.DRAG_FLAG_OPAQUE doesn't exist in M-release, so it's an indication of N+.
- return true;
- } catch (NoSuchFieldException e) {
- return false;
- }
- }
-
- // TODO: Use Intent.ACTION_APPLICATION_PREFERENCES when N SDK is available.
- public static final String ACTION_APPLICATION_PREFERENCES
- = "android.intent.action.APPLICATION_PREFERENCES";
-
public static Bitmap createIconBitmap(Cursor c, int iconIndex, Context context) {
byte[] data = c.getBlob(iconIndex);
try {
@@ -780,16 +763,21 @@
}
public static boolean isBootCompleted() {
+ return "1".equals(getSystemProperty("sys.boot_completed", "1"));
+ }
+
+ public static String getSystemProperty(String property, String defaultValue) {
try {
Class clazz = Class.forName("android.os.SystemProperties");
Method getter = clazz.getDeclaredMethod("get", String.class);
- String value = (String) getter.invoke(null, "sys.boot_completed");
- return "1".equals(value);
+ String value = (String) getter.invoke(null, property);
+ if (!TextUtils.isEmpty(value)) {
+ return value;
+ }
} catch (Exception e) {
Log.d(TAG, "Unable to read system properties");
- // Assume that boot has completed
- return true;
}
+ return defaultValue;
}
/**
@@ -920,4 +908,15 @@
ta.recycle();
return colorAccent;
}
+
+ public static void sendCustomAccessibilityEvent(View target, int type, String text) {
+ AccessibilityManager accessibilityManager = (AccessibilityManager)
+ target.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
+ if (accessibilityManager.isEnabled()) {
+ AccessibilityEvent event = AccessibilityEvent.obtain(type);
+ target.onInitializeAccessibilityEvent(event);
+ event.getText().add(text);
+ accessibilityManager.sendAccessibilityEvent(event);
+ }
+ }
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 6f61688..d5f1363 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -59,7 +59,7 @@
import com.android.launcher3.Launcher.CustomContentCallbacks;
import com.android.launcher3.Launcher.LauncherOverlay;
import com.android.launcher3.UninstallDropTarget.DropTargetSource;
-import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource;
+import com.android.launcher3.accessibility.AccessibileDragListenerAdapter;
import com.android.launcher3.accessibility.OverviewAccessibilityDelegate;
import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
@@ -69,12 +69,13 @@
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
-import com.android.launcher3.graphics.DragPreviewProvider;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragScroller;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dragndrop.SpringLoadedDragController;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutsContainerListener;
@@ -100,7 +101,7 @@
public class Workspace extends PagedView
implements DropTarget, DragSource, DragScroller, View.OnTouchListener,
DragController.DragListener, LauncherTransitionable, ViewGroup.OnHierarchyChangeListener,
- Insettable, DropTargetSource, AccessibilityDragSource, UserEventDispatcher.LaunchSourceProvider {
+ Insettable, DropTargetSource {
private static final String TAG = "Launcher.Workspace";
private static boolean ENFORCE_DRAG_EVENT_ORDER = false;
@@ -134,7 +135,6 @@
@Thunk Runnable mRemoveEmptyScreenRunnable;
@Thunk boolean mDeferRemoveExtraEmptyScreen = false;
- @Thunk boolean mAddNewPageOnDrag = true;
/**
* CellInfo for the cell that is currently being dragged
@@ -247,8 +247,7 @@
/** Is the user is dragging an item near the edge of a page? */
private boolean mInScrollArea = false;
- private HolographicOutlineHelper mOutlineHelper;
- @Thunk Bitmap mDragOutline = null;
+ private DragPreviewProvider mOutlineProvider = null;
public static final int DRAG_BITMAP_PADDING = DragPreviewProvider.DRAG_BITMAP_PADDING;
private boolean mWorkspaceFadeInAdjacentScreens;
@@ -343,8 +342,6 @@
public Workspace(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- mOutlineHelper = HolographicOutlineHelper.obtain(context);
-
mLauncher = (Launcher) context;
mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
final Resources res = getResources();
@@ -412,25 +409,56 @@
}
@Override
- public void onDragStart(final DragSource source, ItemInfo info, int dragAction) {
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
if (ENFORCE_DRAG_EVENT_ORDER) {
enfoceDragParity("onDragStart", 0, 0);
}
+ if (mOutlineProvider != null) {
+ // The outline is used to visualize where the item will land if dropped
+ mOutlineProvider.generateDragOutline(mCanvas);
+ }
+
updateChildrenLayersEnabled(false);
+ mLauncher.onDragStarted();
mLauncher.lockScreenOrientation();
mLauncher.onInteractionBegin();
// Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
InstallShortcutReceiver.enableInstallQueue();
- if (mAddNewPageOnDrag) {
+ // Do not add a new page if it is a accessible drag which was not started by the workspace.
+ // We do not support accessibility drag from other sources and instead provide a direct
+ // action for move/add to homescreen.
+ // When a accessible drag is started by the folder, we only allow rearranging withing the
+ // folder.
+ boolean addNewPage = !(options.isAccessibleDrag && dragObject.dragSource != this);
+
+ if (addNewPage) {
mDeferRemoveExtraEmptyScreen = false;
addExtraEmptyScreenOnDrag();
- }
- }
- public void setAddNewPageOnDrag(boolean addPage) {
- mAddNewPageOnDrag = addPage;
+ if (dragObject.dragInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
+ && dragObject.dragSource != this) {
+ // When dragging a widget from different source, move to a page which has
+ // enough space to place this widget (after rearranging/resizing). We special case
+ // widgets as they cannot be placed inside a folder.
+ // Start at the current page and search right (on LTR) until finding a page with
+ // enough space. Since an empty screen is the furthest right, a page must be found.
+ int currentPage = getPageNearestToCenterOfScreen();
+ for (int pageIndex = currentPage; pageIndex < getPageCount(); pageIndex++) {
+ CellLayout page = (CellLayout) getPageAt(pageIndex);
+ if (page.hasReorderSolution(dragObject.dragInfo)) {
+ setCurrentPage(pageIndex);
+ break;
+ }
+ }
+ }
+ }
+
+ if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
+ // Always enter the spring loaded mode
+ mLauncher.enterSpringLoadedDragMode();
+ }
}
public void deferRemoveExtraEmptyScreen() {
@@ -600,8 +628,8 @@
ViewGroup.LayoutParams lp = qsbContainer.getLayoutParams();
if (cellHeight > 0 && lp.height != cellHeight) {
lp.height = cellHeight;
+ qsbContainer.setLayoutParams(lp);
}
- qsbContainer.setLayoutParams(lp);
}
}
@@ -1698,26 +1726,6 @@
}
}
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- @Override
- public void enableAccessibleDrag(boolean enable) {
- for (int i = 0; i < getChildCount(); i++) {
- CellLayout child = (CellLayout) getChildAt(i);
- child.enableAccessibleDrag(enable, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG);
- }
-
- if (enable) {
- // We need to allow our individual children to become click handlers in this case
- setOnClickListener(null);
- } else {
- // Reset our click listener
- setOnClickListener(mLauncher);
- }
- mLauncher.getDropTargetBar().enableAccessibleDrag(enable);
- mLauncher.getHotseat().getLayout()
- .enableAccessibleDrag(enable, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG);
- }
-
public boolean hasCustomContent() {
return (mScreenOrder.size() > 0 && mScreenOrder.get(0) == CUSTOM_CONTENT_SCREEN_ID);
}
@@ -1850,19 +1858,6 @@
}
@Override
- protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
- if (!mLauncher.isAppsViewVisible()) {
- final Folder openFolder = getOpenFolder();
- if (openFolder != null) {
- return openFolder.requestFocus(direction, previouslyFocusedRect);
- } else {
- return super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
- }
- }
- return false;
- }
-
- @Override
public int getDescendantFocusability() {
if (workspaceInModalState()) {
return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
@@ -1870,18 +1865,6 @@
return super.getDescendantFocusability();
}
- @Override
- public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
- if (!mLauncher.isAppsViewVisible()) {
- final Folder openFolder = getOpenFolder();
- if (openFolder != null) {
- openFolder.addFocusables(views, direction);
- } else {
- super.addFocusables(views, direction, focusableMode);
- }
- }
- }
-
public boolean workspaceInModalState() {
return mState != State.NORMAL;
}
@@ -1999,23 +1982,8 @@
position[0], position[1], 0, null);
}
- public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, boolean clipAlpha) {
- // Find a page that has enough space to place this widget (after rearranging/resizing).
- // Start at the current page and search right (on LTR) until finding a page with enough
- // space. Since an empty screen is the furthest right, a page must be found.
- int currentPageInOverview = getPageNearestToCenterOfScreen();
- for (int pageIndex = currentPageInOverview; pageIndex < getPageCount(); pageIndex++) {
- CellLayout page = (CellLayout) getPageAt(pageIndex);
- if (page.hasReorderSolution(info)) {
- setCurrentPage(pageIndex);
- break;
- }
- }
-
- int[] size = estimateItemSize(info, false);
-
- // The outline is used to visualize where the item will land if dropped
- mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, size[0], size[1], clipAlpha);
+ public void prepareDragWithProvider(DragPreviewProvider outlineProvider) {
+ mOutlineProvider = outlineProvider;
}
public void exitWidgetResizeMode() {
@@ -2271,40 +2239,7 @@
return null;
}
- /**
- * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
- * Responsibility for the bitmap is transferred to the caller.
- */
- private Bitmap createDragOutline(Bitmap orig, int padding, int w, int h,
- boolean clipAlpha) {
- final int outlineColor = getResources().getColor(R.color.outline_color);
- final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
- mCanvas.setBitmap(b);
-
- Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight());
- float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(),
- (h - padding) / (float) orig.getHeight());
- int scaledWidth = (int) (scaleFactor * orig.getWidth());
- int scaledHeight = (int) (scaleFactor * orig.getHeight());
- Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);
-
- // center the image
- dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2);
-
- mCanvas.drawBitmap(orig, src, dst, null);
- mOutlineHelper.applyExpensiveOutlineWithBlur(b, mCanvas, outlineColor, outlineColor,
- clipAlpha);
- mCanvas.setBitmap(null);
-
- return b;
- }
-
- public void startDrag(CellLayout.CellInfo cellInfo) {
- startDrag(cellInfo, false);
- }
-
- @Override
- public void startDrag(CellLayout.CellInfo cellInfo, boolean accessible) {
+ public void startDrag(CellLayout.CellInfo cellInfo, DragOptions options) {
View child = cellInfo.cell;
// Make sure the drag was started by a long press as opposed to a long click.
@@ -2317,10 +2252,25 @@
CellLayout layout = (CellLayout) child.getParent().getParent();
layout.prepareChildForDrag(child);
- beginDragShared(child, this, accessible);
+ if (options.isAccessibleDrag) {
+ mDragController.addDragListener(new AccessibileDragListenerAdapter(
+ this, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG) {
+ @Override
+ protected void enableAccessibleDrag(boolean enable) {
+ super.enableAccessibleDrag(enable);
+ setEnableForLayout(mLauncher.getHotseat().getLayout(),enable);
+
+ // We need to allow our individual children to become click handlers in this
+ // case, so temporarily unset the click handlers.
+ setOnClickListener(enable ? null : mLauncher);
+ }
+ });
+ }
+
+ beginDragShared(child, this, options);
}
- public void beginDragShared(View child, DragSource source, boolean accessible) {
+ public void beginDragShared(View child, DragSource source, DragOptions options) {
Object dragObject = child.getTag();
if (!(dragObject instanceof ItemInfo)) {
String msg = "Drag started with a view that has no tag set. This "
@@ -2328,20 +2278,17 @@
+ "View: " + child + " tag: " + child.getTag();
throw new IllegalStateException(msg);
}
- beginDragShared(child, source, accessible, (ItemInfo) dragObject,
- new DragPreviewProvider(child));
+ beginDragShared(child, source, (ItemInfo) dragObject,
+ new DragPreviewProvider(child), options);
}
- public DragView beginDragShared(View child, DragSource source, boolean accessible,
- ItemInfo dragObject, DragPreviewProvider previewProvider) {
+ public DragView beginDragShared(View child, DragSource source, ItemInfo dragObject,
+ DragPreviewProvider previewProvider, DragOptions dragOptions) {
child.clearFocus();
child.setPressed(false);
+ mOutlineProvider = previewProvider;
- // The outline is used to visualize where the item will land if dropped
- mDragOutline = previewProvider.createDragOutline(mCanvas);
-
- mLauncher.onDragStarted(child);
// The drag bitmap follows the touch point around on the screen
final Bitmap b = previewProvider.createDragBitmap(mCanvas);
int halfPadding = previewProvider.previewPadding / 2;
@@ -2381,15 +2328,9 @@
}
DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source,
- dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset,
- dragRect, scale, accessible);
+ dragObject, dragVisualizeOffset, dragRect, scale, dragOptions);
dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());
-
b.recycle();
-
- if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
- mLauncher.enterSpringLoadedDragMode();
- }
return dv;
}
@@ -3180,7 +3121,7 @@
item.spanY, child, mTargetCell);
if (!nearestDropOccupied) {
- mDragTargetLayout.visualizeDropLocation(child, mDragOutline,
+ mDragTargetLayout.visualizeDropLocation(child, mOutlineProvider,
mTargetCell[0], mTargetCell[1], item.spanX, item.spanY, false, d);
} else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER)
&& !mReorderAlarm.alarmPending() && (mLastReorderX != reorderX ||
@@ -3325,7 +3266,7 @@
}
boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY;
- mDragTargetLayout.visualizeDropLocation(child, mDragOutline,
+ mDragTargetLayout.visualizeDropLocation(child, mOutlineProvider,
mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, dragObject);
}
}
@@ -3453,6 +3394,7 @@
if (info.container == NO_ID && info instanceof AppInfo) {
// Came from all apps -- make a copy
info = ((AppInfo) info).makeShortcut();
+ d.dragInfo = info;
}
view = mLauncher.createShortcut(cellLayout, (ShortcutInfo) info);
break;
@@ -3716,7 +3658,7 @@
&& mDragInfo.cell != null) {
mDragInfo.cell.setVisibility(VISIBLE);
}
- mDragOutline = null;
+ mOutlineProvider = null;
mDragInfo = null;
if (!isFlingToDelete) {
@@ -4322,6 +4264,12 @@
target.gridY = info.cellY;
target.pageIndex = getCurrentPage();
targetParent.containerType = LauncherLogProto.WORKSPACE;
+ if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
+ target.rank = info.rank;
+ targetParent.containerType = LauncherLogProto.HOTSEAT;
+ } else if (info.container >= 0) {
+ targetParent.containerType = LauncherLogProto.FOLDER;
+ }
}
/**
diff --git a/src/com/android/launcher3/accessibility/AccessibileDragListenerAdapter.java b/src/com/android/launcher3/accessibility/AccessibileDragListenerAdapter.java
new file mode 100644
index 0000000..62a9a6d
--- /dev/null
+++ b/src/com/android/launcher3/accessibility/AccessibileDragListenerAdapter.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016 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.accessibility;
+
+import android.view.ViewGroup;
+
+import com.android.launcher3.CellLayout;
+import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.dragndrop.DragController.DragListener;
+import com.android.launcher3.dragndrop.DragOptions;
+
+/**
+ * Utility listener to enable/disable accessibility drag flags for a ViewGroup
+ * containing CellLayouts
+ */
+public class AccessibileDragListenerAdapter implements DragListener {
+
+ private final ViewGroup mViewGroup;
+ private final int mDragType;
+
+ /**
+ * @param parent
+ * @param dragType either {@link CellLayout#WORKSPACE_ACCESSIBILITY_DRAG} or
+ * {@link CellLayout#FOLDER_ACCESSIBILITY_DRAG}
+ */
+ public AccessibileDragListenerAdapter(ViewGroup parent, int dragType) {
+ mViewGroup = parent;
+ mDragType = dragType;
+ }
+
+ @Override
+ public void onDragStart(DragObject dragObject, DragOptions options) {
+ enableAccessibleDrag(true);
+ }
+
+ @Override
+ public void onDragEnd() {
+ enableAccessibleDrag(false);
+ Launcher.getLauncher(mViewGroup.getContext()).getDragController().removeDragListener(this);
+ }
+
+ protected void enableAccessibleDrag(boolean enable) {
+ for (int i = 0; i < mViewGroup.getChildCount(); i++) {
+ setEnableForLayout((CellLayout) mViewGroup.getChildAt(i), enable);
+ }
+ }
+
+ protected final void setEnableForLayout(CellLayout layout, boolean enable) {
+ layout.enableAccessibleDrag(enable, mDragType);
+ }
+}
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 0562cf5..173aad0 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -22,6 +22,8 @@
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DragSource;
+import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.FolderInfo;
import com.android.launcher3.InfoDropTarget;
@@ -73,7 +75,6 @@
@Thunk final Launcher mLauncher;
private DragInfo mDragInfo = null;
- private AccessibilityDragSource mDragSource = null;
public LauncherAccessibilityDelegate(Launcher launcher) {
mLauncher = launcher;
@@ -372,26 +373,25 @@
Folder folder = workspace.getOpenFolder();
if (folder != null) {
- if (folder.getItemsInReadingOrder().contains(item)) {
- mDragSource = folder;
- } else {
+ if (!folder.getItemsInReadingOrder().contains(item)) {
mLauncher.closeFolder();
+ folder = null;
}
}
- if (mDragSource == null) {
- mDragSource = workspace;
- }
- mDragSource.enableAccessibleDrag(true);
- mDragSource.startDrag(cellInfo, true);
- if (mLauncher.getDragController().isDragging()) {
- mLauncher.getDragController().addDragListener(this);
+ mLauncher.getDragController().addDragListener(this);
+
+ DragOptions options = new DragOptions();
+ options.isAccessibleDrag = true;
+ if (folder != null) {
+ folder.startDrag(cellInfo.cell, options);
+ } else {
+ workspace.startDrag(cellInfo, options);
}
}
-
@Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) {
+ public void onDragStart(DragObject dragObject, DragOptions options) {
// No-op
}
@@ -399,16 +399,6 @@
public void onDragEnd() {
mLauncher.getDragController().removeDragListener(this);
mDragInfo = null;
- if (mDragSource != null) {
- mDragSource.enableAccessibleDrag(false);
- mDragSource = null;
- }
- }
-
- public static interface AccessibilityDragSource {
- void startDrag(CellLayout.CellInfo cellInfo, boolean accessible);
-
- void enableAccessibleDrag(boolean enable);
}
/**
diff --git a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
index ff70279..0baa8f3 100644
--- a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
@@ -25,6 +25,7 @@
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
+import com.android.launcher3.shortcuts.DeepShortcutView;
import java.util.ArrayList;
@@ -46,7 +47,10 @@
@Override
public boolean performAction(View host, ItemInfo item, int action) {
if (action == ADD_TO_WORKSPACE) {
- final ShortcutInfo info = (ShortcutInfo) item;
+ if (!(host.getParent() instanceof DeepShortcutView)) {
+ return false;
+ }
+ final ShortcutInfo info = ((DeepShortcutView) host.getParent()).getFinalInfo();
final int[] coordinates = new int[2];
final long screenId = findSpaceOnWorkspace(item, coordinates);
Runnable onComplete = new Runnable() {
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index c7bc23b..a3786fa 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -48,9 +48,12 @@
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.graphics.TintedDrawableSpan;
import com.android.launcher3.keyboard.FocusedItemDecorator;
+import com.android.launcher3.userevent.nano.LauncherLogProto;
+import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ComponentKey;
import java.nio.charset.Charset;
@@ -537,7 +540,7 @@
if (!mLauncher.isDraggingEnabled()) return false;
// Start the drag
- mLauncher.getWorkspace().beginDragShared(v, this, false);
+ mLauncher.getWorkspace().beginDragShared(v, this, new DragOptions());
// Enter spring loaded mode
mLauncher.enterSpringLoadedDragMode();
@@ -700,4 +703,9 @@
mSearchQueryBuilder.clearSpans();
Selection.setSelection(mSearchQueryBuilder, 0);
}
+
+ @Override
+ public void fillInLaunchSourceData(View v, ItemInfo info, Target target, Target targetParent) {
+ targetParent.containerType = mAppsRecyclerView.getContainerType(v);
+ }
}
diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
index 25ed3b8..0173847 100644
--- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
@@ -27,20 +27,16 @@
import com.android.launcher3.BaseRecyclerView;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.DeviceProfile;
-import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
-import com.android.launcher3.logging.UserEventDispatcher.LaunchSourceProvider;
import com.android.launcher3.userevent.nano.LauncherLogProto;
-import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import java.util.List;
/**
* A RecyclerView with custom fast scroll support for the all apps view.
*/
-public class AllAppsRecyclerView extends BaseRecyclerView
- implements LaunchSourceProvider {
+public class AllAppsRecyclerView extends BaseRecyclerView {
private AlphabeticalAppsList mApps;
private AllAppsFastScrollHelper mFastScrollHelper;
@@ -207,10 +203,9 @@
updateEmptySearchBackgroundBounds();
}
- @Override
- public void fillInLaunchSourceData(View v, ItemInfo info, Target target, Target targetParent) {
+ public int getContainerType(View v) {
if (mApps.hasFilter()) {
- targetParent.containerType = LauncherLogProto.SEARCHRESULT;
+ return LauncherLogProto.SEARCHRESULT;
} else {
if (v instanceof BubbleTextView) {
BubbleTextView icon = (BubbleTextView) v;
@@ -219,12 +214,11 @@
List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems();
AlphabeticalAppsList.AdapterItem item = items.get(position);
if (item.viewType == AllAppsGridAdapter.VIEW_TYPE_PREDICTION_ICON) {
- targetParent.containerType = LauncherLogProto.PREDICTION;
- return;
+ return LauncherLogProto.PREDICTION;
}
}
}
- targetParent.containerType = LauncherLogProto.ALLAPPS;
+ return LauncherLogProto.ALLAPPS;
}
}
diff --git a/src/com/android/launcher3/compat/UserManagerCompat.java b/src/com/android/launcher3/compat/UserManagerCompat.java
index 29ed5d9..a5f8dd2 100644
--- a/src/com/android/launcher3/compat/UserManagerCompat.java
+++ b/src/com/android/launcher3/compat/UserManagerCompat.java
@@ -32,8 +32,12 @@
public static UserManagerCompat getInstance(Context context) {
synchronized (sInstanceLock) {
if (sInstance == null) {
- if (Utilities.isNycOrAbove()) {
+ if (Utilities.isNycMR1OrAbove()) {
+ sInstance = new UserManagerCompatVNMr1(context.getApplicationContext());
+ } else if (Utilities.isNycOrAbove()) {
sInstance = new UserManagerCompatVN(context.getApplicationContext());
+ } else if (Utilities.ATLEAST_MARSHMALLOW) {
+ sInstance = new UserManagerCompatVM(context.getApplicationContext());
} else if (Utilities.ATLEAST_LOLLIPOP) {
sInstance = new UserManagerCompatVL(context.getApplicationContext());
} else if (Utilities.ATLEAST_JB_MR1) {
@@ -58,4 +62,6 @@
public abstract long getUserCreationTime(UserHandleCompat user);
public abstract boolean isQuietModeEnabled(UserHandleCompat user);
public abstract boolean isUserUnlocked(UserHandleCompat user);
+
+ public abstract boolean isDemoUser();
}
diff --git a/src/com/android/launcher3/compat/UserManagerCompatV16.java b/src/com/android/launcher3/compat/UserManagerCompatV16.java
index e678ffa..9bd4567 100644
--- a/src/com/android/launcher3/compat/UserManagerCompatV16.java
+++ b/src/com/android/launcher3/compat/UserManagerCompatV16.java
@@ -60,4 +60,9 @@
public boolean isUserUnlocked(UserHandleCompat user) {
return true;
}
+
+ @Override
+ public boolean isDemoUser() {
+ return false;
+ }
}
diff --git a/src/com/android/launcher3/compat/UserManagerCompatVL.java b/src/com/android/launcher3/compat/UserManagerCompatVL.java
index c53d702..2552b0c 100644
--- a/src/com/android/launcher3/compat/UserManagerCompatVL.java
+++ b/src/com/android/launcher3/compat/UserManagerCompatVL.java
@@ -1,4 +1,3 @@
-
/*
* Copyright (C) 2014 The Android Open Source Project
*
@@ -94,9 +93,6 @@
@Override
public long getUserCreationTime(UserHandleCompat user) {
- if (Utilities.ATLEAST_MARSHMALLOW) {
- return mUserManager.getUserCreationTime(user.getUser());
- }
SharedPreferences prefs = Utilities.getPrefs(mContext);
String key = USER_CREATION_TIME_KEY + getSerialNumberForUser(user);
if (!prefs.contains(key)) {
diff --git a/src/com/android/launcher3/compat/UserManagerCompatVM.java b/src/com/android/launcher3/compat/UserManagerCompatVM.java
new file mode 100644
index 0000000..81d67ea
--- /dev/null
+++ b/src/com/android/launcher3/compat/UserManagerCompatVM.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 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.compat;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.os.Build;
+
+@TargetApi(Build.VERSION_CODES.M)
+public class UserManagerCompatVM extends UserManagerCompatVL {
+
+ UserManagerCompatVM(Context context) {
+ super(context);
+ }
+
+ @Override
+ public long getUserCreationTime(UserHandleCompat user) {
+ return mUserManager.getUserCreationTime(user.getUser());
+ }
+}
diff --git a/src/com/android/launcher3/compat/UserManagerCompatVN.java b/src/com/android/launcher3/compat/UserManagerCompatVN.java
index 771d141..4edac05 100644
--- a/src/com/android/launcher3/compat/UserManagerCompatVN.java
+++ b/src/com/android/launcher3/compat/UserManagerCompatVN.java
@@ -20,10 +20,10 @@
import android.content.Context;
import android.os.Build;
-@TargetApi(Build.VERSION_CODES.N)
-public class UserManagerCompatVN extends UserManagerCompatVL {
+import com.android.launcher3.Utilities;
- private static final String TAG = "UserManagerCompatVN";
+@TargetApi(Build.VERSION_CODES.N)
+public class UserManagerCompatVN extends UserManagerCompatVM {
UserManagerCompatVN(Context context) {
super(context);
@@ -36,12 +36,7 @@
@Override
public boolean isUserUnlocked(UserHandleCompat user) {
- // TODO: Remove the try-catch block when the API permission has been relaxed (b/30475753)
- try {
- return mUserManager.isUserUnlocked(user.getUser());
- } catch (RuntimeException e) {
- return !isQuietModeEnabled(user);
- }
+ return mUserManager.isUserUnlocked(user.getUser());
}
}
diff --git a/src/com/android/launcher3/compat/UserManagerCompatVNMr1.java b/src/com/android/launcher3/compat/UserManagerCompatVNMr1.java
new file mode 100644
index 0000000..3f64bc8
--- /dev/null
+++ b/src/com/android/launcher3/compat/UserManagerCompatVNMr1.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 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.compat;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.os.Build;
+
+@TargetApi(Build.VERSION_CODES.N_MR1)
+public class UserManagerCompatVNMr1 extends UserManagerCompatVN {
+
+ UserManagerCompatVNMr1(Context context) {
+ super(context);
+ }
+
+ @Override
+ public boolean isDemoUser() {
+ return mUserManager.isDemoUser();
+ }
+}
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index 9da1cb3..b67d3b8 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -43,7 +43,6 @@
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
-import com.android.launcher3.Workspace;
import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.ItemInfoMatcher;
@@ -51,7 +50,6 @@
import com.android.launcher3.util.TouchController;
import java.util.ArrayList;
-import java.util.HashSet;
/**
* Class for initiating a drag within a view or across multiple views.
@@ -59,12 +57,6 @@
public class DragController implements DragDriver.EventListener, TouchController {
private static final String TAG = "Launcher.DragController";
- /** Indicates the drag is a move. */
- public static int DRAG_ACTION_MOVE = 0;
-
- /** Indicates the drag is a copy. */
- public static int DRAG_ACTION_COPY = 1;
-
public static final int SCROLL_DELAY = 500;
public static final int RESCROLL_DELAY = PagedView.PAGE_SNAP_ANIMATION_DURATION + 150;
@@ -93,8 +85,8 @@
*/
private DragDriver mDragDriver = null;
- /** Whether or not an accessible drag operation is in progress. */
- private boolean mIsAccessibleDrag;
+ /** Options controlling the drag behavior. */
+ private DragOptions mOptions;
/** X coordinate of the down event. */
private int mMotionDownX;
@@ -147,12 +139,10 @@
/**
* A drag has begun
*
- * @param source An object representing where the drag originated
- * @param info The data associated with the object that is being dragged
- * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE}
- * or {@link DragController#DRAG_ACTION_COPY}
+ * @param dragObject The object being dragged
+ * @param options Options used to start the drag
*/
- void onDragStart(DragSource source, ItemInfo info, int dragAction);
+ void onDragStart(DropTarget.DragObject dragObject, DragOptions options);
/**
* The drag has ended
@@ -162,8 +152,6 @@
/**
* Used to create a new DragLayer from XML.
- *
- * @param context The application's context.
*/
public DragController(Launcher launcher) {
Resources r = launcher.getResources();
@@ -185,11 +173,9 @@
* @param source An object representing where the drag originated
* @param dragInfo The data associated with the object that is being dragged
* @param viewImageBounds the position of the image inside the view
- * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
- * {@link #DRAG_ACTION_COPY}
*/
public void startDrag(View v, Bitmap bmp, DragSource source, ItemInfo dragInfo,
- Rect viewImageBounds, int dragAction, float initialDragViewScale) {
+ Rect viewImageBounds, float initialDragViewScale, DragOptions options) {
int[] loc = mCoordinatesTemp;
mLauncher.getDragLayer().getLocationInDragLayer(v, loc);
int dragLayerX = loc[0] + viewImageBounds.left
@@ -197,12 +183,8 @@
int dragLayerY = loc[1] + viewImageBounds.top
+ (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2);
- startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null,
- null, initialDragViewScale, false);
-
- if (dragAction == DRAG_ACTION_MOVE) {
- v.setVisibility(View.GONE);
- }
+ startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, null,
+ null, initialDragViewScale, options);
}
/**
@@ -214,15 +196,12 @@
* @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
* @param source An object representing where the drag originated
* @param dragInfo The data associated with the object that is being dragged
- * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
- * {@link #DRAG_ACTION_COPY}
* @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
* Makes dragging feel more precise, e.g. you can clip out a transparent border
- * @param accessible whether this drag should occur in accessibility mode
*/
public DragView startDrag(Bitmap b, int dragLayerX, int dragLayerY,
- DragSource source, ItemInfo dragInfo, int dragAction, Point dragOffset, Rect dragRegion,
- float initialDragViewScale, boolean accessible) {
+ DragSource source, ItemInfo dragInfo, Point dragOffset, Rect dragRegion,
+ float initialDragViewScale, DragOptions options) {
if (PROFILE_DRAWING_DURING_DRAG) {
android.os.Debug.startMethodTracing("Launcher");
}
@@ -234,19 +213,15 @@
}
mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);
- for (DragListener listener : mListeners) {
- listener.onDragStart(source, dragInfo, dragAction);
- }
-
final int registrationX = mMotionDownX - dragLayerX;
final int registrationY = mMotionDownY - dragLayerY;
final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
- mIsAccessibleDrag = accessible;
mLastDropTarget = null;
+ mOptions = options;
mDragObject = new DropTarget.DragObject();
final Resources res = mLauncher.getResources();
@@ -256,7 +231,7 @@
registrationY, initialDragViewScale, scaleDps);
mDragObject.dragComplete = false;
- if (mIsAccessibleDrag) {
+ if (mOptions.isAccessibleDrag) {
// For an accessible drag, we assume the view is being dragged from the center.
mDragObject.xOffset = b.getWidth() / 2;
mDragObject.yOffset = b.getHeight() / 2;
@@ -271,6 +246,8 @@
mDragObject.dragSource = source;
mDragObject.dragInfo = dragInfo;
+ mDragObject.originalDragInfo = new ItemInfo();
+ mDragObject.originalDragInfo.copyFrom(dragInfo);
if (dragOffset != null) {
dragView.setDragVisualizeOffset(new Point(dragOffset));
@@ -282,9 +259,15 @@
mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
dragView.show(mMotionDownX, mMotionDownY);
mDistanceSinceScroll = 0;
+
+ for (DragListener listener : mListeners) {
+ listener.onDragStart(mDragObject, mOptions);
+ }
+
mLastTouch[0] = mMotionDownX;
mLastTouch[1] = mMotionDownY;
handleMoveEvent(mMotionDownX, mMotionDownY);
+ mLauncher.getUserEventDispatcher().resetActionDurationMillis();
return dragView;
}
@@ -307,7 +290,7 @@
}
public boolean isDragging() {
- return mDragDriver != null || mIsAccessibleDrag;
+ return mDragDriver != null || (mOptions != null && mOptions.isAccessibleDrag);
}
/**
@@ -342,7 +325,7 @@
private void endDrag() {
if (isDragging()) {
mDragDriver = null;
- mIsAccessibleDrag = false;
+ mOptions = null;
clearScrollRunnable();
boolean isDeferred = false;
if (mDragObject.dragView != null) {
@@ -421,10 +404,6 @@
@Override
public void onDriverDragEnd(float x, float y, DropTarget dropTargetOverride) {
- final int[] dragLayerPos = getClampedDragLayerPos(x, y);
- final int dragLayerX = dragLayerPos[0];
- final int dragLayerY = dragLayerPos[1];
-
DropTarget dropTarget;
PointF vec = null;
@@ -453,14 +432,7 @@
* Call this from a drag source view.
*/
public boolean onInterceptTouchEvent(MotionEvent ev) {
- @SuppressWarnings("all") // suppress dead code warning
- final boolean debug = false;
- if (debug) {
- Log.d(Launcher.TAG, "DragController.onInterceptTouchEvent " + ev + " Dragging="
- + (mDragDriver != null));
- }
-
- if (mIsAccessibleDrag) {
+ if (mOptions != null && mOptions.isAccessibleDrag) {
return false;
}
@@ -507,7 +479,7 @@
*/
public void setMoveTarget(View view) {
mMoveTarget = view;
- }
+ }
public boolean dispatchUnhandledMove(View focused, int direction) {
return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction);
@@ -603,7 +575,7 @@
* Call this from a drag source view.
*/
public boolean onTouchEvent(MotionEvent ev) {
- if (mDragDriver == null || mIsAccessibleDrag) {
+ if (mDragDriver == null || mOptions == null || mOptions.isAccessibleDrag) {
return false;
}
@@ -734,6 +706,7 @@
final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null;
mDragObject.dragSource.onDropCompleted(
dropTargetAsView, mDragObject, flingVel != null, accepted);
+ mLauncher.getUserEventDispatcher().logDragNDrop(mDragObject, dropTargetAsView);
}
private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index e88e77e..e5ec6ba 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -100,7 +100,6 @@
private TouchCompleteListener mTouchCompleteListener;
- private View mOverlayView;
private int mTopViewIndex;
private int mChildCountOnLastUpdate = -1;
@@ -172,20 +171,6 @@
? null : new PinchToOverviewListener(mLauncher);
}
- public void showOverlayView(View overlayView) {
- LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- mOverlayView = overlayView;
- addView(overlayView, lp);
-
- // ensure that the overlay view stays on top. we can't use drawing order for this
- // because in API level 16 touch dispatch doesn't respect drawing order.
- mOverlayView.bringToFront();
- }
-
- public void dismissOverlayView() {
- removeView(mOverlayView);
- }
-
public boolean isEventOverPageIndicator(MotionEvent ev) {
getDescendantRectRelativeToSelf(mLauncher.getWorkspace().getPageIndicator(), mHitRect);
return mHitRect.contains((int) ev.getX(), (int) ev.getY());
@@ -358,16 +343,9 @@
}
private void sendTapOutsideFolderAccessibilityEvent(boolean isEditingName) {
- AccessibilityManager accessibilityManager = (AccessibilityManager)
- getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
- if (accessibilityManager.isEnabled()) {
- int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close;
- AccessibilityEvent event = AccessibilityEvent.obtain(
- AccessibilityEvent.TYPE_VIEW_FOCUSED);
- onInitializeAccessibilityEvent(event);
- event.getText().add(getContext().getString(stringId));
- accessibilityManager.sendAccessibilityEvent(event);
- }
+ int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close;
+ Utilities.sendCustomAccessibilityEvent(
+ this, AccessibilityEvent.TYPE_VIEW_FOCUSED, getContext().getString(stringId));
}
private boolean isInAccessibleDrag() {
@@ -377,37 +355,27 @@
@Override
public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
// Shortcuts can appear above folder
- View topView = mLauncher.getOpenShortcutsContainer();
+ View topView = mLauncher.getTopFloatingView();
if (topView != null) {
- return handleTopViewSendAccessibilityEvent(topView, child, event);
- }
-
- topView = mLauncher.getWorkspace().getOpenFolder();
- if (topView != null) {
- return handleTopViewSendAccessibilityEvent(topView, child, event);
+ if (child == topView) {
+ return super.onRequestSendAccessibilityEvent(child, event);
+ }
+ if (isInAccessibleDrag() && child instanceof DropTargetBar) {
+ return super.onRequestSendAccessibilityEvent(child, event);
+ }
+ // Skip propagating onRequestSendAccessibilityEvent for all other children
+ // which are not topView
+ return false;
}
return super.onRequestSendAccessibilityEvent(child, event);
}
- private boolean handleTopViewSendAccessibilityEvent(
- View topView, View child, AccessibilityEvent event) {
- if (child == topView) {
- return super.onRequestSendAccessibilityEvent(child, event);
- }
- if (isInAccessibleDrag() && child instanceof DropTargetBar) {
- return super.onRequestSendAccessibilityEvent(child, event);
- }
- // Skip propagating onRequestSendAccessibilityEvent for all other children
- // which are not topView
- return false;
- }
-
@Override
public void addChildrenForAccessibility(ArrayList<View> childrenForAccessibility) {
- Folder currentFolder = mLauncher.getWorkspace().getOpenFolder();
- if (currentFolder != null) {
- // Only add the folder as a child for accessibility when it is open
- childrenForAccessibility.add(currentFolder);
+ View topView = mLauncher.getTopFloatingView();
+ if (topView != null) {
+ // Only add the top view as a child for accessibility when it is open
+ childrenForAccessibility.add(topView);
if (isInAccessibleDrag()) {
childrenForAccessibility.add(mLauncher.getDropTargetBar());
@@ -903,11 +871,6 @@
@Override
public void onChildViewAdded(View parent, View child) {
super.onChildViewAdded(parent, child);
- if (mOverlayView != null) {
- // ensure that the overlay view stays on top. we can't use drawing order for this
- // because in API level 16 touch dispatch doesn't respect drawing order.
- mOverlayView.bringToFront();
- }
updateChildIndices();
}
@@ -919,11 +882,6 @@
@Override
public void bringChildToFront(View child) {
super.bringChildToFront(child);
- if (child != mOverlayView && mOverlayView != null) {
- // ensure that the overlay view stays on top. we can't use drawing order for this
- // because in API level 16 touch dispatch doesn't respect drawing order.
- mOverlayView.bringToFront();
- }
updateChildIndices();
}
@@ -1062,6 +1020,26 @@
return mBackgroundAlpha;
}
+ @Override
+ protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
+ View topView = mLauncher.getTopFloatingView();
+ if (topView != null) {
+ return topView.requestFocus(direction, previouslyFocusedRect);
+ } else {
+ return super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
+ }
+ }
+
+ @Override
+ public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
+ View topView = mLauncher.getTopFloatingView();
+ if (topView != null) {
+ topView.addFocusables(views, direction);
+ } else {
+ super.addFocusables(views, direction, focusableMode);
+ }
+ }
+
public void setTouchCompleteListener(TouchCompleteListener listener) {
mTouchCompleteListener = listener;
}
diff --git a/src/com/android/launcher3/dragndrop/DragOptions.java b/src/com/android/launcher3/dragndrop/DragOptions.java
new file mode 100644
index 0000000..a7f2872
--- /dev/null
+++ b/src/com/android/launcher3/dragndrop/DragOptions.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2016 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.dragndrop;
+
+/**
+ * Set of options to control the drag and drop behavior.
+ */
+public class DragOptions {
+
+ /** Whether or not an accessible drag operation is in progress. */
+ public boolean isAccessibleDrag = false;
+}
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 96da181..19956a9 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -42,7 +42,6 @@
import android.view.View;
import android.view.ViewDebug;
import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
@@ -52,7 +51,6 @@
import com.android.launcher3.Alarm;
import com.android.launcher3.CellLayout;
-import com.android.launcher3.CellLayout.CellInfo;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
@@ -71,12 +69,12 @@
import com.android.launcher3.UninstallDropTarget.DropTargetSource;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace.ItemOperator;
-import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource;
+import com.android.launcher3.accessibility.AccessibileDragListenerAdapter;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragController.DragListener;
import com.android.launcher3.dragndrop.DragLayer;
-import com.android.launcher3.logging.UserEventDispatcher.LaunchSourceProvider;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.pageindicators.PageIndicatorDots;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -92,8 +90,7 @@
*/
public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
- View.OnFocusChangeListener, DragListener, DropTargetSource, AccessibilityDragSource,
- LaunchSourceProvider {
+ View.OnFocusChangeListener, DragListener, DropTargetSource {
private static final String TAG = "Launcher.Folder";
/**
@@ -283,10 +280,10 @@
public boolean onLongClick(View v) {
// Return if global dragging is not enabled
if (!mLauncher.isDraggingEnabled()) return true;
- return beginDrag(v, false);
+ return startDrag(v, new DragOptions());
}
- private boolean beginDrag(View v, boolean accessible) {
+ public boolean startDrag(View v, DragOptions options) {
Object tag = v.getTag();
if (tag instanceof ShortcutInfo) {
ShortcutInfo item = (ShortcutInfo) tag;
@@ -294,35 +291,48 @@
return false;
}
- mLauncher.getWorkspace().beginDragShared(v, this, accessible);
-
mCurrentDragInfo = item;
mEmptyCellRank = item.rank;
mCurrentDragView = v;
- mContent.removeItem(mCurrentDragView);
- mInfo.remove(mCurrentDragInfo, true);
- mDragInProgress = true;
- mItemAddedBackToSelfViaIcon = false;
+ mDragController.addDragListener(this);
+ if (options.isAccessibleDrag) {
+ mDragController.addDragListener(new AccessibileDragListenerAdapter(
+ mContent, CellLayout.FOLDER_ACCESSIBILITY_DRAG) {
+
+ @Override
+ protected void enableAccessibleDrag(boolean enable) {
+ super.enableAccessibleDrag(enable);
+ mFooter.setImportantForAccessibility(enable
+ ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
+ : IMPORTANT_FOR_ACCESSIBILITY_AUTO);
+ }
+ });
+ }
+
+ mLauncher.getWorkspace().beginDragShared(v, this, options);
}
return true;
}
@Override
- public void startDrag(CellInfo cellInfo, boolean accessible) {
- beginDrag(cellInfo.cell, accessible);
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
+ if (dragObject.dragSource != this) {
+ return;
+ }
+
+ mContent.removeItem(mCurrentDragView);
+ mInfo.remove(mCurrentDragInfo, true);
+ mDragInProgress = true;
+ mItemAddedBackToSelfViaIcon = false;
}
@Override
- public void enableAccessibleDrag(boolean enable) {
- mLauncher.getDropTargetBar().enableAccessibleDrag(enable);
- for (int i = 0; i < mContent.getChildCount(); i++) {
- mContent.getPageAt(i).enableAccessibleDrag(enable, CellLayout.FOLDER_ACCESSIBILITY_DRAG);
+ public void onDragEnd() {
+ if (mIsExternalDrag && mDragInProgress) {
+ completeDragExit();
}
-
- mFooter.setImportantForAccessibility(enable ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS :
- IMPORTANT_FOR_ACCESSIBILITY_AUTO);
- mLauncher.getWorkspace().setAddNewPageOnDrag(!enable);
+ mDragController.removeDragListener(this);
}
public boolean isEditingName() {
@@ -353,7 +363,8 @@
LauncherModel.updateItemInDatabase(mLauncher, mInfo);
if (commit) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
getContext().getString(R.string.folder_renamed, newTitle));
}
@@ -592,7 +603,9 @@
openFolderAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ Folder.this,
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
mContent.getAccessibilityDescription());
mState = STATE_ANIMATING;
}
@@ -662,28 +675,6 @@
mDragController.addDragListener(this);
}
- @Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) { }
-
- @Override
- public void onDragEnd() {
- if (mIsExternalDrag && mDragInProgress) {
- completeDragExit();
- }
- mDragController.removeDragListener(this);
- }
-
- @Thunk void sendCustomAccessibilityEvent(int type, String text) {
- AccessibilityManager accessibilityManager = (AccessibilityManager)
- getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
- if (accessibilityManager.isEnabled()) {
- AccessibilityEvent event = AccessibilityEvent.obtain(type);
- onInitializeAccessibilityEvent(event);
- event.getText().add(text);
- accessibilityManager.sendAccessibilityEvent(event);
- }
- }
-
public void animateClosed() {
if (!(getParent() instanceof DragLayer)) return;
final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 0, 0.9f, 0.9f);
@@ -695,7 +686,9 @@
}
@Override
public void onAnimationStart(Animator animation) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ Folder.this,
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
getContext().getString(R.string.folder_closed));
mState = STATE_ANIMATING;
}
diff --git a/src/com/android/launcher3/graphics/DragPreviewProvider.java b/src/com/android/launcher3/graphics/DragPreviewProvider.java
index b90c2fd..bc91c15 100644
--- a/src/com/android/launcher3/graphics/DragPreviewProvider.java
+++ b/src/com/android/launcher3/graphics/DragPreviewProvider.java
@@ -27,8 +27,8 @@
import com.android.launcher3.HolographicOutlineHelper;
import com.android.launcher3.Launcher;
import com.android.launcher3.PreloadIconDrawable;
-import com.android.launcher3.R;
import com.android.launcher3.Workspace;
+import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.folder.FolderIcon;
/**
@@ -45,6 +45,8 @@
// The padding added to the drag view during the preview generation.
public final int previewPadding;
+ public Bitmap gerenatedDragOutline;
+
public DragPreviewProvider(View view) {
mView = view;
@@ -118,19 +120,25 @@
return b;
}
+ public final void generateDragOutline(Canvas canvas) {
+ if (ProviderConfig.IS_DOGFOOD_BUILD && gerenatedDragOutline != null) {
+ throw new RuntimeException("Drag outline generated twice");
+ }
+
+ gerenatedDragOutline = createDragOutline(canvas);
+ }
+
/**
* Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
* Responsibility for the bitmap is transferred to the caller.
*/
public Bitmap createDragOutline(Canvas canvas) {
- final int outlineColor = mView.getResources().getColor(R.color.outline_color);
final Bitmap b = Bitmap.createBitmap(mView.getWidth() + DRAG_BITMAP_PADDING,
- mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ARGB_8888);
-
+ mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ALPHA_8);
canvas.setBitmap(b);
drawDragView(canvas);
HolographicOutlineHelper.obtain(mView.getContext())
- .applyExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor);
+ .applyExpensiveOutlineWithBlur(b, canvas);
canvas.setBitmap(null);
return b;
}
diff --git a/src/com/android/launcher3/logging/LoggerUtils.java b/src/com/android/launcher3/logging/LoggerUtils.java
index dc04597..845dbc2 100644
--- a/src/com/android/launcher3/logging/LoggerUtils.java
+++ b/src/com/android/launcher3/logging/LoggerUtils.java
@@ -2,8 +2,12 @@
import android.view.View;
+import com.android.launcher3.ButtonDropTarget;
+import com.android.launcher3.DeleteDropTarget;
+import com.android.launcher3.InfoDropTarget;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.UninstallDropTarget;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -164,14 +168,35 @@
return event;
}
- private static Target initTarget(View v) {
+ /**
+ * Used for drag and drop interaction.
+ */
+ public static LauncherLogProto.LauncherEvent initLauncherEvent(
+ int actionType,
+ View v,
+ ItemInfo info,
+ int parentSrcTargetType,
+ View parentDestTargetType){
+ LauncherLogProto.LauncherEvent event = new LauncherLogProto.LauncherEvent();
+
+ event.srcTarget = new LauncherLogProto.Target[2];
+ event.srcTarget[0] = initTarget(v, info);
+ event.srcTarget[1] = new LauncherLogProto.Target();
+ event.srcTarget[1].type = parentSrcTargetType;
+
+ event.destTarget = new LauncherLogProto.Target[2];
+ event.destTarget[0] = initTarget(v, info);
+ event.destTarget[1] = initDropTarget(parentDestTargetType);
+
+ event.action = new LauncherLogProto.Action();
+ event.action.type = actionType;
+ return event;
+ }
+
+ private static Target initTarget(View v, ItemInfo info) {
Target t = new LauncherLogProto.Target();
t.type = Target.ITEM;
- if (!(v.getTag() instanceof ItemInfo)) {
- return t;
- }
- ItemInfo itemInfo = (ItemInfo) v.getTag();
- switch (itemInfo.itemType) {
+ switch (info.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
t.itemType = LauncherLogProto.APP_ICON;
break;
@@ -190,4 +215,30 @@
}
return t;
}
+
+ private static Target initDropTarget(View v) {
+ Target t = new LauncherLogProto.Target();
+ t.type = (v instanceof ButtonDropTarget)? Target.CONTROL : Target.CONTAINER;
+ if (t.type == Target.CONTAINER) {
+ return t;
+ }
+
+ if (v instanceof InfoDropTarget) {
+ t.controlType = LauncherLogProto.APPINFO_TARGET;
+ } else if (v instanceof UninstallDropTarget) {
+ t.controlType = LauncherLogProto.UNINSTALL_TARGET;
+ } else if (v instanceof DeleteDropTarget) {
+ t.controlType = LauncherLogProto.REMOVE_TARGET;
+ }
+ return t;
+ }
+
+ private static Target initTarget(View v) {
+ Target t = new LauncherLogProto.Target();
+ t.type = Target.ITEM;
+ if (!(v.getTag() instanceof ItemInfo)) {
+ return t;
+ }
+ return initTarget(v, (ItemInfo) v.getTag());
+ }
}
diff --git a/src/com/android/launcher3/logging/UserEventDispatcher.java b/src/com/android/launcher3/logging/UserEventDispatcher.java
index e4cc182..0356a9c 100644
--- a/src/com/android/launcher3/logging/UserEventDispatcher.java
+++ b/src/com/android/launcher3/logging/UserEventDispatcher.java
@@ -18,12 +18,15 @@
import android.content.ComponentName;
import android.content.Intent;
+import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.view.ViewParent;
+import com.android.launcher3.DropTarget;
import com.android.launcher3.ItemInfo;
-import com.android.launcher3.userevent.nano.LauncherLogProto;
+import com.android.launcher3.Utilities;
+import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -37,10 +40,15 @@
*/
public class UserEventDispatcher {
- private static final boolean DEBUG_LOGGING = false;
private final static int MAXIMUM_VIEW_HIERARCHY_LEVEL = 5;
+ private final boolean mIsVerbose;
+
/**
+ * TODO: change the name of this interface to LogContainerProvider
+ * and the method name to fillInLogContainerData. Not changed to minimize CL diff
+ * in this branch.
+ *
* Implemented by containers to provide a launch source for a given child.
*/
public interface LaunchSourceProvider {
@@ -61,6 +69,7 @@
*/
public static LaunchSourceProvider getLaunchProviderRecursive(View v) {
ViewParent parent = null;
+
if (v != null) {
parent = v.getParent();
} else {
@@ -88,6 +97,14 @@
// Used for filling in predictedRank on {@link Target}s.
private List<ComponentKey> mPredictedApps;
+ public UserEventDispatcher() {
+ if (ProviderConfig.IS_DOGFOOD_BUILD) {
+ mIsVerbose = Utilities.isPropertyEnabled(TAG);
+ } else {
+ mIsVerbose = false;
+ }
+ }
+
// APP_ICON SHORTCUT WIDGET
// --------------------------------------------------------------
// packageNameHash required optional required
@@ -104,7 +121,7 @@
// TODO: make this percolate up the view hierarchy if needed.
int idx = 0;
LaunchSourceProvider provider = getLaunchProviderRecursive(v);
- if (!(v.getTag() instanceof ItemInfo)) {
+ if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) {
return null;
}
ItemInfo itemInfo = (ItemInfo) v.getTag();
@@ -122,8 +139,8 @@
}
// Fill in the duration of time spent navigating in Launcher and the container.
- event.elapsedContainerMillis = System.currentTimeMillis() - mElapsedContainerMillis;
- event.elapsedSessionMillis = System.currentTimeMillis() - mElapsedSessionMillis;
+ event.elapsedContainerMillis = SystemClock.uptimeMillis() - mElapsedContainerMillis;
+ event.elapsedSessionMillis = SystemClock.uptimeMillis() - mElapsedSessionMillis;
return event;
}
@@ -139,8 +156,8 @@
LauncherEvent event = LoggerUtils.initLauncherEvent(Action.TOUCH, Target.CONTROL);
event.action.touch = action;
event.srcTarget[0].controlType = controlType;
- event.elapsedContainerMillis = System.currentTimeMillis() - mElapsedContainerMillis;
- event.elapsedSessionMillis = System.currentTimeMillis() - mElapsedSessionMillis;
+ event.elapsedContainerMillis = SystemClock.uptimeMillis() - mElapsedContainerMillis;
+ event.elapsedSessionMillis = SystemClock.uptimeMillis() - mElapsedSessionMillis;
dispatchUserEvent(event, null);
}
@@ -149,8 +166,8 @@
event.action.touch = action;
event.action.dir = dir;
event.srcTarget[0].containerType = containerType;
- event.elapsedContainerMillis = System.currentTimeMillis() - mElapsedContainerMillis;
- event.elapsedSessionMillis = System.currentTimeMillis() - mElapsedSessionMillis;
+ event.elapsedContainerMillis = SystemClock.uptimeMillis() - mElapsedContainerMillis;
+ event.elapsedSessionMillis = SystemClock.uptimeMillis() - mElapsedSessionMillis;
dispatchUserEvent(event, null);
}
@@ -158,14 +175,14 @@
LauncherEvent event = LoggerUtils.initLauncherEvent(
Action.TOUCH, icon, Target.CONTAINER);
LaunchSourceProvider provider = getLaunchProviderRecursive(icon);
- if (!(icon.getTag() instanceof ItemInfo)) {
+ if (icon == null && !(icon.getTag() instanceof ItemInfo)) {
return;
}
ItemInfo info = (ItemInfo) icon.getTag();
provider.fillInLaunchSourceData(icon, info, event.srcTarget[0], event.srcTarget[1]);
event.action.touch = Action.LONGPRESS;
- event.elapsedContainerMillis = System.currentTimeMillis() - mElapsedContainerMillis;
- event.elapsedSessionMillis = System.currentTimeMillis() - mElapsedSessionMillis;
+ event.elapsedContainerMillis = SystemClock.uptimeMillis() - mElapsedContainerMillis;
+ event.elapsedSessionMillis = SystemClock.uptimeMillis() - mElapsedSessionMillis;
dispatchUserEvent(event, null);
}
@@ -173,39 +190,66 @@
mPredictedApps = predictedApps;
}
+ public void logDragNDrop(DropTarget.DragObject dragObj, View dropTargetAsView) {
+ LauncherEvent event = LoggerUtils.initLauncherEvent(Action.TOUCH,
+ dragObj.dragView,
+ dragObj.originalDragInfo,
+ Target.CONTAINER,
+ dropTargetAsView);
+ event.action.touch = Action.DRAGDROP;
+
+ dragObj.dragSource.fillInLaunchSourceData(null, dragObj.originalDragInfo,
+ event.srcTarget[0], event.srcTarget[1]);
+
+ if (dropTargetAsView instanceof LaunchSourceProvider) {
+ ((LaunchSourceProvider) dropTargetAsView).fillInLaunchSourceData(null,
+ dragObj.dragInfo, event.destTarget[0], event.destTarget[1]);
+
+ }
+
+ event.elapsedContainerMillis = SystemClock.uptimeMillis() - mElapsedContainerMillis;
+ event.elapsedSessionMillis = SystemClock.uptimeMillis() - mElapsedSessionMillis;
+ event.actionDurationMillis = SystemClock.uptimeMillis() - mActionDurationMillis;
+ dispatchUserEvent(event, null);
+ }
+
/**
* Currently logs following containers: workspace, allapps, widget tray.
*/
public final void resetElapsedContainerMillis() {
- mElapsedContainerMillis = System.currentTimeMillis();
+ mElapsedContainerMillis = SystemClock.uptimeMillis();
}
public final void resetElapsedSessionMillis() {
- mElapsedSessionMillis = System.currentTimeMillis();
- mElapsedContainerMillis = System.currentTimeMillis();
+ mElapsedSessionMillis = SystemClock.uptimeMillis();
+ mElapsedContainerMillis = SystemClock.uptimeMillis();
}
public final void resetActionDurationMillis() {
- mActionDurationMillis = System.currentTimeMillis();
+ mActionDurationMillis = SystemClock.uptimeMillis();
}
public void dispatchUserEvent(LauncherEvent ev, Intent intent) {
- if (DEBUG_LOGGING) {
- Log.d(TAG, String.format(Locale.US,
- "\naction:%s\n Source child:%s\tparent:%s",
- LoggerUtils.getActionStr(ev.action),
- LoggerUtils.getTargetStr(ev.srcTarget != null ? ev.srcTarget[0] : null),
- LoggerUtils.getTargetStr(ev.srcTarget.length > 1 ? ev.srcTarget[1] : null)));
- if (ev.destTarget != null && ev.destTarget.length > 0) {
- Log.d(TAG, String.format(Locale.US,
- " Destination child:%s\tparent:%s",
- LoggerUtils.getTargetStr(ev.destTarget != null ? ev.destTarget[0] : null),
- LoggerUtils.getTargetStr(ev.destTarget.length > 1 ? ev.destTarget[1] : null)));
- }
- Log.d(TAG, String.format(Locale.US,
- " Elapsed container %d ms session %d ms",
- ev.elapsedContainerMillis,
- ev.elapsedSessionMillis));
+ if (!mIsVerbose) {
+ return;
}
+ Log.d(TAG, String.format(Locale.US,
+ "\naction:%s\n Source child:%s\tparent:%s",
+ LoggerUtils.getActionStr(ev.action),
+ LoggerUtils.getTargetStr(ev.srcTarget != null ? ev.srcTarget[0] : null),
+ LoggerUtils.getTargetStr(ev.srcTarget != null && ev.srcTarget.length > 1 ?
+ ev.srcTarget[1] : null)));
+ if (ev.destTarget != null && ev.destTarget.length > 0) {
+ Log.d(TAG, String.format(Locale.US,
+ " Destination child:%s\tparent:%s",
+ LoggerUtils.getTargetStr(ev.destTarget != null ? ev.destTarget[0] : null),
+ LoggerUtils.getTargetStr(ev.destTarget != null && ev.destTarget.length > 1 ?
+ ev.destTarget[1] : null)));
+ }
+ Log.d(TAG, String.format(Locale.US,
+ " Elapsed container %d ms session %d ms action %d ms",
+ ev.elapsedContainerMillis,
+ ev.elapsedSessionMillis,
+ ev.actionDurationMillis));
}
}
diff --git a/src/com/android/launcher3/model/PackageItemInfo.java b/src/com/android/launcher3/model/PackageItemInfo.java
index ddc9cbf..c86ba86 100644
--- a/src/com/android/launcher3/model/PackageItemInfo.java
+++ b/src/com/android/launcher3/model/PackageItemInfo.java
@@ -46,17 +46,12 @@
*/
public String titleSectionName;
- int flags = 0;
-
PackageItemInfo(String packageName) {
this.packageName = packageName;
}
@Override
- public String toString() {
- return "PackageItemInfo(title=" + title + " id=" + this.id
- + " type=" + this.itemType + " container=" + this.container
- + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
- + " spanX=" + spanX + " spanY=" + spanY + " user=" + user + ")";
+ protected String dumpProperties() {
+ return super.dumpProperties() + " packageName=" + packageName;
}
}
diff --git a/src/com/android/launcher3/model/WidgetItem.java b/src/com/android/launcher3/model/WidgetItem.java
index b3f0c82..0d7ba1e 100644
--- a/src/com/android/launcher3/model/WidgetItem.java
+++ b/src/com/android/launcher3/model/WidgetItem.java
@@ -68,6 +68,17 @@
return thisWorkProfile ? 1 : -1;
}
- return sCollator.compare(label, another.label);
+ int labelCompare = sCollator.compare(label, another.label);
+ if (labelCompare != 0) {
+ return labelCompare;
+ }
+
+ // If the label is same, put the smaller widget before the larger widget. If the area is
+ // also same, put the widget with smaller height before.
+ int thisArea = spanX * spanY;
+ int otherArea = another.spanX * another.spanY;
+ return thisArea == otherArea
+ ? Integer.compare(spanY, another.spanY)
+ : Integer.compare(thisArea, otherArea);
}
}
diff --git a/src/com/android/launcher3/provider/RestoreDbTask.java b/src/com/android/launcher3/provider/RestoreDbTask.java
index 9d8b6b3..47bee06 100644
--- a/src/com/android/launcher3/provider/RestoreDbTask.java
+++ b/src/com/android/launcher3/provider/RestoreDbTask.java
@@ -24,6 +24,7 @@
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.LauncherProvider.DatabaseHelper;
import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.logging.FileLog;
@@ -43,6 +44,13 @@
private static final String INFO_COLUMN_NAME = "name";
private static final String INFO_COLUMN_DEFAULT_VALUE = "dflt_value";
+ /**
+ * When enabled all icons are kept on the home screen, even if they don't have an active
+ * session. To enable use:
+ * adb shell setprop log.tag.launcher_keep_all_icons VERBOSE
+ */
+ private static final String KEEP_ALL_ICONS = "launcher_keep_all_icons";
+
public static boolean performRestore(DatabaseHelper helper) {
SQLiteDatabase db = helper.getWritableDatabase();
db.beginTransaction();
@@ -77,15 +85,17 @@
}
// Mark all items as restored.
+ boolean keepAllIcons = Utilities.isPropertyEnabled(KEEP_ALL_ICONS);
ContentValues values = new ContentValues();
- values.put(Favorites.RESTORED, 1);
+ values.put(Favorites.RESTORED, ShortcutInfo.FLAG_RESTORED_ICON
+ | (keepAllIcons ? ShortcutInfo.FLAG_RESTORE_STARTED : 0));
db.update(Favorites.TABLE_NAME, values, null, null);
// Mark widgets with appropriate restore flag
- values.put(Favorites.RESTORED,
- LauncherAppWidgetInfo.FLAG_ID_NOT_VALID |
- LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY |
- LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
+ values.put(Favorites.RESTORED, LauncherAppWidgetInfo.FLAG_ID_NOT_VALID |
+ LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY |
+ LauncherAppWidgetInfo.FLAG_UI_NOT_READY |
+ (keepAllIcons ? LauncherAppWidgetInfo.FLAG_RESTORE_STARTED : 0));
db.update(Favorites.TABLE_NAME, values, "itemType = ?",
new String[]{Integer.toString(Favorites.ITEM_TYPE_APPWIDGET)});
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java
index 37b6d04..e7fc415 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java
@@ -21,16 +21,19 @@
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import com.android.launcher3.IconCache;
+import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LogAccelerateInterpolator;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
+import com.android.launcher3.shortcuts.DeepShortcutsContainer.UnbadgedShortcutInfo;
import com.android.launcher3.util.PillRevealOutlineProvider;
import com.android.launcher3.util.PillWidthRevealOutlineProvider;
@@ -48,6 +51,8 @@
private View mIconView;
private float mOpenAnimationProgress;
+ private UnbadgedShortcutInfo mInfo;
+
public DeepShortcutView(Context context) {
this(context, null, 0);
}
@@ -87,10 +92,36 @@
mPillRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
- public void applyShortcutInfo(ShortcutInfo info) {
+ /** package private **/
+ void applyShortcutInfo(UnbadgedShortcutInfo info, DeepShortcutsContainer container) {
+ mInfo = info;
IconCache cache = LauncherAppState.getInstance().getIconCache();
mBubbleText.applyFromShortcutInfo(info, cache);
mIconView.setBackground(mBubbleText.getIcon());
+
+ // Use the long label as long as it exists and fits.
+ CharSequence longLabel = info.mDetail.getLongLabel();
+ int availableWidth = mBubbleText.getWidth() - mBubbleText.getTotalPaddingLeft()
+ - mBubbleText.getTotalPaddingRight();
+ boolean usingLongLabel = !TextUtils.isEmpty(longLabel)
+ && mBubbleText.getPaint().measureText(longLabel.toString()) <= availableWidth;
+ mBubbleText.setText(usingLongLabel ? longLabel : info.mDetail.getShortLabel());
+
+ // TODO: Add the click handler to this view directly and not the child view.
+ mBubbleText.setOnClickListener(Launcher.getLauncher(getContext()));
+ mBubbleText.setOnLongClickListener(container);
+ mBubbleText.setOnTouchListener(container);
+ }
+
+ /**
+ * Returns the shortcut info that is suitable to be added on the homescreen
+ */
+ public ShortcutInfo getFinalInfo() {
+ ShortcutInfo badged = new ShortcutInfo(mInfo);
+ // Queue an update task on the worker thread. This ensures that the badged
+ // shortcut eventually gets its icon updated.
+ Launcher.getLauncher(getContext()).getModel().updateShortcutInfo(mInfo.mDetail, badged);
+ return badged;
}
public View getIconView() {
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
index cfeccfc..3c7ba32 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
@@ -31,7 +31,6 @@
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
-import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
@@ -62,9 +61,9 @@
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.graphics.TriangleShape;
-import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -76,8 +75,7 @@
*/
@TargetApi(Build.VERSION_CODES.N)
public class DeepShortcutsContainer extends LinearLayout implements View.OnLongClickListener,
- View.OnTouchListener, DragSource, DragController.DragListener,
- UserEventDispatcher.LaunchSourceProvider {
+ View.OnTouchListener, DragSource, DragController.DragListener {
private static final String TAG = "ShortcutsContainer";
private final Point mIconShift = new Point();
@@ -183,12 +181,8 @@
}
for (int i = 0; i < shortcuts.size(); i++) {
final ShortcutInfoCompat shortcut = shortcuts.get(i);
- final ShortcutInfo launcherShortcutInfo =
- new UnbadgedShortcutInfo(shortcut, mLauncher);
- CharSequence shortLabel = shortcut.getShortLabel();
- CharSequence longLabel = shortcut.getLongLabel();
- uiHandler.post(new UpdateShortcutChild(i, launcherShortcutInfo,
- shortLabel, longLabel));
+ uiHandler.post(new UpdateShortcutChild(
+ i, new UnbadgedShortcutInfo(shortcut, mLauncher)));
}
}
});
@@ -197,32 +191,17 @@
/** Updates the child of this container at the given index based on the given shortcut info. */
private class UpdateShortcutChild implements Runnable {
private int mShortcutChildIndex;
- private ShortcutInfo mShortcutChildInfo;
- private CharSequence mShortLabel;
- private CharSequence mLongLabel;
+ private UnbadgedShortcutInfo mShortcutChildInfo;
- public UpdateShortcutChild(int shortcutChildIndex, ShortcutInfo shortcutChildInfo,
- CharSequence shortLabel, CharSequence longLabel) {
+ public UpdateShortcutChild(int shortcutChildIndex, UnbadgedShortcutInfo shortcutChildInfo) {
mShortcutChildIndex = shortcutChildIndex;
mShortcutChildInfo = shortcutChildInfo;
- mShortLabel = shortLabel;
- mLongLabel = longLabel;
}
@Override
public void run() {
- DeepShortcutView shortcutViewContainer = getShortcutAt(mShortcutChildIndex);
- shortcutViewContainer.applyShortcutInfo(mShortcutChildInfo);
- BubbleTextView shortcutView = getShortcutAt(mShortcutChildIndex).getBubbleText();
- // Use the long label as long as it exists and fits.
- int availableWidth = shortcutView.getWidth() - shortcutView.getTotalPaddingLeft()
- - shortcutView.getTotalPaddingRight();
- boolean usingLongLabel = !TextUtils.isEmpty(mLongLabel)
- && shortcutView.getPaint().measureText(mLongLabel.toString()) <= availableWidth;
- shortcutView.setText(usingLongLabel ? mLongLabel : mShortLabel);
- shortcutView.setOnClickListener(mLauncher);
- shortcutView.setOnLongClickListener(DeepShortcutsContainer.this);
- shortcutView.setOnTouchListener(DeepShortcutsContainer.this);
+ getShortcutAt(mShortcutChildIndex)
+ .applyShortcutInfo(mShortcutChildInfo, DeepShortcutsContainer.this);
}
}
@@ -274,8 +253,10 @@
@Override
public void onAnimationEnd(Animator animation) {
mOpenCloseAnimator = null;
-
- sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
+ Utilities.sendCustomAccessibilityEvent(
+ DeepShortcutsContainer.this,
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ getContext().getString(R.string.action_deep_shortcut));
}
});
@@ -525,14 +506,7 @@
// Return if global dragging is not enabled
if (!mLauncher.isDraggingEnabled()) return false;
- UnbadgedShortcutInfo unbadgedInfo = (UnbadgedShortcutInfo) v.getTag();
- ShortcutInfo badged = new ShortcutInfo(unbadgedInfo);
- // Queue an update task on the worker thread. This ensures that the badged
- // shortcut eventually gets its icon updated.
- mLauncher.getModel().updateShortcutInfo(unbadgedInfo.mDetail, badged);
-
// Long clicked on a shortcut.
-
mDeferContainerRemoval = true;
DeepShortcutView sv = (DeepShortcutView) v.getParent();
sv.setWillDrawIcon(false);
@@ -542,8 +516,8 @@
mIconShift.y = mIconLastTouchPos.y - mLauncher.getDeviceProfile().iconSizePx;
DragView dv = mLauncher.getWorkspace().beginDragShared(
- sv.getBubbleText(), this, false, badged,
- new ShortcutDragPreviewProvider(sv.getIconView(), mIconShift));
+ sv.getBubbleText(), this, sv.getFinalInfo(),
+ new ShortcutDragPreviewProvider(sv.getIconView(), mIconShift), new DragOptions());
dv.animateShift(-mIconShift.x, -mIconShift.y);
// TODO: support dragging from within folder without having to close it
@@ -587,7 +561,7 @@
}
@Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) {
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
// Either the original icon or one of the shortcuts was dragged.
// Hide the container, but don't remove it yet because that interferes with touch events.
animateClose();
@@ -754,8 +728,8 @@
/**
* Extension of {@link ShortcutInfo} which does not badge the icons.
*/
- private static class UnbadgedShortcutInfo extends ShortcutInfo {
- private final ShortcutInfoCompat mDetail;
+ static class UnbadgedShortcutInfo extends ShortcutInfo {
+ public final ShortcutInfoCompat mDetail;
public UnbadgedShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
super(shortcutInfo, context);
diff --git a/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java b/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java
index a25e475..2adb82e 100644
--- a/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java
+++ b/src/com/android/launcher3/shortcuts/ShortcutDragPreviewProvider.java
@@ -22,12 +22,9 @@
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
-import android.widget.ImageView;
-import com.android.launcher3.BubbleTextView;
import com.android.launcher3.HolographicOutlineHelper;
import com.android.launcher3.Launcher;
-import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.graphics.DragPreviewProvider;
@@ -45,23 +42,22 @@
@Override
public Bitmap createDragOutline(Canvas canvas) {
- Bitmap b = drawScaledPreview(canvas);
+ Bitmap b = drawScaledPreview(canvas, Bitmap.Config.ALPHA_8);
- final int outlineColor = mView.getResources().getColor(R.color.outline_color);
HolographicOutlineHelper.obtain(mView.getContext())
- .applyExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor);
+ .applyExpensiveOutlineWithBlur(b, canvas);
canvas.setBitmap(null);
return b;
}
@Override
public Bitmap createDragBitmap(Canvas canvas) {
- Bitmap b = drawScaledPreview(canvas);
+ Bitmap b = drawScaledPreview(canvas, Bitmap.Config.ARGB_8888);
canvas.setBitmap(null);
return b;
}
- private Bitmap drawScaledPreview(Canvas canvas) {
+ private Bitmap drawScaledPreview(Canvas canvas, Bitmap.Config config) {
Drawable d = mView.getBackground();
Rect bounds = getDrawableBounds(d);
@@ -70,7 +66,7 @@
final Bitmap b = Bitmap.createBitmap(
size + DRAG_BITMAP_PADDING,
size + DRAG_BITMAP_PADDING,
- Bitmap.Config.ARGB_8888);
+ config);
canvas.setBitmap(b);
canvas.save(Canvas.MATRIX_SAVE_FLAG);
diff --git a/src/com/android/launcher3/testing/LauncherExtension.java b/src/com/android/launcher3/testing/LauncherExtension.java
index ae552d2..0affc81 100644
--- a/src/com/android/launcher3/testing/LauncherExtension.java
+++ b/src/com/android/launcher3/testing/LauncherExtension.java
@@ -198,26 +198,6 @@
}
@Override
- public Intent getFirstRunActivity() {
- return null;
- }
-
- @Override
- public boolean hasFirstRunActivity() {
- return false;
- }
-
- @Override
- public boolean hasDismissableIntroScreen() {
- return false;
- }
-
- @Override
- public View getIntroScreen() {
- return null;
- }
-
- @Override
public boolean shouldMoveToDefaultScreenOnHomeIntent() {
return true;
}
diff --git a/src/com/android/launcher3/util/ComponentKey.java b/src/com/android/launcher3/util/ComponentKey.java
index 144b411..5882f21 100644
--- a/src/com/android/launcher3/util/ComponentKey.java
+++ b/src/com/android/launcher3/util/ComponentKey.java
@@ -32,8 +32,8 @@
private final int mHashCode;
public ComponentKey(ComponentName componentName, UserHandleCompat user) {
- assert (componentName != null);
- assert (user != null);
+ Preconditions.assertNotNull(componentName);
+ Preconditions.assertNotNull(user);
this.componentName = componentName;
this.user = user;
mHashCode = Arrays.hashCode(new Object[] {componentName, user});
@@ -58,6 +58,8 @@
componentName = ComponentName.unflattenFromString(componentKeyStr);
user = UserHandleCompat.myUserHandle();
}
+ Preconditions.assertNotNull(componentName);
+ Preconditions.assertNotNull(user);
mHashCode = Arrays.hashCode(new Object[] {componentName, user});
}
diff --git a/src/com/android/launcher3/util/Preconditions.java b/src/com/android/launcher3/util/Preconditions.java
index 3760c63..89353e1 100644
--- a/src/com/android/launcher3/util/Preconditions.java
+++ b/src/com/android/launcher3/util/Preconditions.java
@@ -26,6 +26,12 @@
*/
public class Preconditions {
+ public static void assertNotNull(Object o) {
+ if (ProviderConfig.IS_DOGFOOD_BUILD && o == null) {
+ throw new IllegalStateException();
+ }
+ }
+
public static void assertWorkerThread() {
if (ProviderConfig.IS_DOGFOOD_BUILD && !isSameLooper(LauncherModel.getWorkerLooper())) {
throw new IllegalStateException();
diff --git a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
index a569850..486b18e 100644
--- a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
+++ b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
@@ -35,10 +35,4 @@
componentName = new ComponentName(activityInfo.packageName, activityInfo.name);
itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
}
-
- @Override
- public String toString() {
- return String.format("PendingAddShortcutInfo package=%s, name=%s",
- activityInfo.packageName, activityInfo.name);
- }
}
diff --git a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
index de06ab6..f800ac4 100644
--- a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
+++ b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
@@ -59,10 +59,4 @@
public boolean isCustomWidget() {
return itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
}
-
- @Override
- public String toString() {
- return String.format("PendingAddWidgetInfo package=%s, name=%s",
- componentName.getPackageName(), componentName.getShortClassName());
- }
}
diff --git a/src/com/android/launcher3/widget/PendingItemPreviewProvider.java b/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
new file mode 100644
index 0000000..eaa0bb3
--- /dev/null
+++ b/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2016 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.widget;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.view.View;
+
+import com.android.launcher3.HolographicOutlineHelper;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.PendingAddItemInfo;
+import com.android.launcher3.Workspace;
+import com.android.launcher3.graphics.DragPreviewProvider;
+
+/**
+ * Extension of {@link DragPreviewProvider} with logic specific to pending widgets/shortcuts
+ * dragged from the widget tray.
+ */
+public class PendingItemPreviewProvider extends DragPreviewProvider {
+
+ private final PendingAddItemInfo mAddInfo;
+ private final Bitmap mPreviewBitmap;
+
+ public PendingItemPreviewProvider(View view, PendingAddItemInfo addInfo, Bitmap preview) {
+ super(view);
+ mAddInfo = addInfo;
+ mPreviewBitmap = preview;
+ }
+
+ @Override
+ public Bitmap createDragOutline(Canvas canvas) {
+ Workspace workspace = Launcher.getLauncher(mView.getContext()).getWorkspace();
+ int[] size = workspace.estimateItemSize(mAddInfo, false);
+
+ int w = size[0];
+ int h = size[1];
+ final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ALPHA_8);
+ canvas.setBitmap(b);
+
+ Rect src = new Rect(0, 0, mPreviewBitmap.getWidth(), mPreviewBitmap.getHeight());
+ float scaleFactor = Math.min((w - DRAG_BITMAP_PADDING) / (float) mPreviewBitmap.getWidth(),
+ (h - DRAG_BITMAP_PADDING) / (float) mPreviewBitmap.getHeight());
+ int scaledWidth = (int) (scaleFactor * mPreviewBitmap.getWidth());
+ int scaledHeight = (int) (scaleFactor * mPreviewBitmap.getHeight());
+ Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);
+
+ // center the image
+ dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2);
+
+ canvas.drawBitmap(mPreviewBitmap, src, dst, null);
+
+ // Don't clip alpha values for the drag outline if we're using the default widget preview
+ boolean clipAlpha = !(mAddInfo instanceof PendingAddWidgetInfo &&
+ (((PendingAddWidgetInfo) mAddInfo).previewImage == 0));
+ HolographicOutlineHelper.obtain(mView.getContext())
+ .applyExpensiveOutlineWithBlur(b, canvas, clipAlpha);
+ canvas.setBitmap(null);
+
+ return b;
+ }
+}
diff --git a/src/com/android/launcher3/widget/WidgetHostViewLoader.java b/src/com/android/launcher3/widget/WidgetHostViewLoader.java
index 297505b..049871f 100644
--- a/src/com/android/launcher3/widget/WidgetHostViewLoader.java
+++ b/src/com/android/launcher3/widget/WidgetHostViewLoader.java
@@ -11,6 +11,7 @@
import com.android.launcher3.AppWidgetResizeFrame;
import com.android.launcher3.DragSource;
+import com.android.launcher3.DropTarget;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
@@ -18,6 +19,7 @@
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.util.Thunk;
public class WidgetHostViewLoader implements DragController.DragListener {
@@ -47,7 +49,7 @@
}
@Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) { }
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { }
@Override
public void onDragEnd() {
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index 34bee1b..70b2945 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -33,6 +33,7 @@
import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.IconCache;
import com.android.launcher3.ItemInfo;
@@ -45,6 +46,8 @@
import com.android.launcher3.Workspace;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.model.WidgetsModel;
+import com.android.launcher3.userevent.nano.LauncherLogProto;
+import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.Thunk;
/**
@@ -205,7 +208,7 @@
// Compose the drag image
Bitmap preview;
- float scale = 1f;
+ final float scale;
final Rect bounds = image.getBitmapBounds();
if (createItemInfo instanceof PendingAddWidgetInfo) {
@@ -242,19 +245,14 @@
scale = ((float) mLauncher.getDeviceProfile().iconSizePx) / preview.getWidth();
}
- // Don't clip alpha values for the drag outline if we're using the default widget preview
- boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo &&
- (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));
+ // Since we are not going through the workspace for starting the drag, set drag related
+ // information on the workspace before starting the drag.
+ mLauncher.getWorkspace().prepareDragWithProvider(
+ new PendingItemPreviewProvider(v, createItemInfo, preview));
// Start the drag
- mLauncher.lockScreenOrientation();
mDragController.startDrag(image, preview, this, createItemInfo,
- bounds, DragController.DRAG_ACTION_COPY, scale);
- // This call expects the extra empty screen to already be created, which is why we call it
- // after mDragController.startDrag().
- mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, preview, clipAlpha);
-
- preview.recycle();
+ bounds, scale, new DragOptions());
return true;
}
@@ -354,4 +352,9 @@
}
return mWidgetPreviewLoader;
}
+
+ @Override
+ public void fillInLaunchSourceData(View v, ItemInfo info, Target target, Target targetParent) {
+ targetParent.containerType = LauncherLogProto.WIDGETS;
+ }
}
\ No newline at end of file
diff --git a/tests/src/com/android/launcher3/util/Wait.java b/tests/src/com/android/launcher3/util/Wait.java
index 02a1913..f9e53ba 100644
--- a/tests/src/com/android/launcher3/util/Wait.java
+++ b/tests/src/com/android/launcher3/util/Wait.java
@@ -25,6 +25,15 @@
}
SystemClock.sleep(sleepMillis);
}
+
+ // Check once more before returning false.
+ try {
+ if (condition.isTrue()) {
+ return true;
+ }
+ } catch (Throwable t) {
+ // Ignore
+ }
return false;
}
}