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:org.cgiar.ilri.odk.pull.backend.DataHandler.java

/**
 * This method sets a shared preference to the specified value. Note that shared preferences can only handle strings
 *
 * @param context The context from where you want to set the value
 * @param sharedPreferenceKey The key corresponding to the shared preference. All shared preferences accessible by this app are defined in
 *                            DataHandler e.g DataHandler.SP_KEY_LOCALE
 * @param value The value the sharedPreference is to be set to
 */// w  w  w  .jav a  2s  .c om
public static void setSharedPreference(Context context, String sharedPreferenceKey, String value) {
    SharedPreferences.Editor editor = context
            .getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE).edit();
    editor.putString(sharedPreferenceKey, value);
    editor.commit();
    Log.d(TAG, sharedPreferenceKey + " shared preference saved as " + value);
}

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

public static InstallLocation[] getInstallLocations(Context context) {
    if (sInstallLocations == null) {
        ArrayList<InstallLocation> locations = new ArrayList<>();

        InstallLocation location = new InstallLocation();
        location.id = "primary";
        location.name = context.getString(R.string.install_location_primary_upgrade);
        location.description = context.getString(R.string.install_location_primary_upgrade_desc);

        locations.add(location);/*w  w  w. ja v  a  2s .c  om*/

        location = new InstallLocation();
        location.id = "dual";
        location.name = context.getString(R.string.secondary);
        location.description = String.format(context.getString(R.string.install_location_desc),
                "/system/multiboot/dual");
        locations.add(location);

        for (int i = 1; i <= 3; i++) {
            location = new InstallLocation();
            location.id = "multi-slot-" + i;
            location.name = String.format(context.getString(R.string.multislot), i);
            location.description = String.format(context.getString(R.string.install_location_desc),
                    "/cache/multiboot/multi-slot-" + i);
            locations.add(location);
        }

        sInstallLocations = locations.toArray(new InstallLocation[locations.size()]);
    }

    return sInstallLocations;
}

From source file:com.frostwire.android.gui.util.UIUtils.java

public static void showLongMessage(Context context, @StringRes int resId) {
    showLongMessage(context, context.getString(resId));
}

From source file:com.manning.androidhacks.hack046.helper.NotificationHelper.java

public static void showMsgNotification(Context ctx) {
    final NotificationManager mgr;
    mgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(android.R.drawable.sym_def_app_icon).setTicker("New msg!")
            .setContentTitle("This is the msg title").setContentText("content...")
            .setContentIntent(getPendingIntent(ctx));

    builder.addAction(android.R.drawable.ic_menu_send, ctx.getString(R.string.activity_msg_button_reply),
            getReplyPendingIntent(ctx));

    builder.addAction(android.R.drawable.ic_menu_delete, ctx.getString(R.string.activity_msg_button_delete),
            getDeletePendingIntent(ctx));

    mgr.notify(R.id.activity_main_receive_msg, builder.build());
}

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

/**
 * Unregister this account/device pair within the server.
 *//*from   www  .jav  a2 s.c  o  m*/
static void unregister(final Context context, final String regId) {
    Log.i(TAG, "unregistering device (regId = " + regId + ")");
    String serverUrl = SERVER_URL + "/unregister";
    Map<String, String> params = new HashMap<String, String>();
    params.put("regId", regId);
    try {
        post(serverUrl, params);
        GCMRegistrar.setRegisteredOnServer(context, false);
        String message = context.getString(R.string.server_unregistered);
        CommonUtilities.displayMessage(context, message);
    } 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.
        String message = context.getString(R.string.server_unregister_error, e.getMessage());
        CommonUtilities.displayMessage(context, message);
    }
}

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

/**
 * Issues a notification to inform the user that server has sent a message.
 *///  w  ww.j av a2 s .com
private static void generateNotification(Context context, String message, String data) {
    int icon = R.drawable.ic_stat_gcm;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(0);

    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, DemoActivity.class);
    notificationIntent.putExtra(CommonUtilities.EXTRA_TEAM_IN_JSON, data);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:com.wms.opensource.images3android.manager.MenuManager.java

