本文整理匯總了Java中android.content.pm.ShortcutManager.addDynamicShortcuts方法的典型用法代碼示例。如果您正苦於以下問題:Java ShortcutManager.addDynamicShortcuts方法的具體用法?Java ShortcutManager.addDynamicShortcuts怎麽用?Java ShortcutManager.addDynamicShortcuts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.pm.ShortcutManager
的用法示例。
在下文中一共展示了ShortcutManager.addDynamicShortcuts方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.N_MR1)
private void createShortcut(String label, String packageName, Bitmap icon, Intent intent) {
ShortcutManager shortcutManager;
shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, packageName)
.setShortLabel(label)
.setLongLabel(label)
.setIcon(Icon.createWithBitmap(icon))
.setIntent(intent)
.setRank(0)
.build();
List<ShortcutInfo> shortcutList = shortcutManager.getDynamicShortcuts();
int shortcutSize = shortcutList.size();
if (shortcutSize >= 5) {
for (int i = 0; i < shortcutSize - 4; i++) {
shortcutManager.removeDynamicShortcuts(Collections.singletonList(shortcutList.get(0).getId()));
}
}
shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
}
示例2: updateShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
public static void updateShortcut(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
Log.d("Daedalus", "Updating shortcut");
//shortcut!
String notice = context.getString(R.string.button_text_activate);
boolean activate = true;
ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (DaedalusVpnService.class.getName().equals(service.service.getClassName())) {
notice = context.getString(R.string.button_text_deactivate);
activate = false;
}
}
ShortcutInfo info = new ShortcutInfo.Builder(context, Daedalus.SHORTCUT_ID_ACTIVATE)
.setLongLabel(notice)
.setShortLabel(notice)
.setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
.setIntent(new Intent(context, MainActivity.class).setAction(Intent.ACTION_VIEW)
.putExtra(MainActivity.LAUNCH_ACTION, activate ? MainActivity.LAUNCH_ACTION_ACTIVATE : MainActivity.LAUNCH_ACTION_DEACTIVATE))
.build();
ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(SHORTCUT_SERVICE);
shortcutManager.addDynamicShortcuts(Collections.singletonList(info));
}
}
示例3: addShortcutForChannel
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
/**
* Adds the given channel as shortcut to the launcher icon.
* Only call on api level >= 25.
*
* @param context to access system services
* @param channel channel to create a shortcut for
* @return true if the channel could be added
*/
@TargetApi(25)
public static boolean addShortcutForChannel(Context context, ChannelModel channel) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager == null || shortcutManager.getDynamicShortcuts().size() >= 4) {
return false;
}
ShortcutInfo shortcut = new ShortcutInfo.Builder(context, channel.getId())
.setShortLabel(channel.getName())
.setLongLabel(channel.getName())
.setIcon(Icon.createWithResource(context, channel.getDrawableId()))
.setIntent(ChannelDetailActivity.getStartIntent(context, channel.getId()))
.build();
try {
return shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
} catch (IllegalArgumentException e) {
// too many shortcuts
return false;
}
}
示例4: enablePostShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
Intent intent = new Intent(context, PostNewDesignerNewsStory.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
ShortcutInfo postShortcut
= new ShortcutInfo.Builder(context, POST_SHORTCUT_ID)
.setShortLabel(context.getString(R.string.shortcut_post_short_label))
.setLongLabel(context.getString(R.string.shortcut_post_long_label))
.setDisabledMessage(context.getString(R.string.shortcut_post_disabled))
.setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post))
.setIntent(intent)
.build();
shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}
示例5: addIncognitoLauncherShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
/**
* Adds a "New incognito tab" dynamic launcher shortcut.
* @param context The context used to retrieve the system {@link ShortcutManager}.
* @return True if addint the shortcut has succeeded. False if the call fails due to rate
* limiting. See {@link ShortcutManager#addDynamicShortcuts}.
*/
@TargetApi(Build.VERSION_CODES.N_MR1)
private static boolean addIncognitoLauncherShortcut(Context context) {
Intent intent = new Intent(LauncherShortcutActivity.ACTION_OPEN_NEW_INCOGNITO_TAB);
intent.setPackage(context.getPackageName());
intent.setClass(context, LauncherShortcutActivity.class);
ShortcutInfo shortcut =
new ShortcutInfo.Builder(context, DYNAMIC_OPEN_NEW_INCOGNITO_TAB_ID)
.setShortLabel(context.getResources().getString(
R.string.accessibility_tabstrip_incognito_identifier))
.setLongLabel(
context.getResources().getString(R.string.menu_new_incognito_tab))
.setIcon(Icon.createWithResource(context, R.drawable.shortcut_incognito))
.setIntent(intent)
.build();
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
return shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
}
示例6: updateShortcuts
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
public static void updateShortcuts(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
shortcutManager.removeAllDynamicShortcuts();
List<PreferredJourney> l;
if ((l = PreferredStationsPreferences.getAllPreferredJourneys(context)).size() > 0) {
shortcutManager.addDynamicShortcuts(setShortcuts(context, l.get(0)));
}
}
}
示例7: addDynamicShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
private void addDynamicShortcut(Place place) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
String name = HTTextUtils.isEmpty(place.getName()) ? place.getAddress() : place.getName();
int count = 0;
if (shortcutManager.getDynamicShortcuts() != null) {
count = shortcutManager.getDynamicShortcuts().size();
}
if (count > 2) {
String id = shortcutManager.getDynamicShortcuts().get(0).getId();
List<String> shortcutIds = new ArrayList<>();
shortcutIds.add(id);
shortcutManager.removeDynamicShortcuts(shortcutIds);
}
List<ShortcutInfo> shortcut = new ArrayList<>();
shortcut.add(0, new ShortcutInfo.Builder(this, place.getLocation().getLatLng().toString())
.setShortLabel(name)
.setIcon(Icon.createWithResource(this, R.drawable.ic_marker_gray))
.setIntent(new Intent(Intent.ACTION_VIEW,
Uri.parse("share.location://hypertrack")))
.build());
shortcutManager.addDynamicShortcuts(shortcut);
}
} catch (Exception e) {
Crashlytics.logException(e);
}
}
示例8: addShowScenarioShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
private void addShowScenarioShortcut() {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo showScenarioShortcut = new ShortcutInfo.Builder(this, IdUtil.getRandomUniqueShortcutId())
.setShortLabel(getString(R.string.shortcut_title_show_scenario))
.setLongLabel(getString(R.string.shortcut_title_show_scenario))
.setDisabledMessage(getString(R.string.shortcut_disabled_message))
.setIcon(Icon.createWithBitmap(BitmapUtil.getShortcutIcon(
this, ContextCompat.getColor(this, R.color.color_shortcut_background),
R.drawable.ic_info_outline_black_24dp, ContextCompat.getColor(this, R.color.color_primary))))
.setIntent(IntentUtil.choice(this, mChoice))
.setRank(0)
.build();
shortcutManager.addDynamicShortcuts(Collections.singletonList(showScenarioShortcut));
}
示例9: addDynamicShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
public static boolean addDynamicShortcut(@NonNull final Shortcut shortcut) {
final ShortcutManager shortcutManager = SystemServices.shortcutManager();
if (shortcutManager.getDynamicShortcuts().size() + 1 >= MAX_RECOMMENDED_SHORTCUTS) {
LogHelper.wtf("Lots of shortcuts");
}
return (! shortcutManager.isRateLimitingActive()
&& shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut.shortcutInfo())));
}
示例10: onCreate
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
String id = getIntent().getExtras().getString(RAIL_ID_KEY);
int railNumber = ShortcutsUtils.getRailNumber(id);
int rotation = getIntent().getExtras().getInt(RAIL_ROTATION_KEY);
int nextIcon = 0;
int nextRotation = 0;
switch (rotation) {
case RailInfo.NOT_SET:
nextIcon = R.drawable.horizontal;
nextRotation = RailInfo.HORIZONTAL;
break;
case RailInfo.HORIZONTAL:
nextIcon = R.drawable.vertical;
nextRotation = RailInfo.VERTICAL;
break;
case RailInfo.VERTICAL:
nextIcon = R.drawable.bottom_left_corner;
nextRotation = RailInfo.BOTTOM_LEFT_CORNER;
break;
case RailInfo.BOTTOM_LEFT_CORNER:
nextIcon = R.drawable.bottom_right_corner;
nextRotation = RailInfo.BOTTOM_RIGHT_CORNER;
break;
case RailInfo.BOTTOM_RIGHT_CORNER:
nextIcon = R.drawable.top_left_corner;
nextRotation = RailInfo.TOP_LEFT_CORNER;
break;
case RailInfo.TOP_LEFT_CORNER:
nextIcon = R.drawable.top_right_corner;
nextRotation = RailInfo.TOP_RIGHT_CORNER;
break;
case RailInfo.TOP_RIGHT_CORNER:
nextIcon = R.drawable.horizontal;
nextRotation = RailInfo.HORIZONTAL;
break;
}
Rect r = getIntent().getSourceBounds();
ShortcutInfo thisRailShortcut = ShortcutsUtils.createRailShortcut(this, railNumber, nextIcon, nextRotation, r);
shortcutManager.updateShortcuts(Collections.singletonList(thisRailShortcut));
shortcutManager.removeDynamicShortcuts(Collections.singletonList(id));
int newRailId = ShortcutsUtils.getNextRailNumber(shortcutManager);
ShortcutInfo railShortcut = ShortcutsUtils.createRailShortcut(this, newRailId);
shortcutManager.addDynamicShortcuts(Collections.singletonList(railShortcut));
finish();
super.onCreate(savedInstanceState);
}