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:dk.cafeanalog.AnalogWidget.java

private void handleIsOpen(final Context mContext, final OpeningStatus openingStatus) {
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
    final int[] appWidgetIds = appWidgetManager
            .getAppWidgetIds(new ComponentName(mContext, AnalogWidget.class));
    final RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.analog_widget);
    views.setTextViewText(R.id.appwidget_text, mContext.getText(R.string.refreshing_analog));
    views.setTextColor(R.id.appwidget_text,
            ContextCompat.getColor(mContext, android.R.color.primary_text_dark));
    // Instruct the widget manager to update the widget
    for (int appWidgetId : appWidgetIds) {
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }/*  www.  j  a  va 2 s  . c om*/

    CharSequence widgetText;
    if (openingStatus.open) {
        widgetText = mContext.getString(R.string.widget_open_analog);
        views.setTextColor(R.id.appwidget_text, ContextCompat.getColor(mContext, R.color.openColor));
    } else {
        widgetText = mContext.getString(R.string.widget_closed_analog);
        views.setTextColor(R.id.appwidget_text, ContextCompat.getColor(mContext, R.color.closedColor));
    }

    views.setTextViewText(R.id.appwidget_text, widgetText);
    views.setOnClickPendingIntent(R.id.appwidget_text, getPendingSelfIntent(mContext));
    // Instruct the widget manager to update the widget
    for (int appWidgetId : appWidgetIds) {
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected void notifyNextDlaNotActivated(Context context, Date dla, PreferencesHolder preferences) {
    CharSequence notifTitle = context.getText(R.string.next_dla_not_activated_title);
    String format = context.getText(R.string.next_dla_not_activated_text).toString();
    CharSequence notifText = String.format(format, MhDlaNotifierUtils.formatHour(dla));

    Pair<Boolean, Boolean> soundAndVibrate = soundAndVibrate(context, preferences);

    displayNotification(context, NotificationType.DLA, notifTitle, notifText, soundAndVibrate);
}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected void notifyNextDlaAboutToExpire(Context context, Date dla, PreferencesHolder preferences) {
    CharSequence notifTitle = context.getText(R.string.next_dla_expiring_title);
    String format = context.getText(R.string.next_dla_expiring_text).toString();
    CharSequence notifText = String.format(format, MhDlaNotifierUtils.formatHour(dla));

    Pair<Boolean, Boolean> soundAndVibrate = soundAndVibrate(context, preferences);

    displayNotification(context, NotificationType.DLA, notifTitle, notifText, soundAndVibrate);
}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected void notifyPvLoss(Context context, int pvLoss, int pv, PreferencesHolder preferences) {
    String titleFormat = context.getText(R.string.pv_loss_title).toString();
    CharSequence notifTitle = String.format(titleFormat, pvLoss);
    String messageFormat = context.getText(R.string.pv_remaining_text).toString();
    CharSequence notifText = String.format(messageFormat, pv);

    Pair<Boolean, Boolean> soundAndVibrate = soundAndVibrate(context, preferences);

    displayNotification(context, NotificationType.PV_LOSS, notifTitle, notifText, soundAndVibrate);
}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected void notifyCurrentDlaAboutToExpire(Context context, Date dla, Integer pa,
        PreferencesHolder preferences) {
    CharSequence notifTitle = context.getText(R.string.current_dla_expiring_title);
    if (pa != null && pa == 0) {
        notifTitle = context.getText(R.string.current_dla_expiring_title_noPA);
    }/*w ww .ja  v a 2  s  . c o  m*/
    String format = context.getText(R.string.current_dla_expiring_text).toString();
    CharSequence notifText = String.format(format, MhDlaNotifierUtils.formatHour(dla), pa);

    Pair<Boolean, Boolean> soundAndVibrate = soundAndVibrate(context, preferences);

    displayNotification(context, NotificationType.DLA, notifTitle, notifText, soundAndVibrate);
}

From source file:com.onyx.latinime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Notifies the user of changes in the keyboard shift state.
 *///from  w w w.  j a v  a2s .  c om
public void notifyShiftState() {
    if (mView == null) {
        return;
    }

    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);
}

From source file:com.putlocker.upload.DownloadService.java

/**
 * @param job The job to notify about/*  w w w  .j a  v  a2  s. c  o  m*/
 * @param context The context to use
 * Show a notification while this service is running.
 */
