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.cpyf.twelve.spies.qr.code.result.supplement.URIResultInfoRetriever.java

URIResultInfoRetriever(TextView textView, URIParsedResult result, Handler handler, Context context) {
    super(textView, handler, context);
    redirectString = context.getString(R.string.msg_redirect);
    this.result = result;
}

From source file:org.nhnnext.android.basic.ImageDownload.java

public ImageDownload(Context context) {
    this.context = context;
    this.pref = context.getSharedPreferences(context.getString(R.string.pref_name), context.MODE_PRIVATE);
}

From source file:com.lillicoder.newsblurry.feeds.DownloadFeedsTask.java

@Override
protected List<IFeed> doInBackground(Void... params) {
    try {/*  w w w  . j a  va 2  s  .  c  o  m*/
        Context context = this.getContext();

        String feedsUrl = context.getString(R.string.api_feedsUrl);
        HttpGet feedsGet = new HttpGet(feedsUrl);

        // Pull entity and parse JSON response.
        HttpResponse httpResponse = this.executeWebRequest(feedsGet);
        JSONObject responseJson = this.getJsonFromResponse(httpResponse);

        // Save the newly fetched feeds in cache and persistent storage.
        FeedParser parser = new FeedParser(context);
        Map<Integer, Feed> feedsById = parser.parseFeedsById(responseJson);

        FeedCache cache = new FeedCache();
        cache.updateFeeds(feedsById);

        FeedRepository repository = new FeedRepository(this.getContext());
        repository.saveFeeds(feedsById);

        // Sort feeds before returning.
        List<IFeed> feeds = parser.parseFeeds(responseJson);
        Collections.sort(feeds);

        return feeds;
    } catch (ApiRequestException e) {
        Log.e(TAG, EXCEPTION_API_REQUEST_FAILED, e);
        this.setException(e);
    } catch (IOException e) {
        Log.e(TAG, EXCEPTION_FAILED_TO_PARSE_RESPONSE, e);
        this.setException(e);
    } catch (JSONException e) {
        Log.e(TAG, EXCEPTION_UNABLE_TO_CREATE_JSON_FROM_RESPONSE, e);
        this.setException(e);
    }

    return null;
}

From source file:info.ericyue.es.zxing.client.android.result.supplement.URIResultInfoRetriever.java

URIResultInfoRetriever(TextView textView, URIParsedResult result, Handler handler,
        HistoryManager historyManager, Context context) {
    super(textView, handler, historyManager, context);
    redirectString = context.getString(R.string.msg_redirect);
    this.result = result;
}

From source file:com.apecat.shoppingadvisor.scan.result.supplement.BookResultInfoRetriever.java

BookResultInfoRetriever(TextView textView, String isbn, Context context) {
    super(textView);
    this.isbn = isbn;
    this.source = context.getString(R.string.msg_google_books);
    this.context = context;
}

From source file:im.delight.android.commons.Social.java

/**
 * Displays an application chooser and composes the described email using the selected application
 *
 * @param recipientEmail the recipient's email address
 * @param subjectText the subject line of the message
 * @param bodyText the body text of the message
 * @param captionRes a string resource ID for the title of the application chooser's window
 * @param restrictToPackage an application's package name to restricted the selection to
 * @param context a context reference/*from  w w w . j av a 2s.  c  om*/
 * @throws Exception if there was an error trying to launch the email application
 */
public static void sendMail(final String recipientEmail, final String subjectText, final String bodyText,
        final int captionRes, final String restrictToPackage, final Context context) throws Exception {
    final String uriString = "mailto:" + Uri.encode(recipientEmail) + "?subject=" + Uri.encode(subjectText)
            + "&body=" + Uri.encode(bodyText);
    final Uri uri = Uri.parse(uriString);
    final Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(uri);

    if (restrictToPackage != null && restrictToPackage.length() > 0) {
        emailIntent.setPackage(restrictToPackage);
        if (context != null) {
            // launch the target app directly
            context.startActivity(emailIntent);
        }
    } else {
        if (context != null) {
            // offer a selection of all applications that can handle the email Intent
            context.startActivity(Intent.createChooser(emailIntent, context.getString(captionRes)));
        }
    }
}

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