public static void displayTemplatesMenu(final Context context, final Image image) {
    IconContextMenu cm = new IconContextMenu(context, R.menu.templates_menu);
    if (templateCollection == null) {
        String templateCollectionString = "";
        templateCollectionString = FileUtil.getStringFromFileInCache(StorageUtil.getTempDirectory(context),
                PersistFileNameUtil.getTemplateCollectionFileName(image.getImagePlantId()),
                context.getString(R.string.charSetName));
        try {//from  w  ww  . j a  v a2s  . c  o m
            templateCollection = (TemplateCollection) JsonUtil.deserialize(templateCollectionString, "",
                    TemplateCollection.class);
        } catch (JsonParseException e) {

        } catch (JsonMappingException e) {

        } catch (IOException e) {

        }
    }
    for (int i = 0; i < templateCollection.getResults().size(); i++) {
        TemplateResult result = templateCollection.getResults().get(i);
        cm.getMenu().add(0, i + 1, i, result.getId().getTemplateName());
    }

    cm.setOnIconContextItemSelectedListener(new IconContextItemSelectedListener() {
        @Override
        public void onIconContextItemSelected(MenuItem item, Object info) {
            if (item.getItemId() == R.id.action_hint) {
                // Position 0 is the indication for selecting a template, so we do nothing
            } else {
                String templateName = item.getTitle().toString();
                ReviewImageManager reviewImageManager = new ReviewImageManager(context);
                reviewImageManager.showImagePopupWindow(image, templateName);
            }
        }
    });

    cm.show();
}

From source file:net.mandaria.radioreddit.apis.RedditAPI.java

public static String updateModHash(Context context) {
    // Calls me.json to get the current modhash for the user
    String output = "";
    boolean errorGettingModHash = false;

    try {/* w  ww. j  ava2s . c o m*/
        try {
            output = HTTPUtil.get(context, context.getString(R.string.reddit_me));
        } catch (Exception ex) {
            ex.printStackTrace();
            errorGettingModHash = true;
            // For now, not used. It is acceptable to error out and not alert the user
            // radiosong.ErrorMessage = "Unable to connect to reddit";//context.getString(R.string.error_RadioRedditServerIsDownNotification);
        }

        if (!errorGettingModHash && output.length() > 0) {
            JSONTokener reddit_me_tokener = new JSONTokener(output);
            JSONObject reddit_me_json = new JSONObject(reddit_me_tokener);

            JSONObject data = reddit_me_json.getJSONObject("data");

            String modhash = data.getString("modhash");

            return modhash;
        } else {
            return null;
        }
    } catch (Exception ex) {
        //         CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        //         ceh.sendEmail(ex);

        ex.printStackTrace();

        return null;
    }
}

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

public static int getPagePreference(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    switch (getSortByPreference(c)) {
    case 1://from w  ww . java2  s  .  c om
        return prefs.getInt(c.getString(R.string.pop_page), 1);
    case 2:
        return prefs.getInt(c.getString(R.string.release_page), 1);
    case 3:
        return prefs.getInt(c.getString(R.string.votes_page), 1);
    }
    return -1;
}

From source file:mp.paschalis.App.java

public static int getBookStatusCode(String status, Context c) {

    if (status.equals(c.getString(R.string.rented))) {
        return App.BOOK_STATE_USER_RENTED;
    } else if (status.equals(c.getString(R.string.available))) {
        return App.BOOK_STATE_USER_AVAILABLE;
    } else if (status.equals(c.getString(R.string.dontLent))) {
        return App.BOOK_STATE_USER_NO_RENTAL;
    } else if (status.equals(c.getString(R.string.otherDontLent))) {
        return App.BOOK_STATE_USER_OTHER;
    } else if (status.equals(c.getString(R.string.dontOwn))) {
        return App.BOOK_STATE_USER_DONT_OWNS;
    } else {// www  .  ja v  a2s.com
        return App.BOOK_STATE_WRONG_STATUS;

    }

}