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:me.xiaopan.android.gohttp.requestobject.RequestParser.java

/**
 * ?True//from w w w  .ja va2 s.co  m
 * @param context 
 * @param field ?
 */
public static String parseTrueAnnotation(Context context, Field field) {
    True annotation = field.getAnnotation(True.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

/**
 * ?False//from  ww  w. j a v  a  2 s  .  c o  m
 * @param context 
 * @param field ?
 */
public static String parseFalseAnnotation(Context context, Field field) {
    False annotation = field.getAnnotation(False.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

/**
 * ????/*from  ww w . j  ava2  s . c o m*/
 * @param context 
 * @param field 
 */
public static String parseParamAnnotation(Context context, Field field) {
    Param annotation = field.getAnnotation(Param.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

/**
 * ??/*from   ww  w .  ja  va 2 s  .c o  m*/
 * @param context 
 * @param field 
 */
public static String parseValueAnnotation(Context context, Field field) {
    Value annotation = field.getAnnotation(Value.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:net.mandaria.radioreddit.apis.RadioRedditAPI.java

public static List<RadioSong> GetTopChartsByType(Context context, RadioRedditApplication application,
        String type) {/*w ww  .ja  va 2 s .  co  m*/
    List<RadioSong> radiosongs = new ArrayList<RadioSong>();

    try {
        String chart_url = "";

        if (type.equals("all"))
            chart_url = context.getString(R.string.radio_reddit_charts_all);
        else if (type.equals("month"))
            chart_url = context.getString(R.string.radio_reddit_charts_month);
        else if (type.equals("week"))
            chart_url = context.getString(R.string.radio_reddit_charts_week);
        else if (type.equals("day"))
            chart_url = context.getString(R.string.radio_reddit_charts_day);

        // TODO: might could merge this code with GetCurrentSongInformation

        String outputStatus = "";
        boolean errorGettingStatus = false;

        try {
            outputStatus = HTTPUtil.get(context, chart_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);

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

            // get the first song in the array
            for (int i = 0; i < songs_array.length(); i++) {
                RadioSong radiosong = new RadioSong();
                radiosong.ErrorMessage = "";

                JSONObject song = songs_array.getJSONObject(i);
                //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");

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

        ex.printStackTrace();
        // TODO: return error message?? Might need to wrap List<RadioSong> in an object that has an ErrorMessage data member
        //radiosong.ErrorMessage = ex.toString();
        //return radiosong;
    }
    return radiosongs;
}

From source file:de.ub0r.android.websms.connector.common.Utils.java

/**
 * Show update notification.//from w  w w . jav a 2  s.  c  o m
 * 
 * @param context
 *            {@link Context}
 * @param pkg
 *            package
 */
public static void showUpdateNotification(final Context context, final String pkg) {
    Notification n = new Notification(android.R.drawable.stat_sys_warning,
            context.getString(R.string.update_title), 0);
    n.flags = Notification.FLAG_AUTO_CANCEL;
    PendingIntent pi = PendingIntent.getActivity(context, 0,
            new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkg)),
            PendingIntent.FLAG_UPDATE_CURRENT);
    n.setLatestEventInfo(context, context.getString(R.string.update_title),
            context.getString(R.string.update_message), pi);

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(0, n);
}

From source file:de.ub0r.android.websms.connector.custom.ConnectorCustom.java

@Override
public ConnectorSpec initSpec(final Context context) {
    String name = context.getString(R.string.connector_name);
    ConnectorSpec c = new ConnectorSpec(name);
    c.setAuthor(context.getString(R.string.connector_author));
    c.setBalance(null);/*ww  w  . j  a v a  2  s  .c  o  m*/
    c.setCapabilities(ConnectorSpec.CAPABILITIES_UPDATE | ConnectorSpec.CAPABILITIES_SEND
            | ConnectorSpec.CAPABILITIES_PREFS);
    c.addSubConnector(SUBCONN0, SUBCONN0, 0);

    return c;
}

From source file:com.application.food.zxing.client.android.result.supplement.BookResultInfoRetriever.java

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

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

public static RadioStreams GetStreams(Context context, RadioRedditApplication application) {
    RadioStreams radiostreams = new RadioStreams();
    radiostreams.ErrorMessage = "";
    radiostreams.RadioStreams = new ArrayList<RadioStream>();

    try {//  w w w .j  a  v a2 s.  c o m
        String url = context.getString(R.string.radio_reddit_streams);
        String outputStreams = "";
        boolean errorGettingStreams = false;

        try {
            outputStreams = HTTPUtil.get(context, url);
        } catch (Exception ex) {
            errorGettingStreams = true;
            radiostreams.ErrorMessage = context.getString(R.string.error_RadioRedditServerIsDownNotification);
            application.radioRedditIsDownErrorMessage = radiostreams.ErrorMessage;
            application.isRadioRedditDown = true;
        }

        if (!errorGettingStreams && outputStreams.length() > 0) {
            JSONTokener tokener = new JSONTokener(outputStreams);
            JSONObject json = new JSONObject(tokener);

            JSONObject streams = json.getJSONObject("streams");
            JSONArray streams_names = streams.names();
            ArrayList<RadioStream> list_radiostreams = new ArrayList<RadioStream>();

            // loop through each stream
            for (int i = 0; i < streams.length(); i++) {
                String name = streams_names.getString(i);
                JSONObject stream = streams.getJSONObject(name);

                RadioStream radiostream = new RadioStream();
                radiostream.Name = name;
                // if(stream.has("type"))
                radiostream.Type = stream.getString("type");
                radiostream.Description = stream.getString("description");
                radiostream.Status = stream.getString("status");

                // call status.json to get Relay
                // form url radioreddit.com + status + json
                String status_url = context.getString(R.string.radio_reddit_base_url) + radiostream.Status
                        + context.getString(R.string.radio_reddit_status);

                String outputStatus = "";
                boolean errorGettingStatus = false;

                try {
                    outputStatus = HTTPUtil.get(context, status_url);
                } catch (Exception ex) {
                    errorGettingStatus = true;
                    radiostreams.ErrorMessage = context
                            .getString(R.string.error_RadioRedditServerIsDownNotification);
                }

                //Log.e("RadioReddit", "Length of output: "+ outputStatus.length() + "; Content of output: " + outputStatus);
                // TODO: does  outputStatus.length() > 0 need to be checked here and return a ErrorMessage back and set ErrorGettingStatus = true? 

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

                    radiostream.Online = Boolean.parseBoolean(status_json.getString("online").toLowerCase());

                    if (radiostream.Online == true) // if offline, no other nodes are available
                    {
                        radiostream.Relay = status_json.getString("relay");

                        list_radiostreams.add(radiostream);
                    }
                }
            }

            // JSON parsing reverses the list for some reason, fixing it...
            if (list_radiostreams.size() > 0) {
                // Sorting will happen later on select station activity
                //Collections.reverse(list_radiostreams);

                radiostreams.RadioStreams = list_radiostreams;
                application.isRadioRedditDown = false;
            } else {
                radiostreams.ErrorMessage = context.getString(R.string.error_NoStreams);
                application.radioRedditIsDownErrorMessage = radiostreams.ErrorMessage;
                application.isRadioRedditDown = true;
            }
        }
    } catch (Exception ex) {
        // We fail to get the streams...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        radiostreams.ErrorMessage = ex.toString();
        ex.printStackTrace();
    }

    return radiostreams;
}

From source file:de.dan_nrw.android.scroid.dao.wallpapers.WallpaperDAO.java

public Wallpaper[] getAvailableWallpapers(Context context) throws WallpaperListReceivingException {
    try {//w  w w  .j av a2 s .c  o m
        String data = this.download(URI.create(context.getString(R.string.galleryUrl)),
                new TextFileHttpResponseHandler(), MAX_DOWNLOAD_RETRIES);

        List<Wallpaper> wallpapers = this.wallpaperParser.parse(data);

        return wallpapers.toArray(new Wallpaper[wallpapers.size()]);
    } catch (IllegalStateException ex) {
        throw new WallpaperListReceivingException(context.getString(R.string.receivingException), ex);
    } catch (IOException ex) {
        throw new WallpaperListReceivingException(context.getString(R.string.receivingException), ex);
    } catch (ParseException ex) {
        throw new WallpaperListReceivingException(context.getString(R.string.parseExceptionText), ex);
    }
}