Example usage for android.content.res Resources getStringArray

List of usage examples for android.content.res Resources getStringArray

Introduction

In this page you can find the example usage for android.content.res Resources getStringArray.

Prototype

@NonNull
public String[] getStringArray(@ArrayRes int id) throws NotFoundException 

Source Link

Document

Return the string array associated with a particular resource ID.

Usage

From source file:can.yrt.onebusaway.TripInfoActivity.java

static String getRepeatText(Context ctx, int days) {
    final Resources res = ctx.getResources();

    if ((days & ObaContract.Trips.DAY_ALL) == ObaContract.Trips.DAY_ALL) {
        return res.getString(R.string.trip_info_repeat_everyday);
    }//from   w w  w  . j av  a  2  s.  c  om
    if (((days & ObaContract.Trips.DAY_WEEKDAY) == ObaContract.Trips.DAY_WEEKDAY)
            && (days & ~ObaContract.Trips.DAY_WEEKDAY) == 0) {
        return res.getString(R.string.trip_info_repeat_weekdays);
    }
    if (days == 0) {
        return res.getString(R.string.trip_info_repeat_norepeat);
    }
    // Otherwise, it's not normal -- format a string
    final boolean[] array = ObaContract.Trips.daysToArray(days);
    final String[] dayNames = res.getStringArray(R.array.reminder_days);

    StringBuffer buf = new StringBuffer();

    // Find the first day
    int rangeStart = 0;
    while (rangeStart < 7) {
        for (; rangeStart < 7 && array[rangeStart] != true; ++rangeStart) {
        }

        if (rangeStart == 7) {
            break;
        }

        int rangeEnd = rangeStart + 1;
        for (; rangeEnd < 7 && array[rangeEnd] == true; ++rangeEnd) {
        }

        if (buf.length() != 0) {
            // TODO: Move to string table
            buf.append(", ");
        }

        // Single day?
        if ((rangeEnd - rangeStart) == 1) {
            buf.append(dayNames[rangeStart]);
        } else {
            buf.append(dayNames[rangeStart]);
            // TODO: Move to string table
            buf.append(" - ");
            buf.append(dayNames[rangeEnd - 1]);
        }
        rangeStart = rangeEnd;
    }

    return res.getString(R.string.trip_info_repeat_every, buf.toString());
}

From source file:com.mikecorrigan.trainscorekeeper.Players.java

@SuppressLint("NewApi")
public Players(final Activity context, ViewGroup viewGroup, final JSONArray jsonPlayers) {
    Log.vc(VERBOSE, TAG,//from  w w  w.  j  a v a  2s  .  c  o  m
            "ctor: context=" + context + ", viewGroup=" + viewGroup + ", jsonPlayers=" + jsonPlayers);

    viewGroup.removeAllViews();

    Resources resources = context.getResources();

    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray colorIdsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] colorIds = new int[colorIdsArray.length()];
    for (int i = 0; i < colorIdsArray.length(); i++) {
        colorIds[i] = colorIdsArray.getResourceId(i, -1);
    }

    listeners = new HashSet<Listener>();
    players = new SparseArray<Player>();

    for (int i = 0; i < playerNames.length; i++) {
        PlayerButton toggleButton = new PlayerButton(context);
        toggleButton.setPlayerId(i);
        LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, 1f);
        toggleButton.setLayoutParams(layoutParams);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setTextColor(resources.getColor(colorIds[i]));
        toggleButton.setOnClickListener(onSelect);

        viewGroup.addView(toggleButton);

        final String name = playerNames[i];

        boolean enabled = true;

        // If the players configuration is available, determine which players are enabled.
        if (jsonPlayers != null) {
            enabled = false;
            for (int j = 0; j < jsonPlayers.length(); j++) {
                String jsonName = jsonPlayers.optString(j, "");
                if (jsonName.equalsIgnoreCase(name)) {
                    enabled = true;
                    break;
                }
            }
        }

        Player player = new Player(toggleButton, i, name, enabled);
        players.put(i, player);
    }

    setSelection(-1);

    drawablesArray.recycle();
    colorIdsArray.recycle();
}

From source file:com.crystal.CrystalBeanWallpapers.Wallpaper.java

