Example usage for android.content Context getString

List of usage examples for android.content Context getString

Introduction

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

Prototype

@NonNull
public final String getString(@StringRes int resId) 

Source Link

Document

Returns a localized string from the application's package's default string table.

Usage

From source file:com.google.android.gcm.demo.app.utils.ServerUtilities.java

/**
 * Unregister this account/device pair within the server.
 *//*from w  ww .j a  va2 s  .  c  om*/
public static void unregister(final Context context, final String registrationId) {
    Log.i(TAG, "unregistering device (registrationId = " + registrationId + ")");
    try {
        doHttpDelete(REGISTRATION_URL + "/" + registrationId);
        GCMRegistrar.setRegisteredOnServer(context, false);
        displayMessage(context, context.getString(R.string.server_unregistered));
    } catch (IOException e) {
        // At this point the device is unregistered from GCM, but still registered in the server.
        // We could try to unregister again, but it is not necessary: if the server tries to send
        // a message to the device, it will get a "NotRegistered" error message and should unregister the device.
        displayMessage(context, context.getString(R.string.server_unregister_error, e.getMessage()));
    }
}

From source file:com.ilearnrw.reader.utils.HttpHelper.java

public static boolean log(Context ctx, String msg, String tag) {
    if (msg.trim().isEmpty())
        return false;

    if (!isNetworkAvailable(ctx))
        return false;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String username = prefs.getString(ctx.getString(R.string.sp_user_name), "");

    if (username.isEmpty())
        return false;

    new LogTask(tag).run(username, msg);

    return true;//from www .j  a  v a2  s  .c  om
}

From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatcherUtils.java

public static InstallLocation getDataSlotInstallLocation(Context context, String dataSlotId) {
    InstallLocation location = new InstallLocation();
    location.id = getDataSlotRomId(dataSlotId);
    location.name = String.format(context.getString(R.string.dataslot), dataSlotId);
    location.description = context.getString(R.string.install_location_desc,
            "/data/multiboot/data-slot-" + dataSlotId);
    return location;
}

From source file:air.com.snagfilms.cast.chromecast.utils.Utils.java

/**
 * A utility method to show a simple error dialog. The textual content of
 * the dialog is provided through the passed-in resource id.
 * /*from   w ww  . jav a2  s  .  com*/
 * @param context
 * @param resourceId
 */
public static final void showErrorDialog(Context context, int resourceId) {
    showErrorDialog(context, context.getString(resourceId));
}

From source file:com.hybris.mobile.lib.commerce.helper.UrlHelper.java

/**
 * Build the webservice Http Address/*w  ww.  j av  a  2s  .  com*/
 *
 * @param context               Application-specific resources
 * @param configuration         URL settings
 * @param pathUrlStringResource Webservice path
 * @param formatArgs            Values to replace on the final returned String
 * @return Formatted String Url for WebService
 */
private static String buildWebserviceUrl(Context context, Configuration configuration,
        int pathUrlStringResource, Object... formatArgs) {
    if (configuration == null || StringUtils.isBlank(configuration.getBackendUrl())
            || StringUtils.isBlank(configuration.getCatalog())) {
        throw new IllegalArgumentException();
    }

    String url = configuration.getBackendUrl() + context.getString(R.string.path_webservice)
            + configuration.getCatalog();

    if (formatArgs != null && formatArgs.length > 0) {
        return url + context.getString(pathUrlStringResource, formatArgs);
    } else {
        return url + context.getString(pathUrlStringResource);
    }
}

From source file:com.example.igorklimov.popularmoviesdemo.helpers.Utility.java

public static int getSortByPreference(Context c) {
    return PreferenceManager.getDefaultSharedPreferences(c).getInt(c.getString(R.string.key_sort_types), 1);
}

From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatcherUtils.java

public static InstallLocation getExtsdSlotInstallLocation(Context context, String extsdSlotId) {
    InstallLocation location = new InstallLocation();
    location.id = getExtsdSlotRomId(extsdSlotId);
    location.name = String.format(context.getString(R.string.extsdslot), extsdSlotId);
    location.description = context.getString(R.string.install_location_desc,
            "[External SD]/multiboot/extsd-slot-" + extsdSlotId);
    return location;
}

From source file:com.example.igorklimov.popularmoviesdemo.helpers.Utility.java

public static boolean isTabletPreference(Context c) {
    return PreferenceManager.getDefaultSharedPreferences(c).getBoolean(c.getString(R.string.is_two_pane),
            false);//w w  w  .j  av a  2s  .  c  o  m
}

From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java

private static void issueNotification(Context context, Set<String> addedMilestones,
        Set<String> removedMilestones, Map<String, int[]> changedProgresses) {
    String title = context.getString(R.string.notification_title);
    StringBuilder message = new StringBuilder();

    // Changed progresses
    for (String milestoneTitle : changedProgresses.keySet()) {
        int oldProgress = changedProgresses.get(milestoneTitle)[0];
        int newProgress = changedProgresses.get(milestoneTitle)[1];
        message.append("\n").append(String.format(context.getString(R.string.notific_msg_text_format),
                milestoneTitle, oldProgress, newProgress));
    }//from  w  ww  .j a v a2  s.c  om

    // Added milestones
    for (String milestoneTitle : addedMilestones) {
        message.append("\n").append(context.getString(R.string.milestone_added_notification, milestoneTitle));
    }

    // Removed milestones
    for (String milestoneTitle : removedMilestones) {
        message.append("\n").append(context.getString(R.string.milestone_removed_notification, milestoneTitle));
    }

    // Remove first newline
    message.delete(0, 1);

    // Create PendingIntent
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class),
            PendingIntent.FLAG_UPDATE_CURRENT);

    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    boolean sound = pref.getBoolean(Constants.NOTIFICATION_SOUND_PREF, true);
    boolean vibrate = pref.getBoolean(Constants.NOTIFICATION_VIBRATE_PREF, true);
    boolean light = pref.getBoolean(Constants.NOTIFICATION_LIGHT_PREF, true);
    int defaults = 0;
    if (sound)
        defaults = defaults | Notification.DEFAULT_SOUND;
    if (vibrate)
        defaults = defaults | Notification.DEFAULT_VIBRATE;
    if (light)
        defaults = defaults | Notification.DEFAULT_LIGHTS;

    // Build the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setSmallIcon(R.mipmap.notification_small_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setDefaults(defaults).setAutoCancel(true);

    // Issue the notification
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(PROGRESS_NOTIFICATION_ID, builder.build());
}

From source file:com.yojiokisoft.japanesecalc.MyUncaughtExceptionHandler.java

/** 
 * ??????.//from  w w w .  jav a 2s .  c  o m
 * 
 * @param activityContext ??Activity?????
 */
public static void sendBugReport(Context activityContext) {
    sBugReportFile = new File(MyConst.getUncaughtBugFilePath());
    if (sBugReportFile == null || !sBugReportFile.exists()) {
        return;
    }

    setVersionName();

    MyDialog.Builder.newInstance(activityContext).setTitle(activityContext.getString(R.string.err_dialog_title))
            .setMessage(activityContext.getString(R.string.err_dialog_msg))
            .setPositiveLabel(activityContext.getString(R.string.send))
            .setPositiveClickListener(mBugDialogOkClicked)
            .setNegativeLabel(activityContext.getString(R.string.cancel))
            .setNegativeClickListener(mBugDialogCancelClicked).show();
}