Install long-click action for apps that are not installed.

Bug: 65059282
Change-Id: Ifec3ac15c9cf52c456e695846eb91024b07fe333
This commit is contained in:
Mario Bertschler 2017-08-31 11:47:53 -07:00
parent 9458cbe779
commit f41edbe875
5 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,27 @@
<?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="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?android:attr/textColorPrimary"
android:pathData="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" />
<path
android:pathData="M0 0h24v24H0z" />
</vector>

View File

@ -90,6 +90,8 @@
<string name="uninstall_drop_target_label">Uninstall</string> <string name="uninstall_drop_target_label">Uninstall</string>
<!-- Label for app info drop target. [CHAR_LIMIT=20] --> <!-- Label for app info drop target. [CHAR_LIMIT=20] -->
<string name="app_info_drop_target_label">App info</string> <string name="app_info_drop_target_label">App info</string>
<!-- Label for install drop target. [CHAR_LIMIT=20] -->
<string name="install_drop_target_label">Install</string>
<!-- Permissions: --> <!-- Permissions: -->
<skip /> <skip />

View File

@ -53,6 +53,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan
private static final SystemShortcut[] SYSTEM_SHORTCUTS = new SystemShortcut[] { private static final SystemShortcut[] SYSTEM_SHORTCUTS = new SystemShortcut[] {
new SystemShortcut.AppInfo(), new SystemShortcut.AppInfo(),
new SystemShortcut.Widgets(), new SystemShortcut.Widgets(),
new SystemShortcut.Install()
}; };
private final Launcher mLauncher; private final Launcher mLauncher;

View File

@ -1,6 +1,7 @@
package com.android.launcher3.popup; package com.android.launcher3.popup;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
@ -11,7 +12,10 @@ import com.android.launcher3.InfoDropTarget;
import com.android.launcher3.ItemInfo; import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.InstantAppResolver;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.widget.WidgetsBottomSheet; import com.android.launcher3.widget.WidgetsBottomSheet;
@ -95,4 +99,35 @@ public abstract class SystemShortcut extends ItemInfo {
}; };
} }
} }
public static class Install extends SystemShortcut {
public Install() {
super(R.drawable.ic_install_no_shadow, R.string.install_drop_target_label);
}
@Override
public View.OnClickListener getOnClickListener(final Launcher launcher,
final ItemInfo itemInfo) {
boolean supportsWebUI = (itemInfo instanceof ShortcutInfo) &&
((ShortcutInfo) itemInfo).hasStatusFlag(ShortcutInfo.FLAG_SUPPORTS_WEB_UI);
boolean isInstantApp = false;
if (itemInfo instanceof com.android.launcher3.AppInfo) {
com.android.launcher3.AppInfo appInfo = (com.android.launcher3.AppInfo) itemInfo;
isInstantApp = InstantAppResolver.newInstance(launcher).isInstantApp(appInfo);
}
boolean enabled = supportsWebUI || isInstantApp;
if (!enabled) {
return null;
}
return new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = PackageManagerHelper.getMarketIntent(itemInfo
.getTargetComponent().getPackageName());
launcher.startActivitySafely(view, intent, itemInfo);
AbstractFloatingView.closeAllOpenViews(launcher);
}
};
}
}
} }

View File

@ -19,6 +19,7 @@ package com.android.launcher3.util;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import com.android.launcher3.AppInfo;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.Utilities; import com.android.launcher3.Utilities;
@ -39,6 +40,10 @@ public class InstantAppResolver {
return false; return false;
} }
public boolean isInstantApp(AppInfo info) {
return false;
}
public List<ApplicationInfo> getInstantApps() { public List<ApplicationInfo> getInstantApps() {
return Collections.emptyList(); return Collections.emptyList();
} }