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.example.igorklimov.popularmoviesdemo.helpers.Utility.java

public static void incrementPage(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    switch (getSortByPreference(c)) {
    case 1://from  w w  w  .ja va  2s.  c o  m
        prefs.edit().putInt(c.getString(R.string.pop_page), (getPagePreference(c) + 1)).apply();
        break;
    case 2:
        prefs.edit().putInt(c.getString(R.string.release_page), (getPagePreference(c) + 1)).apply();
        break;
    case 3:
        prefs.edit().putInt(c.getString(R.string.votes_page), (getPagePreference(c) + 1)).apply();
    }
}

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

/**
 * Unregister this account/device pair within the server.
 *//*w  w w. j a  va2 s.  c o m*/
public static void unregister(final Context context, final String regId) {
    Log.i(TAG, "unregistering device (regId = " + regId + ")");
    Map<String, String> params = new HashMap<String, String>();
    params.put("key", regId);
    try {
        request(DELETE, SERVER_URL, 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.creationgroundmedia.popularmovies.sync.MovieSyncAdapter.java

public static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if (null == accountManager.getPassword(newAccount)) {

        /*//from  ww w . j  a  va  2 s  . c om
         * Add the account and account type, no password or user data
         * If successful, return the Account object, otherwise report an error.
         */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */
        onAccountCreated(newAccount, context);
    }
    return newAccount;
}

From source file:com.geotrackin.gpslogger.senders.osm.OSMHelper.java

public static OAuthConsumer GetOSMAuthConsumer(Context ctx) {

    OAuthConsumer consumer = null;/*from  www.  ja  v  a 2s  .  co m*/

    try {
        int osmConsumerKey = ctx.getResources().getIdentifier("osm_consumerkey", "string",
                ctx.getPackageName());
        int osmConsumerSecret = ctx.getResources().getIdentifier("osm_consumersecret", "string",
                ctx.getPackageName());
        consumer = new CommonsHttpOAuthConsumer(ctx.getString(osmConsumerKey),
                ctx.getString(osmConsumerSecret));

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
        String osmAccessToken = prefs.getString("osm_accesstoken", "");
        String osmAccessTokenSecret = prefs.getString("osm_accesstokensecret", "");

        if (osmAccessToken != null && osmAccessToken.length() > 0 && osmAccessTokenSecret != null
                && osmAccessTokenSecret.length() > 0) {
            consumer.setTokenWithSecret(osmAccessToken, osmAccessTokenSecret);
        }

    } catch (Exception e) {
        //Swallow the exception
    }

    return consumer;
}

From source file:com.grarak.romswitcher.Utils.Utils.java

private static void checkNewPass(Context context) {
    if (mNewPassword.getText().toString().trim().equals(mConfirmPassword.getText().toString().trim())
            && !mNewPassword.getText().toString().trim().isEmpty()) {
        savePassword();/*from   ww  w  .ja v  a 2  s.  c  om*/
    } else {
        if (mNewPassword.getText().toString().trim().isEmpty()) {
            Utils.toast(context, context.getString(R.string.emptypass), 0);
        } else {
            Utils.toast(context, context.getString(R.string.newnotmatch), 0);
        }
        setupPassword(context);
    }
}

From source file:ee.ioc.phon.android.speak.Utils.java

public static AlertDialog getYesNoDialog(Context context, String confirmationMessage, final Executable ex) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(confirmationMessage).setCancelable(false)
            .setPositiveButton(context.getString(R.string.buttonYes), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ex.execute();//from   w  w  w. java 2 s  .c  o m
                }
            }).setNegativeButton(context.getString(R.string.buttonNo), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    return builder.create();
}

From source file:me.xiaopan.android.gohttp.JsonHttpResponseHandler.java

/**
 * ??/*from   w w w  .j  a  v a 2 s. c o  m*/
 * @param context 
 * @param responseClass ?class
 */
public static String parseResponseBodyAnnotation(Context context, Class<?> responseClass) {
    ResponseBody annotation = responseClass.getAnnotation(ResponseBody.class);
    if (annotation == null) {
        return null;
    }
    String annotationValue = annotation.value();
    if (annotationValue != null && !"".equals(annotationValue)) {
        return annotationValue;
    } else if (context != null && annotation.resId() > 0) {
        return context.getString(annotation.resId());
    } else {
        return null;
    }
}

From source file:com.twitt4droid.Twitt4droid.java

public static boolean areConsumerTokensAvailable(Context context) {
    return Resources.getMetaData(context, context.getString(R.string.twitt4droid_consumer_key_metadata),
            null) != null/*  ww  w.  java 2  s.  com*/
            && Resources.getMetaData(context, context.getString(R.string.twitt4droid_consumer_secret_metadata),
                    null) != null;
}

From source file:net.peterkuterna.android.apps.devoxxsched.service.SyncService.java

/**
 * Should we perform a remote sync?/*from  ww  w .j a  v a  2  s. c o  m*/
 */
private static boolean performRemoteSync(ContentResolver resolver, HttpClient httpClient, Intent intent,
        Context context) {
    final SharedPreferences settingsPrefs = context.getSharedPreferences(SettingsActivity.SETTINGS_NAME,
            MODE_PRIVATE);
    final SharedPreferences syncServicePrefs = context.getSharedPreferences(SyncPrefs.DEVOXXSCHED_SYNC,
            Context.MODE_PRIVATE);
    final boolean onlySyncWifi = settingsPrefs.getBoolean(context.getString(R.string.sync_only_wifi_key),
            false);
    final int localVersion = syncServicePrefs.getInt(SyncPrefs.LOCAL_VERSION, VERSION_NONE);
    if (!onlySyncWifi || isWifiConnected(context)) {
        final boolean remoteParse = localVersion < VERSION_REMOTE;
        final boolean forceRemoteRefresh = intent.getBooleanExtra(EXTRA_FORCE_REFRESH, false);
        final boolean hasContentChanged = hasContentChanged(resolver, httpClient);
        return remoteParse || forceRemoteRefresh || hasContentChanged;
    }
    return false;
}

From source file:com.android.incallui.ContactInfoCache.java

/**
 * Gets name strings based on some special presentation modes.
 *///w  ww  .  j  av a2s.co  m
private static String getPresentationString(Context context, int presentation) {
    String name = context.getString(R.string.unknown);
    if (presentation == TelecomManager.PRESENTATION_RESTRICTED) {
        name = context.getString(R.string.private_num);
    } else if (presentation == TelecomManager.PRESENTATION_PAYPHONE) {
        name = context.getString(R.string.payphone);
    }
    return name;
}