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:Main.java

public static String getStringFormat(Context context, int format, Object... str) {
    return String.format(context.getText(format).toString(), str);
}

From source file:Main.java

public static void showToast(Context context, int id, int millisTime) {
    Toast.makeText(context, context.getText(id), millisTime).show();
}

From source file:Main.java

public static Spanned getStringToHtml(Context context, int format, Object... str) {
    return Html.fromHtml(String.format(context.getText(format).toString(), str));
}

From source file:Main.java

public static void showFormattedToast(Context context, int id, Object... args) {
    Toast.makeText(context, String.format(context.getText(id).toString(), args), Toast.LENGTH_LONG).show();
}

From source file:com.google.android.gcm.demo.ui.MainMenu.java

private static void addTest(Context context, LinkedHashMap<String, QuickTest> arrayMap, QuickTest test) {
    arrayMap.put(context.getText(test.getName()).toString(), test);
}

From source file:com.codefupanda.app.swish.util.NotificationUtil.java

/**
 * Show notification.//  w ww.  j a  v a 2 s  .com
 * 
 * @param context
 */
public static void showNotification(final Context context) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getText(R.string.notification_title))
            .setContentText(context.getText(R.string.notification_text)).setSound(soundUri);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for
    // the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.gcm.MyGCMIntentService.java

public static void generateNotification(Context context) {
    String message = (String) context.getText(R.string.notification_body);
    String titleSingle = (String) context.getText(R.string.notification_title_single);
    String titlePlural = (String) context.getText(R.string.notification_title_plural);
    String titleFrom = (String) context.getText(R.string.notification_title_from);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher_light)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
            .setVibrate(new long[] { 0, 1000, 0, 0, 0 }) // {delay, vibrate, sleep, vibrate, sleep}
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    if (newMessagesFromDifferentUsers) {
        mBuilder.setContentTitle(//from   w  w  w  .j  a v  a2  s  .  co m
                newMessages + " " + context.getText(R.string.notification_new_messages) + " " + titlePlural)
                .setContentText(message);
    } else {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        if (newMessages == 1) {
            mBuilder.setContentTitle(
                    newMessages + " " + titleSingle + " " + titleFrom + " " + newMessagePartyName)
                    .setContentText(newMessageContent.get(0));
            inboxStyle.setBigContentTitle(
                    newMessages + " " + titleSingle + " " + titleFrom + " " + newMessagePartyName);
            inboxStyle.addLine(newMessageContent.get(0));
        } else {
            mBuilder.setContentTitle(
                    newMessages + " " + titlePlural + " " + titleFrom + " " + newMessagePartyName)
                    .setContentText(message);
            inboxStyle.setBigContentTitle(
                    newMessages + " " + titlePlural + " " + titleFrom + " " + newMessagePartyName);

            for (int i = 0; i < newMessageContent.size(); i++) {
                inboxStyle.addLine(newMessageContent.get(i));
            }
            if (newMessages > 2) {
                inboxStyle.addLine((String) context.getText(R.string.notification_dots) + (newMessages - 2)
                        + " " + context.getText(R.string.notification_more_messages)
                        + context.getText(R.string.notification_dots));
            }
        }

        mBuilder.setStyle(inboxStyle);
    }

    int myPackage = context.getResources().getIdentifier(NOTIFICATION_PACKAGE, ConstantKeys.STRING,
            context.getPackageName());

    int myClass = context.getResources().getIdentifier(NOTIFICATION_CLASS, ConstantKeys.STRING,
            context.getPackageName());

    ComponentName c = new ComponentName(context.getString(myPackage), context.getString(myClass));
    Intent notificationIntent = new Intent();
    notificationIntent.setComponent(c);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.putExtra(ConstantKeys.NOTIFICATION, newMessageTimelineId);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(intent);

    NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    mNotifyMgr.notify(0, mBuilder.build());
}

From source file:org.adblockplus.android.Utils.java

protected static void showUpdateNotification(final Context context, final String url, final String error) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(context.getText(R.string.app_name));
    builder.setSmallIcon(R.drawable.ic_stat_warning);
    builder.setAutoCancel(true);//from  w  ww  . j a v a2s. c om
    builder.setOnlyAlertOnce(true);
    final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
    builder.setContentIntent(emptyIntent);

    if (StringUtils.isNotEmpty(error)) {
        builder.setContentText(context.getString(R.string.msg_update_fail));
    } else if (StringUtils.isNotEmpty(url)) {
        builder.setSmallIcon(R.drawable.ic_stat_download);
        final Intent intent = new Intent(context, UpdaterActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction("download");
        intent.putExtra("url", url);
        final PendingIntent updateIntent = PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(updateIntent);
        builder.setContentText(context.getString(R.string.msg_update_available));
    } else {
        builder.setContentText(context.getString(R.string.msg_update_missing));
    }

    final Notification notification = builder.getNotification();
    final NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(AdblockPlus.UPDATE_NOTIFICATION_ID, notification);
}

From source file:Main.java

public static Spanned getStringResourceByName(Context context, String key) {
    String packageName = context.getPackageName();
    int resId = context.getResources().getIdentifier(key, "string", packageName);
    if (resId == 0) {
        return Spannable.Factory.getInstance().newSpannable(key);
    } else {//from   w  ww .  j a  v a2 s.  c  o  m
        return Spannable.Factory.getInstance().newSpannable(context.getText(resId));
    }
}

From source file:com.moubry.worthwatching.ui.BaseActivity.java

public static AlertDialog createWhatsNewAlert(Context context) {
    final TextView message = new TextView(context);
    final SpannableString s = new SpannableString(context.getText(R.string.whats_new_message));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setPadding(10, 10, 10, 10);/*from ww  w  .  j a v a  2 s  . c o m*/
    message.setText(s);
    message.setLinkTextColor(context.getResources().getColor(R.color.blue));
    message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    message.setMovementMethod(LinkMovementMethod.getInstance());

    return new AlertDialog.Builder(context).setTitle(R.string.title_whats_new).setCancelable(true)
            .setPositiveButton("OK", null).setView(message).create();
}