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.ilearnrw.reader.utils.HttpHelper.java

public static boolean refreshTokens(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String refreshToken = preferences.getString(context.getString(R.string.sp_refreshToken), "");

    if (refreshToken.isEmpty())
        return false;

    HttpResponse refreshResponse = HttpHelper
            .get("https://ssl.ilearnrw.eu/ilearnrw/user/newtokens?refresh=" + refreshToken);
    ArrayList<String> refreshData = HttpHelper.handleResponse(refreshResponse);

    if (refreshData == null)
        return false;

    if (refreshData.size() > 1) {
        try {//from  w  w w  .  j a  v a 2  s  .com
            TokenResult lr = new Gson().fromJson(refreshData.get(1), TokenResult.class);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString(context.getString(R.string.sp_authToken), lr.authToken);
            editor.putString(context.getString(R.string.sp_refreshToken), lr.refreshToken);
            editor.apply();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    } else {
        Log.e("Error", refreshData.get(0));
    }

    return false;
}

From source file:Main.java

/**
 * Gets resource string from values xml without relying on generated R.java. This allows to
 * compile the donations lib on its own, while having the configuration xml in the main project.
 * //from   ww  w  .j  a va  2  s. co  m
 * @param name
 * @param context
 * @return
 */
public static String getResourceString(Context context, String name) {
    int nameResourceID = context.getResources().getIdentifier(name, "string",
            context.getApplicationInfo().packageName);
    if (nameResourceID == 0) {
        throw new IllegalArgumentException("No resource string found with name " + name);
    } else {
        return context.getString(nameResourceID);
    }
}

From source file:com.pursuer.reader.easyrss.Utils.java

public static String timestampToTimeAgo(final Context context, final long timestamp) {
    final Date date = timestampToDate(timestamp);
    final long delta = new Date().getTime() - date.getTime();
    if (delta < 60 * 60 * 1000) {
        return context.getString(R.string.TxtLessThanOneHourAgo);
    } else if (delta < 40 * 60 * 60 * 1000) {
        return String.valueOf(delta / (60 * 60 * 1000) + 1) + " " + context.getString(R.string.TxtHoursAgo);
    } else {//from  w ww .  j  a va2 s  .c o  m
        return String.valueOf(delta / (24 * 60 * 60 * 1000) + 1) + " " + context.getString(R.string.TxtDaysAgo);
    }
}

From source file:Main.java

/**
 * Show Alert Dialog//from   w  ww . ja  v a  2 s .  c  o  m
 * @param context
 * @param titleId
 * @param messageId
 * @param positiveButtontxt
 * @param positiveListener
 * @param negativeButtontxt
 * @param negativeListener
 */
public static void showAlert(Context context, int titleId, int messageId, CharSequence positiveButtontxt,
        DialogInterface.OnClickListener positiveListener, CharSequence negativeButtontxt,
        DialogInterface.OnClickListener negativeListener) {

    showAlert(context, context.getString(titleId), context.getString(messageId), positiveButtontxt,
            positiveListener, negativeButtontxt, negativeListener);

}

From source file:net.naonedbus.utils.InfoDialogUtils.java

/**
 * Crer une dialog avec le titre et le contenu donn.
 * //w ww . ja v  a2  s . c o  m
 * @param context
 * @param titleId
 * @param messageId
 * @return La dialogue.
 */
public static AlertDialog getDialog(final Context context, final int titleId, final int messageId) {

    final AlertDialog.Builder moreDetailsDialog = new AlertDialog.Builder(context);
    moreDetailsDialog.setTitle(context.getString(titleId));
    moreDetailsDialog.setMessage(context.getString(messageId));
    moreDetailsDialog.setPositiveButton(android.R.string.ok, null);

    return moreDetailsDialog.create();
}

From source file:jog.my.memory.gcm.ServerUtilities.java

/**
 * Sends the registration ID to your server over HTTP, so it can use
 * GCM/HTTP or CCS to send messages to your app. Not needed for this demo
 * since the device sends upstream messages to a server that echoes back the
 * message using the 'from' address in the message.
 *//*from w  w w  .  j  a v  a  2 s . c  om*/
public static void sendRegistrationIdToBackend(Context context, String regId) {
    String serverUrl = context.getString(R.string.server_addr) + "/register";
    Map<String, String> params = new HashMap<String, String>();
    params.put("regId", regId);

    // Once GCM returns a registration id, we need to register it in the
    // server. As the server might be down, we will retry it a couple
    // times.
    long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000);
    for (int i = 1; i <= ServerUtilities.MAX_ATTEMPTS; i++) {
        try {
            ServerUtilities.post(serverUrl, params);
        } catch (IOException e) {
            // Here we are simplifying and retrying on any error; in a real
            // application, it should retry only on unrecoverable errors
            // (like HTTP error code 503).
            if (i == MAX_ATTEMPTS) {
                break;
            }
            try {
                Thread.sleep(backoff);
            } catch (InterruptedException e1) {
                // Activity finished before we complete - exit.
                Thread.currentThread().interrupt();
            }
            // increase backoff exponentially
            backoff *= 2;
        }
    }

}

