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.twitt4droid.Twitt4droid.java

/**
 * Saves a twitter user.// w  w w . ja va 2  s  .  c  o m
 * 
 * @param user the user to save.
 * @param context the application context.
 */
public static void saveOrUpdateUser(User user, Context context) {
    Resources.getPreferences(context).edit()
            .putString(context.getString(R.string.twitt4droid_user_key), UserJSONImpl.toJSON(user)).commit();
}

From source file:edu.mit.mobile.android.locast.accounts.AuthenticatorActivity.java

public static Dialog createLogoutDialog(Context context, LogoutHandler onLogoutHandler) {

    final AlertDialog.Builder b = new AlertDialog.Builder(context);
    final String appName = context.getString(R.string.app_name);
    b.setTitle(context.getString(R.string.auth_logout_title, appName));
    b.setMessage(context.getString(R.string.auth_logout_message, appName));
    b.setCancelable(true);//  w  ww.j a  v  a 2s .  com
    b.setPositiveButton(R.string.auth_logout, onLogoutHandler);
    b.setNegativeButton(android.R.string.cancel, null);

    return b.create();
}

From source file:com.twitt4droid.Twitt4droid.java

/**
 * Checks if there is any user authentication information stored in this app.
 * /*from www. j av  a 2  s .  co m*/
 * @param context the application context.
 * @return {@code true} if there is any user authentication information stored in this app;
 *         otherwise {@code false}.
 */
public static boolean isUserLoggedIn(Context context) {
    return Resources.getPreferences(context)
            .getBoolean(context.getString(R.string.twitt4droid_user_is_logged_in_key), false);
}

From source file:com.silentcircle.silenttext.util.DeviceUtils.java

public static Intent getShareDebugInformationIntent(Context context) {

    Intent intent = new Intent(Intent.ACTION_SENDTO,
            Uri.fromParts("mailto", context.getString(R.string.support_email_address), null));

    intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.support_email_subject));
    intent.putExtra(Intent.EXTRA_TEXT, wrap(LABEL_DEBUG_INFO, getDebugInformation(context)));

    ResolveInfo info = context.getPackageManager().resolveActivity(intent, 0);

    if (info == null) {
        intent.setAction(Intent.ACTION_SEND);
        intent.setDataAndType(null, "text/plain");
    }/*from  w  w w  .  j  a va2s  . c  o m*/

    return Intent.createChooser(intent,
            context.getString(R.string.share_with, context.getString(R.string.feedback)));

}

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

@SuppressLint("NewApi")
public static void alert(final Context context, String title, String message) {
    Builder builder = new Builder(context);
    builder.setTitle(title).setMessage(message).setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override//  w w w.j ava  2  s  . c o  m
        public void onDismiss(DialogInterface dialog) {
            ((Activity) context).finish();
        }
    }).setNeutralButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ((Activity) context).finish();
        }
    }).show();
}

From source file:com.vendsy.bartsy.venue.GCMIntentService.java

/**
 * To generate a notification to inform the user that server has sent a message.
 * // w  w  w.  jav  a  2s  .c  om
 * @param count
 * @param count 
 */
private static void generateNotification(Context context, String message, String count) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);

    Intent notificationIntent = new Intent(context, MainActivity.class);
    // 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, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    try {
        int countValue = Integer.parseInt(count);
        notification.number = countValue;
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    // // Play default notification sound
    notification.defaults = Notification.DEFAULT_SOUND;
    notificationManager.notify(0, notification);
}

From source file:fr.free.nrw.commons.Utils.java

public static void handleGeoCoordinates(Context context, String coords) {
    try {// w  ww . j  a v a2 s. co m
        Uri gmmIntentUri = Uri.parse("google.streetview:cbll=" + coords);
        Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
        mapIntent.setPackage("com.google.android.apps.maps");
        context.startActivity(mapIntent);
    } catch (ActivityNotFoundException ex) {
        Toast toast = Toast.makeText(context, context.getString(R.string.map_application_missing),
                LENGTH_SHORT);
        toast.show();
    }
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.CommandService.java

public static boolean sendCommand(Context ctx, CommandObject cmd)
        throws KurentoCommandException, InvalidDataException, NotFoundException {
    PerformanceMonitor.monitor(ctx, PerformanceMonitor.Type.CMD_SEND_REQUEST_START, cmd.getJson());

    HttpResp<Void> resp;/*www  .ja va  2  s  .  c  om*/

    try {
        if (cmd.getMedia().length() > 2) {
            resp = sendCommandWithMedia(ctx, cmd);
        } else {
            resp = HttpManager.sendPostVoid(ctx, ctx.getString(R.string.url_command), cmd.getJson());
        }
    } catch (TransportException e) {
        log.error("Cannot send command", e);
        return false;
    }

    PerformanceMonitor.monitor(ctx, PerformanceMonitor.Type.CMD_SEND_REQUEST_FINISH, cmd.getJson());

    return resp.getCode() == HttpStatus.SC_CREATED;
}

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

public static String Vote(Context context, RedditAccount account, int voteDirection, String fullname) {
    String errorMessage = "";

    try {//from ww w .j av  a 2  s .c  o  m
        try {
            account.Modhash = updateModHash(context);

            if (account.Modhash == null) {
                errorMessage = context.getString(R.string.error_ThereWasAProblemVotingPleaseTryAgain);
                return errorMessage;
            }
        } catch (Exception ex) {
            errorMessage = ex.getMessage();
            return errorMessage;
        }

        String url = context.getString(R.string.reddit_vote);

        // post values
        ArrayList<NameValuePair> post_values = new ArrayList<NameValuePair>();

        BasicNameValuePair id = new BasicNameValuePair("id", fullname);
        post_values.add(id);

        BasicNameValuePair dir = new BasicNameValuePair("dir", Integer.toString(voteDirection));
        post_values.add(dir);

        // not required
        //BasicNameValuePair r = new BasicNameValuePair("r", "radioreddit"); // TODO: shouldn't be hard coded, could be talkradioreddit
        //post_values.add(r);

        BasicNameValuePair uh = new BasicNameValuePair("uh", account.Modhash);
        post_values.add(uh);

        BasicNameValuePair api_type = new BasicNameValuePair("api_type", "json");
        post_values.add(api_type);

        String outputVote = HTTPUtil.post(context, url, post_values);

        JSONTokener reddit_vote_tokener = new JSONTokener(outputVote);
        JSONObject reddit_vote_json = new JSONObject(reddit_vote_tokener);

        if (reddit_vote_json.has("json")) {
            JSONObject json = reddit_vote_json.getJSONObject("json");

            if (json.has("errors") && json.getJSONArray("errors").length() > 0) {
                String error = json.getJSONArray("errors").getJSONArray(0).getString(1);

                errorMessage = error;
            }
        }
        // success!
    } catch (Exception ex) {
        // We fail to vote...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();

        errorMessage = ex.toString();
    }

    return errorMessage;
}

From source file:com.twitt4droid.Twitt4droid.java

/**
 * Saves authentication information from the given AccessToken in {@code SharedPreferences}.
 * /*from   ww  w. j av a  2 s .  com*/
 * @param context the application context.
 * @param token an AccessToken.
 */
public static void saveAuthenticationInfo(Context context, AccessToken token) {
    Resources.getPreferences(context).edit()
            .putString(context.getString(R.string.twitt4droid_oauth_token_key), token.getToken())
            .putString(context.getString(R.string.twitt4droid_oauth_secret_key), token.getTokenSecret())
            .putBoolean(context.getString(R.string.twitt4droid_user_is_logged_in_key), true).commit();
}