List of usage examples for android.content.res Resources getString
@NonNull public String getString(@StringRes int id, Object... formatArgs) throws NotFoundException
From source file:com.ichi2.anki.DeckPicker.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { // Null check to prevent crash on API23 when we don't have required permission to access db if (getCol() == null) { return false; }/* ww w . j av a 2s . c o m*/ // Show / hide undo if (mFragmented || !getCol().undoAvailable()) { menu.findItem(R.id.action_undo).setVisible(false); } else { Resources res = getResources(); menu.findItem(R.id.action_undo).setVisible(true); String undo = res.getString(R.string.studyoptions_congrats_undo, getCol().undoName(res)); menu.findItem(R.id.action_undo).setTitle(undo); } return super.onPrepareOptionsMenu(menu); }
From source file:com.android.deskclock.data.StopwatchNotificationBuilderN.java
@Override public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) { @StringRes/*from w ww. java 2 s. c o m*/ final int eventLabel = R.string.label_notification; // Intent to load the app when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); // Compute some values required below. final boolean running = stopwatch.isRunning(); final String pname = context.getPackageName(); final Resources res = context.getResources(); final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime(); final RemoteViews content = new RemoteViews(pname, R.layout.chronometer_notif_content); content.setChronometer(R.id.chronometer, base, null, running); final List<Notification.Action> actions = new ArrayList<>(2); if (running) { // Left button: Pause final Intent pause = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_pause_24dp); final CharSequence title1 = res.getText(R.string.sw_pause_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right button: Add Lap if (DataModel.getDataModel().canAddMoreLaps()) { final Intent lap = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_sw_lap_24dp); final CharSequence title2 = res.getText(R.string.sw_lap_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, lap); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } // Show the current lap number if any laps have been recorded. final int lapCount = DataModel.getDataModel().getLaps().size(); if (lapCount > 0) { final int lapNumber = lapCount + 1; final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber); content.setTextViewText(R.id.state, lap); content.setViewVisibility(R.id.state, VISIBLE); } else { content.setViewVisibility(R.id.state, GONE); } } else { // Left button: Start final Intent start = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_start_24dp); final CharSequence title1 = res.getText(R.string.sw_start_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right button: Reset (dismisses notification and resets stopwatch) final Intent reset = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_reset_24dp); final CharSequence title2 = res.getText(R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); // Indicate the stopwatch is paused. content.setTextViewText(R.id.state, res.getString(R.string.swn_paused)); content.setViewVisibility(R.id.state, VISIBLE); } // Swipe away will reset the stopwatch without bringing forward the app. final Intent reset = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); return new Notification.Builder(context).setLocalOnly(true).setOngoing(running) .setCustomContentView(content).setContentIntent(pendingShowApp).setAutoCancel(stopwatch.isPaused()) .setPriority(Notification.PRIORITY_MAX).setSmallIcon(R.drawable.stat_notify_stopwatch) .setGroup(nm.getStopwatchNotificationGroupKey()) .setStyle(new Notification.DecoratedCustomViewStyle()) .setDeleteIntent(Utils.pendingServiceIntent(context, reset)) .setActions(actions.toArray(new Notification.Action[actions.size()])) .setColor(ContextCompat.getColor(context, R.color.default_background)).build(); }
From source file:com.androidinspain.deskclock.data.StopwatchNotificationBuilder.java
public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) { @StringRes/*from www . java 2 s. c o m*/ final int eventLabel = com.androidinspain.deskclock.R.string.label_notification; // Intent to load the app when the notification is tapped. final Intent showApp = new Intent(context, StopwatchService.class) .setAction(StopwatchService.ACTION_SHOW_STOPWATCH).putExtra(Events.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingShowApp = PendingIntent.getService(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); // Compute some values required below. final boolean running = stopwatch.isRunning(); final String pname = context.getPackageName(); final Resources res = context.getResources(); final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime(); final RemoteViews content = new RemoteViews(pname, com.androidinspain.deskclock.R.layout.chronometer_notif_content); content.setChronometer(com.androidinspain.deskclock.R.id.chronometer, base, null, running); final List<Action> actions = new ArrayList<>(2); if (running) { // Left button: Pause final Intent pause = new Intent(context, StopwatchService.class) .setAction(StopwatchService.ACTION_PAUSE_STOPWATCH) .putExtra(Events.EXTRA_EVENT_LABEL, eventLabel); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_pause_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.sw_pause_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Action.Builder(icon1, title1, intent1).build()); // Right button: Add Lap if (DataModel.getDataModel().canAddMoreLaps()) { final Intent lap = new Intent(context, StopwatchService.class) .setAction(StopwatchService.ACTION_LAP_STOPWATCH) .putExtra(Events.EXTRA_EVENT_LABEL, eventLabel); @DrawableRes final int icon2 = com.androidinspain.deskclock.R.drawable.ic_sw_lap_24dp; final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.sw_lap_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, lap); actions.add(new Action.Builder(icon2, title2, intent2).build()); } // Show the current lap number if any laps have been recorded. final int lapCount = DataModel.getDataModel().getLaps().size(); if (lapCount > 0) { final int lapNumber = lapCount + 1; final String lap = res.getString(com.androidinspain.deskclock.R.string.sw_notification_lap_number, lapNumber); content.setTextViewText(com.androidinspain.deskclock.R.id.state, lap); content.setViewVisibility(com.androidinspain.deskclock.R.id.state, VISIBLE); } else { content.setViewVisibility(com.androidinspain.deskclock.R.id.state, GONE); } } else { // Left button: Start final Intent start = new Intent(context, StopwatchService.class) .setAction(StopwatchService.ACTION_START_STOPWATCH) .putExtra(Events.EXTRA_EVENT_LABEL, eventLabel); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_start_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.sw_start_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Action.Builder(icon1, title1, intent1).build()); // Right button: Reset (dismisses notification and resets stopwatch) final Intent reset = new Intent(context, StopwatchService.class) .setAction(StopwatchService.ACTION_RESET_STOPWATCH) .putExtra(Events.EXTRA_EVENT_LABEL, eventLabel); @DrawableRes final int icon2 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp; final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Action.Builder(icon2, title2, intent2).build()); // Indicate the stopwatch is paused. content.setTextViewText(com.androidinspain.deskclock.R.id.state, res.getString(com.androidinspain.deskclock.R.string.swn_paused)); content.setViewVisibility(com.androidinspain.deskclock.R.id.state, VISIBLE); } final Builder notification = new NotificationCompat.Builder(context).setLocalOnly(true).setOngoing(running) .setCustomContentView(content).setContentIntent(pendingShowApp).setAutoCancel(stopwatch.isPaused()) .setPriority(Notification.PRIORITY_MAX) .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_stopwatch) .setStyle(new NotificationCompat.DecoratedCustomViewStyle()) .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background)); if (Utils.isNOrLater()) { notification.setGroup(nm.getStopwatchNotificationGroupKey()); } for (Action action : actions) { notification.addAction(action); } return notification.build(); }
From source file:com.ichi2.anki.DeckPicker.java
/** * Launch an asynchronous task to rebuild the deck list and recalculate the deck counts. Use this * after any change to a deck (e.g., rename, collapse, add/delete) that needs to be reflected * in the deck list./*from w ww .jav a 2 s . c o m*/ * * This method also triggers an update for the widget to reflect the newly calculated counts. */ private void updateDeckList() { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_LOAD_DECK_COUNTS, new DeckTask.TaskListener() { @Override public void onPreExecute() { if (!colIsOpen()) { showProgressBar(); } Timber.d("Refreshing deck list"); } @Override public void onPostExecute(TaskData result) { hideProgressBar(); // Make sure the fragment is visible if (mFragmented) { mStudyoptionsFrame.setVisibility(View.VISIBLE); } if (result == null) { Timber.e("null result loading deck counts"); onCollectionLoadError(); return; } List<Sched.DeckDueTreeNode> nodes = (List<Sched.DeckDueTreeNode>) result.getObjArray()[0]; mDeckListAdapter.buildDeckList(nodes, getCol()); // Set the "x due in y minutes" subtitle try { int eta = mDeckListAdapter.getEta(); int due = mDeckListAdapter.getDue(); Resources res = getResources(); if (getCol().cardCount() != -1) { String time = "-"; if (eta != -1) { time = res.getString(R.string.time_quantity_minutes, eta); } if (getSupportActionBar() != null) { getSupportActionBar() .setSubtitle(res.getQuantityString(R.plurals.deckpicker_title, due, due, time)); } } } catch (RuntimeException e) { Timber.e(e, "RuntimeException setting time remaining"); } long current = getCol().getDecks().current().optLong("id"); if (mFocusedDeck != current) { scrollDecklistToDeck(current); mFocusedDeck = current; } // Update the mini statistics bar as well AnkiStatsTaskHandler.createSmallTodayOverview(getCol(), mTodayTextView); } @Override public void onProgressUpdate(TaskData... values) { } @Override public void onCancelled() { } }); }
From source file:com.android.mms.ui.MessageUtils.java
/** M: * Return the current storage status./* w w w. j a v a 2 s.com*/ */ public static String getStorageStatus(Context context) { /// M: we need count only final String[] PROJECTION = new String[] { BaseColumns._ID, Mms.MESSAGE_SIZE }; final ContentResolver cr = context.getContentResolver(); final Resources res = context.getResources(); Cursor cursor = null; StringBuilder buffer = new StringBuilder(); // Mms count cursor = cr.query(Mms.CONTENT_URI, PROJECTION, null, null, null); int mmsCount = 0; if (cursor != null) { mmsCount = cursor.getCount(); } buffer.append(res.getString(R.string.storage_dialog_mms, mmsCount)); buffer.append("\n"); //Mms size long size = 0; if (cursor != null) { if (cursor.moveToFirst()) { do { size += cursor.getInt(1); } while (cursor.moveToNext()); } cursor.close(); } buffer.append(res.getString(R.string.storage_dialog_mms_size) + getHumanReadableSize(size)); buffer.append("\n"); // Attachment size size = getAttachmentSize(context); Log.d(TAG, "mms attachment size = " + size); final String sizeTag = getHumanReadableSize(size); buffer.append(res.getString(R.string.storage_dialog_attachments) + sizeTag); buffer.append("\n"); // Sms count cursor = cr.query(Sms.CONTENT_URI, PROJECTION, null, null, null); int smsCount = 0; if (cursor != null) { smsCount = cursor.getCount(); cursor.close(); } buffer.append(res.getString(R.string.storage_dialog_sms, smsCount)); buffer.append("\n"); // Database size final long dbsize = getDatabaseSize(context); buffer.append(res.getString(R.string.storage_dialog_database) + getHumanReadableSize(dbsize)); buffer.append("\n"); // Available space final StatFs datafs = new StatFs(Environment.getDataDirectory().getAbsolutePath()); final long availableSpace = (long) datafs.getAvailableBlocks() * datafs.getBlockSize(); buffer.append( res.getString(R.string.storage_dialog_available_space) + getHumanReadableSize(availableSpace)); return buffer.toString(); }
From source file:com.ichi2.anki.Info.java
@Override protected Dialog onCreateDialog(int id) { StyledDialog dialog = null;//from w ww. ja va 2s . c o m Resources res = getResources(); StyledDialog.Builder builder = new StyledDialog.Builder(this); switch (id) { case DIALOG_USER_NOT_LOGGED_IN_SYNC: builder.setTitle(R.string.not_logged_in_title); builder.setIcon(R.drawable.ic_dialog_alert); builder.setMessage(R.string.login_create_account_message); builder.setNegativeButton(R.string.dialog_cancel, null); builder.setPositiveButton(R.string.log_in, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent myAccount = new Intent(Info.this, MyAccount.class); myAccount.putExtra("notLoggedIn", true); startActivityForResult(myAccount, LOG_IN_FOR_SYNC); ActivityTransitionAnimation.slide(Info.this, ActivityTransitionAnimation.FADE); } }); dialog = builder.create(); break; case DIALOG_UPGRADE_ERROR: builder.setTitle(R.string.import_title); builder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { setResult(RESULT_CANCELED); finishWithAnimation(); } }); dialog = builder.create(); break; case DIALOG_SYNC_LOG: builder.setPositiveButton(R.string.dialog_ok, null); dialog = builder.create(); break; case DIALOG_SYNC_UPGRADE_REQUIRED: builder.setMessage(res.getString(R.string.upgrade_required, res.getString(R.string.link_ankiweb))); builder.setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { downloadCollection(); } }); builder.setNegativeButton(R.string.dialog_cancel, null); dialog = builder.create(); break; } return dialog; }
From source file:com.android.deskclock.data.StopwatchModel.java
/** * Updates the notification to reflect the latest state of the stopwatch and recorded laps. */// w ww .j a v a2 s . c om void updateNotification() { final Stopwatch stopwatch = getStopwatch(); // Notification should be hidden if the stopwatch has no time or the app is open. if (stopwatch.isReset() || mNotificationModel.isApplicationInForeground()) { mNotificationManager.cancel(mNotificationModel.getStopwatchNotificationId()); return; } @StringRes final int eventLabel = R.string.label_notification; // Intent to load the app when the notification is tapped. final Intent showApp = new Intent(mContext, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingShowApp = PendingIntent.getActivity(mContext, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); // Compute some values required below. final boolean running = stopwatch.isRunning(); final String pname = mContext.getPackageName(); final Resources res = mContext.getResources(); final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime(); final RemoteViews collapsed = new RemoteViews(pname, R.layout.stopwatch_notif_collapsed); collapsed.setChronometer(R.id.swn_collapsed_chronometer, base, null, running); collapsed.setOnClickPendingIntent(R.id.swn_collapsed_hitspace, pendingShowApp); collapsed.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch); final RemoteViews expanded = new RemoteViews(pname, R.layout.stopwatch_notif_expanded); expanded.setChronometer(R.id.swn_expanded_chronometer, base, null, running); expanded.setOnClickPendingIntent(R.id.swn_expanded_hitspace, pendingShowApp); expanded.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch); @IdRes final int leftButtonId = R.id.swn_left_button; @IdRes final int rightButtonId = R.id.swn_right_button; if (running) { // Left button: Pause expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_pause_button)); setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_pause_24dp); final Intent pause = new Intent(mContext, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); expanded.setOnClickPendingIntent(leftButtonId, pendingServiceIntent(pause)); // Right button: Add Lap if (canAddMoreLaps()) { expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_lap_button)); setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_sw_lap_24dp); final Intent lap = new Intent(mContext, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); expanded.setOnClickPendingIntent(rightButtonId, pendingServiceIntent(lap)); expanded.setViewVisibility(rightButtonId, VISIBLE); } else { expanded.setViewVisibility(rightButtonId, INVISIBLE); } // Show the current lap number if any laps have been recorded. final int lapCount = getLaps().size(); if (lapCount > 0) { final int lapNumber = lapCount + 1; final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber); collapsed.setTextViewText(R.id.swn_collapsed_laps, lap); collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE); expanded.setTextViewText(R.id.swn_expanded_laps, lap); expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE); } else { collapsed.setViewVisibility(R.id.swn_collapsed_laps, GONE); expanded.setViewVisibility(R.id.swn_expanded_laps, GONE); } } else { // Left button: Start expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_start_button)); setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_start_24dp); final Intent start = new Intent(mContext, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); expanded.setOnClickPendingIntent(leftButtonId, pendingServiceIntent(start)); // Right button: Reset (HandleDeskClockApiCalls will also bring forward the app) expanded.setViewVisibility(rightButtonId, VISIBLE); expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_reset_button)); setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_reset_24dp); final Intent reset = new Intent(mContext, HandleDeskClockApiCalls.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); expanded.setOnClickPendingIntent(rightButtonId, pendingActivityIntent(reset)); // Indicate the stopwatch is paused. collapsed.setTextViewText(R.id.swn_collapsed_laps, res.getString(R.string.swn_paused)); collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE); expanded.setTextViewText(R.id.swn_expanded_laps, res.getString(R.string.swn_paused)); expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE); } // Swipe away will reset the stopwatch without bringing forward the app. final Intent reset = new Intent(mContext, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Notification notification = new NotificationCompat.Builder(mContext).setLocalOnly(true) .setOngoing(running).setContent(collapsed).setAutoCancel(stopwatch.isPaused()) .setPriority(Notification.PRIORITY_MAX).setDeleteIntent(pendingServiceIntent(reset)) .setSmallIcon(R.drawable.ic_tab_stopwatch_activated).build(); notification.bigContentView = expanded; mNotificationManager.notify(mNotificationModel.getStopwatchNotificationId(), notification); }
From source file:com.android.deskclock.data.StopwatchNotificationBuilderPreN.java
@Override public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) { @StringRes/*from w w w . j av a 2s . c o m*/ final int eventLabel = R.string.label_notification; // Intent to load the app when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); // Compute some values required below. final boolean running = stopwatch.isRunning(); final String pname = context.getPackageName(); final Resources res = context.getResources(); final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime(); final RemoteViews collapsed = new RemoteViews(pname, R.layout.stopwatch_notif_collapsed); collapsed.setChronometer(R.id.swn_collapsed_chronometer, base, null, running); collapsed.setOnClickPendingIntent(R.id.swn_collapsed_hitspace, pendingShowApp); collapsed.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch); final RemoteViews expanded = new RemoteViews(pname, R.layout.stopwatch_notif_expanded); expanded.setChronometer(R.id.swn_expanded_chronometer, base, null, running); expanded.setOnClickPendingIntent(R.id.swn_expanded_hitspace, pendingShowApp); expanded.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch); @IdRes final int leftButtonId = R.id.swn_left_button; @IdRes final int rightButtonId = R.id.swn_right_button; if (running) { // Left button: Pause expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_pause_button)); setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_pause_24dp); final Intent pause = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingPause = Utils.pendingServiceIntent(context, pause); expanded.setOnClickPendingIntent(leftButtonId, pendingPause); // Right button: Add Lap if (DataModel.getDataModel().canAddMoreLaps()) { expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_lap_button)); setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_sw_lap_24dp); final Intent lap = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingLap = Utils.pendingServiceIntent(context, lap); expanded.setOnClickPendingIntent(rightButtonId, pendingLap); expanded.setViewVisibility(rightButtonId, VISIBLE); } else { expanded.setViewVisibility(rightButtonId, INVISIBLE); } // Show the current lap number if any laps have been recorded. final int lapCount = DataModel.getDataModel().getLaps().size(); if (lapCount > 0) { final int lapNumber = lapCount + 1; final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber); collapsed.setTextViewText(R.id.swn_collapsed_laps, lap); collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE); expanded.setTextViewText(R.id.swn_expanded_laps, lap); expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE); } else { collapsed.setViewVisibility(R.id.swn_collapsed_laps, GONE); expanded.setViewVisibility(R.id.swn_expanded_laps, GONE); } } else { // Left button: Start expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_start_button)); setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_start_24dp); final Intent start = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingStart = Utils.pendingServiceIntent(context, start); expanded.setOnClickPendingIntent(leftButtonId, pendingStart); // Right button: Reset (dismisses notification and resets stopwatch) expanded.setViewVisibility(rightButtonId, VISIBLE); expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_reset_button)); setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_reset_24dp); final Intent reset = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingReset = Utils.pendingServiceIntent(context, reset); expanded.setOnClickPendingIntent(rightButtonId, pendingReset); // Indicate the stopwatch is paused. collapsed.setTextViewText(R.id.swn_collapsed_laps, res.getString(R.string.swn_paused)); collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE); expanded.setTextViewText(R.id.swn_expanded_laps, res.getString(R.string.swn_paused)); expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE); } // Swipe away will reset the stopwatch without bringing forward the app. final Intent reset = new Intent(context, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Notification notification = new NotificationCompat.Builder(context).setLocalOnly(true) .setOngoing(running).setContent(collapsed).setAutoCancel(stopwatch.isPaused()) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.stat_notify_stopwatch) .setDeleteIntent(Utils.pendingServiceIntent(context, reset)) .setColor(ContextCompat.getColor(context, R.color.default_background)).build(); notification.bigContentView = expanded; return notification; }
From source file:com.hichinaschool.flashcards.anki.Info.java
@Override protected Dialog onCreateDialog(int id) { StyledDialog dialog = null;/* w ww. j av a2s. co m*/ Resources res = getResources(); StyledDialog.Builder builder = new StyledDialog.Builder(this); switch (id) { case DIALOG_USER_NOT_LOGGED_IN_SYNC: builder.setTitle(R.string.connection_error_title); builder.setIcon(R.drawable.ic_dialog_alert); builder.setMessage(R.string.no_user_password_error_message); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(R.string.log_in, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent myAccount = new Intent(Info.this, MyAccount.class); myAccount.putExtra("notLoggedIn", true); startActivityForResult(myAccount, LOG_IN_FOR_SYNC); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(Info.this, ActivityTransitionAnimation.FADE); } } }); dialog = builder.create(); break; case DIALOG_UPGRADE_ERROR: builder.setTitle(R.string.import_title); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { setResult(RESULT_CANCELED); finishWithAnimation(); } }); dialog = builder.create(); break; case DIALOG_SYNC_LOG: builder.setTitle(R.string.sync_log_title); builder.setPositiveButton(R.string.ok, null); dialog = builder.create(); break; case DIALOG_SYNC_UPGRADE_REQUIRED: builder.setMessage(res.getString(R.string.upgrade_required, res.getString(R.string.link_anki))); builder.setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { downloadCollection(); } }); builder.setNegativeButton(R.string.cancel, null); builder.setTitle(R.string.sync_log_title); dialog = builder.create(); break; } return dialog; }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private String getResourcesString(int id, String mediaName) { Resources r = getResources(); return r.getString(id, mediaName); }