public static RadioSong GetCurrentSongInformation(Context context, RadioRedditApplication application) {
    RadioSong radiosong = new RadioSong();
    radiosong.ErrorMessage = "";

    try {/*from   w w  w. j  a  v a  2  s . c  o  m*/
        String status_url = context.getString(R.string.radio_reddit_base_url) + application.CurrentStream.Status
                + context.getString(R.string.radio_reddit_status);

        String outputStatus = "";
        boolean errorGettingStatus = false;

        try {
            outputStatus = HTTPUtil.get(context, status_url);
        } catch (Exception ex) {
            ex.printStackTrace();
            errorGettingStatus = true;
            // For now, not used. It is acceptable to error out and not alert the user
            // radiosong.ErrorMessage = context.getString(R.string.error_RadioRedditServerIsDownNotification);
        }

        if (!errorGettingStatus && outputStatus.length() > 0) {
            JSONTokener status_tokener = new JSONTokener(outputStatus);
            JSONObject status_json = new JSONObject(status_tokener);

            radiosong.Playlist = status_json.getString("playlist");

            JSONObject songs = status_json.getJSONObject("songs");
            JSONArray songs_array = songs.getJSONArray("song");

            // get the first song in the array
            JSONObject song = songs_array.getJSONObject(0);
            radiosong.ID = song.getInt("id");
            radiosong.Title = song.getString("title");
            radiosong.Artist = song.getString("artist");
            radiosong.Redditor = song.getString("redditor");
            radiosong.Genre = song.getString("genre");
            radiosong.CumulativeScore = song.getString("score");

            if (radiosong.CumulativeScore.equals("{}"))
                radiosong.CumulativeScore = null;

            radiosong.Reddit_title = song.getString("reddit_title");
            radiosong.Reddit_url = song.getString("reddit_url");
            if (song.has("preview_url"))
                radiosong.Preview_url = song.getString("preview_url");
            if (song.has("download_url"))
                radiosong.Download_url = song.getString("download_url");
            if (song.has("bandcamp_link"))
                radiosong.Bandcamp_link = song.getString("bandcamp_link");
            if (song.has("bandcamp_art"))
                radiosong.Bandcamp_art = song.getString("bandcamp_art");
            if (song.has("itunes_link"))
                radiosong.Itunes_link = song.getString("itunes_link");
            if (song.has("itunes_art"))
                radiosong.Itunes_art = song.getString("itunes_art");
            if (song.has("itunes_price"))
                radiosong.Itunes_price = song.getString("itunes_price");

            // get vote score 
            String reddit_info_url = context.getString(R.string.reddit_link_by)
                    + URLEncoder.encode(radiosong.Reddit_url);

            String outputRedditInfo = "";
            boolean errorGettingRedditInfo = false;

            try {
                outputRedditInfo = HTTPUtil.get(context, reddit_info_url);
            } catch (Exception ex) {
                ex.printStackTrace();
                errorGettingRedditInfo = true;
                // For now, not used. It is acceptable to error out and not alert the user
                // radiosong.ErrorMessage = "Unable to connect to reddit";//context.getString(R.string.error_RadioRedditServerIsDownNotification);
            }

            if (!errorGettingRedditInfo && outputRedditInfo.length() > 0) {
                // Log.e("radio_reddit_test", "Length: " + outputRedditInfo.length());
                // Log.e("radio_reddit_test", "Value: " + outputRedditInfo); // TODO: sometimes the value contains "error: 404", need to check for that. (We can probably safely ignore this for now)
                JSONTokener reddit_info_tokener = new JSONTokener(outputRedditInfo);
                JSONObject reddit_info_json = new JSONObject(reddit_info_tokener);

                JSONObject data = reddit_info_json.getJSONObject("data");

                // default value of score
                String score = context.getString(R.string.vote_to_submit_song);
                String likes = "null";
                String name = "";

                JSONArray children_array = data.getJSONArray("children");

                // Song hasn't been submitted yet
                if (children_array.length() > 0) {
                    JSONObject children = children_array.getJSONObject(0);

                    JSONObject children_data = children.getJSONObject("data");
                    score = children_data.getString("score");

                    likes = children_data.getString("likes");
                    name = children_data.getString("name");
                }

                radiosong.Score = score;
                radiosong.Likes = likes;
                radiosong.Name = name;
            } else {
                radiosong.Score = "?";
                radiosong.Likes = "null";
                radiosong.Name = "";
            }

            return radiosong;
        }
        return null;
    } catch (Exception ex) {
        // We fail to get the current song information...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();
        radiosong.ErrorMessage = ex.toString();
        return radiosong;
    }
}

