List of usage examples for android.content.res TypedArray length
public int length()
From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java
private ArrayList<TargetDrawable> loadDrawableArray(int resourceId) { Resources res = getContext().getResources(); TypedArray array = res.obtainTypedArray(resourceId); final int count = array.length(); ArrayList<TargetDrawable> drawables = new ArrayList<TargetDrawable>(count); for (int i = 0; i < count; i++) { TypedValue value = array.peekValue(i); TargetDrawable target = new TargetDrawable(res, value != null ? value.resourceId : 0, 3); drawables.add(target);//from w w w. jav a2 s . co m } array.recycle(); return drawables; }
From source file:ir.actfun.toofan.activities.MainActivity.java
private String setWeatherIcon(int actualId, int hourOfDay) { movingImageView = (MovingImageView) findViewById(R.id.movingimageview2); int id = actualId / 100; String icon = ""; if (actualId == 800) { if (hourOfDay >= 7 && hourOfDay < 20) { if (universal_flag) { final TypedArray images = getResources().obtainTypedArray(R.array.sunny_images); final int choice = (int) (Math.random() * images.length()); MainActivity.this.runOnUiThread(new Runnable() { public void run() { movingImageView.setImageResource(images.getResourceId(choice, R.drawable.sun1)); }/*from w w w.j a va 2 s . c o m*/ }); universal_flag = false; } icon = this.getString(R.string.weather_sunny); } else { if (universal_flag) { final TypedArray images = getResources().obtainTypedArray(R.array.night_images); final int choice = (int) (Math.random() * images.length()); MainActivity.this.runOnUiThread(new Runnable() { public void run() { movingImageView.setImageResource(images.getResourceId(choice, R.drawable.night1)); } }); universal_flag = false; } icon = this.getString(R.string.weather_clear_night); } } else { switch (id) { case 2: { if (universal_flag) { final TypedArray images = getResources().obtainTypedArray(R.array.thunder_images); final int choice = (int) (Math.random() * images.length()); MainActivity.this.runOnUiThread(new Runnable() { public void run() { movingImageView.setImageResource(images.getResourceId(choice, R.drawable.thunder1)); } }); universal_flag = false; } icon = this.getString(R.string.weather_thunder); break; } case 3: { if (universal_flag) { final TypedArray images = getResources().obtainTypedArray(R.array.rainy_images); final int choice = (int) (Math.random() * images.length()); MainActivity.this.runOnUiThread(new Runnable() { public void run() { movingImageView.setImageResource(images.getResourceId(choice, R.drawable.rain1)); } }); universal_flag = false; } icon = this.getString(R.string.weather_drizzle); break; } case 7: { if (universal_flag) { final TypedArray images = getResources().obtainTypedArray(R.array.fog_images); final int choice = (int) (Math.random() * images.length()); MainActivity.this.runOnUiThread(new Runnable() { public void run() { movingImageView.setImageResource(images.getResourceId(choice, R.drawable.fog1)); } }); universal_flag = false; } icon = this.getString(R.string.weather_foggy); break; } case 8: { if (universal_flag) { final TypedArray images = getResources().obtainTypedArray(R.array.cloudy_images); final int choice = (int) (Math.random() * images.length()); MainActivity.this.runOnUiThread(new Runnable() { public void run() { movingImageView.setImageResource(images.getResourceId(choice, R.drawable.cloud1)); } }); universal_flag = false; } icon = this.getString(R.string.weather_cloudy); break; } case 6: { if (universal_flag) { final TypedArray images = getResources().obtainTypedArray(R.array.snowy_images); final int choice = (int) (Math.random() * images.length()); MainActivity.this.runOnUiThread(new Runnable() { public void run() { movingImageView.setImageResource(images.getResourceId(choice, R.drawable.snow1)); } }); universal_flag = false; } icon = this.getString(R.string.weather_snowy); break; } case 5: { if (universal_flag) { final TypedArray images = getResources().obtainTypedArray(R.array.rainy_images); final int choice = (int) (Math.random() * images.length()); MainActivity.this.runOnUiThread(new Runnable() { public void run() { movingImageView.setImageResource(images.getResourceId(choice, R.drawable.rain1)); } }); universal_flag = false; } icon = this.getString(R.string.weather_rainy); break; } } } return icon; }
From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java
private ArrayList<String> loadDescriptions(int resourceId) { TypedArray array = getContext().getResources().obtainTypedArray(resourceId); final int count = array.length(); ArrayList<String> targetContentDescriptions = new ArrayList<String>(count); for (int i = 0; i < count; i++) { String contentDescription = array.getString(i); targetContentDescriptions.add(contentDescription); }/*ww w. j av a2 s. com*/ array.recycle(); return targetContentDescriptions; }
From source file:org.onebusaway.android.ui.TripPlanFragment.java
private void advancedSettings() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()); final TypedArray transitModeResource = getContext().getResources() .obtainTypedArray(R.array.transit_mode_array); final boolean unitsAreImperial = !PreferenceUtils.getUnitsAreMetricFromPreferences(getContext()); dialogBuilder.setTitle(R.string.trip_plan_advanced_settings) .setView(R.layout.trip_plan_advanced_settings_dialog); dialogBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override/*from ww w. j a v a 2s. co m*/ public void onClick(DialogInterface dialogInterface, int which) { Dialog dialog = (Dialog) dialogInterface; boolean optimizeTransfers = ((CheckBox) dialog.findViewById(R.id.checkbox_minimize_transfers)) .isChecked(); Spinner spinnerTravelBy = (Spinner) dialog.findViewById(R.id.spinner_travel_by); int modeId = transitModeResource.getResourceId(spinnerTravelBy.getSelectedItemPosition(), 0); boolean wheelchair = ((CheckBox) dialog.findViewById(R.id.checkbox_wheelchair_acccesible)) .isChecked(); String maxWalkString = ((EditText) dialog.findViewById(R.id.number_maximum_walk_distance)).getText() .toString(); double maxWalkDistance; if (TextUtils.isEmpty(maxWalkString)) { maxWalkDistance = Double.MAX_VALUE; } else { double d = Double.parseDouble(maxWalkString); maxWalkDistance = unitsAreImperial ? ConversionUtils.feetToMeters(d) : d; } mBuilder.setOptimizeTransfers(optimizeTransfers).setModeSetById(modeId) .setWheelchairAccessible(wheelchair).setMaxWalkDistance(maxWalkDistance); checkRequestAndSubmit(); } }); final AlertDialog dialog = dialogBuilder.create(); dialog.show(); CheckBox minimizeTransfersCheckbox = (CheckBox) dialog.findViewById(R.id.checkbox_minimize_transfers); Spinner spinnerTravelBy = (Spinner) dialog.findViewById(R.id.spinner_travel_by); CheckBox wheelchairCheckbox = (CheckBox) dialog.findViewById(R.id.checkbox_wheelchair_acccesible); EditText maxWalkEditText = (EditText) dialog.findViewById(R.id.number_maximum_walk_distance); minimizeTransfersCheckbox.setChecked(mBuilder.getOptimizeTransfers()); wheelchairCheckbox.setChecked(mBuilder.getWheelchairAccessible()); ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.transit_mode_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerTravelBy.setAdapter(adapter); int modeSetId = mBuilder.getModeSetId(); if (modeSetId != -1) { for (int i = 0; i < transitModeResource.length(); i++) { if (transitModeResource.getResourceId(i, -1) == modeSetId) { spinnerTravelBy.setSelection(i); break; } } } Double maxWalk = mBuilder.getMaxWalkDistance(); if (maxWalk != null && Double.MAX_VALUE != maxWalk) { if (unitsAreImperial) { maxWalk = ConversionUtils.metersToFeet(maxWalk); } maxWalkEditText.setText(String.format("%d", maxWalk.longValue())); } if (unitsAreImperial) { TextView label = (TextView) dialog.findViewById(R.id.label_minimum_walk_distance); label.setText(getString(R.string.feet_abbreviation)); } }