use of android.content.pm.ShortcutManager in project rebootmenu by ryuunoakaihitomi.
the class Shortcut method onCreate.
// 来自UnRootMode.java -- 结束
@TargetApi(Build.VERSION_CODES.N_MR1)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
componentName = new ComponentName(this, AdminReceiver.class);
devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
// shortcut功能选项
final int REBOOT = 2;
final int SHUTDOWN = 3;
final int RECOVERY = 8;
final int FASTBOOT = 9;
final int REBOOT_UI = 4;
final int UR_REBOOT = 10;
final int LOCKSCREEN = 5;
final int UR_LOCKSCREEN = 6;
final int UR_POWERDIALOG = 7;
int param = getIntent().getIntExtra(extraTag, -1);
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
switch(param) {
// Root模式下的快捷方式
case ROOT:
ShortcutInfo fastboot = new ShortcutInfo.Builder(this, "r_ffb").setShortLabel("*" + getString(R.string.fastboot_short)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_sort_by_size)).setIntent(new Intent(action).putExtra(extraTag, FASTBOOT)).setRank(5).build();
ShortcutInfo recovery = new ShortcutInfo.Builder(this, "r_frr").setShortLabel("*" + getString(R.string.recovery_short)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_today)).setIntent(new Intent(action).putExtra(extraTag, RECOVERY)).setRank(4).build();
ShortcutInfo reboot = new ShortcutInfo.Builder(this, "r_fr").setShortLabel("*" + getString(R.string.reboot)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_rotate)).setIntent(new Intent(action).putExtra(extraTag, REBOOT)).setRank(3).build();
ShortcutInfo shutdown = new ShortcutInfo.Builder(this, "r_fs").setShortLabel("*" + getString(R.string.shutdown)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_delete)).setIntent(new Intent(action).putExtra(extraTag, SHUTDOWN)).setRank(2).build();
ShortcutInfo rebootui = new ShortcutInfo.Builder(this, "r_ru").setShortLabel(getString(R.string.reboot_ui)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_view)).setIntent(new Intent(action).putExtra(extraTag, REBOOT_UI)).setRank(1).build();
ShortcutInfo lockscreen = new ShortcutInfo.Builder(this, "r_l").setShortLabel(getString(R.string.lockscreen)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_slideshow)).setIntent(new Intent(action).putExtra(extraTag, LOCKSCREEN)).setRank(0).build();
assert shortcutManager != null;
// 无论如何,没有root不能用shell锁屏和重启UI,所以在不检查root模式下的无root模式改为增加fast boot。
if (ShellUtils.isRoot())
shortcutManager.setDynamicShortcuts(Arrays.asList(recovery, reboot, shutdown, rebootui, lockscreen));
else
shortcutManager.setDynamicShortcuts(Arrays.asList(fastboot, recovery, reboot, shutdown));
finish();
break;
// 免root模式下的快捷方式
case UNROOT:
boolean isDevOwner = devicePolicyManager.isDeviceOwnerApp(getPackageName());
ShortcutInfo ur_reboot = null;
if (isDevOwner)
ur_reboot = new ShortcutInfo.Builder(this, "ur_r").setShortLabel(getString(R.string.reboot)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_rotate)).setIntent(new Intent(action).putExtra(extraTag, UR_REBOOT)).setRank(2).build();
ShortcutInfo ur_lockscreen = new ShortcutInfo.Builder(this, "ur_l").setShortLabel(getString(R.string.lockscreen)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_slideshow)).setIntent(new Intent(action).putExtra(extraTag, UR_LOCKSCREEN)).setRank(1).build();
ShortcutInfo ur_powerdialog = new ShortcutInfo.Builder(this, "ur_p").setShortLabel(getString(R.string.system_power_dialog)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_preferences)).setIntent(new Intent(action).putExtra(extraTag, UR_POWERDIALOG)).setRank(0).build();
assert shortcutManager != null;
if (isDevOwner)
shortcutManager.setDynamicShortcuts(Arrays.asList(ur_lockscreen, ur_powerdialog, ur_reboot));
else
shortcutManager.setDynamicShortcuts(Arrays.asList(ur_lockscreen, ur_powerdialog));
finish();
break;
// 快捷方式使用强制执行
case FASTBOOT:
rebootExec("bootloader");
break;
case RECOVERY:
rebootExec("recovery");
break;
case REBOOT:
rebootExec(null);
break;
case SHUTDOWN:
rebootExec("-p");
break;
case REBOOT_UI:
ShellUtils.suCmdExec("busybox pkill com.android.systemui");
finish();
break;
case LOCKSCREEN:
ShellUtils.suCmdExec("input keyevent 26");
finish();
break;
// 免root模式
case UR_LOCKSCREEN:
lockscreen();
break;
case UR_POWERDIALOG:
UnRootMode.accessbilityon(Shortcut.this);
break;
case UR_REBOOT:
if (devicePolicyManager.isDeviceOwnerApp(getPackageName()))
UnRootMode.reboot(devicePolicyManager, componentName, this);
else {
int random = new Random().nextInt(99);
// 保留日志
new DebugLog("DEVICE_OWNER_DISABLED from SHORTCUT random=" + random, DebugLog.LogLevel.V);
new TextToast(getApplicationContext(), random > 50, getString(R.string.device_owner_disabled));
finish();
}
default:
finish();
}
}
use of android.content.pm.ShortcutManager in project VirtualXposed by android-hacker.
the class VirtualCore method createShortcutAboveN.
@TargetApi(Build.VERSION_CODES.N_MR1)
private static boolean createShortcutAboveN(Context context, ShortcutInfo likeShortcut) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager == null) {
return false;
}
try {
int max = shortcutManager.getMaxShortcutCountPerActivity();
List<ShortcutInfo> dynamicShortcuts = shortcutManager.getDynamicShortcuts();
if (dynamicShortcuts.size() >= max) {
Collections.sort(dynamicShortcuts, new Comparator<ShortcutInfo>() {
@Override
public int compare(ShortcutInfo o1, ShortcutInfo o2) {
long r = o1.getLastChangedTimestamp() - o2.getLastChangedTimestamp();
return r == 0 ? 0 : (r > 0 ? 1 : -1);
}
});
// remove old.
ShortcutInfo remove = dynamicShortcuts.remove(0);
shortcutManager.removeDynamicShortcuts(Collections.singletonList(remove.getId()));
}
shortcutManager.addDynamicShortcuts(Collections.singletonList(likeShortcut));
return true;
} catch (Throwable e) {
return false;
}
}
use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by omnirom.
the class CreateShortcut method createResultIntent.
protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) {
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
ShortcutManager sm = getSystemService(ShortcutManager.class);
ActivityInfo activityInfo = resolveInfo.activityInfo;
Icon maskableIcon = activityInfo.icon != 0 ? Icon.createWithAdaptiveBitmap(createIcon(activityInfo.icon, R.layout.shortcut_badge_maskable, getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable))) : Icon.createWithResource(this, R.drawable.ic_launcher_settings);
String shortcutId = SHORTCUT_ID_PREFIX + shortcutIntent.getComponent().flattenToShortString();
ShortcutInfo info = new ShortcutInfo.Builder(this, shortcutId).setShortLabel(label).setIntent(shortcutIntent).setIcon(maskableIcon).build();
Intent intent = sm.createShortcutResultIntent(info);
if (intent == null) {
intent = new Intent();
}
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings));
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
if (activityInfo.icon != 0) {
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon, R.layout.shortcut_badge, getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
}
return intent;
}
use of android.content.pm.ShortcutManager in project Taskbar by farmerbb.
the class MainActivity method proceedWithAppLaunch.
private void proceedWithAppLaunch(Bundle savedInstanceState) {
setContentView(R.layout.main);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setCustomView(R.layout.switch_layout);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
}
theSwitch = U.findViewById(this, R.id.the_switch);
if (theSwitch != null) {
final SharedPreferences pref = U.getSharedPreferences(this);
theSwitch.setChecked(pref.getBoolean("taskbar_active", false));
theSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
if (b) {
if (U.canDrawOverlays(this)) {
boolean firstRun = pref.getBoolean("first_run", true);
startTaskbarService();
if (firstRun)
U.showRecentAppsDialog(this);
} else {
U.showPermissionDialog(this);
compoundButton.setChecked(false);
}
} else
stopTaskbarService();
});
}
if (savedInstanceState == null) {
if (!getIntent().hasExtra("theme_change"))
getFragmentManager().beginTransaction().replace(R.id.fragmentContainer, new AboutFragment(), "AboutFragment").commit();
else
getFragmentManager().beginTransaction().replace(R.id.fragmentContainer, new AppearanceFragment(), "AppearanceFragment").commit();
}
if (!BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) {
final SharedPreferences pref = U.getSharedPreferences(this);
if (!pref.getBoolean("dont_show_uninstall_dialog", false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.settings_imported_successfully).setMessage(R.string.import_dialog_message).setPositiveButton(R.string.action_uninstall, (dialog, which) -> {
pref.edit().putBoolean("uninstall_dialog_shown", true).apply();
try {
startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID)));
} catch (ActivityNotFoundException e) {
/* Gracefully fail */
}
});
if (pref.getBoolean("uninstall_dialog_shown", false))
builder.setNegativeButton(R.string.action_dont_show_again, (dialogInterface, i) -> pref.edit().putBoolean("dont_show_uninstall_dialog", true).apply());
AlertDialog dialog = builder.create();
dialog.show();
dialog.setCancelable(false);
}
if (!pref.getBoolean("uninstall_dialog_shown", false)) {
if (theSwitch != null)
theSwitch.setChecked(false);
SharedPreferences.Editor editor = pref.edit();
String iconPack = pref.getString("icon_pack", BuildConfig.BASE_APPLICATION_ID);
if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) {
editor.putString("icon_pack", BuildConfig.APPLICATION_ID);
} else {
U.refreshPinnedIcons(this);
}
editor.putBoolean("first_run", true);
editor.apply();
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager.getDynamicShortcuts().size() == 0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, StartTaskbarActivity.class);
intent.putExtra("is_launching_shortcut", true);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar").setShortLabel(getString(R.string.start_taskbar)).setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_start)).setIntent(intent).build();
Intent intent2 = new Intent(Intent.ACTION_MAIN);
intent2.setClass(this, ShortcutActivity.class);
intent2.putExtra("is_launching_shortcut", true);
ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode").setShortLabel(getString(R.string.pref_header_freeform)).setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_freeform)).setIntent(intent2).build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2));
}
}
}
use of android.content.pm.ShortcutManager in project Taskbar by farmerbb.
the class CompatUtils method pinAppShortcut.
public static void pinAppShortcut(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ShortcutManager mShortcutManager = context.getSystemService(ShortcutManager.class);
if (mShortcutManager.isRequestPinShortcutSupported()) {
ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(context, "freeform_mode").build();
mShortcutManager.requestPinShortcut(pinShortcutInfo, null);
} else
U.showToastLong(context, R.string.pin_shortcut_not_supported);
} else
U.pinAppShortcut(context);
}
Aggregations