Example usage for android.content Context getText

List of usage examples for android.content Context getText

Introduction

In this page you can find the example usage for android.content Context getText.

Prototype

@NonNull
public final CharSequence getText(@StringRes int resId) 

Source Link

Document

Return a localized, styled CharSequence from the application's package's default string table.

Usage

From source file:com.noshufou.android.su.util.Util.java

public static void showOutdatedNotification(Context context) {
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Preferences.OUTDATED_NOTIFICATION,
            true)) {/*from  w w  w  . java2 s  .  com*/
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, UpdaterActivity.class), 0);
        Notification notification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.stat_su)
                .setTicker(context.getText(R.string.notif_outdated_ticker)).setWhen(System.currentTimeMillis())
                .setContentTitle(context.getText(R.string.notif_outdated_title))
                .setContentText(context.getText(R.string.notif_outdated_text)).setContentIntent(contentIntent)
                .setAutoCancel(true).setOnlyAlertOnce(true).getNotification();
        nm.notify(UpdaterService.NOTIFICATION_ID, notification);
    }
}

From source file:com.android.settings.applications.ClearDefaultsPreference.java

public boolean updateUI(PreferenceViewHolder view) {
    boolean hasBindAppWidgetPermission = mAppWidgetManager
            .hasBindAppWidgetPermission(mAppEntry.info.packageName);

    TextView autoLaunchView = (TextView) view.findViewById(R.id.auto_launch);
    boolean autoLaunchEnabled = AppUtils.hasPreferredActivities(mPm, mPackageName)
            || isDefaultBrowser(mPackageName) || AppUtils.hasUsbDefaults(mUsbManager, mPackageName);
    if (!autoLaunchEnabled && !hasBindAppWidgetPermission) {
        resetLaunchDefaultsUi(autoLaunchView);
    } else {//from  w w  w.j  a  v  a  2s .c om
        boolean useBullets = hasBindAppWidgetPermission && autoLaunchEnabled;

        if (hasBindAppWidgetPermission) {
            autoLaunchView.setText(R.string.auto_launch_label_generic);
        } else {
            autoLaunchView.setText(R.string.auto_launch_label);
        }

        Context context = getContext();
        CharSequence text = null;
        int bulletIndent = context.getResources()
                .getDimensionPixelSize(R.dimen.installed_app_details_bullet_offset);
        if (autoLaunchEnabled) {
            CharSequence autoLaunchEnableText = context.getText(R.string.auto_launch_enable_text);
            SpannableString s = new SpannableString(autoLaunchEnableText);
            if (useBullets) {
                s.setSpan(new BulletSpan(bulletIndent), 0, autoLaunchEnableText.length(), 0);
            }
            text = (text == null) ? TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n");
        }
        if (hasBindAppWidgetPermission) {
            CharSequence alwaysAllowBindAppWidgetsText = context
                    .getText(R.string.always_allow_bind_appwidgets_text);
            SpannableString s = new SpannableString(alwaysAllowBindAppWidgetsText);
            if (useBullets) {
                s.setSpan(new BulletSpan(bulletIndent), 0, alwaysAllowBindAppWidgetsText.length(), 0);
            }
            text = (text == null) ? TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n");
        }
        autoLaunchView.setText(text);
        mActivitiesButton.setEnabled(true);
    }
    return true;
}

From source file:com.mutu.gpstracker.streaming.CustomUpload.java

