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.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java

/**
 * Configure a periodic sync of the data then Sync data immediately.
 * Display a Toast message to let the user know what is happening.
 *
 * @param newAccount/*from  w  w w .  ja va  2s  .  co  m*/
 *         account to configure sync on
 * @param context
 *         current application environment context
 */
private static void onAccountCreated(Account newAccount, Context context) {

    configurePeriodicSync(context, SYNC_INTERVAL, SYNC_FLEXTIME);
    ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true);

    // sync the initial data
    syncImmediately(context);
    Toast.makeText(context, context.getString(R.string.toast_retrieving_data_message), Toast.LENGTH_LONG)
            .show();
}

From source file:com.librelio.products.ui.ProductsBillingActivity.java

private static String buildSubscriptionCodeQuery(Context context, String code, String fileName) {

    StringBuilder query = new StringBuilder(LibrelioApplication.getServerUrl(context));

    String command = context.getString(R.string.command_pswd).replace(PARAM_CODE, Uri.encode(code))
            .replace(PARAM_URLSTRING, Uri.encode(LibrelioApplication.getUrlString(fileName)))
            .replace(PARAM_CLIENT, Uri.encode(LibrelioApplication.getClientName(context)))
            .replace(PARAM_APP, Uri.encode(LibrelioApplication.getMagazineName(context)))
            .replace(PARAM_DEVICEID, LibrelioApplication.getAndroidId(context));

    return query.append(command).toString();
}

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

/**
 * Constructs an email Intent for the given message details and opens the application choooser for this Intent
 *
 * @param recipient the recipient's email address
 * @param subject the subject of the message
 * @param body the body text as a string
 * @param captionRes the string resource ID for the application chooser's window title
 * @param restrictToPackage an optional package name that the Intent may be restricted to (or null)
 * @param context the Context instance to start the Intent from
 * @throws Exception if there was an error trying to launch the email Intent
 *//*  w  ww . j  a  v  a2s.c o  m*/
public static void sendMail(final String recipient, final String subject, final String body,
        final int captionRes, final String restrictToPackage, final Context context) throws Exception {
    final String uriString = "mailto:" + Uri.encode(recipient) + "?subject=" + Uri.encode(subject) + "&body="
            + Uri.encode(body);
    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 GetSongVoteScore(Context context, RadioRedditApplication application,
        RadioSong radiosong) {//from w w w . ja  v  a  2s  . co m
    try {
        // 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 = "";
        }
    } catch (Exception ex) {
        // We fail to get the vote information...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();
        // return error message??
        radiosong.ErrorMessage = context.getString(R.string.error_GettingVoteInformation);
        //return radiosong;
    }

    return radiosong;
}

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

public static RadioEpisode GetEpisodeVoteScore(Context context, RadioRedditApplication application,
        RadioEpisode radioepisode) {/*from w w  w .  java2 s.  c  om*/
    try {
        // 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");

            // 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");
            }

            radioepisode.Score = score;
            radioepisode.Likes = likes;
            radioepisode.Name = name;
        } else {
            radioepisode.Score = "?";
            radioepisode.Likes = "null";
            radioepisode.Name = "";
        }
    } catch (Exception ex) {
        // We fail to get the vote information...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();
        // return error message??
        radioepisode.ErrorMessage = context.getString(R.string.error_GettingVoteInformation);
        //return radiosong;
    }

    return radioepisode;
}

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

public static void Download(Context context, RadioSong song, RadioEpisode episode) {
    String downloadURL = "";
    String title = "";
    String description = "radio reddit";

    String songTitle = context.getString(R.string.app_name);
    String songArtist = "";
    String filename = "";

    if (song != null && song.Download_url != null) {
        if (song.Title != null)
            songTitle = song.Title;//ww w. j  a v  a 2 s.  c  om
        if (song.Artist != null && song.Redditor != null)
            songArtist = song.Artist + " (" + song.Redditor + ")";

        downloadURL = song.Download_url;
    } else if (episode != null && episode.Download_url != null) {
        if (episode.EpisodeTitle != null)
            songTitle = episode.EpisodeTitle;
        if (episode.ShowTitle != null)
            songArtist = episode.ShowTitle;

        downloadURL = episode.Download_url;
    }

    title = songTitle + " by " + songArtist;

    filename = songArtist + " " + songTitle + ".mp3";
    filename = filename.replace(" ", "_");

    if (!downloadURL.equals("")) {
        DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        Uri uri = Uri.parse(downloadURL);

        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        path = new File(path, "radioreddit");
        path.mkdirs();

        DownloadManager.Request request = new DownloadManager.Request(uri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        }

        request.setTitle(title).setDescription(description).setMimeType("audio/mpeg")
                .setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, "/radioreddit/" + filename);

        long lastDownload = -1L;
        lastDownload = downloadManager.enqueue(request);
    }
}

