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:edu.mit.mobile.android.livingpostcards.data.Card.java

public static CharSequence getTitle(Context context, Cursor c) {
    CharSequence title = c.getString(c.getColumnIndexOrThrow(Card.COL_TITLE));
    if (title == null || title.length() == 0) {
        title = context.getText(R.string.untitled);
    }/*from   w  w  w.ja  va2  s . c om*/
    return title;
}

From source file:org.voidsink.anewjkuapp.notification.KusssNotificationBuilder.java

public static void showErrorNotification(final Context mContext, int stringResID, Exception e) {
    // contenIntent required for all Versions before ICS
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.ic_stat_notify_kusss).setContentTitle(mContext.getText(stringResID))
            .setContentIntent(pendingIntent).setAutoCancel(true);

    if (e != null) {
        mBuilder.setContentText(e.getLocalizedMessage());
    } else {/* ww w.  j av a2 s .  c  o  m*/
        mBuilder.setContentText("...");
    }

    ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ERROR,
            mBuilder.build());

}

From source file:nl.sogeti.android.gpstracker.streaming.CustomUpload.java

private static void notifyError(Context context, Exception e) {
    Log.e(CustomUpload.class, "Custom upload failed", e);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.ic_maps_indicator_current_position;
    CharSequence tickerText = context.getText(R.string.customupload_failed);
    Intent notificationIntent = new Intent(context, CustomUpload.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(icon)
            .setContentTitle(tickerText).setContentText(e.getMessage()).setContentIntent(contentIntent)
            .setAutoCancel(true);/*  w  w w. j  av a 2s  .  co  m*/

    notificationManager.notify(NOTIFICATION_ID, builder.build());
}

From source file:com.google.android.apps.iosched.util.UIUtils.java

/**
 * Format and return the given {@link Blocks} and {@link Rooms} values using
 * {@link #CONFERENCE_TIME_ZONE}.//from  w  w  w.  j a v a  2s. c  o m
 */
public static String formatSessionSubtitle(String sessionTitle, long blockStart, long blockEnd, String roomName,
        Context context) {
    if (sEmptyRoomText == null || sCodeLabRoomText == null) {
        sEmptyRoomText = context.getText(R.string.unknown_room);
        sCodeLabRoomText = context.getText(R.string.codelab_room);
    }

    if (roomName == null) {
        // TODO: remove the WAR for API not returning rooms for code labs
        return context.getString(R.string.session_subtitle,
                formatBlockTimeString(blockStart, blockEnd, context),
                sessionTitle.contains("Code Lab") ? sCodeLabRoomText : sEmptyRoomText);
    }

    return context.getString(R.string.session_subtitle, formatBlockTimeString(blockStart, blockEnd, context),
            roomName);
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static void showIncompatibleVersionNotification(Context context) {
    Intent intent = new Intent(context, UpdateRequiredActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
    Notification notification = new Notification.Builder(context)
            .setContentTitle(context.getText(R.string.cmaccount_update_required_title))
            .setContentText(context.getText(R.string.cmaccount_update_required_short))
            .setSmallIcon(R.drawable.ic_dialog_alert)
            .setLargeIcon(((BitmapDrawable) context.getResources().getDrawable(R.drawable.icon)).getBitmap())
            .setContentIntent(contentIntent).build();
    CMAccountUtils.showNotification(context, CMAccount.NOTIFICATION_ID_INCOMPATIBLE_VERSION, notification);
}

From source file:com.phonemetra.account.util.AccountUtils.java

public static void showIncompatibleVersionNotification(Context context) {
    Intent intent = new Intent(context, UpdateRequiredActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
    Notification notification = new Notification.Builder(context)
            .setContentTitle(context.getText(R.string.Account_update_required_title))
            .setContentText(context.getText(R.string.Account_update_required_short))
            .setSmallIcon(R.drawable.ic_dialog_alert)
            .setLargeIcon(((BitmapDrawable) context.getResources().getDrawable(R.drawable.icon)).getBitmap())
            .setContentIntent(contentIntent).build();
    AccountUtils.showNotification(context, Account.NOTIFICATION_ID_INCOMPATIBLE_VERSION, notification);
}

From source file:com.neuron.trafikanten.HelperFunctions.java

public static void renderTime(final StringBuffer txt, Long currentTime, Context context, long time) {
    int diffMinutes = Math.round(((float) (time - currentTime)) / MINUTE);

    if (diffMinutes < -1) {
        // Negative time!
        diffMinutes = diffMinutes * -1;/*from  w w  w . j  a v a  2s  . c o  m*/
        txt.append("-");
        txt.append(diffMinutes);
        txt.append(" min");
        return;
    } else if (diffMinutes < 1) {
        if (nowText == null) {
            nowText = context.getText(R.string.now);
        }
        txt.append(nowText);
        return;
    } else if (diffMinutes <= 9) {
        txt.append(diffMinutes);
        txt.append(" min");
        return;
    }

    //TODO Performance : hourFormater slow? can we construct HH:mm faster ourselfes and write directly to stringbuffer? aprox 110ms here
    txt.append(hourFormater.format(time));
}

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

public static String formatDLAForDisplay(Context context, Date input) {
    String result = N_C;//from  www .  j av  a 2  s . co  m
    if (input != null) {
        CharSequence format = context.getText(R.string.dla_format);
        DateFormat outputDF = new SimpleDateFormat(format.toString(), Locale.FRENCH);
        outputDF.setTimeZone(getDisplayTimeZone(context));
        result = outputDF.format(input);
    }
    return result;
}

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

public static String formatDLAForDisplayShort(Context context, Date input) {
    String result = N_C;// ww w .java 2s  .  c o  m
    if (input != null) {
        CharSequence format = context.getText(R.string.dla_format_short);
        DateFormat outputDF = new SimpleDateFormat(format.toString(), Locale.FRENCH);
        outputDF.setTimeZone(getDisplayTimeZone(context));
        result = outputDF.format(input);
    }
    return result;
}

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

public static String prettyPrintDuration(Context context, Integer duration) {
    int durationHours = duration / 60;
    int durationMinutes = duration % 60;
    CharSequence format = context.getText(R.string.dla_duration_format);
    String result = String.format(format.toString(), durationHours, durationMinutes);
    return result;
}