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.ntsync.android.sync.activities.PaymentVerificationService.java

private static void sendNotification(Context context, Account account, int msg,
        Class<? extends Activity> activityClass, boolean showMsg) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent viewIntent = new Intent(context, activityClass);
    if (ShopActivity.class.equals(activityClass)) {
        // Vollstndige Meldung in der View anzeigen
        CharSequence msgText = context.getText(msg);
        if (showMsg) {
            // Show Full Message in ShopActivity
            viewIntent.putExtra(ShopActivity.PARM_MSG, String
                    .format(context.getText(R.string.shop_activity_delayedverif_failed).toString(), msgText));
        }/* w ww  .  j  a v  a2 s.  com*/
        viewIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, account.name);
    }

    // Adds the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(activityClass);
    stackBuilder.addNextIntent(viewIntent);

    // Photo sync possible.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(Constants.NOTIF_ICON).setContentTitle(context.getText(msg))
            .setContentText(account.name).setAutoCancel(true).setOnlyAlertOnce(true)
            .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
    notificationManager.notify(Constants.NOTIF_PAYMENT_VERIFICATIONRESULT, builder.build());
}

From source file:org.ttrssreader.utils.Utils.java

/**
 * Shows a notification with the given parameters
 *
 * @param content the string to display//  ww  w.ja  v  a  2 s  . com
 * @param time    how long the process took
 * @param error   set to true if an error occured
 * @param context the context
 */
public static void showFinishedNotification(String content, int time, boolean error, Context context,
        Intent intent) {
    if (context == null)
        return;

    NotificationManager mNotMan = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.icon;
    CharSequence title = String.format((String) context.getText(R.string.Utils_DownloadFinishedTitle), time);
    CharSequence ticker = context.getText(R.string.Utils_DownloadFinishedTicker);
    CharSequence text = content;

    if (content == null)
        text = context.getText(R.string.Utils_DownloadFinishedText);

    if (error) {
        icon = R.drawable.icon;
        title = context.getText(R.string.Utils_DownloadErrorTitle);
        ticker = context.getText(R.string.Utils_DownloadErrorTicker);
    }

    Notification notification = buildNotification(context, icon, ticker, title, text, true, intent);
    mNotMan.notify(ID_FINISHED, notification);
}

From source file:com.s16.inputmethod.skeyboard.IMESettings.java

static boolean AlertForInstallLocation(Context context,
        DialogInterface.OnDismissListener dismissListener) {
    String pkgPath = context.getPackageCodePath();
    if (pkgPath == null || pkgPath == "") {
        try {/* ww  w  .  j av a 2  s  .c  om*/
            pkgPath = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0).sourceDir;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (pkgPath != null && !pkgPath.startsWith("/data/app/") && !pkgPath.startsWith("/system/app/")) {

        if (context instanceof Activity) {
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle(context.getText(R.string.alert_installocation_title));
            builder.setMessage(context.getText(R.string.alert_installocation_message));
            builder.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            AlertDialog dialog = builder.create();
            if (dismissListener != null)
                dialog.setOnDismissListener(dismissListener);
            dialog.show();
            return false;
        } else {
            Toast.makeText(context, R.string.alert_installocation_message, Toast.LENGTH_LONG).show();
            return false;
        }
    }
    return true;
}

From source file:org.ttrssreader.utils.Utils.java

/**
 * Shows a notification indicating that something is running. When called with finished=true it removes the
 * notification.// w  w  w  . j a va  2  s .c  om
 *
 * @param context  the context
 * @param finished if the notification is to be removed
 */
private static void showRunningNotification(Context context, boolean finished, Intent intent) {
    if (context == null)
        return;

    NotificationManager mNotMan = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    // if finished remove notification and return, else display notification
    if (finished) {
        mNotMan.cancel(ID_RUNNING);
        return;
    }

    int icon = R.drawable.notification_icon;
    CharSequence title = context.getText(R.string.Utils_DownloadRunningTitle);
    CharSequence ticker = context.getText(R.string.Utils_DownloadRunningTicker);

    Notification notification = buildNotification(context, icon, ticker, title, "", true, intent);
    mNotMan.notify(ID_RUNNING, notification);
}

From source file:com.anysoftkeyboard.ui.tutorials.TutorialsProvider.java

public static void showDragonsIfNeeded(Context context) {
    if (BuildConfig.TESTING_BUILD && firstTestersTimeVersionLoaded(context)) {
        Logger.i(TAG, "TESTERS VERSION added");

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, TestersNoticeActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);

        final NotificationManager manager = ((NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE));

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
        notificationBuilder/*from  w  w w.j  av a 2s  .c o  m*/
                .setSmallIcon(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
                        ? R.drawable.notification_icon_beta_version
                        : R.drawable.ic_notification_debug_version)
                .setContentText(context.getText(R.string.notification_text_testers))
                .setContentTitle(context.getText(R.string.ime_name_beta)).setWhen(System.currentTimeMillis())
                .setContentIntent(contentIntent)
                .setColor(ContextCompat.getColor(context, R.color.notification_background_debug_version))
                .setDefaults(0/*no sound, vibrate, etc*/).setAutoCancel(true);

        manager.notify(R.id.notification_icon_debug_version, notificationBuilder.build());
    }
}