private void fetchWallpapers(Resources resources, String packageName, int list) {
    final String[] extras = resources.getStringArray(list);
    for (String extra : extras) {
        int res = resources.getIdentifier(extra, "drawable", packageName);
        if (res != 0) {
            mWallpapers.add(res);//from  w w  w. j  a  va  2s .co  m
        }
    }
}

From source file:com.csipsimple.plugins.betamax.CallHandlerWeb.java

@Override
public void onReceive(Context context, Intent intent) {
    if (Utils.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {

        PendingIntent pendingIntent = null;
        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, "");
        String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, "");

        // We must handle that clean way cause when call just to
        // get the row in account list expect this to reply correctly
        if (!TextUtils.isEmpty(number) && !TextUtils.isEmpty(user) && !TextUtils.isEmpty(nbr)
                && !TextUtils.isEmpty(pwd) && !TextUtils.isEmpty(provider)) {
            // Build pending intent
            Intent i = new Intent(ACTION_DO_WEB_CALL);
            i.setClass(context, getClass());
            i.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
            pendingIntent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

        }//from   ww w .j a  v a  2s .c om

        // Build icon
        Bitmap bmp = Utils.getBitmapFromResource(context, R.drawable.icon_web);

        // Build the result for the row (label, icon, pending intent, and
        // excluded phone number)
        Bundle results = getResultExtras(true);
        if (pendingIntent != null) {
            results.putParcelable(Utils.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        }

        // Text for the row
        String providerName = "";
        Resources r = context.getResources();
        if (!TextUtils.isEmpty(provider)) {
            String[] arr = r.getStringArray(R.array.provider_values);
            String[] arrEntries = r.getStringArray(R.array.provider_entries);
            int i = 0;
            for (String prov : arr) {
                if (prov.equalsIgnoreCase(provider)) {
                    providerName = arrEntries[i];
                    break;
                }
                i++;
            }
        }
        results.putString(Intent.EXTRA_TITLE, providerName + " " + r.getString(R.string.web_callback));
        Log.d(THIS_FILE, "icon is " + bmp);
        if (bmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, bmp);
        }

        // DO *NOT* exclude from next tel: intent cause we use a http method
        // results.putString(Intent.EXTRA_PHONE_NUMBER, number);

    } else if (ACTION_DO_WEB_CALL.equals(intent.getAction())) {

        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, "");
        String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, "");

        // params
        List<NameValuePair> params = new LinkedList<NameValuePair>();
        params.add(new BasicNameValuePair("username", user));
        params.add(new BasicNameValuePair("password", pwd));
        params.add(new BasicNameValuePair("from", nbr));
        params.add(new BasicNameValuePair("to", number));
        String paramString = URLEncodedUtils.format(params, "utf-8");

        String requestURL = "https://www." + provider + "/myaccount/makecall.php?" + paramString;

        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(requestURL);

        // Create a response handler
        HttpResponse httpResponse;
        try {
            httpResponse = httpClient.execute(httpGet);
            Log.d(THIS_FILE, "response code is " + httpResponse.getStatusLine().getStatusCode());
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                InputStreamReader isr = new InputStreamReader(httpResponse.getEntity().getContent());
                BufferedReader br = new BufferedReader(isr);

                String line;
                String fullReply = "";
                boolean foundSuccess = false;
                while ((line = br.readLine()) != null) {
                    if (!TextUtils.isEmpty(line) && line.toLowerCase().contains("success")) {
                        showToaster(context, "Success... wait a while you'll called back");
                        foundSuccess = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(line)) {
                        fullReply = fullReply.concat(line);
                    }
                }
                if (!foundSuccess) {
                    showToaster(context, "Error : server error : " + fullReply);
                }
            } else {
                showToaster(context, "Error : invalid request " + httpResponse.getStatusLine().getStatusCode());
            }
        } catch (ClientProtocolException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        } catch (IOException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        }

    }
}

