下面列出了android.content.res.Resources#getIntArray() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private float[] loadBoltPoints(Resources res) {
if (!isInEditMode()) {
final int[] pts = res.getIntArray(getBoltPointsArrayResource());
int maxX = 0, maxY = 0;
for (int i = 0; i < pts.length; i += 2) {
maxX = Math.max(maxX, pts[i]);
maxY = Math.max(maxY, pts[i + 1]);
}
final float[] ptsF = new float[pts.length];
for (int i = 0; i < pts.length; i += 2) {
ptsF[i] = (float) pts[i] / maxX;
ptsF[i + 1] = (float) pts[i + 1] / maxY;
}
return ptsF;
} else {
return new float[]{0, 0, 1, 1};
}
}
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_theme);
final PreferenceScreen screen = getPreferenceScreen();
final Context context = getActivity();
final Resources res = getResources();
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
for (int index = 0; index < keyboardThemeNames.length; index++) {
final KeyboardThemePreference pref = new KeyboardThemePreference(
context, keyboardThemeNames[index], keyboardThemeIds[index]);
screen.addPreference(pref);
pref.setOnRadioButtonClickedListener(this);
}
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
mSelectedThemeId = keyboardTheme.mThemeId;
}
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_theme);
final PreferenceScreen screen = getPreferenceScreen();
final Context context = getActivity();
final Resources res = getResources();
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
for (int index = 0; index < keyboardThemeNames.length; index++) {
final KeyboardThemePreference pref = new KeyboardThemePreference(
context, keyboardThemeNames[index], keyboardThemeIds[index]);
screen.addPreference(pref);
pref.setOnRadioButtonClickedListener(this);
}
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
mSelectedThemeId = keyboardTheme.mThemeId;
}
private SpinnerItems<FontSizeSpinnerItem> getTextSizeItems() {
SpinnerItems<FontSizeSpinnerItem> spinnerItems = new SpinnerItems<FontSizeSpinnerItem>();
Resources res = getResources();
// empty size
spinnerItems.add(new FontSizeSpinnerItem(-1, "", true));
// regular sizes
String[] fontSizeEntries = res.getStringArray(R.array.rte_toolbar_fontsizes_entries);
int[] fontSizeValues = res.getIntArray(R.array.rte_toolbar_fontsizes_values);
for (int i = 0; i < fontSizeEntries.length; i++) {
spinnerItems.add(new FontSizeSpinnerItem(fontSizeValues[i], fontSizeEntries[i], false));
}
return spinnerItems;
}
private SpinnerItems<FontSizeSpinnerItem> getTextSizeItems() {
SpinnerItems<FontSizeSpinnerItem> spinnerItems = new SpinnerItems<>();
Resources res = getResources();
// empty size
spinnerItems.add(new FontSizeSpinnerItem(-1, "", true));
// regular sizes
String[] fontSizeEntries = res.getStringArray(R.array.rte_toolbar_fontsizes_entries);
int[] fontSizeValues = res.getIntArray(R.array.rte_toolbar_fontsizes_values);
for (int i = 0; i < fontSizeEntries.length; i++) {
spinnerItems.add(new FontSizeSpinnerItem(fontSizeValues[i], fontSizeEntries[i], false));
}
return spinnerItems;
}
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 };
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;
}
private SpinnerItems<FontSizeSpinnerItem> getTextSizeItems() {
SpinnerItems<FontSizeSpinnerItem> spinnerItems = new SpinnerItems<FontSizeSpinnerItem>();
Resources res = getResources();
// empty size
spinnerItems.add(new FontSizeSpinnerItem(-1, "", true));
// regular sizes
String[] fontSizeEntries = res.getStringArray(R.array.rte_toolbar_fontsizes_entries);
int[] fontSizeValues = res.getIntArray(R.array.rte_toolbar_fontsizes_values);
for (int i = 0; i < fontSizeEntries.length; i++) {
spinnerItems.add(new FontSizeSpinnerItem(fontSizeValues[i], fontSizeEntries[i], false));
}
return spinnerItems;
}
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_theme);
final PreferenceScreen screen = getPreferenceScreen();
final Context context = getActivity();
final Resources res = getResources();
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
for (int index = 0; index < keyboardThemeNames.length; index++) {
final KeyboardThemePreference pref = new KeyboardThemePreference(
context, keyboardThemeNames[index], keyboardThemeIds[index]);
screen.addPreference(pref);
pref.setOnRadioButtonClickedListener(this);
}
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
mSelectedThemeId = keyboardTheme.mThemeId;
}
@Nullable
public static BrightnessMappingStrategy create(Resources resources) {
float[] luxLevels = getLuxLevels(resources.getIntArray(
com.android.internal.R.array.config_autoBrightnessLevels));
int[] brightnessLevelsBacklight = resources.getIntArray(
com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);
float[] brightnessLevelsNits = getFloatArray(resources.obtainTypedArray(
com.android.internal.R.array.config_autoBrightnessDisplayValuesNits));
float autoBrightnessAdjustmentMaxGamma = resources.getFraction(
com.android.internal.R.fraction.config_autoBrightnessAdjustmentMaxGamma,
1, 1);
float[] nitsRange = getFloatArray(resources.obtainTypedArray(
com.android.internal.R.array.config_screenBrightnessNits));
int[] backlightRange = resources.getIntArray(
com.android.internal.R.array.config_screenBrightnessBacklight);
if (isValidMapping(nitsRange, backlightRange)
&& isValidMapping(luxLevels, brightnessLevelsNits)) {
int minimumBacklight = resources.getInteger(
com.android.internal.R.integer.config_screenBrightnessSettingMinimum);
int maximumBacklight = resources.getInteger(
com.android.internal.R.integer.config_screenBrightnessSettingMaximum);
if (backlightRange[0] > minimumBacklight
|| backlightRange[backlightRange.length - 1] < maximumBacklight) {
Slog.w(TAG, "Screen brightness mapping does not cover whole range of available " +
"backlight values, autobrightness functionality may be impaired.");
}
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
builder.setCurve(luxLevels, brightnessLevelsNits);
return new PhysicalMappingStrategy(builder.build(), nitsRange, backlightRange,
autoBrightnessAdjustmentMaxGamma);
} else if (isValidMapping(luxLevels, brightnessLevelsBacklight)) {
return new SimpleMappingStrategy(luxLevels, brightnessLevelsBacklight,
autoBrightnessAdjustmentMaxGamma);
} else {
return null;
}
}
@Override
protected String doInBackground(String... params) {
activityRef.get().mApp.onStart();
Resources r = activityRef.get().getResources();
String[] defCategories = r.getStringArray(R.array.category_names);
int i = 0;
AccountManager am = new AccountManager(null);
activityRef.get().mApp.setAccountManager(am, -1, activityRef.get().getString(R.string.def_category));
for(String s : defCategories) {
am.addCategory(i++, s);
}
String[] defAccountNames = r.getStringArray(R.array.def_account_names);
String[] defNames = r.getStringArray(R.array.def_field_names);
String[] defValues = r.getStringArray(R.array.def_values);
int[] defTypes = r.getIntArray(R.array.def_field_types);
TypedArray defAccountData = r.obtainTypedArray(R.array.def_account_data);
int[] dataDetails;
AccountManager.Account a;
for (i = 0; i < defAccountNames.length; ++i) {
dataDetails = r.getIntArray(defAccountData.getResourceId(i, 0));
a = am.newAccount(dataDetails[0]);
a.mProfile = defAccountNames[i];
for (int j = 1; j < dataDetails.length; j += 3){
try {
a.addEntry(defTypes[dataDetails[j + 2]],
defNames[dataDetails[j]],
defValues[dataDetails[j + 1]]);
} catch (ArrayIndexOutOfBoundsException e) {
Log.e("Passbook", "This should really not happen.");
}
}
am.addAccount(dataDetails[0], a);
}
defAccountData.recycle();
return "OK";
}
static void updateKeyboardThemeSummary(final Preference pref) {
final Context context = pref.getContext();
final Resources res = context.getResources();
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
for (int index = 0; index < keyboardThemeNames.length; index++) {
if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
pref.setSummary(keyboardThemeNames[index]);
return;
}
}
}
public void setThemeSilent(int theme, Resources resources) {
try {
this.theme = theme;
colors = resources.getIntArray(theme);
} catch (Resources.NotFoundException e) {
// setting theme blood if exception occurs (especially used for preview rendering by IDE)
colors = new int[]{Color.parseColor("#732219"), Color.parseColor("#a63124"),
Color.parseColor("#d94130"), Color.parseColor("#f2b6ae")};
}
}
static void updateKeyboardThemeSummary(final Preference pref) {
final Context context = pref.getContext();
final Resources res = context.getResources();
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
for (int index = 0; index < keyboardThemeNames.length; index++) {
if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
pref.setSummary(keyboardThemeNames[index]);
return;
}
}
}
static void updateKeyboardThemeSummary(final Preference pref) {
final Context context = pref.getContext();
final Resources res = context.getResources();
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
for (int index = 0; index < keyboardThemeNames.length; index++) {
if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
pref.setSummary(keyboardThemeNames[index]);
return;
}
}
}
public void setThemeSilent(int theme, Resources resources) {
try {
this.theme = theme;
colors = resources.getIntArray(theme);
} catch (Resources.NotFoundException e) {
// setting theme blood if exception occurs (especially used for preview rendering by IDE)
colors = new int[]{Color.parseColor("#732219"), Color.parseColor("#a63124"),
Color.parseColor("#d94130"), Color.parseColor("#f2b6ae")};
}
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_basic);
final ArrayList<String> objects = new ArrayList<String>();
for (int i = 0; i < 50; i++) {
objects.add(String.format("Item %d", i));
}
final RefreshNowProgressIndicator indicator = (RefreshNowProgressIndicator) findViewById(android.R.id.progress);
final Resources res = getResources();
final int[] colors = res.getIntArray(R.array.gplus_colors);
final float width = (res.getDisplayMetrics().density * 3);
final IndicatorConfig.Builder cb = new IndicatorConfig.Builder(this);
cb.reversed(true);
cb.mirrorMode(true);
cb.speed(1.7f);
cb.separatorLength(0);
cb.interpolator(new AccelerateDecelerateInterpolator());
cb.progressColor(colors[0]);
cb.indeterminateColors(colors);
cb.sectionsCount(2);
cb.indeterminateStrokeWidth(width);
cb.progressStrokeWidth(width);
mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, objects));
mListView.setOnRefreshListener(this);
mListView.setRefreshIndicatorView(indicator);
indicator.setConfig(cb.build());
}
private int[] getColorValues(String colorSectionName) {
Resources res = mContext.getResources();
if (res.getString(R.string.red).equals(colorSectionName)) {
return res.getIntArray(R.array.reds);
} else if (res.getString(R.string.pink).equals(colorSectionName)) {
return res.getIntArray(R.array.pinks);
} else if (res.getString(R.string.purple).equals(colorSectionName)) {
return res.getIntArray(R.array.purples);
} else if (res.getString(R.string.deep_purple).equals(colorSectionName)) {
return res.getIntArray(R.array.deep_purples);
} else if (res.getString(R.string.indigo).equals(colorSectionName)) {
return res.getIntArray(R.array.indigos);
} else if (res.getString(R.string.blue).equals(colorSectionName)) {
return res.getIntArray(R.array.blues);
} else if (res.getString(R.string.light_blue).equals(colorSectionName)) {
return res.getIntArray(R.array.light_blues);
} else if (res.getString(R.string.cyan).equals(colorSectionName)) {
return res.getIntArray(R.array.cyans);
} else if (res.getString(R.string.teal).equals(colorSectionName)) {
return res.getIntArray(R.array.teals);
} else if (res.getString(R.string.green).equals(colorSectionName)) {
return res.getIntArray(R.array.greens);
} else if (res.getString(R.string.light_green).equals(colorSectionName)) {
return res.getIntArray(R.array.light_greens);
} else if (res.getString(R.string.lime).equals(colorSectionName)) {
return res.getIntArray(R.array.limes);
} else if (res.getString(R.string.yellow).equals(colorSectionName)) {
return res.getIntArray(R.array.yellows);
} else if (res.getString(R.string.amber).equals(colorSectionName)) {
return res.getIntArray(R.array.ambers);
} else if (res.getString(R.string.orange).equals(colorSectionName)) {
return res.getIntArray(R.array.oranges);
} else if (res.getString(R.string.deep_orange).equals(colorSectionName)) {
return res.getIntArray(R.array.deep_oranges);
} else if (res.getString(R.string.brown).equals(colorSectionName)) {
return res.getIntArray(R.array.browns);
} else if (res.getString(R.string.grey).equals(colorSectionName)) {
return res.getIntArray(R.array.greys);
} else if (res.getString(R.string.blue_grey).equals(colorSectionName)) {
return res.getIntArray(R.array.blue_greys);
} else {
throw new RuntimeException("Invalid color section: " + colorSectionName);
}
}
@Override
public void onCreate(SurfaceHolder holder) {
super.onCreate(holder);
setWatchFaceStyle(new WatchFaceStyle.Builder(SunsetsWatchFace.this)
.setAcceptsTapEvents(true)
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
.setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
.setShowSystemUiTime(false).
setViewProtectionMode(WatchFaceStyle.PROTECT_STATUS_BAR)
.build());
Resources resources = SunsetsWatchFace.this.getResources();
maskFront = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.front);
ambient = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ambient);
frontGradient = resources.getIntArray(R.array.front_array);
skyGradient = resources.getIntArray(R.array.sky_array);
bitmapPaint = new Paint();
bitmapPaint.setAntiAlias(true);
paint = new Paint();
paint.setAntiAlias(true);
skyPaint = new Paint();
mBackgroundPaint = new Paint();
mBackgroundPaint.setAntiAlias(true);
mBackgroundPaint.setColor(Color.YELLOW);
mTimePaint = new Paint();
mTimePaint.setColor(resources.getColor(R.color.time_date_color));
mTimePaint.setAntiAlias(true);
mTimePaint.setStrokeCap(Paint.Cap.BUTT);
mTimePaint.setTypeface(Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Dolce Vita Light.ttf"));
mTimePaint.setTextSize(getResources().getDimension(R.dimen.font_size_time_round));
//mTimePaint.setShadowLayer(1, 1, 1, resources.getColor(R.color.front_orange));
mDatePaint = new Paint();
mDatePaint.setColor(resources.getColor(R.color.time_date_color));
mDatePaint.setAntiAlias(true);
mDatePaint.setStrokeCap(Paint.Cap.BUTT);
mDatePaint.setTypeface(NORMAL_TYPEFACE);
mDatePaint.setTextSize(getResources().getDimension(R.dimen.font_size_date));
mDatePaint.setTypeface(Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Dolce Vita Light.ttf"));
mTime = new Time();
mCalendar = Calendar.getInstance();
}
public CircularProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (isInEditMode()) {
setIndeterminateDrawable(new CircularProgressDrawable.Builder(context).build());
return;
}
Resources res = context.getResources();
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircularProgressBar, defStyle, 0);
final int colorResId = a.getResourceId(R.styleable.CircularProgressBar_cpb_color, ThemeUtils.getThemeColor(context, R.attr.colorPrimary));
final int color = getResources().getColor(colorResId);
final float strokeWidth = a.getDimension(R.styleable.CircularProgressBar_cpb_stroke_width, res.getDimension(R.dimen.cpb_default_stroke_width));
final float sweepSpeed = a.getFloat(R.styleable.CircularProgressBar_cpb_sweep_speed, Float.parseFloat(res.getString(R.string.cpb_default_sweep_speed)));
final float rotationSpeed = a.getFloat(R.styleable.CircularProgressBar_cpb_rotation_speed, Float.parseFloat(res.getString(R.string.cpb_default_rotation_speed)));
final int colorsId = a.getResourceId(R.styleable.CircularProgressBar_cpb_colors, 0);
final int minSweepAngle = a.getInteger(R.styleable.CircularProgressBar_cpb_min_sweep_angle, res.getInteger(R.integer.cpb_default_min_sweep_angle));
final int maxSweepAngle = a.getInteger(R.styleable.CircularProgressBar_cpb_max_sweep_angle, res.getInteger(R.integer.cpb_default_max_sweep_angle));
a.recycle();
int[] colors = null;
//colors
if (colorsId != 0) {
colors = res.getIntArray(colorsId);
}
Drawable indeterminateDrawable;
CircularProgressDrawable.Builder builder = new CircularProgressDrawable.Builder(context)
.sweepSpeed(sweepSpeed)
.rotationSpeed(rotationSpeed)
.strokeWidth(strokeWidth)
.minSweepAngle(minSweepAngle)
.maxSweepAngle(maxSweepAngle);
if (colors != null && colors.length > 0)
builder.colors(colors);
else
builder.color(color);
indeterminateDrawable = builder.build();
setIndeterminateDrawable(indeterminateDrawable);
}
/**
* Get an {@link ArrayPalette} from {@link Resources}.
*
* @param resources
* The {@link Resources}.
* @param id
* An identifier for this palette.
* @param paletteName
* A string resource id for the palette name.
* @param colorArray
* The integer array resource id for the colors.
* @param columns
* The number of columns to use for the layout.
* @param colorNameArray
* A string array resource for the color names.
*
* @return An {@link ArrayPalette} instance.
*/
public static ArrayPalette fromResources(Resources resources, String id, int paletteName, int colorArray, int columns, int colorNameArray)
{
return new ArrayPalette(id, resources.getString(paletteName), resources.getIntArray(colorArray), columns, resources.getStringArray(colorNameArray));
}