List of usage examples for android.content.res Resources getStringArray
@NonNull public String[] getStringArray(@ArrayRes int id) throws NotFoundException
From source file:com.z299studio.pb.EditFragment.java
private AccountManager.Account getDefaultTemplate(int id) { int intArrayIds[] = { R.array.index_5, R.array.index_0, R.array.index_1, R.array.index_2, R.array.index_3, R.array.index_4 };/* www .ja va 2s . c o m*/ Resources r = getResources(); String[] defNames = r.getStringArray(R.array.def_field_names); int[] defTypes = r.getIntArray(R.array.def_field_types); int[] indexArray; AccountManager.Account account = mApp.getAccountManager().newAccount(id); if (id < intArrayIds.length) { indexArray = r.getIntArray(intArrayIds[id]); } else { indexArray = r.getIntArray(intArrayIds[0]); } for (int i : indexArray) { account.addEntry(defTypes[i], defNames[i], ""); } return account; }
From source file:pl.itiner.nutiteq.NutiteqMap.java
private PoznanAPIMap getMap() { Resources res = getResources(); final String baseUrl = res.getString(R.string.base_url); final int tileSize = res.getInteger(R.integer.tile_size); final double[] resolutions = createResolutionsArray(res.getStringArray(R.array.resolutions)); final int minZoom = res.getInteger(R.integer.min_zoom); final int maxZoom = minZoom + resolutions.length - 1; final String layerName = res.getString(R.string.base_layer_name); final String gravesLayer = res.getString(R.string.graves_layer_name); final String imageType = res.getString(R.string.png_type); final String getString = res.getString(R.string.map_get_string); final String copyrightTxt = res.getString(R.string.map_copyright_txt); final int minEpsgX = res.getInteger(R.integer.epsg_min_x); final int minEpsgY = res.getInteger(R.integer.epsg_min_y); PoznanAPIMap mainMap = new PoznanAPIMap(baseUrl, tileSize, minZoom, maxZoom, layerName, imageType, "", getString, copyrightTxt, resolutions, minEpsgX, minEpsgY); mainMap.setMissingTileImage(Image.createImage(createMissingTileBitmap(mainMap.getTileSize(), getString(R.string.map_no_connection), getResources()))); mainMap.addTileOverlay(new MapTileOverlay() { @Override//ww w . j ava2 s . c o m public String getOverlayTileUrl(MapTile tile) { String url = tile.getIDString(); url = url.replaceFirst(Tools.urlEncode(layerName), Tools.urlEncode(gravesLayer)); return url; } }); return mainMap; }
From source file:com.foodsurvey.foodsurvey.ui.ReviewActivity.java
private void populatePageList() { mCurrentPageSequence = new ArrayList<Page>(); Resources res = getResources(); Page[] pageList = new Page[] { new SingleFixedChoicePage(this, res.getString(R.string.q1_title), res.getString(R.string.q1_question)).setChoices(res.getStringArray(R.array.q1_options)) .setRequired(true), new SingleFixedChoicePage(this, res.getString(R.string.q2_title), res.getString(R.string.q2_question)).setChoices(res.getStringArray(R.array.q2_options)) .setRequired(true), new SingleFixedChoicePage(this, res.getString(R.string.q3_title), res.getString(R.string.q3_question)).setChoices(res.getStringArray(R.array.q3_options)) .setRequired(true), new SingleFixedChoicePage(this, res.getString(R.string.q4_title), res.getString(R.string.q4_question)).setChoices(res.getStringArray(R.array.q4_options)) .setRequired(true), new TextPage(this, res.getString(R.string.q5_question)), new ImagePage(this, res.getString(R.string.q6_question)) }; mCurrentPageSequence.addAll(Arrays.asList(pageList)); }
From source file:com.cettco.buycar.activity.BargainActivity.java
private void getArray() { Resources res = getResources(); String[] tmp = res.getStringArray(R.array.getcarTime_array); getcarTimeList = new ArrayList<String>(Arrays.asList(tmp)); // ArrayList<String> aa= (ArrayList<String>) Arrays.asList(tmp); tmp = res.getStringArray(R.array.loan_array); loanList = new ArrayList<String>(Arrays.asList(tmp)); tmp = res.getStringArray(R.array.location_array); locationList = new ArrayList<String>(Arrays.asList(tmp)); SharedPreferences settings = getSharedPreferences("city_selection", 0); int selection = settings.getInt("city", 0); if (selection == 0) locationList.set(0, locationList.get(0) + "()"); else if (selection == 1) locationList.set(0, locationList.get(0) + "()"); tmp = res.getStringArray(R.array.plate_array); plateList = new ArrayList<String>(Arrays.asList(tmp)); }
From source file:com.mikecorrigan.trainscorekeeper.FragmentSummary.java
@SuppressLint("NewApi") @Override/*from w w w . j a v a 2s . co m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState)); View rootView = inflater.inflate(R.layout.fragment_summary, container, false); final MainActivity activity = (MainActivity) getActivity(); final Context context = activity; final Resources resources = context.getResources(); // Get the model and attach a listener. game = activity.getGame(); if (game != null) { game.addListener(mGameListener); } players = activity.getPlayers(); // Get resources. String[] playerNames = resources.getStringArray(R.array.playerNames); TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables); TypedArray playerTextColorsArray = resources.obtainTypedArray(R.array.playerTextColors); int[] playerTextColorsIds = new int[playerTextColorsArray.length()]; for (int i = 0; i < playerTextColorsArray.length(); i++) { playerTextColorsIds[i] = playerTextColorsArray.getResourceId(i, -1); } // Get root view. ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view); // Create table. tableLayout = new TableLayout(context); TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); tableLayout.setLayoutParams(tableLayoutParams); scrollView.addView(tableLayout); // Add header. { TableRow row = new TableRow(context); row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tableLayout.addView(row); TextView tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.player)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.trains)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.contracts)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.bonuses)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); } // Add rows. for (int i = 0; i < players.getNum(); i++) { TableRow row = new TableRow(context); row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tableLayout.addView(row); ToggleButton toggleButton = new ToggleButton(context); toggleButton.setGravity(Gravity.CENTER); toggleButton.setPadding(10, 10, 10, 10); toggleButton.setText(playerNames[i]); toggleButton.setClickable(false); 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.setTextColor(resources.getColor(playerTextColorsIds[i])); row.addView(toggleButton); TextView tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); } Bundle args = getArguments(); if (args == null) { Log.e(TAG, "onCreateView: missing arguments"); return rootView; } drawablesArray.recycle(); playerTextColorsArray.recycle(); // final int index = args.getInt(ARG_INDEX); // final String tabSpec = args.getString(ARG_TAB_SPEC); return rootView; }
From source file:com.grokkingandroid.sampleapp.samples.about.AboutFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Resources res = getResources(); if (getArguments() == null) { throw new IllegalStateException("Arguments bundle must not be empty"); }// w w w. j a v a 2 s. co m int[] resIds = getArguments().getIntArray(KEY_RESOURCE_IDS); getDialog().setTitle(res.getString(R.string.about)); View view = inflater.inflate(R.layout.fragment_about, container, false); ViewGroup libParent = (ViewGroup) view.findViewById(R.id.about_container); String[] libTitles = null; String[] libDescriptions = null; if (resIds[0] != -1) { libTitles = res.getStringArray(resIds[0]); libDescriptions = res.getStringArray(resIds[1]); } if (getArguments().getBoolean(KEY_ADD_DEFAULT_LIBS, true)) { if (resIds[0] == -1) { libTitles = res.getStringArray(R.array.grokkingandroidsample_about_titles); libDescriptions = res.getStringArray(R.array.grokkingandroidsample_about_contents); } else { String[] defaultTitles = res.getStringArray(R.array.grokkingandroidsample_about_titles); String[] target = new String[defaultTitles.length + libTitles.length]; System.arraycopy(libTitles, 0, target, 0, libTitles.length); System.arraycopy(defaultTitles, 0, target, libTitles.length, defaultTitles.length); libTitles = target; String[] defaultDescriptions = res.getStringArray(R.array.grokkingandroidsample_about_contents); target = new String[defaultDescriptions.length + libTitles.length]; System.arraycopy(libDescriptions, 0, target, 0, libDescriptions.length); System.arraycopy(defaultDescriptions, 0, target, libDescriptions.length, defaultDescriptions.length); libDescriptions = target; } } String libraryPlural = res.getQuantityString(R.plurals.plural_libraries, libTitles.length); String appTitle = res.getString(resIds[3]); String copyrightYear = res.getString(resIds[4]); String repositoryLink = res.getString(resIds[5]); String aboutText = res.getString(resIds[2], appTitle, copyrightYear, repositoryLink, libraryPlural); Spanned spannedAboutText = Html.fromHtml(aboutText); TextView aboutTv = (TextView) libParent.findViewById(R.id.about_text); aboutTv.setText(spannedAboutText); aboutTv.setMovementMethod(LinkMovementMethod.getInstance()); if (libTitles != null) { for (int i = 0; i < libTitles.length; i++) { View libContainer = inflater.inflate(R.layout.single_library_layout, libParent, false); TextView currLibTitle = (TextView) libContainer.findViewById(R.id.library_title); currLibTitle.setText(libTitles[i]); TextView currLibDesc = (TextView) libContainer.findViewById(R.id.library_text); Spanned spanned = Html.fromHtml(libDescriptions[i]); currLibDesc.setText(spanned); currLibDesc.setMovementMethod(LinkMovementMethod.getInstance()); libParent.addView(libContainer); } } return view; }
From source file:com.sean.takeastand.ui.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }/*w ww.j av a2 s . co m*/ Resources resources = getResources(); switch (item.getItemId()) { case R.id.main_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(); break; case R.id.pauseplay: togglePausePlay(); break; } return super.onOptionsItemSelected(item); }
From source file:org.noise_planet.noisecapture.CommentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_comment); View mainView = findViewById(R.id.mainLayout); if (mainView != null) { mainView.setOnTouchListener(new MainOnTouchListener(this)); }/*from w ww . j av a 2s . c om*/ // Read record activity parameter // Use last record of no parameter provided this.measurementManager = new MeasurementManager(this); Intent intent = getIntent(); // Read the last stored record List<Storage.Record> recordList = measurementManager.getRecords(); if (intent != null && intent.hasExtra(COMMENT_RECORD_ID)) { record = measurementManager.getRecord(intent.getIntExtra(COMMENT_RECORD_ID, -1)); } else { if (!recordList.isEmpty()) { record = recordList.get(0); } else { // Message for starting a record Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show(); return; } } if (record != null) { View addPhoto = findViewById(R.id.btn_add_photo); addPhoto.setOnClickListener(new OnAddPhotoClickListener(this)); View resultsBtn = findViewById(R.id.resultsBtn); resultsBtn.setOnClickListener(new OnGoToResultPage(this)); View deleteBts = findViewById(R.id.deleteBtn); deleteBts.setOnClickListener(new OnDeleteMeasurement(this)); TextView noisePartyTag = (TextView) findViewById(R.id.edit_noiseparty_tag); noisePartyTag.setEnabled(record.getUploadId().isEmpty()); noisePartyTag.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { // [^A-Za-z0-9_] StringBuilder stringBuilder = new StringBuilder(); for (int i = start; i < end; i++) { char c = source.charAt(i); if (Character.isLetterOrDigit(c) || c == '_') { stringBuilder.append(c); } } // keep original if unchanged or return swapped chars boolean modified = (stringBuilder.length() == end - start); return modified ? null : stringBuilder.toString(); } } }); if (record.getNoisePartyTag() == null) { // Read last stored NoiseParty id for (Storage.Record recordItem : recordList) { if (recordItem.getId() != record.getId()) { if (recordItem.getNoisePartyTag() != null) { noisePartyTag.setText(recordItem.getNoisePartyTag()); } break; } } } else { noisePartyTag.setText(record.getNoisePartyTag()); } } initDrawer(record != null ? record.getId() : null); SeekBar seekBar = (SeekBar) findViewById(R.id.pleasantness_slider); // Load stored user comment // Pleasantness and tags are read only if the record has been uploaded Map<String, Storage.TagInfo> tagToIndex = new HashMap<>(Storage.TAGS_INFO.length); for (Storage.TagInfo sysTag : Storage.TAGS_INFO) { tagToIndex.put(sysTag.name, sysTag); } View thumbnail = findViewById(R.id.image_thumbnail); thumbnail.setOnClickListener(new OnImageClickListener(this)); if (record != null) { // Load selected tags for (String sysTag : measurementManager.getTags(record.getId())) { Storage.TagInfo tagInfo = tagToIndex.get(sysTag); if (tagInfo != null) { checkedTags.add(tagInfo.id); } } // Load description if (record.getDescription() != null) { TextView description = (TextView) findViewById(R.id.edit_description); description.setText(record.getDescription()); } Integer pleasantness = record.getPleasantness(); if (pleasantness != null) { seekBar.setProgress((int) (Math.round((pleasantness / 100.0) * seekBar.getMax()))); seekBar.setThumb( seekBar.getResources().getDrawable(R.drawable.seekguess_scrubber_control_normal_holo)); userInputSeekBar.set(true); } else { seekBar.setThumb( seekBar.getResources().getDrawable(R.drawable.seekguess_scrubber_control_disabled_holo)); } photo_uri = record.getPhotoUri(); // User can only update not uploaded data seekBar.setEnabled(record.getUploadId().isEmpty()); } else { // Message for starting a record Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show(); } thumbnailImageLayoutDoneObserver = new OnThumbnailImageLayoutDoneObserver(this); thumbnail.getViewTreeObserver().addOnGlobalLayoutListener(thumbnailImageLayoutDoneObserver); seekBar.setOnSeekBarChangeListener(new OnSeekBarUserInput(userInputSeekBar)); // Fill tags grid Resources r = getResources(); String[] tags = r.getStringArray(R.array.tags); // Append tags items for (Storage.TagInfo tagInfo : Storage.TAGS_INFO) { ViewGroup tagContainer = (ViewGroup) findViewById(tagInfo.location); if (tagContainer != null && tagInfo.id < tags.length) { addTag(tags[tagInfo.id], tagInfo.id, tagContainer, tagInfo.color != -1 ? r.getColor(tagInfo.color) : -1); } } }
From source file:com.android.settings.accessibility.AccessibilitySettings.java
private void updateFontSizeSummary(Preference pref) { final float currentScale = Settings.System.getFloat(getContext().getContentResolver(), Settings.System.FONT_SCALE, 1.0f); final Resources res = getContext().getResources(); final String[] entries = res.getStringArray(R.array.entries_font_size); final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size); final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale, strEntryValues); pref.setSummary(entries[index]);/*from w w w .j a v a 2 s . c om*/ }
From source file:jackpal.androidterm.TermPreferences.java
@Override protected void onCreate(Bundle savedInstanceState) { final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this); final TermSettings settings = new TermSettings(getResources(), mPrefs); if (mFirst && settings.getColorTheme() == 0) setTheme(R.style.Theme_AppCompat); mFirst = false;//from w w w . j a va 2 s. c om super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); if (FLAVOR_VIM) { addPreferencesFromResource(R.xml.preferences_apps); Resources res = getResources(); String[] array = res.getStringArray(R.array.entries_app_filepicker_preference); OnPreferenceChangeListener listener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Resources res = getResources(); String[] array = res.getStringArray(R.array.entries_app_filepicker_preference); int value = Integer.valueOf((String) newValue); String summary = array[value]; preference.setSummary(summary); return true; } }; String id = "cloud_dropbox_filepicker"; Preference filePicker = findPreference(id); String summary = array[settings.getDropboxFilePicker()]; filePicker.setSummary(summary); filePicker.setOnPreferenceChangeListener(listener); id = "cloud_googledrive_filepicker"; filePicker = findPreference(id); summary = array[settings.getGoogleDriveFilePicker()]; filePicker.setSummary(summary); filePicker.setOnPreferenceChangeListener(listener); id = "cloud_onedrive_filepicker"; filePicker = findPreference(id); summary = array[settings.getOneDriveFilePicker()]; filePicker.setSummary(summary); filePicker.setOnPreferenceChangeListener(listener); id = "external_app_button"; filePicker = findPreference(id); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); OnPreferenceChangeListener AppButtonListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { sp.edit().putBoolean(EXTERNAL_APP_BUTTON, (Boolean) newValue).apply(); return true; } }; filePicker.setOnPreferenceChangeListener(AppButtonListener); id = "external_app_package_name"; Preference pref = getPreferenceScreen().findPreference(id); String appId = mPrefs.getString(id, ""); setAppPickerLabel(pref, appId); new Thread() { @Override public void run() { setAppPickerList(); } }.start(); pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { setAppPickerLabel(preference, (String) newValue); return true; } }); } if (AndroidCompat.SDK >= 19) { addPreferencesFromResource(R.xml.preferences_prefs); final String PREFS_KEY = "prefs_rw"; Preference prefsPicker = getPreferenceScreen().findPreference(PREFS_KEY); prefsPicker.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { prefsPicker(); return true; } }); final String LICENSE_KEY = "license"; Preference licensePrefs = getPreferenceScreen().findPreference(LICENSE_KEY); licensePrefs.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { licensePrefs(); return true; } }); } // Remove the action bar pref on older platforms without an action bar Preference actionBarPref = findPreference(ACTIONBAR_KEY); PreferenceCategory screenCategory = (PreferenceCategory) findPreference(CATEGORY_SCREEN_KEY); if ((actionBarPref != null) && (screenCategory != null)) { screenCategory.removePreference(actionBarPref); } Preference statusBarPref = findPreference(STATUSBAR_KEY); if ((statusBarPref != null) && (screenCategory != null)) { screenCategory.removePreference(statusBarPref); } PreferenceCategory keyboardCategory = (PreferenceCategory) findPreference("categoryKeyboard"); Preference controlKeyPref = findPreference("controlkey"); if ((controlKeyPref != null) && (keyboardCategory != null)) { keyboardCategory.removePreference(controlKeyPref); } Preference fnKeyPref = findPreference("fnkey"); if ((fnKeyPref != null) && (keyboardCategory != null)) { keyboardCategory.removePreference(fnKeyPref); } if (FLAVOR_VIM) { findPreference("functionbar_vim_paste").setDefaultValue(true); } // FIXME: if (AndroidCompat.SDK < 19 && !new File(FONTPATH).exists()) new File(FONTPATH).mkdirs(); Preference fontPicker = getPreferenceScreen().findPreference("fontfile_picker"); fontPicker.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { filePicker(); return true; } }); ListPreference fontFileList = (ListPreference) getPreferenceScreen().findPreference("fontfile"); setFontList(fontFileList); Preference fontSelect = findPreference("fontfile"); Resources res = getResources(); fontSelect .setSummary(res.getString(R.string.summary_fontfile_preference) + String.format(" (%s)", FONTPATH)); fontSelect.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { ListPreference fontFileList = (ListPreference) preference; setFontList(fontFileList); return true; } }); fontSelect.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { ListPreference fontFileList = (ListPreference) preference; setFontList(fontFileList); fontFileList.setDefaultValue(newValue); return true; } }); PreferenceCategory textCategory = (PreferenceCategory) findPreference(CATEGORY_TEXT_KEY); Preference fontPref; if (AndroidCompat.SDK >= 19) { fontPref = findPreference("fontfile"); } else { fontPref = findPreference("fontfile_picker"); } if ((fontPref != null) && (textCategory != null)) { textCategory.removePreference(fontPref); } }