From source file:com.blockhead.gussilva.threemorewords.GameActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);

    Resources res = getResources();

    //Get array of words to draw from
    words = res.getStringArray(R.array.technologyeasy);

    rand = new Random();

    currWord1 = "";
    currWord2 = "";
    currWord3 = "";

    chancesLeftView = (TextView) findViewById(R.id.chancesText);
    wordLayout1 = (LinearLayout) findViewById(R.id.word1);
    wordLayout2 = (LinearLayout) findViewById(R.id.word2);
    wordLayout3 = (LinearLayout) findViewById(R.id.word3);

    letters = (GridView) findViewById(R.id.letters);

    mActionBar = getActionBar();/* w w w .ja  v a 2 s.  co m*/
    if (mActionBar != null)
        getActionBar().setDisplayHomeAsUpEnabled(true);

    playGame();
}

From source file:com.heneryh.aquanotes.ui.controllers.OutletsDataAdapter.java

public OutletsDataAdapter(Activity activity) {
    super(activity, null);
    mActivity = activity;/*from   w  w w.j  av  a  2s .co  m*/
    mHasAllItem = false;
    mPositionDisplacement = 0;
    Resources res = mActivity.getResources();
    outletStates = res.getStringArray(R.array.outlet_spinner);
    adapter = new ArrayAdapter<String>(mActivity, android.R.layout.simple_spinner_item, outletStates);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}

From source file:de.hackerspacebremen.fragments.StatusFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Resources res = getResources();
    SpeakingDateFormat.setFormatAds(res.getStringArray(R.array.format_ads));
    SpeakingDateFormat.setWeekdayAds(res.getStringArray(R.array.weekday_ads));
    return inflater.inflate(R.layout.status_fragment, container, false);
}

From source file:org.openoverlayrouter.noroot.noroot_OOR.java

public void updateStatus() {
    final TextView oorCheckBoxLabel = (TextView) llLayout.findViewById(R.id.startStopCheckboxLabel);
    final TextView oorTextClick = (TextView) llLayout.findViewById(R.id.textClick);

    oorRunning = vpn.vpn_running;/*from w w w .j  a va2s  .  com*/

    if (vpn.vpn_running) {
        oorTextClick.setText("Click on the icon to stop the service");
        oorCheckBoxLabel.setText(R.string.oorRunning);
        oorCheckBoxLabel.setTextColor(Color.BLACK);
        oorWasRunning = true;
    } else if (oorWasRunning) {
        oorTextClick.setText("Click on the icon to restart the service");
        oorCheckBoxLabel.setText("OOR has exited");
        oorCheckBoxLabel.setTextColor(Color.RED);
    } else {
        oorTextClick.setText("Click on the icon to start the service");
        oorCheckBoxLabel.setText(R.string.oorNotRunning);
        oorCheckBoxLabel.setTextColor(Color.BLACK);
    }

    if (!err_msg_detected && noroot_OORVPNService.err_msg_code != 0) {
        err_msg_detected = true;
        Resources res = getResources();
        String[] err_msg = res.getStringArray(R.array.ErrMsgArray);
        showMessage(err_msg[noroot_OORVPNService.err_msg_code], false, new Runnable() {
            public void run() {
                noroot_OORVPNService.err_msg_code = 0;
                err_msg_detected = false;
            }
        });
    }

}

From source file:com.vuze.android.remote.AndroidUtils.java

public static ValueStringArray getValueStringArray(Resources resources, int id) {
    String[] stringArray = resources.getStringArray(id);
    String[] strings = new String[stringArray.length];
    long[] values = new long[stringArray.length];

    for (int i = 0; i < stringArray.length; i++) {
        String[] s = stringArray[i].split(",");
        values[i] = Integer.parseInt(s[0]);
        strings[i] = s[1];//from w  ww  .jav a 2  s  .  c om
    }
    return new ValueStringArray(values, strings);
}

From source file:com.sean.takeastand.ui.ScheduleListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Resources resources = getResources();
    if (item.getItemId() == R.id.help) {
        new AlertDialog.Builder(this).setTitle(resources.getStringArray(R.array.ActivityTitle)[ACTIVITY_NUMBER])
                .setMessage(resources.getStringArray(R.array.ActivityHelpText)[ACTIVITY_NUMBER])
                .setPositiveButton(getString(R.string.ok), null).show();
    } else {/* ww w  .j av a 2s  . c om*/
        //Closes Activity when user presses title
        finish();
    }
    return super.onOptionsItemSelected(item);
}