From source file:com.liferay.mobile.android.oauth.test.OAuthTest.java

public void testGetUserSites() throws Exception {
    Context context = getContext();

    String server = context.getString(R.string.oauth_server);
    String consumerKey = context.getString(R.string.oauth_consumer_key);
    String consumerSecret = context.getString(R.string.oauth_consumer_secret);

    String token = context.getString(R.string.oauth_token);
    String tokenSecret = context.getString(R.string.oauth_token_secret);

    if (Validator.isNull(server) || Validator.isNull(consumerKey) || Validator.isNull(consumerSecret)
            || Validator.isNull(token) || Validator.isNull(tokenSecret)) {

        fail("oauth.xml is not properly configured.");

        return;//from  www .j a va2  s . co  m
    }

    Authentication auth = new OAuth(consumerKey, consumerSecret, token, tokenSecret);

    Session session = new SessionImpl(server, auth);
    GroupService service = new GroupService(session);

    JSONArray sites = service.getUserSites();

    assertNotNull(sites);
    assertTrue(sites.length() > 0);
}

From source file:com.librelio.products.ui.ProductsBillingActivity.java

private static String buildUsernamePasswordLoginQuery(Context context, String username, String password,
        String fileName) {//  w w  w . j ava  2s .c om

    StringBuilder query = new StringBuilder(LibrelioApplication.getServerUrl(context));

    String command = context.getString(R.string.command_username_pswd)
            .replace(PARAM_URLSTRING, Uri.encode(LibrelioApplication.getUrlString(fileName)))
            .replace(PARAM_USERNAME, Uri.encode(username)).replace(PARAM_PASSWORD, Uri.encode(password))
            .replace(PARAM_CLIENT, Uri.encode(LibrelioApplication.getClientName(context)))
            .replace(PARAM_APP, Uri.encode(LibrelioApplication.getMagazineName(context)))
            .replace(PARAM_SERVICE, Uri.encode(LibrelioApplication.getServiceName(context)))
            .replace(PARAM_DEVICEID, LibrelioApplication.getAndroidId(context));

    return query.append(command).toString();
}

From source file:fr.cph.chicago.connection.GStreetViewConnect.java

/**
 * Private constructor, that get the API key from property file
 *//*from www .java2s  . c  om*/
private GStreetViewConnect(@NonNull final Context context) {
    googleKey = context.getString(R.string.google_maps_api_key);
}

From source file:at.wada811.utils.CameraUtils.java

/**
 * ????????/*  www .  j  ava  2 s  .co m*/
 * 
 * @param context
 * @param camera
 * @return scaledPreviewSize
 */