From source file:by.gdgminsk.animationguide.Sample.java

public CharSequence getLabel(Context context) {
    return context.getText(mLabelId);
}

From source file:org.agilespain.kitaos.TalksActivity.java

private TabHost.TabSpec createTabSpec(TabHost tabHost, String tag, int labelId) {
    final Context context = tabHost.getContext();

    final TabHost.TabSpec tabSpec = tabHost.newTabSpec(tag);

    final CharSequence label = context.getText(labelId);

    AttributeSet attrs = null;/*from  ww  w  .j  a v a2s.c o  m*/
    int defStyle = R.attr.kitaosTabViewStyle;
    final TextView view = new TextView(context, attrs, defStyle);
    view.setText(label);

    tabSpec.setIndicator(view);

    return tabSpec;
}

From source file:me.futuretechnology.blops.ui.util.FeedsAdapter.java

/**
 * Constructor.//from   ww w.j av  a2 s.  c  om
 *
 * @param context a general app context: e.g. getApplication()
 */
public FeedsAdapter(Context context, FragmentManager fm) {
    super(fm);

    mTxtBookmarks = context.getText(R.string.tab_bookmarks);
    mTxtMyNews = context.getText(R.string.tab_my_news);

    mFeedsManager = FeedsManager.getInstance();
    mFragments = new SparseArray<Fragment>(mFeedsManager.getFeedsCount() + 1);
    mFeedState = new HashMap<String, Integer>(mFeedsManager.getFeedsCount() + 1);

    EventBus.getDefault().register(this);
}

From source file:com.silentcircle.contacts.list.EmailAddressListAdapter.java

public EmailAddressListAdapter(Context context) {
    super(context);

    mUnknownNameText = context.getText(android.R.string.unknownName);
}

From source file:com.google.android.apps.muzei.notifications.NotificationSettingsDialogFragment.java

@NonNull
@Override//  w  w  w  .  j a v  a  2  s. c om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context context = getContext();
    if (context == null) {
        return super.onCreateDialog(savedInstanceState);
    }
    CharSequence[] items = new CharSequence[] {
            context.getText(R.string.notification_new_wallpaper_channel_name) };
    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    boolean[] checkedItems = new boolean[] {
            sharedPreferences.getBoolean(NewWallpaperNotificationReceiver.PREF_ENABLED, true) };
    return new AlertDialog.Builder(getContext()).setTitle(R.string.notification_settings)
            .setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    sharedPreferences.edit()
                            .putBoolean(NewWallpaperNotificationReceiver.PREF_ENABLED, isChecked).apply();
                }
            }).setPositiveButton(R.string.notification_settings_done, null).create();
}