private void notifyError(Context context, Exception e) {
    Log.e(TAG, "Custom upload failed", e);
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

    int icon = R.drawable.ic_maps_indicator_current_position;
    CharSequence tickerText = context.getText(R.string.customupload_failed);
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, tickerText, when);

    Context appContext = context.getApplicationContext();
    CharSequence contentTitle = tickerText;
    CharSequence contentText = e.getMessage();
    Intent notificationIntent = new Intent(context, CustomUpload.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(appContext, contentTitle, contentText, contentIntent);
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    mNotificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:monakhv.android.samlib.service.NotificationData.java

/**
 * Make notification for update successful all types
 *
 * @param context//  w  ww . ja  v a  2 s.com
 * @return
 */
private NotificationCompat.Builder makeUpdateNotification(Context context) {
    NotificationCompat.Builder mBuilder = makeNotification(context);

    mBuilder.setDeleteIntent(PendingIntent.getService(context, 0, CleanNotificationData.getIntent(context), 0));

    mBuilder.setSmallIcon(R.drawable.note_book);
    mBuilder.setTicker(context.getText(R.string.notification_updates));
    return mBuilder;
}

From source file:org.andstatus.app.msg.MessageViewItem.java

private void setMessageSource(Context context, StringBuilder messageDetails) {
    if (!SharedPreferencesUtil.isEmpty(messageSource) && !"ostatus".equals(messageSource)
            && !"unknown".equals(messageSource)) {
        messageDetails.append(/*  w  w w.j  av a  2 s .  com*/
                " " + String.format(context.getText(R.string.message_source_from).toString(), messageSource));
    }
}

From source file:monakhv.android.samlib.service.NotificationData.java

/**
 * Make notification for successful update when we have really news
 *
 * @param context//from w  ww  .  ja  v a2s. c  om
 * @param updatedAuthors
 */
public void notifyUpdate(Context context, List<Author> updatedAuthors) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = makeUpdateNotification(context);

    String contentText = context.getText(R.string.author_update_number).toString();

    addData(updatedAuthors);

    NotificationCompat.InboxStyle inboxStyle = getinboxStyle();
    if (updatedAuthors != null) {

        inboxStyle.setBigContentTitle(context.getText(R.string.notification_updates).toString());
        mBuilder.setContentText(contentText + " " + num);
        inboxStyle.setSummaryText(contentText + " " + num);
    } else {
        mBuilder.setContentText("DEBUG MESSAGE");
        inboxStyle.setSummaryText("DEBUG MESSAGE - " + num + " update");
    }

    mBuilder.setStyle(inboxStyle);
    saveData(context, this);
    notificationManager.notify(LIST_UPDATE_NOTIFICATION, mBuilder.build());
}

From source file:com.android.hareime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Notifies the user of changes in the keyboard shift state.
 *///ww  w  .  ja v  a  2s. c  o  m
public void notifyShiftState() {
    final Keyboard keyboard = mView.getKeyboard();
    final KeyboardId keyboardId = keyboard.mId;
    final int elementId = keyboardId.mElementId;
    final Context context = mView.getContext();
    final CharSequence text;

    switch (elementId) {
    case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED:
    case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED:
        text = context.getText(R.string.spoken_description_shiftmode_locked);
        break;
    case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED:
    case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED:
    case KeyboardId.ELEMENT_SYMBOLS_SHIFTED:
        text = context.getText(R.string.spoken_description_shiftmode_on);
        break;
    default:
        text = context.getText(R.string.spoken_description_shiftmode_off);
    }

    AccessibilityUtils.getInstance().speak(text);
}

From source file:org.andstatus.app.msg.MessageViewItem.java

protected void setInReplyTo(Context context, StringBuilder messageDetails) {
    if (inReplyToMsgId != 0 && TextUtils.isEmpty(inReplyToName)) {
        inReplyToName = "...";
    }//from   ww  w  .  jav a 2  s  .c om
    if (!TextUtils.isEmpty(inReplyToName)) {
        messageDetails.append(" ").append(
                String.format(context.getText(R.string.message_source_in_reply_to).toString(), inReplyToName));
    }
}

From source file:monakhv.android.samlib.service.NotificationData.java

/**
 * Notification about error during update
 *
 * @param context/*  w w  w. j ava  2 s .  com*/
 */
public void notifyUpdateError(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = makeNotification(context);
    mBuilder.setSmallIcon(android.R.drawable.stat_notify_error);
    mBuilder.setTicker(context.getText(R.string.notification_error));
    mBuilder.setContentText(context.getText(R.string.notification_update_error_detais).toString());

    notificationManager.notify(LIST_UPDATE_ERROR, mBuilder.build());

}

From source file:com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Notifies the user of changes in the keyboard shift state.
 *///from w ww .ja  va 2  s  . c o m
public void notifyShiftState() {
    final Keyboard keyboard = mView.getKeyboard();
    final KeyboardId keyboardId = keyboard.mId;
    final int elementId = keyboardId.mElementId;
    final Context context = mView.getContext();
    final CharSequence text;

    switch (elementId) {
    case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED:
    case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED:
        text = context.getText(R.string.spoken_description_shiftmode_locked);
        break;
    case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED:
    case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED:
    case KeyboardId.ELEMENT_SYMBOLS_SHIFTED:
        text = context.getText(R.string.spoken_description_shiftmode_on);
        break;
    default:
        text = context.getText(R.string.spoken_description_shiftmode_off);
    }

    AccessibilityUtils.getInstance().announceForAccessibility(mView, text);
}