public static Size getScaledPreviewSize(Context context, Camera camera) {
    Size previewSize = camera.getParameters().getPreviewSize();
    boolean isPortrait = DisplayUtils.isPortrait(context);
    final int displayWidth = DisplayUtils.getWidth(context);
    final int displayHeight = DisplayUtils.getHeight(context);
    if (DEBUG) {
        LogUtils.v("displayWidth: " + displayWidth);
    }
    if (DEBUG) {
        LogUtils.v("displayHeight: " + displayHeight);
    }
    PreferenceUtils.putInt(context, context.getString(R.string.keyDisplayWidth), displayWidth);
    PreferenceUtils.putInt(context, context.getString(R.string.keyDisplayHeight), displayHeight);
    final int previewWidth = isPortrait ? previewSize.height : previewSize.width;
    final int previewHeight = isPortrait ? previewSize.width : previewSize.height;
    if (DEBUG) {
        LogUtils.v("previewWidth: " + previewWidth);
    }
    if (DEBUG) {
        LogUtils.v("previewHeight: " + previewHeight);
    }
    PreferenceUtils.putInt(context, context.getString(R.string.keyPreviewWidth), previewWidth);
    PreferenceUtils.putInt(context, context.getString(R.string.keyPreviewHeight), previewHeight);
    double displayRatio = displayHeight > displayWidth ? (double) displayHeight / displayWidth
            : (double) displayWidth / displayHeight;
    double previewRatio = previewHeight > previewWidth ? (double) previewHeight / previewWidth
            : (double) previewWidth / previewHeight;
    if (DEBUG) {
        LogUtils.v("displayRatio: " + displayRatio);
    }
    if (DEBUG) {
        LogUtils.v("previewRatio: " + previewRatio);
    }
    PreferenceUtils.putFloat(context, context.getString(R.string.keyDisplayRatio), (float) displayRatio);
    PreferenceUtils.putFloat(context, context.getString(R.string.keyPreviewRatio), (float) previewRatio);
    int scaledChildWidth = displayWidth;
    int scaledChildHeight = displayHeight;
    if (displayRatio <= previewRatio) {
        if (isPortrait) {
            if (DEBUG) {
                LogUtils.v("Portrait");
            }
            scaledChildWidth = (displayHeight * previewWidth) / previewHeight;
            scaledChildHeight = (scaledChildWidth * previewHeight) / previewWidth;
        } else {
            if (DEBUG) {
                LogUtils.v("Landscape");
            }
            scaledChildHeight = (displayWidth * previewHeight) / previewWidth;
            scaledChildWidth = (scaledChildHeight * previewWidth) / previewHeight;
        }
    } else {
        if (isPortrait) {
            if (DEBUG) {
                LogUtils.v("Portrait");
            }
            scaledChildHeight = (displayWidth * previewHeight) / previewWidth;
            scaledChildWidth = (scaledChildHeight * previewWidth) / previewHeight;
        } else {
            if (DEBUG) {
                LogUtils.v("Landscape");
            }
            scaledChildWidth = (displayHeight * previewWidth) / previewHeight;
            scaledChildHeight = (scaledChildWidth * previewHeight) / previewWidth;
        }
    }
    if (DEBUG) {
        LogUtils.v("scaledChildWidth: " + scaledChildWidth);
    }
    if (DEBUG) {
        LogUtils.v("scaledChildHeight: " + scaledChildHeight);
    }
    PreferenceUtils.putInt(context, context.getString(R.string.keyScaledChildWidth), scaledChildWidth);
    PreferenceUtils.putInt(context, context.getString(R.string.keyScaledChildHeight), scaledChildHeight);
    int scaledWidth = scaledChildWidth;
    int scaledHeight = scaledChildHeight;
    if (displayRatio <= previewRatio) {
        if (isPortrait) {
            if (DEBUG) {
                LogUtils.v("Portrait");
            }
            scaledHeight = (displayWidth * previewHeight) / previewWidth;
            scaledWidth = (scaledHeight * previewWidth) / previewHeight;
        } else {
            if (DEBUG) {
                LogUtils.v("Landscape");
            }
            scaledWidth = (displayHeight * previewWidth) / previewHeight;
            scaledHeight = (scaledWidth * previewHeight) / previewWidth;
        }
    } else {
        if (isPortrait) {
            if (DEBUG) {
                LogUtils.v("Portrait");
                //                scaledWidth = (displayHeight * previewWidth) / previewHeight;
                //                scaledHeight = (scaledWidth * previewHeight) / previewWidth;
            }
        } else {
            if (DEBUG) {
                LogUtils.v("Landscape");
                //                scaledHeight = (displayWidth * previewHeight) / previewWidth;
                //                scaledWidth = (scaledHeight * previewWidth) / previewHeight;
            }
        }
    }
    if (DEBUG) {
        LogUtils.v("scaledWidth: " + scaledWidth);
    }
    if (DEBUG) {
        LogUtils.v("scaledHeight: " + scaledHeight);
    }
    PreferenceUtils.putInt(context, context.getString(R.string.keyScaledWidth), scaledWidth);
    PreferenceUtils.putInt(context, context.getString(R.string.keyScaledHeight), scaledHeight);
    return camera.new Size(scaledWidth, scaledHeight);
}