本文整理匯總了Java中android.graphics.drawable.Icon.createWithResource方法的典型用法代碼示例。如果您正苦於以下問題:Java Icon.createWithResource方法的具體用法?Java Icon.createWithResource怎麽用?Java Icon.createWithResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Icon
的用法示例。
在下文中一共展示了Icon.createWithResource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createShortcutForAndroidN
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private void createShortcutForAndroidN() {
Icon icon;
if (mIsDefaultIcon) {
icon = Icon.createWithResource(this, R.drawable.ic_node_js_black);
} else {
Bitmap bitmap = BitmapTool.drawableToBitmap(mIcon.getDrawable());
icon = Icon.createWithBitmap(bitmap);
}
PersistableBundle extras = new PersistableBundle(1);
extras.putString(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath());
ShortcutManager.getInstance(this).addDynamicShortcut(mName.getText(), mScriptFile.getPath(), icon,
new Intent(this, ShortcutActivity.class)
.putExtra(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath())
.setAction(Intent.ACTION_MAIN));
}
示例2: createNotify
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private void createNotify(){
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent piShot = PendingIntent.getService(this, 0, shotIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Icon icon = Icon.createWithResource(this, R.drawable.ic_camera);
Notification.Action shotAction = new Notification.Action.Builder(icon, getString(R.string.notify_title_shot), piShot).build();
NotifyUtil.notifyShot(this, resultIntent, 1, shotAction);
}
示例3: create
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
/**
* Shortucts features on android N
* @param context
*/
public static void create(Context context) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
Icon pause = Icon.createWithResource(context, R.drawable.ic_shortcut_aw_ic_pause);
ShortcutInfo pauses = new ShortcutInfo.Builder(context, Constants.PAUSE_SHORTCUTS)
.setShortLabel("Pause")
.setIcon(pause)
.setIntent(shortcut(context,2))
.build();
Icon play = Icon.createWithResource(context, R.drawable.ic_shortcut_aw_ic_play);
ShortcutInfo plays = new ShortcutInfo.Builder(context, Constants.PLAY_SHORTCUTS)
.setShortLabel("Play")
.setIcon(play)
.setIntent(shortcut(context, 1))
.build();
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
shortcuts.add(plays);
shortcuts.add(pauses);
shortcutManager.setDynamicShortcuts(shortcuts);
}
}
示例4: onClick
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@Override
public void onClick() {
super.onClick();
Icon icon;
if (toggleState == 1) {
toggleState = 0;
// Hide/unmount Magisk root
Shell.su("setprop magisk.root 0");
icon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_root_off);
getQsTile().setIcon(icon);
getQsTile().setState(Tile.STATE_INACTIVE);
getQsTile().updateTile();
} else {
toggleState = 1;
// Mount Magisk root
Shell.su("setprop magisk.root 1");
icon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_root);
getQsTile().setIcon(icon);
getQsTile().setState(Tile.STATE_ACTIVE);
getQsTile().updateTile();
}
}
示例5: createShortcut
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
@NonNull
private static ShortcutInfo createShortcut(Context context,
String extraName,
boolean enabled,
String shortcutId,
String shortLabel,
String longLabel,
int rank) {
Intent intent = new Intent(context, AppShortcutActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_RUN);
intent.putExtra(extraName, enabled);
Icon acIcon = Icon.createWithResource(context, enabled ? R.drawable.ic_check_box : R.drawable.ic_check_box_blank);
return new ShortcutInfo.Builder(context.getApplicationContext(), shortcutId)
.setShortLabel(shortLabel)
.setLongLabel(longLabel)
.setIcon(acIcon)
.setRank(rank)
.setIntent(intent)
.build();
}
示例6: updatePictureInPictureActions
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
/**
* Update the state of pause/resume action item in Picture-in-Picture mode.
*
* @param iconId The icon to be used.
* @param title The title text.
* @param controlType The type of the action. either {@link #CONTROL_TYPE_PLAY} or {@link
* #CONTROL_TYPE_PAUSE}.
* @param requestCode The request code for the {@link PendingIntent}.
*/
void updatePictureInPictureActions(
@DrawableRes int iconId, String title, int controlType, int requestCode) {
final ArrayList<RemoteAction> actions = new ArrayList<>();
// This is the PendingIntent that is invoked when a user clicks on the action item.
// You need to use distinct request codes for play and pause, or the PendingIntent won't
// be properly updated.
final PendingIntent intent =
PendingIntent.getBroadcast(
MainActivity.this,
requestCode,
new Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
0);
final Icon icon = Icon.createWithResource(MainActivity.this, iconId);
actions.add(new RemoteAction(icon, title, title, intent));
// Another action item. This is a fixed action.
actions.add(
new RemoteAction(
Icon.createWithResource(MainActivity.this, R.drawable.ic_info_24dp),
getString(R.string.info),
getString(R.string.info_description),
PendingIntent.getActivity(
MainActivity.this,
REQUEST_INFO,
new Intent(
Intent.ACTION_VIEW,
Uri.parse(getString(R.string.info_uri))),
0)));
mPictureInPictureParamsBuilder.setActions(actions);
// This is how you can update action items (or aspect ratio) for Picture-in-Picture mode.
// Note this call can happen even when the app is not in PiP mode. In that case, the
// arguments will be used for at the next call of #enterPictureInPictureMode.
setPictureInPictureParams(mPictureInPictureParamsBuilder.build());
}
示例7: onStartListening
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@Override
public void onStartListening() {
super.onStartListening();
tile = getQsTile();
icon = Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher);
if (ServiceUtils.isRunning(getApplicationContext(), FloatViewService.class.getName())) {
setEnableTile();
} else {
setDisableTile();
}
tile.updateTile();
}
示例8: onCreate
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
mHandler = new Handler();
mIconEyeOpen = Icon.createWithResource(this, R.drawable.ic_stat_visibility);
mIconEyeClosed = Icon.createWithResource(this, R.drawable.ic_stat_visibility_off);
d(TAG, "onCreate: ");
}
示例9: onClick
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick() {
Log.d(LOG_TAG, "onClick state = " + Integer.toString(getQsTile().getState()));
Icon icon;
String title;
if (toggleState == STATE_ON) {
toggleState = STATE_OFF;
title = getResources().getString(R.string.notify_total_switch_off);
icon = Icon.createWithResource(getApplicationContext(), R.drawable.notify_off);
getQsTile().setState(Tile.STATE_INACTIVE);// 更改成非活躍狀態
} else {
toggleState = STATE_ON;
title = getResources().getString(R.string.notify_total_switch_on);
icon = Icon.createWithResource(getApplicationContext(), R.drawable.notify_on);
getQsTile().setState(Tile.STATE_ACTIVE);//更改成活躍狀態
}
getQsTile().setIcon(icon);//設置圖標
getQsTile().setLabel(title);
getQsTile().updateTile();//更新Tile
Intent intent = new Intent();
intent.setClass(this, TotalSwitchActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityAndCollapse(intent);
}
示例10: updateTileUI
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
/**
* Updates the QSTile icon and label
* @param state - State of night light. True value means night light is on, and vice versa
*/
private void updateTileUI(boolean state) {
Tile tile = this.getQsTile();
if (tile == null) return;
Icon newIcon;
int newState;
String title;
// Change the tile to match the service status.
if (state) {
newIcon = Icon.createWithResource(getApplicationContext(), ic_lightbulb_outline);
newState = Tile.STATE_ACTIVE;
title = getString(R.string.on);
} else {
newIcon = Icon.createWithResource(getApplicationContext(), ic_lightbulb_outline_disabled);
newState = Tile.STATE_INACTIVE;
title = getString(R.string.off);
}
// Change the UI of the tile.
tile.setLabel(title);
tile.setIcon(newIcon);
tile.setState(newState);
// Need to call updateTile for the tile to pick up changes.
tile.updateTile();
}
示例11: updateTile
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private void updateTile() {
Tile tile = this.getQsTile();
boolean isActive = this.getServiceStatus();
String newLabel;
Icon newIcon;
int newState;
if (isActive) {
newLabel = "MyQs is active.";
newIcon = Icon.createWithResource(getApplicationContext(),
android.R.drawable.ic_dialog_alert);
newState = Tile.STATE_ACTIVE;
//open result activity
Intent intent = new Intent(getApplicationContext(), ResultActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} else {
newLabel = "MyQs is inactive.";
newIcon = Icon.createWithResource(getApplicationContext(),
R.mipmap.ic_tile_inactive);
newState = Tile.STATE_INACTIVE;
}
tile.setIcon(newIcon);
tile.setLabel(newLabel);
tile.setState(newState);
tile.updateTile();
}
示例12: updateInactiveTile
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private void updateInactiveTile(Tile tile) {
Icon inActiveIcon = Icon
.createWithResource(getApplicationContext(),
R.drawable.ic_qs_night_mode_off);
tile.setIcon(inActiveIcon);
tile.setState(Tile.STATE_INACTIVE);
tile.updateTile();
}
示例13: updateActiveTile
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private void updateActiveTile(Tile tile) {
Icon activeIcon = Icon
.createWithResource(getApplicationContext(),
R.drawable.ic_qs_night_mode_on);
tile.setIcon(activeIcon);
tile.setState(Tile.STATE_ACTIVE);
tile.updateTile();
}
示例14: getShortcutsIcon
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static Icon getShortcutsIcon(Context context,
@DrawableRes int id, @DrawableRes int foregroundId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
DisplayUtils utils = new DisplayUtils(context);
int size = (int) Math.min(utils.dpToPx(108), 288);
Bitmap bitmap = ImageHelper.loadBitmap(context, foregroundId, size, size);
return Icon.createWithAdaptiveBitmap(bitmap);
} catch (ExecutionException | InterruptedException ignored) {
}
}
return Icon.createWithResource(context, id);
}
示例15: fixIconPkg
import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
private Icon fixIconPkg(final Icon icon, final String pkg) {
if (Icon_getType != null && Icon_mString1 != null) try {
final int type = (Integer) Icon_getType.invoke(icon);
if (type == 2) Icon_mString1.set(icon, pkg);
return icon;
} catch (final IllegalAccessException | InvocationTargetException ignored) {} // Should not happen
return Icon.createWithResource("", android.R.drawable.ic_media_play); // Fall-back to default icon
}