List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:org.jboss.aerogear.android.cookbook.agreddit.authentication.RedditAuthenticationModule.java
public RedditAuthenticationModule(Context context) { try {//w ww . j av a2s .c o m baseURL = new URL(context.getString(R.string.reddit_base) + "api"); loginURL = new URL(baseURL.toString() + "/login"); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static String VoteOnSong(Context context, RadioRedditApplication application, RadioSong song, boolean liked, String iden, String captcha) { String errorMessage = ""; RedditAccount account = Settings.getRedditAccount(context); if (account == null) { errorMessage = context.getString(R.string.error_YouMustBeLoggedInToVote); return errorMessage; }/*from w w w . j ava 2 s . co m*/ int voteDirection = 0; // TODO: handle case to rescind vote if (liked == true) voteDirection = 1; else voteDirection = -1; // 1. Get most up to date song information (in case cached info is old) // TODO: need to get updated information specific song // e.g. if this is a recently played song it was not submitted // then we must check and see if someone has submitted it since we have tried to vote on it // for top of charts, this isn't necessary as everything has already been submitted. Will re-visit this later // Actually: we need to request an API to search for a song to get updated info on it // TODO: create a GetVoteInfo function that gets reddit vote info on song to determine if already submitted or not // pull GetVoteInfo out of GetCurrentSongInformation //song = RadioRedditAPI.GetCurrentSongInformation(context, application); if (song == null) return context.getString(R.string.error_ThereWasAProblemVotingPleaseTryAgain); if (!song.ErrorMessage.equals("")) return song.ErrorMessage; // 2a. If it exist: // a. Get the FULLNAME from reddit and vote on it: http://www.reddit.com/api/vote // 2b. If it exists, but is archived // a. Submit as a new post to be voted on? Or simply say that the song has been archived and cannot be voted on? // b. BUG: apparently the API allows votes on archived posts. This needs to be discussed with reddit admins or similar // TODO: return to user that it must be submitted? e.g. they must accept to submit, so pull the submit into its own function? // 3. If it doesn't exist: // a. Try to submit the post http://www.reddit.com/api/submit: // b. If it fails, display error (or CAPTCHA) and try again //String title = "Song Title by Song Artist (redditor)"; if (!song.Name.equals("")) { errorMessage = RedditAPI.Vote(context, account, voteDirection, song.Name); } else // not yet submitted { String title = song.Title + " by " + song.Artist + " (" + song.Redditor + ")"; // future note: do not pull "by" into strings.xml, this is used for submission on r/radioreddit String url = song.Reddit_url; String subreddit = "radioreddit"; errorMessage = RedditAPI.SubmitLink(context, account, title, url, subreddit, iden, captcha); // TODO: if submiting while voting down, vote down after it is submitted? //return context.getString(R.string.error_ThereWasAProblemPleaseTryAgain); } // 4. After voting/submiting, get the most up to date version of the episode/song again // TODO: Only do this if the song is currently playing? if (application.playBackType.equals("song") && song.Title.equals(application.CurrentSong.Title)) { song = RadioRedditAPI.GetSongVoteScore(context, application, song); application.CurrentSong = song; } return errorMessage; }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static String VoteOnEpisode(Context context, RadioRedditApplication application, RadioEpisode episode, boolean liked, String iden, String captcha) { String errorMessage = ""; RedditAccount account = Settings.getRedditAccount(context); if (account == null) { errorMessage = context.getString(R.string.error_YouMustBeLoggedInToVote); return errorMessage; }/*from w w w . j a va2 s. c o m*/ int voteDirection = 0; // TODO: handle case to rescind vote if (liked == true) voteDirection = 1; else voteDirection = -1; // 1. Get most up to date song information (in case cached info is old) // TODO: need to get updated information specific song // e.g. if this is a recently played song it was not submitted // then we must check and see if someone has submitted it since we have tried to vote on it // for top of charts, this isn't necessary as everything has already been submitted. Will re-visit this later // Actually: we need to request an API to search for a song to get updated info on it // TODO: create a GetVoteInfo function that gets reddit vote info on song to determine if already submitted or not // pull GetVoteInfo out of GetCurrentSongInformation //song = RadioRedditAPI.GetCurrentSongInformation(context, application); if (episode == null) return context.getString(R.string.error_ThereWasAProblemVotingPleaseTryAgain); if (!episode.ErrorMessage.equals("")) return episode.ErrorMessage; // 2a. If it exist: // a. Get the FULLNAME from reddit and vote on it: http://www.reddit.com/api/vote // 2b. If it exists, but is archived // a. Submit as a new post to be voted on? Or simply say that the song has been archived and cannot be voted on? // b. BUG: apparently the API allows votes on archived posts. This needs to be discussed with reddit admins or similar // TODO: return to user that it must be submitted? e.g. they must accept to submit, so pull the submit into its own function? // 3. If it doesn't exist: // a. Try to submit the post http://www.reddit.com/api/submit: // b. If it fails, display error (or CAPTCHA) and try again //String title = "Song Title by Song Artist (redditor)"; if (!episode.Name.equals("")) { errorMessage = RedditAPI.Vote(context, account, voteDirection, episode.Name); } else // not yet submitted { String title = episode.ShowTitle + ": " + episode.EpisodeTitle; // future note: do not pull into strings.xml, this is used for submission on r/talkradioreddit String url = episode.Reddit_url; String subreddit = "talkradioreddit"; errorMessage = RedditAPI.SubmitLink(context, account, title, url, subreddit, iden, captcha); // TODO: if submiting while voting down, vote down after it is submitted? //return context.getString(R.string.error_ThereWasAProblemPleaseTryAgain); } // 4. After voting/submiting, get the most up to date version of the episode/song again // TODO: Only do this if the song is currently playing? if (application.playBackType.equals("episode") && episode.EpisodeTitle.equals(application.CurrentEpisode.EpisodeTitle)) { episode = RadioRedditAPI.GetEpisodeVoteScore(context, application, episode); application.CurrentEpisode = episode; } return errorMessage; }
From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one if the * fake account doesn't exist yet.//from ww w . j a va 2 s. c om * * @param context * The context used to access the account service * @return a fake account. */ public static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { // Add the account and account type, no password or user data // If successful, return the Account object, otherwise report an error. if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } // If you don't set android:syncable="true" in your <provider> element in the manifest, // then call context.setIsSyncable(account, AUTHORITY, 1) here. onAccountCreated(newAccount, context); } return newAccount; }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static String VoteOnCurrentlyPlaying(Context context, RadioRedditApplication application, boolean liked, String iden, String captcha) { String errorMessage = ""; RedditAccount account = Settings.getRedditAccount(context); if (account == null) { errorMessage = context.getString(R.string.error_YouMustBeLoggedInToVote); return errorMessage; }/*w w w .jav a 2s . c om*/ int voteDirection = 0; // TODO: handle case to rescind vote if (liked == true) voteDirection = 1; else voteDirection = -1; RadioSong song = null; RadioEpisode episode = null; // 1. Get most up to date song information (in case cached info is old) if (application.CurrentStream.Type.equals("music")) { song = RadioRedditAPI.GetCurrentSongInformation(context, application); if (song == null) return context.getString(R.string.error_ThereWasAProblemVotingPleaseTryAgain); if (!song.ErrorMessage.equals("")) return song.ErrorMessage; } else if (application.CurrentStream.Type.equals("talk")) { episode = RadioRedditAPI.GetCurrentEpisodeInformation(context, application); if (episode == null) return context.getString(R.string.error_ThereWasAProblemVotingPleaseTryAgain); if (!episode.ErrorMessage.equals("")) return episode.ErrorMessage; } // 2a. If it exist: // a. Get the FULLNAME from reddit and vote on it: http://www.reddit.com/api/vote // 2b. If it exists, but is archived // a. Submit as a new post to be voted on? Or simply say that the song has been archived and cannot be voted on? // b. BUG: apparently the API allows votes on archived posts. This needs to be discussed with reddit admins or similar // TODO: return to user that it must be submitted? e.g. they must accept to submit, so pull the submit into its own function? // 3. If it doesn't exist: // a. Try to submit the post http://www.reddit.com/api/submit: // b. If it fails, display error (or CAPTCHA) and try again //String title = "Song Title by Song Artist (redditor)"; // TODO: I don't really like the if else going on here due to currentsong vs currentepisode if (application.CurrentStream.Type.equals("music")) { if (!song.Name.equals("")) { errorMessage = RedditAPI.Vote(context, account, voteDirection, song.Name); } else // not yet submitted { String title = song.Title + " by " + song.Artist + " (" + song.Redditor + ")"; // future note: do not pull "by" into strings.xml, this is used for submission on r/radioreddit String url = song.Reddit_url; String subreddit = "radioreddit"; errorMessage = RedditAPI.SubmitLink(context, account, title, url, subreddit, iden, captcha); // TODO: if submiting while voting down, vote down after it is submitted? //return context.getString(R.string.error_ThereWasAProblemPleaseTryAgain); } // 4. After voting/submiting, get the most up to date version of the episode/song again song = RadioRedditAPI.GetCurrentSongInformation(context, application); if (song != null && song.ErrorMessage.equals("")) { application.CurrentSong = song; } } else if (application.CurrentStream.Type.equals("talk")) { if (!episode.Name.equals("")) { errorMessage = RedditAPI.Vote(context, account, voteDirection, episode.Name); } else // not yet submitted { String title = episode.ShowTitle + ": " + episode.EpisodeTitle; String url = episode.Reddit_url; String subreddit = "talkradioreddit"; errorMessage = RedditAPI.SubmitLink(context, account, title, url, subreddit, iden, captcha); // TODO: if submiting while voting down, vote down after it is submitted? //return context.getString(R.string.error_ThereWasAProblemVotingPleaseTryAgain); } // 4. After voting/submiting, get the most up to date version of the episode/song again episode = RadioRedditAPI.GetCurrentEpisodeInformation(context, application); if (episode != null && episode.ErrorMessage.equals("")) { application.CurrentEpisode = episode; } } return errorMessage; }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ?URL//from ww w . j a v a 2 s.c om * @param context * @param requestClass */ public static String parseURLAnnotation(Context context, Class<? extends Request> requestClass) { URL annotation = requestClass.getAnnotation(URL.class); if (annotation == null) { return null; } String annotationValue = annotation.value(); if (annotationValue != null && !"".equals(annotationValue)) { return annotationValue; } else if (context != null && annotation.resId() > 0) { return context.getString(annotation.resId()); } else { return null; } }
From source file:de.ub0r.android.websms.connector.sipgate.ConnectorSipgate.java
/** * {@inheritDoc}//from w w w . j a va2s. c om */ @Override public final ConnectorSpec initSpec(final Context context) { final String name = context.getString(R.string.connector_sipgate_name); ConnectorSpec c = new ConnectorSpec(name); c.setAuthor(// . context.getString(R.string.connector_sipgate_author)); c.setBalance(null); c.setCapabilities(ConnectorSpec.CAPABILITIES_UPDATE | ConnectorSpec.CAPABILITIES_SEND | ConnectorSpec.CAPABILITIES_PREFS); c.addSubConnector("sipgate", c.getName(), SubConnectorSpec.FEATURE_MULTIRECIPIENTS); return c; }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ??/*from ww w .ja v a 2 s .co m*/ * @param context * @param requestClass */ public static String parseHostAnnotation(Context context, Class<? extends Request> requestClass) { Host annotation = requestClass.getAnnotation(Host.class); if (annotation == null) { return null; } String annotationValue = annotation.value(); if (annotationValue != null && !"".equals(annotationValue)) { return annotationValue; } else if (context != null && annotation.resId() > 0) { return context.getString(annotation.resId()); } else { return null; } }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ???//www . ja v a 2 s . c o m * @param context * @param requestClass */ public static String parseNameAnnotation(Context context, Class<? extends Request> requestClass) { Name annotation = requestClass.getAnnotation(Name.class); if (annotation == null) { return null; } String annotationValue = annotation.value(); if (annotationValue != null && !"".equals(annotationValue)) { return annotationValue; } else if (context != null && annotation.resId() > 0) { return context.getString(annotation.resId()); } else { return null; } }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ?/*www.j av a 2s .co m*/ * @param context * @param requestClass */ public static String parsePathAnnotation(Context context, Class<? extends Request> requestClass) { Path annotation = requestClass.getAnnotation(Path.class); if (annotation == null) { return null; } String annotationValue = annotation.value(); if (annotationValue != null && !"".equals(annotationValue)) { return annotationValue; } else if (context != null && annotation.resId() > 0) { return context.getString(annotation.resId()); } else { return null; } }