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:Main.java

/**
 * Tries to pull the Custom Attribute directly from the TextView.
 *
 * @param context     Activity Context//www.  j ava 2  s  .c  om
 * @param attrs       View Attributes
 * @param attributeId if -1 returns null.
 * @return null if attribute is not defined or added to View
 */
static String pullFontPathFromView(Context context, AttributeSet attrs, int[] attributeId) {
    if (attributeId == null || attrs == null)
        return null;

    final String attributeName;
    try {
        attributeName = context.getResources().getResourceEntryName(attributeId[0]);
    } catch (Resources.NotFoundException e) {
        // invalid attribute ID
        return null;
    }

    final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1);
    return stringResourceId > 0 ? context.getString(stringResourceId)
            : attrs.getAttributeValue(null, attributeName);
}

From source file:com.t2auth.AuthUtils.java

public static final void clearServiceTicket(Context ctx) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    prefs.edit().remove(ctx.getString(R.string.pref_st)).commit();
}

From source file:com.t2auth.AuthUtils.java

public static final void clearTicketGrantingTicket(Context ctx) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    prefs.edit().remove(ctx.getString(R.string.pref_tgt)).commit();
}

From source file:org.cgiar.ilri.odk.pull.backend.DataHandler.java

/**
 * Gets the vaule of a shared preference accessible by the context
 *
 * @param context Context e.g activity that is requesting for the shared preference
 * @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 defaultValue What will be returned by this method if the sharedPreference is empty or unavailable
 *
 * @return The value of the sharedPreference or the default value specified if the sharedPreference is empty
 *///from w  w  w.j  av  a  2 s .c o m
public static String getSharedPreference(Context context, String sharedPreferenceKey, String defaultValue) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(context.getString(R.string.app_name),
            Context.MODE_PRIVATE);
    //Log.d(TAG, "value of " + sharedPreferenceKey + " is " + sharedPreferences.getString(sharedPreferenceKey, defaultValue));
    return sharedPreferences.getString(sharedPreferenceKey, defaultValue);
}

From source file:com.github.chenxiaolong.dualbootpatcher.RomUtils.java

private static String getDefaultName(Context context, RomInformation info) {
    if (info.getId().equals(PRIMARY_ID)) {
        return context.getString(R.string.primary);
    } else if (info.getId().equals(SECONDARY_ID)) {
        return context.getString(R.string.secondary);
    } else if (info.getId().startsWith(MULTI_ID_PREFIX)) {
        String num = info.getId().substring(MULTI_ID_PREFIX.length());
        return context.getString(R.string.multislot, num);
    } else if (info.getId().startsWith(DATA_ID_PREFIX)) {
        String id = info.getId().substring(DATA_ID_PREFIX.length());
        return context.getString(R.string.dataslot, id);
    } else if (info.getId().startsWith(EXTSD_ID_PREFIX)) {
        String id = info.getId().substring(EXTSD_ID_PREFIX.length());
        return context.getString(R.string.extsdslot, id);
    }//  w  w  w . j ava  2s.c  o  m

    return UNKNOWN_ID;
}

From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java

public static void initializeSyncAdapter(Context context) {
    Log.d(LOG_TAG, context.getString(R.string.log_initialize_sync_adapter));

    getSyncAccount(context);//from  w w w  .  j a  v  a2s.  c o m
}

From source file:com.t2auth.AuthUtils.java

public static final String getUsername(Context ctx) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    return prefs.getString(ctx.getString(R.string.pref_last_user), "");
}

From source file:com.t2auth.AuthUtils.java

public static final String getTicketGrantingTicket(Context ctx) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    return prefs.getString(ctx.getString(R.string.pref_tgt), null);
}

From source file:com.t2auth.AuthUtils.java

public static final String getServiceTicket(Context ctx) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    return prefs.getString(ctx.getString(R.string.pref_st), null);
}

From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java

/**
 * Instructs the sync adapter to sync immediately.
 *//*from w ww .  ja va 2s.c om*/
public static void syncImmediately(Context context) {
    Log.d(LOG_TAG, context.getString(R.string.log_sync_immediately));

    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle);
}