From source file:com.lillicoder.newsblurry.login.LoginTask.java

@Override
protected LoginResponse doInBackground(String... params) {
    LoginResponse response = null;/*from   ww w  .  ja v  a2s  . c  o m*/

    try {
        // Create the HttpPost instance for this login request and attach the login parameters.
        Context context = this.getContext();

        String loginUrl = context.getString(R.string.api_loginUrl);
        HttpPost loginPost = new HttpPost(loginUrl);

        List<NameValuePair> loginParameters = this.getLoginParameters(params[0], params[1]);
        loginPost.setEntity(new UrlEncodedFormEntity(loginParameters));

        // Pull entity and parse JSON response.
        HttpResponse httpResponse = this.executeWebRequest(loginPost);
        JSONObject responseJson = this.getJsonFromResponse(httpResponse);

        LoginResponseParser parser = new LoginResponseParser();
        response = parser.parseLoginResponse(responseJson);
    } catch (IndexOutOfBoundsException e) {
        Log.e(TAG, EXCEPTION_UNABLE_TO_GET_USER_NAME_AND_PASSWORD_PARAMS, e);
        this.setException(new InvalidUserCredentialsException(e));
    } catch (ApiRequestException e) {
        Log.e(TAG, EXCEPTION_API_REQUEST_FAILED, e);
        this.setException(e);
    } catch (IOException e) {
        Log.e(TAG, EXCEPTION_FAILED_TO_PARSE_RESPONSE, e);
        this.setException(e);
    } catch (JSONException e) {
        Log.e(TAG, EXCEPTION_UNABLE_TO_CREATE_JSON_FROM_RESPONSE, e);
        this.setException(e);
    }

    return response;
}

From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java

public static String getTwitterFormattedDate(Date date, Context ctx) {
    // if date not found
    if (date == null) {
        date = new Date();
    }/*from w w  w.  ja v a  2 s.c  o m*/

    try {
        String ttt = ctx.getResources().getString(R.string.romanblack_twitter_date_minutes);
        ttt = ctx.getResources().getString(R.string.romanblack_twitter_date_minutes);

        long delta = (System.currentTimeMillis() - date.getTime()) / 1000;
        String strPubdate;
        if (delta <= 0) {
            strPubdate = 0 + ctx.getString(R.string.romanblack_twitter_date_seconds);
            return strPubdate;
        }

        if (delta < 60) {
            strPubdate = delta + ctx.getString(R.string.romanblack_twitter_date_seconds);
        } else if (delta < 120) {
            strPubdate = 1 + ctx.getString(R.string.romanblack_twitter_date_minutes);
        } else if (delta < (45 * 60)) {
            strPubdate = (int) (delta / 60) + ctx.getString(R.string.romanblack_twitter_date_minutes);
        } else if (delta < (2 * 60 * 60)) {
            strPubdate = 1 + ctx.getString(R.string.romanblack_twitter_date_hour_ago);
        } else if (delta < (24 * 60 * 60)) {
            strPubdate = (int) (delta / 3600) + ctx.getString(R.string.romanblack_twitter_date_hour_ago);
        } else {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                    ctx.getString(R.string.twitter_date_format_item));
            strPubdate = simpleDateFormat.format(date);
        }
        return strPubdate;
    } catch (Exception ex) {
        return date.toString();
    }
}

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

