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:com.glandorf1.joe.wsprnetviewer.app.sync.WsprNetViewerSyncAdapter.java

/**
 * Returns name of frequency band, or "" if not within a valid frequency band.
 * @param context//from  w ww  .  java  2 s.com
 * @param idx - pass in 'mBandNameIdx', as set by getFrequencyBandCheck()
 * @return Returns name of frequency band, or "" if not within a valid frequency band.
 */
public String getFrequencyBandName(Context context, int idx) {
    if ((mBandNameStr == null) || (mBandNameStr.length <= 0)) {
        Resources res = context.getResources();
        mBandNameStr = res.getStringArray(R.array.pref_notify_band_options);
    }
    if ((idx >= 0) && (idx < mBandNameStr.length)) {
        return mBandNameStr[idx];
    } else {
        return "";
    }
}

From source file:com.glandorf1.joe.wsprnetviewer.app.sync.WsprNetViewerSyncAdapter.java

/**
 * Determines if a frequency is in one of the bands in R.array.pref_notify_band_values.
 * Checks if it is also in the notification band-- if it is, then set mBandNameIdx.
 * @param context//from  www .  j a  v  a  2  s .c o  m
 * @param freqMhz - a frequency in MHz as returned by a specific WSPR report
 * @param tolerancePercent - freqMhz is in the band if within +/-tolerance of the band's center frequency
 * @return Returns -1 if not within a valid frequency band; also sets mBandNameIdx.
 */
public double getFrequencyBandCheck(Context context, double freqMhz, double tolerancePercent) {
    double band = -1;
    if ((mBandFrequencyStr == null) || (mBandFrequencyStr.length <= 0)) {
        Resources res = context.getResources();
        mBandFrequencyStr = res.getStringArray(R.array.pref_notify_band_values);
    }
    if ((mBandFrequencyStr != null) && mBandFrequencyStr.length > 0) {
        if ((mBandFrequency == null) || (mBandFrequency.length <= 0)) {
            mBandFrequency = new Double[mBandFrequencyStr.length];
            mBandFrequencyMin = new Double[mBandFrequencyStr.length];
            mBandFrequencyMax = new Double[mBandFrequencyStr.length];
            if ((tolerancePercent < 1.) || (tolerancePercent > 20.)) {
                tolerancePercent = 5.;
            }
            for (int i = 0; i < mBandFrequencyStr.length; i++) {
                mBandFrequency[i] = Double.parseDouble(mBandFrequencyStr[i]);
                mBandFrequencyMin[i] = mBandFrequency[i] - (mBandFrequency[i] * (tolerancePercent / 100.));
                mBandFrequencyMax[i] = mBandFrequency[i] + (mBandFrequency[i] * (tolerancePercent / 100.));
            }
        }
        if ((mBandFrequency != null) && (mBandFrequency.length > 0)) {
            for (int i = 0; i < mBandFrequency.length; i++) {
                if ((mBandFrequencyMin[i] <= freqMhz) && (freqMhz <= mBandFrequencyMax[i])) {
                    band = mBandFrequency[i];
                    break;
                }
            }
        }
    }
    return band;
}

From source file:com.sanbo.moveonapp.TabsActivity.java

private void menuLanguage() {
    ArrayList<ImageLanguage> myLang = new ArrayList<ImageLanguage>();
    ImageLanguage newLang;/* w w w. j a v  a 2  s.c  o m*/
    showLang = true;

    //Accedemos al objeto 'Recursos' desde la Activity
    Resources res = this.getResources();
    String[] myCode = res.getStringArray(R.array.language_code);
    String[] myNom = res.getStringArray(R.array.language_options);
    for (int i = 0; i <= myCode.length - 1; i++) {
        int myImage = context.getResources().getIdentifier(myCode[i], "drawable", context.getPackageName());
        newLang = new ImageLanguage(myImage, myCode[i], myNom[i]);
        myLang.add(newLang);
    }
    ListViewAdapterLanguage adapter;
    adapter = new ListViewAdapterLanguage(this, myLang);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.selectlang);
    builder.setAdapter(adapter, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            // When clicked, show a toast with the TextView text
            changeLang(TypeLanguage.values()[which]);

            //saveLocale(which);
            dialog.dismiss();
            showLang = false;
        }
    });

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.android.calendar.event.EditEventView.java

