Show recently used instant apps provided by the app discovery service
in the same section as installed apps.
Change-Id: I2efd41c69960c4982523c58893aacfc7a5d0bb2e
diff --git a/res/drawable/ic_instant_app.xml b/res/drawable/ic_instant_app.xml
deleted file mode 100644
index be5a3e0..0000000
--- a/res/drawable/ic_instant_app.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2017 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="@dimen/badge_size"
- android:height="@dimen/badge_size"
- android:viewportWidth="18"
- android:viewportHeight="18">
-
- <path
- android:fillColor="@android:color/black"
- android:fillType="evenOdd"
- android:strokeWidth="1"
- android:pathData="M 9 0 C 13.9705627485 0 18 4.02943725152 18 9 C 18 13.9705627485 13.9705627485 18 9 18 C 4.02943725152 18 0 13.9705627485 0 9 C 0 4.02943725152 4.02943725152 0 9 0 Z" />
- <path
- android:fillColor="@android:color/white"
- android:fillType="evenOdd"
- android:strokeWidth="1"
- android:pathData="M 9 0 C 13.9705627485 0 18 4.02943725152 18 9 C 18 13.9705627485 13.9705627485 18 9 18 C 4.02943725152 18 0 13.9705627485 0 9 C 0 4.02943725152 4.02943725152 0 9 0 Z" />
- <path
- android:fillColor="@android:color/white"
- android:fillType="evenOdd"
- android:strokeWidth="1"
- android:pathData="M 9 0 C 13.9705627485 0 18 4.02943725152 18 9 C 18 13.9705627485 13.9705627485 18 9 18 C 4.02943725152 18 0 13.9705627485 0 9 C 0 4.02943725152 4.02943725152 0 9 0 Z" />
- <path
- android:fillColor="@android:color/black"
- android:fillAlpha="0.87"
- android:fillType="evenOdd"
- android:strokeWidth="1"
- android:pathData="M 6 10.4123279 L 8.63934949 10.4123279 L 8.63934949 15.6 L 12.5577168 7.84517705 L 9.94547194 7.84517705 L 9.94547194 2 Z" />
-</vector>
diff --git a/res/layout/all_apps_discovery_item.xml b/res/layout/all_apps_discovery_item.xml
index 2b21ef5..1a7eaa7 100644
--- a/res/layout/all_apps_discovery_item.xml
+++ b/res/layout/all_apps_discovery_item.xml
@@ -27,18 +27,6 @@
android:padding="8dp"
android:scaleType="fitCenter"/>
- <ImageView
- android:id="@+id/badge"
- android:layout_width="16dp"
- android:layout_height="16dp"
- android:scaleType="fitCenter"
- android:src="@drawable/ic_instant_app"
- android:layout_marginRight="6dp"
- android:layout_marginBottom="6dp"
- android:layout_alignRight="@+id/image"
- android:layout_alignBottom="@+id/image"
- android:clickable="false"/>
-
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
index f228470..f5cf7ef 100644
--- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
+++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
@@ -292,7 +292,7 @@
mDiscoveredApps.clear();
break;
case UPDATE:
- mDiscoveredApps.add(new AppDiscoveryAppInfo(app, mLauncher));
+ mDiscoveredApps.add(new AppDiscoveryAppInfo(app));
break;
}
updateAdapterItems();
@@ -494,10 +494,13 @@
if (hasFilter()) {
if (isAppDiscoveryRunning() || mDiscoveredApps.size() > 0) {
mAdapterItems.add(AdapterItem.asLoadingDivider(position++));
-
// Append all app discovery results
for (int i = 0; i < mDiscoveredApps.size(); i++) {
AppDiscoveryAppInfo appDiscoveryAppInfo = mDiscoveredApps.get(i);
+ if (appDiscoveryAppInfo.isRecent) {
+ // already handled in getFilteredAppInfos()
+ continue;
+ }
AdapterItem item = AdapterItem.asDiscoveryItem(position++,
"", appDiscoveryAppInfo, appIndex++);
mAdapterItems.add(item);
@@ -589,6 +592,17 @@
result.add(match);
}
}
+
+ // adding recently used instant apps
+ if (mDiscoveredApps.size() > 0) {
+ for (int i = 0; i < mDiscoveredApps.size(); i++) {
+ AppDiscoveryAppInfo discoveryAppInfo = mDiscoveredApps.get(i);
+ if (discoveryAppInfo.isRecent) {
+ result.add(discoveryAppInfo);
+ }
+ }
+ Collections.sort(result, mAppNameComparator);
+ }
return result;
}
diff --git a/src/com/android/launcher3/discovery/AppDiscoveryAppInfo.java b/src/com/android/launcher3/discovery/AppDiscoveryAppInfo.java
index 50e979a..06493b2 100644
--- a/src/com/android/launcher3/discovery/AppDiscoveryAppInfo.java
+++ b/src/com/android/launcher3/discovery/AppDiscoveryAppInfo.java
@@ -18,24 +18,18 @@
import android.content.ComponentName;
import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.android.launcher3.AppInfo;
-import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
public class AppDiscoveryAppInfo extends AppInfo {
- private final @NonNull Launcher mLauncher;
-
public final boolean showAsDiscoveryItem;
public final boolean isInstantApp;
+ public final boolean isRecent;
public final float rating;
public final long reviewCount;
public final @NonNull String publisher;
@@ -43,14 +37,14 @@
public final @NonNull Intent launchIntent;
public final @Nullable String priceFormatted;
- public AppDiscoveryAppInfo(AppDiscoveryItem item, Launcher launcher) {
- this.mLauncher = launcher;
+ public AppDiscoveryAppInfo(AppDiscoveryItem item) {
this.intent = item.isInstantApp ? item.launchIntent : item.installIntent;
this.title = item.title;
this.iconBitmap = item.bitmap;
this.isDisabled = ShortcutInfo.DEFAULT;
this.usingLowResIcon = false;
this.isInstantApp = item.isInstantApp;
+ this.isRecent = item.isRecent;
this.rating = item.starRating;
this.showAsDiscoveryItem = true;
this.publisher = item.publisher != null ? item.publisher : "";
@@ -67,18 +61,7 @@
if (!isDragAndDropSupported()) {
throw new RuntimeException("DnD is currently not supported for discovered store apps");
}
- ShortcutInfo shortcutInfo = super.makeShortcut();
- if (isInstantApp) {
- int iconSize = iconBitmap.getWidth();
- int badgeSize = mLauncher.getResources().getDimensionPixelOffset(R.dimen.badge_size);
- Bitmap icon = Bitmap.createBitmap(iconBitmap);
- Drawable badgeDrawable = mLauncher.getDrawable(R.drawable.ic_instant_app);
- badgeDrawable.setBounds(iconSize - badgeSize, iconSize - badgeSize, iconSize, iconSize);
- Canvas canvas = new Canvas(icon);
- badgeDrawable.draw(canvas);
- shortcutInfo.iconBitmap = icon;
- }
- return shortcutInfo;
+ return super.makeShortcut();
}
public boolean isDragAndDropSupported() {
diff --git a/src/com/android/launcher3/discovery/AppDiscoveryItem.java b/src/com/android/launcher3/discovery/AppDiscoveryItem.java
index 7c10371..09c91ac 100644
--- a/src/com/android/launcher3/discovery/AppDiscoveryItem.java
+++ b/src/com/android/launcher3/discovery/AppDiscoveryItem.java
@@ -28,6 +28,7 @@
public final String packageName;
public final boolean isInstantApp;
+ public final boolean isRecent;
public final float starRating;
public final long reviewCount;
public final Intent launchIntent;
@@ -39,6 +40,7 @@
public AppDiscoveryItem(String packageName,
boolean isInstantApp,
+ boolean isRecent,
float starRating,
long reviewCount,
CharSequence title,
@@ -49,6 +51,7 @@
Intent installIntent) {
this.packageName = packageName;
this.isInstantApp = isInstantApp;
+ this.isRecent = isRecent;
this.starRating = starRating;
this.reviewCount = reviewCount;
this.launchIntent = launchIntent;
diff --git a/src/com/android/launcher3/discovery/AppDiscoveryItemView.java b/src/com/android/launcher3/discovery/AppDiscoveryItemView.java
index 6faad87..9bb3b10 100644
--- a/src/com/android/launcher3/discovery/AppDiscoveryItemView.java
+++ b/src/com/android/launcher3/discovery/AppDiscoveryItemView.java
@@ -34,7 +34,6 @@
private static boolean SHOW_REVIEW_COUNT = false;
private ImageView mImage;
- private ImageView mBadge;
private TextView mTitle;
private TextView mRatingText;
private RatingView mRatingView;
@@ -58,7 +57,6 @@
protected void onFinishInflate() {
super.onFinishInflate();
this.mImage = (ImageView) findViewById(R.id.image);
- this.mBadge = (ImageView) findViewById(R.id.badge);
this.mTitle = (TextView) findViewById(R.id.title);
this.mRatingText = (TextView) findViewById(R.id.rating);
this.mRatingView = (RatingView) findViewById(R.id.rating_view);
@@ -80,7 +78,6 @@
mImage.setTag(info);
mImage.setImageBitmap(info.iconBitmap);
mImage.setOnLongClickListener(info.isDragAndDropSupported() ? mOnLongClickListener : null);
- mBadge.setVisibility(info.isInstantApp ? View.VISIBLE : View.GONE);
mTitle.setText(info.title);
mPrice.setText(info.priceFormatted != null ? info.priceFormatted : "");
mReviewCount.setVisibility(SHOW_REVIEW_COUNT ? View.VISIBLE : View.GONE);