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.github.longkai.zhihu.util.Utils.java

/**
 * ??// w ww.j  a v  a 2  s . co  m
 * @param context
 * @param subject 
 * @param content 
 * @return intent
 */
public static Intent share(Context context, String subject, String content) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("text/plain");
    share.putExtra(Intent.EXTRA_SUBJECT, subject);
    share.putExtra(Intent.EXTRA_TEXT, content + context.getString(R.string.share_from));
    return share;
}

From source file:ru.gkpromtech.exhibition.organizations.OrganizationFilesDownloader.java

private static void download(Context context, String url, Organization organization) {
    String dir = SharedData.EXTERNAL_DIR + "army2016/";
    String file = url.substring(url.lastIndexOf('/') + 1);

    //noinspection ResultOfMethodCallIgnored
    new File(dir).mkdirs();

    DownloadManager.Request req = new DownloadManager.Request(Uri.parse(url));
    req.setTitle(organization.fullname);
    req.setDescription(context.getString(R.string.materials));
    req.allowScanningByMediaScanner();//from  w  w w  . ja va2  s .  c om
    req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    req.setDestinationUri(Uri.parse("file://" + dir + file));

    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    manager.enqueue(req);
}

From source file:net.frygo.findmybuddy.GCMIntentService.java

private static void generateAcceptfriendNotification(Context context, String message, String status) {

    Random rand = new Random();
    int x = rand.nextInt();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, customlistview.class);
    if (status.equalsIgnoreCase("accept"))
        message = message + " added you as buddy";
    else/*w ww  .java  2 s  .  c o m*/
        message = message + " rejected you as buddy";
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis());
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(x, notification);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock mWakelock = pm
            .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title);
    mWakelock.acquire();

    // Timer before putting Android Device to sleep mode.
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        public void run() {
            mWakelock.release();
        }
    };
    timer.schedule(task, 5000);

}

From source file:com.kakao.kakaolink.KakaoLink.java

/**
 * ?? API  singleton KakaoLink .//from  w  w w.jav a 2 s . c om
 * @param context ?  context
 * @return ??    class
 * @throws KakaoParameterException ?   ?   ? ?
 */
public static KakaoLink getKakaoLink(final Context context) throws KakaoParameterException {
    if (singltonKakaoLink != null)
        return singltonKakaoLink;

    SystemInfo.initialize(context);

    if (appKey == null)
        appKey = Utility.getMetadata(context, APP_KEY_PROPERTY);
    if (TextUtils.isEmpty(appKey))
        throw new KakaoParameterException(context.getString(R.string.com_kakao_alert_appKey));
    else {
        appVer = String.valueOf(Utility.getAppVersion(context));
        appPackageName = Utility.getAppPackageName(context);
        appKeyHash = Utility.getKeyHash(context);
        singltonKakaoLink = new KakaoLink();
        return singltonKakaoLink;
    }
}

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

public static RedditAccount login(Context context, String username, String password) {
    RedditAccount account = new RedditAccount();

    try {/* w w  w  . j a va  2  s.co m*/
        String url = context.getString(R.string.reddit_login) + "/" + username;

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

        BasicNameValuePair user = new BasicNameValuePair("user", username);
        post_values.add(user);

        BasicNameValuePair passwd = new BasicNameValuePair("passwd", password);
        post_values.add(passwd);

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

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

        JSONTokener reddit_login_tokener = new JSONTokener(outputLogin);
        JSONObject reddit_login_json = new JSONObject(reddit_login_tokener);

        JSONObject json = reddit_login_json.getJSONObject("json");

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

            account.ErrorMessage = error;
        } else {
            JSONObject data = json.getJSONObject("data");

            // success!
            String cookie = data.getString("cookie");
            String modhash = data.getString("modhash");

            account.Username = username;
            account.Cookie = cookie;
            account.Modhash = modhash;
            account.ErrorMessage = "";
        }
    } catch (Exception ex) {
        // We fail to get the streams...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();

        account.ErrorMessage = ex.toString();
    }

    return account;
}

From source file:Main.java

public static String getStringByName(Context context, String name, int subid) {
    int resid;/* w  w  w .  j  a  v  a 2 s.  c om*/

    if (subid < 0) {
        resid = context.getResources().getIdentifier(String.format("%s_n%d", name, -subid), "string",
                context.getPackageName());
    } else {
        resid = context.getResources().getIdentifier(String.format("%s_p%d", name, subid), "string",
                context.getPackageName());
    }

    if (resid == 0)
        return null;

    return context.getString(resid);
}

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

public static void initializePagePreference(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    prefs.edit().putInt(c.getString(R.string.pop_page), 1).apply();
    prefs.edit().putInt(c.getString(R.string.release_page), 1).apply();
    prefs.edit().putInt(c.getString(R.string.votes_page), 1).apply();
}

From source file:com.beesham.popularmovies.sync.MoviesSyncAdapter.java

public static void syncImmediately(Context context) {
    Bundle b = new Bundle();
    b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);

    ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), b);
}

From source file:net.openwatch.acluaz.fragment.FormFragment.java

public static JSONObject addUuidToJson(Context c, JSONObject json, int db_id) {

    try {// ww  w.j a va2 s  . co  m
        if (json.has(c.getString(R.string.report_tag))) {
            json.getJSONObject(c.getString(R.string.report_tag)).put(c.getString(R.string.uuid_tag),
                    Incident.objects(c).get(db_id).uuid.get());
        }
    } catch (Exception e) {
        Log.e("addUuidToJson", "Error adding uuid");
        e.printStackTrace();
    }
    return json;
}

From source file:Main.java

/**
 * Shows a Dialog with a title, a message, a EditText and two Buttons for OK
 * and Cancel. The user can't click OK when the EditText is empty.
 *
 * @param context/*from  w w w. j av  a  2  s .  c  om*/
 *            The Context of the calling Activity
 * @param title
 *            Title of the Dialog
 * @param message
 *            Message of the Dialog
 * @param inputEditText
 *            The EditText used for this Dialog. You can modify it for
 *            example by setting the input type before passing it to this
 *            method. You can also read the text from the calling method.
 * @param onOkClickListener
 *            The Listener for clicking on the OK button.
 */
public static void showDialog(Context context, String title, String message, EditText inputEditText,
        DialogInterface.OnClickListener onOkClickListener) {

    AlertDialog.Builder alert = new AlertDialog.Builder(context);
    alert.setTitle(title);
    alert.setMessage(message);
    alert.setView(inputEditText);

    /*
     * OK button
     */
    alert.setPositiveButton(context.getString(android.R.string.ok), onOkClickListener);
    /*
     * Cancel button
     */
    alert.setNegativeButton(context.getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            /*
             * Canceled.
             */
        }
    });

    final AlertDialog dialog = alert.show();
    if (dialog != null) {
        /*
         * Disable ok button.
         */
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
        /*
         * Dis- and enable , dependent on the text entered
         */
        inputEditText.addTextChangedListener(new TextWatcher() {
            /**
             * Enable OK button if text entered, disable otherwise.
             */
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                dialog.getButton(DialogInterface.BUTTON_POSITIVE)
                        .setEnabled(!s.toString().equals("") && isValideUrl(s.toString()));
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void afterTextChanged(Editable s) {
            }
        });
    }
}