/**
 * Loads a String array asset into a list.
 *///from w  w w .  j av  a  2s .c  om
private static ArrayList<String> loadStringArray(Resources r, int resNum) {
    String[] labels = r.getStringArray(resNum);
    ArrayList<String> list = new ArrayList<String>(Arrays.asList(labels));
    return list;
}

From source file:com.android.messaging.datamodel.media.VCardResourceEntry.java

private static List<VCardResourceEntryDestinationItem> getContactInfoFromVCardEntry(final VCardEntry vcard) {
    final Resources resources = Factory.get().getApplicationContext().getResources();
    final List<VCardResourceEntry.VCardResourceEntryDestinationItem> retList = new ArrayList<VCardResourceEntry.VCardResourceEntryDestinationItem>();
    if (vcard.getPhoneList() != null) {
        for (final PhoneData phone : vcard.getPhoneList()) {
            final Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:" + phone.getNumber()));
            retList.add(new VCardResourceEntryDestinationItem(phone.getNumber(),
                    Phone.getTypeLabel(resources, phone.getType(), phone.getLabel()).toString(), intent));
        }//from  ww w.j  av  a2 s.c om
    }

    if (vcard.getEmailList() != null) {
        for (final EmailData email : vcard.getEmailList()) {
            final Intent intent = new Intent(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse("mailto:"));
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email.getAddress() });
            retList.add(new VCardResourceEntryDestinationItem(email.getAddress(),
                    Phone.getTypeLabel(resources, email.getType(), email.getLabel()).toString(), intent));
        }
    }

    if (vcard.getPostalList() != null) {
        for (final PostalData postalData : vcard.getPostalList()) {
            String type;
            try {
                type = resources.getStringArray(android.R.array.postalAddressTypes)[postalData.getType() - 1];
            } catch (final NotFoundException ex) {
                type = resources.getStringArray(android.R.array.postalAddressTypes)[2];
            } catch (final Exception e) {
                LogUtil.e(LogUtil.BUGLE_TAG, "createContactItem postal Exception:" + e);
                type = resources.getStringArray(android.R.array.postalAddressTypes)[2];
            }
            Intent intent = new Intent(Intent.ACTION_VIEW);
            final String address = formatAddress(postalData);
            try {
                intent.setData(Uri.parse("geo:0,0?q=" + URLEncoder.encode(address, "UTF-8")));
            } catch (UnsupportedEncodingException e) {
                intent = null;
            }

            retList.add(new VCardResourceEntryDestinationItem(address, type, intent));
        }
    }

    if (vcard.getImList() != null) {
        for (final ImData imData : vcard.getImList()) {
            String type = null;
            try {
                type = resources.getString(Im.getProtocolLabelResource(imData.getProtocol()));
            } catch (final NotFoundException ex) {
                // Do nothing since this implies an empty label.
            }
            retList.add(new VCardResourceEntryDestinationItem(imData.getAddress(), type, null));
        }
    }

    if (vcard.getOrganizationList() != null) {
        for (final OrganizationData organtization : vcard.getOrganizationList()) {
            String type = null;
            try {
                type = resources.getString(Organization.getTypeLabelResource(organtization.getType()));
            } catch (final NotFoundException ex) {
                //set other kind as "other"
                type = resources.getStringArray(android.R.array.organizationTypes)[1];
            } catch (final Exception e) {
                LogUtil.e(LogUtil.BUGLE_TAG, "createContactItem org Exception:" + e);
                type = resources.getStringArray(android.R.array.organizationTypes)[1];
            }
            retList.add(new VCardResourceEntryDestinationItem(organtization.getOrganizationName(), type, null));
        }
    }

    if (vcard.getWebsiteList() != null) {
        for (final WebsiteData web : vcard.getWebsiteList()) {
            if (web != null && TextUtils.isGraphic(web.getWebsite())) {
                String website = web.getWebsite();
                if (!website.startsWith("http://") && !website.startsWith("https://")) {
                    // Prefix required for parsing to end up with a scheme and result in
                    // navigation
                    website = "http://" + website;
                }
                final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(website));
                retList.add(new VCardResourceEntryDestinationItem(web.getWebsite(), null, intent));
            }
        }
    }

    if (vcard.getBirthday() != null) {
        final String birthday = vcard.getBirthday();
        if (TextUtils.isGraphic(birthday)) {
            retList.add(new VCardResourceEntryDestinationItem(birthday,
                    resources.getString(R.string.vcard_detail_birthday_label), null));
        }
    }

    if (vcard.getNotes() != null) {
        for (final NoteData note : vcard.getNotes()) {
            final ArrayMap<String, String> curChildMap = new ArrayMap<String, String>();
            if (TextUtils.isGraphic(note.getNote())) {
                retList.add(new VCardResourceEntryDestinationItem(note.getNote(),
                        resources.getString(R.string.vcard_detail_notes_label), null));
            }
        }
    }
    return retList;
}