public static RadioEpisode GetCurrentEpisodeInformation(Context context, RadioRedditApplication application) {
    RadioEpisode radioepisode = new RadioEpisode();
    radioepisode.ErrorMessage = "";

    try {/*from   w ww  .jav  a 2 s  .  c o  m*/
        String status_url = context.getString(R.string.radio_reddit_base_url) + application.CurrentStream.Status
                + context.getString(R.string.radio_reddit_status);

        String outputStatus = "";
        boolean errorGettingStatus = false;

        try {
            outputStatus = HTTPUtil.get(context, status_url);
        } catch (Exception ex) {
            ex.printStackTrace();
            errorGettingStatus = true;
            // For now, not used. It is acceptable to error out and not alert the user
            // radiosong.ErrorMessage = context.getString(R.string.error_RadioRedditServerIsDownNotification);
        }

        if (!errorGettingStatus && outputStatus.length() > 0) {
            JSONTokener status_tokener = new JSONTokener(outputStatus);
            JSONObject status_json = new JSONObject(status_tokener);

            radioepisode.Playlist = status_json.getString("playlist");

            JSONObject episodes = status_json.getJSONObject("episodes");
            JSONArray episodes_array = episodes.getJSONArray("episode");

            // get the first episode in the array
            JSONObject song = episodes_array.getJSONObject(0);
            radioepisode.ID = song.getInt("id");
            radioepisode.EpisodeTitle = song.getString("episode_title");
            radioepisode.EpisodeDescription = song.getString("episode_description");
            radioepisode.EpisodeKeywords = song.getString("episode_keywords");
            radioepisode.ShowTitle = song.getString("show_title");
            radioepisode.ShowHosts = song.getString("show_hosts").replaceAll(",", ", ");
            radioepisode.ShowRedditors = song.getString("show_redditors").replaceAll(",", ", ");
            radioepisode.ShowGenre = song.getString("show_genre");
            radioepisode.ShowFeed = song.getString("show_feed");
            radioepisode.Reddit_title = song.getString("reddit_title");
            radioepisode.Reddit_url = song.getString("reddit_url");
            if (song.has("preview_url"))
                radioepisode.Preview_url = song.getString("preview_url");
            if (song.has("download_url"))
                radioepisode.Download_url = song.getString("download_url");

            // get vote score
            String reddit_info_url = context.getString(R.string.reddit_link_by)
                    + URLEncoder.encode(radioepisode.Reddit_url);

            String outputRedditInfo = "";
            boolean errorGettingRedditInfo = false;

            try {
                outputRedditInfo = HTTPUtil.get(context, reddit_info_url);
            } catch (Exception ex) {
                ex.printStackTrace();
                errorGettingRedditInfo = true;
                // For now, not used. It is acceptable to error out and not alert the user
                // radiosong.ErrorMessage = "Unable to connect to reddit";//context.getString(R.string.error_RadioRedditServerIsDownNotification);
            }

            if (!errorGettingRedditInfo && outputRedditInfo.length() > 0) {
                // Log.e("radio_reddit_test", "Length: " + outputRedditInfo.length());
                // Log.e("radio_reddit_test", "Value: " + outputRedditInfo); // TODO: sometimes the value contains "error: 404", need to check for that (We can probably safely ignore this for now)
                JSONTokener reddit_info_tokener = new JSONTokener(outputRedditInfo);
                JSONObject reddit_info_json = new JSONObject(reddit_info_tokener);

                JSONObject data = reddit_info_json.getJSONObject("data");

                // default value of score
                String score = context.getString(R.string.vote_to_submit_song);
                String likes = "null";
                String name = "";

                JSONArray children_array = data.getJSONArray("children");

                // Episode hasn't been submitted yet
                if (children_array.length() > 0) {
                    JSONObject children = children_array.getJSONObject(0);

                    JSONObject children_data = children.getJSONObject("data");
                    score = children_data.getString("score");

                    likes = children_data.getString("likes");
                    name = children_data.getString("name");
                }

                radioepisode.Score = score;
                radioepisode.Likes = likes;
                radioepisode.Name = name;
            } else {
                radioepisode.Score = "?";
                radioepisode.Likes = "null";
                radioepisode.Name = "";
            }

            return radioepisode;
        }
        return null;
    } catch (Exception ex) {
        // We fail to get the current song information...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();
        radioepisode.ErrorMessage = ex.toString();
        return radioepisode;
    }

}