From source file:br.com.thiagopagonha.psnapi.gcm.ServerUtilities.java

/**
 * Manda uma requisio pro servidor, solicitando uma atualizao de status
 * Mas essa atualizao  somente um ping, ir vir pelo C2M normalmente
 * //ww w  . j a va  2s .  c o m
 * @param context
 */
public static void sync(final Context context) {
    Log.i(TAG, "Sync device");
    try {
        request(GET, SERVER_URL + "whosonline", null);
    } catch (IOException e) {
        displayMessage(context, context.getString(R.string.server_sync_error));
    }
}

From source file:com.pursuer.reader.easyrss.WebpageItemViewCtrl.java

private static String genFailedToLoadContentPage(final Context context, final int theme) {
    final StringBuilder builder = new StringBuilder();
    builder.append("<div>");
    builder.append(context.getString(R.string.MsgFailedToLoadContent));
    builder.append("</div>");
    builder.append(/*from www . j av  a 2 s.  c  o  m*/
            theme == SettingTheme.THEME_NORMAL ? DataUtils.DEFAULT_NORMAL_CSS : DataUtils.DEFAULT_DARK_CSS);
    return builder.toString();
}

From source file:net.kourlas.voipms_sms.Utils.java

/**
 * Shows a standard information dialog to the user.
 *
 * @param context The source context./* w ww . ja  va2s  .  c  o m*/
 * @param text    The text of the dialog.
 */
public static void showInfoDialog(Context context, String text) {
    showAlertDialog(context, null, text, context.getString(R.string.ok), null, null, null);
}

From source file:at.wada811.dayscounter.CrashExceptionHandler.java

public static void reportProblem(Context context) {
    File file = ResourceUtils.getFile(context, CrashExceptionHandler.FILE_NAME);
    File dirFile = new File(Environment.getExternalStorageDirectory(), context.getString(R.string.app_dir));
    File attachmentFile = new File(dirFile, CrashExceptionHandler.FILE_NAME);
    Intent intent;//from w ww .  j  av a 2 s .  c  o  m
    String report = ResourceUtils.readFileString(context, CrashExceptionHandler.FILE_NAME);
    if (FileUtils.move(file, attachmentFile)) {
        intent = IntentUtils.createSendMailIntent(CrashExceptionHandler.MAILTO,
                context.getString(R.string.reportProblemMailTitle),
                context.getString(R.string.reportProblemMailBody));
        intent = IntentUtils.addFile(intent, attachmentFile);
    } else {
        intent = IntentUtils.createSendMailIntent(CrashExceptionHandler.MAILTO,
                context.getString(R.string.reportProblemMailTitle),
                context.getString(R.string.reportProblemMailBody, report));
    }
    Intent gmailIntent = IntentUtils.createGmailIntent(intent);
    if (IntentUtils.canIntent(context, gmailIntent)) {
        ((Activity) context).startActivityForResult(gmailIntent, REQ_REPORT);
    } else if (IntentUtils.canIntent(context, intent)) {
        ((Activity) context).startActivityForResult(
                Intent.createChooser(intent, context.getString(R.string.reportProblem)), REQ_REPORT);
    } else {
        ToastUtils.show(context, R.string.mailerNotFound);
    }
}