From source file:nl.thehyve.transmartclient.MainActivity.java

public void checkTransmartServerUrl(View view) {
    EditText serverUrlEditText = (EditText) findViewById(R.id.serverUrlField);
    EditText serverLabelField = (EditText) findViewById(R.id.serverLabelField);

    String serverUrl = serverUrlEditText.getText().toString();
    String serverLabel = serverLabelField.getText().toString();
    Log.d(TAG, "Checking serverLabel: " + serverLabel);

    if (serverUrl.equals("")) {
        TextInputLayout inputServerUrl = (TextInputLayout) findViewById(R.id.input_server_url);
        inputServerUrl.setError(getString(R.string.no_server_url_specified));
        return;//from  w  w w.  j  a v  a  2  s . c  o  m
    }

    Log.d(TAG, "Scheme: " + Uri.parse(serverUrl).getScheme());
    if (Uri.parse(serverUrl).getScheme() == null) {
        serverUrl = "https://" + serverUrl;
    }

    try {
        URL url = new URL(serverUrl);
        if (serverLabel.equals("")) {
            serverLabel = url.getHost();
            Log.d(TAG, "Set serverLabel to " + serverLabel);
        }
    } catch (MalformedURLException e) {
        TextInputLayout inputServerUrl = (TextInputLayout) findViewById(R.id.input_server_url);
        inputServerUrl.setError(getString(R.string.malformed_url));
        return;
    }

    Resources res = getResources();
    String[] endings = res.getStringArray(R.array.url_endings);
    for (String ending : endings) {
        if (serverUrl.endsWith(ending)) {
            serverUrl = serverUrl.substring(0, serverUrl.length() - ending.length());
            Log.d(TAG, "Removed ending: " + ending);
            break;
        }
    }
    Log.d(TAG, serverUrl);

    final TransmartServer transmartServer = new TransmartServer();
    transmartServer.setServerUrl(serverUrl);
    transmartServer.setServerLabel(serverLabel);

    boolean duplicate = false;
    List<TransmartServer> connectedServers = getConnectedServers();

    for (TransmartServer transmartServerOther : connectedServers) {
        if (transmartServerOther.getServerUrl().equals(serverUrl)) {
            duplicate = true;
            break;
        }
    }

    if (duplicate) {
        new AlertDialog.Builder(MainActivity.this).setTitle(R.string.duplicate_url)
                .setMessage(R.string.duplicate_url_text)
                .setIcon(R.drawable.ic_control_point_duplicate_black_24dp)
                .setPositiveButton(R.string.duplicate_url_positive, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        connectToTranSMARTServer(transmartServer);
                    }
                }).setNegativeButton(R.string.duplicate_url_negative, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                }).show();
    } else {
        connectToTranSMARTServer(transmartServer);
    }
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpMerchandiseStation.java