public Notification createDownloadNotification(PutlockerUpDownloadJob job, Context context, int progress) {
    CharSequence text;
    if (job.getJobType() == PutlockerUpDownloadJob.DOWNLOAD_JOB) {
        text = context.getText(R.string.remote_service_started);
    } else {
        text = context.getText(R.string.service_upload_started);
    }

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, PutlockerTransferList.class), 0);
    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.ic_launcher, text, System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = new RemoteViews(context.getApplicationContext().getPackageName(),
            R.layout.download_progress);

    notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_launcher);

    if (job.getJobType() == PutlockerUpDownloadJob.DOWNLOAD_JOB) {

        if (FileFactory.typeFromFileName(job.getName()) == FileType.FILE_TYPE_VIDEO) {
            notification.contentIntent = PendingIntent.getActivity(this, 0,
                    getIntentForJob((PutlockerDownloadJob) job), Intent.FLAG_ACTIVITY_NEW_TASK);
        } else {
            notification.contentIntent = contentIntent;
        }

        notification.contentView.setTextViewText(R.id.status_text,
                context.getString(R.string.download_started, job.getName()));
    } else {
        notification.contentView.setTextViewText(R.id.status_text,
                context.getString(R.string.upload_started, job.getName()));
        notification.contentIntent = contentIntent;
    }

    notification.contentView.setProgressBar(R.id.status_progress, 100, progress, false);
    return notification;
}

From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java

private void clickedOnUserBrick(final UserBrick clickedBrick, View view) {
    final Context context = getActivity();

    final List<CharSequence> items = new ArrayList<CharSequence>();

    items.add(context.getText(R.string.brick_context_dialog_add_to_script));

    items.add(context.getText(R.string.brick_context_dialog_edit_brick));

    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    boolean drawingCacheEnabled = view.isDrawingCacheEnabled();
    view.setDrawingCacheEnabled(true);/*w  w  w .java  2  s . co  m*/
    view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);
    view.buildDrawingCache(true);

    if (view.getDrawingCache() != null) {
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(drawingCacheEnabled);

        ImageView imageView = getGlowingBorder(bitmap);
        builder.setCustomTitle(imageView);
    }

    builder.setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            CharSequence clickedItemText = items.get(item);
            if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_add_to_script))) {
                addBrickToScript(clickedBrick);
            } else if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_edit_brick))) {
                launchBrickScriptActivityOnBrick(context, clickedBrick);
            }
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

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

/**
 * Make default builder for all types of notification
 *
 * @param context/*w w w.  j av a2 s .  c o m*/
 * @return notification builder object
 */
private NotificationCompat.Builder makeNotification(Context context) {
    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.putExtra(MainActivity.CLEAN_NOTIFICATION, MainActivity.CLEAN_NOTIFICATION);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setContentIntent(contentIntent);

    mBuilder.setContentTitle(context.getText(R.string.notification_updates).toString());

    SettingsHelper helper = new SettingsHelper(context);
    mBuilder.setSound(helper.getNotificationRingToneURI());//sound
    mBuilder.setLights(0xff00ff00, 300, 100);//Indicator
    mBuilder.setAutoCancel(true);
    return mBuilder;
}

From source file:hku.fyp14017.blencode.ui.fragment.AddBrickFragment.java

private void clickedOnUserBrick(final UserBrick clickedBrick, View view) {
    final Context context = getActivity();

    final List<CharSequence> items = new ArrayList<CharSequence>();

    items.add(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_add_to_script));

    items.add(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_edit_brick));

    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    boolean drawingCacheEnabled = view.isDrawingCacheEnabled();
    view.setDrawingCacheEnabled(true);//w  ww . jav  a 2  s  .  co  m
    view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);
    view.buildDrawingCache(true);

    if (view.getDrawingCache() != null) {
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(drawingCacheEnabled);

        ImageView imageView = getGlowingBorder(bitmap);
        builder.setCustomTitle(imageView);
    }

    builder.setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            CharSequence clickedItemText = items.get(item);
            if (clickedItemText.equals(
                    context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_add_to_script))) {
                addBrickToScript(clickedBrick);
            } else if (clickedItemText
                    .equals(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_edit_brick))) {
                launchBrickScriptActivityOnBrick(context, clickedBrick);
            }

        }

    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}