private void getDataFromDB() {

    mCommentListData.clear();/*w  w w  . j a  v  a 2s. com*/
    Resources res = getResources();
    String[] opt = res.getStringArray(R.array.client_send_merchandise_requirement);
    try {
        // GeoDeviceManagement.deviceList = new ArrayList<UpnpSearchResultBean>();
        // GeoDeviceManagement.deviceList.clear();
        for (int i = 0; i < opt.length; i++) {
            // for listview ?
            ClientTakeRideSelectSpecListItem item = new ClientTakeRideSelectSpecListItem();

            if (i == 0)
                item.check = true;
            else
                item.check = false;
            item.book_title = opt[i];
            mCommentListData.add(item);

        }

    } catch (Throwable t) {
        Toast.makeText(getActivity(), "Exception: " + t.toString(), Toast.LENGTH_SHORT).show();
    }
}

From source file:com.github.omadahealth.slidepager.lib.views.ProgressView.java

/**
 * Loads the {@link #mProgressStrings} from {@link com.github.omadahealth.slidepager.lib.R.array#slide_progress_long_text}
 *
 * @param res//from ww  w.j av  a  2 s.c  o m
 */
private void loadProgressTextLabels(Resources res) {
    if (mProgressStrings == null) {
        mProgressStrings = res.getStringArray(R.array.slide_progress_long_text);
    }
    if (mShowProgressText) {
        getProgressTextView().setVisibility(View.VISIBLE);
    } else {
        getProgressTextView().setVisibility(View.GONE);
    }
}

From source file:com.bluros.updater.UpdatesSettings.java

private String mapCheckValue(Integer value) {
    Resources resources = getResources();
    String[] checkNames = resources.getStringArray(R.array.update_check_entries);
    String[] checkValues = resources.getStringArray(R.array.update_check_values);
    for (int i = 0; i < checkValues.length; i++) {
        if (Integer.decode(checkValues[i]).equals(value)) {
            return checkNames[i];
        }//from   w  w w .  j  av a2  s .c  o  m
    }
    return getString(R.string.unknown);
}

From source file:org.creativecommons.thelist.fragments.MyListFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
        prepForPhotoUpload(data);//w w  w .ja  v  a  2 s  .  co m

        final Resources res = getResources();
        final String[] choices = res.getStringArray(R.array.single_choice_terms_array);
        String title = null;
        String content = res.getString(R.string.single_choice_terms_content);

        switch (requestCode) {
        case PhotoConstants.PICK_PHOTO_REQUEST:
            title = res.getString(R.string.single_choice_choose_photo_title);
            break;
        case PhotoConstants.TAKE_PHOTO_REQUEST:
            title = res.getString(R.string.single_choice_take_photo_title);
            break;
        } //switch

        mMessageHelper.showSingleChoiceDialog(mContext, title, content, choices,
                new MaterialDialog.ListCallbackSingleChoice() {
                    @Override
                    public boolean onSelection(MaterialDialog materialDialog, View view, int i,
                            CharSequence charSequence) {

                        if (charSequence == (choices[0])) {
                            //Positive response
                            startPhotoUpload();

                        } else {
                            //Negative response
                            showUploadCancelledSnackbar();
                        }

                        return true;
                    }
                });

    } else if (resultCode != Activity.RESULT_CANCELED) { //result other than ok or cancelled
        // Toast.makeText(this, R.string.general_error, Toast.LENGTH_SHORT).show();
        Log.d(TAG, "> onActivityResult > resultCode != canceled");
    }

}