List of usage examples for android.content.res TypedArray getResourceId
@AnyRes public int getResourceId(@StyleableRes int index, int defValue)
From source file:com.hongfeiyu.hfykitkat.Calculator.java
@Override public void onCreate(Bundle state) { super.onCreate(state); // Disable IME for this application getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); setContentView(R.layout.main);// w w w.j a v a 2s.c o m mPager = (ViewPager) findViewById(R.id.panelswitch); if (mPager != null) { mPager.setAdapter(new PageAdapter(mPager)); } else { // Single page UI final TypedArray buttons = getResources().obtainTypedArray(R.array.buttons); for (int i = 0; i < buttons.length(); i++) { setOnClickListener(null, buttons.getResourceId(i, 0)); } buttons.recycle(); } if (mClearButton == null) { mClearButton = findViewById(R.id.clear); mClearButton.setOnClickListener(mListener); mClearButton.setOnLongClickListener(mListener); } if (mBackspaceButton == null) { mBackspaceButton = findViewById(R.id.del); mBackspaceButton.setOnClickListener(mListener); mBackspaceButton.setOnLongClickListener(mListener); } mPersist = new Persist(this); mPersist.load(); mHistory = mPersist.history; mDisplay = (CalculatorDisplay) findViewById(R.id.display); mLogic = new Logic(this, mHistory, mDisplay); mLogic.setListener(this); mLogic.setDeleteMode(mPersist.getDeleteMode()); mLogic.setLineLength(mDisplay.getMaxDigits()); HistoryAdapter historyAdapter = new HistoryAdapter(this, mHistory, mLogic); mHistory.setObserver(historyAdapter); if (mPager != null) { mPager.setCurrentItem(state == null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0)); } mListener.setHandler(mLogic, mPager); mDisplay.setOnKeyListener(mListener); mLogic.resumeWithHistory(); updateDeleteMode(); //?SoundManager SoundManager.getInstance().initSounds(this); }
From source file:com.artemchep.horario.ui.fragments.AuthFragment.java
private void showRegisterDialog() { // Load icon/* ww w. j a v a2s. c o m*/ TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.icon_account_plus }); int iconDrawableRes = a.getResourceId(0, 0); a.recycle(); MaterialDialog.SingleButtonCallback positiveCallback = new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { View view = dialog.getCustomView(); assert view != null; SignUpLayout sul = view.findViewById(R.id.sign_up_layout); if (sul.validate()) { signUpWithEmail(sul.getEmailText(), sul.getPasswordText()); dialog.dismiss(); } } }; MaterialDialog.SingleButtonCallback negativeCallback = new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { dialog.dismiss(); } }; MaterialDialog md = new MaterialDialog.Builder(getContext()).customView(R.layout.dialog_auth_register, true) .title(R.string.auth_register).positiveText(R.string.auth_register) .negativeText(android.R.string.cancel).iconRes(iconDrawableRes).autoDismiss(false) .onPositive(positiveCallback).onNegative(negativeCallback).build(); View v = md.getCustomView(); assert v != null; // Pull email from current activity String email = mSignInView.getEmailText(); //noinspection StatementWithEmptyBody if (TextUtils.isEmpty(email)) { } else { EditText editText = v.findViewById(R.id.input_email); editText.setText(email); } // Pull password from current activity String password = mSignInView.getPasswordText(); //noinspection StatementWithEmptyBody if (TextUtils.isEmpty(password)) { } else { EditText editText = v.findViewById(R.id.input_password); editText.setText(password); } md.show(); }
From source file:com.github.preferencefragment.preference.PreferencesFromCode.java
private PreferenceScreen createPreferenceHierarchy() { // Root// w w w . j a va2 s.c o m PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this); // Inline preferences PreferenceCategory inlinePrefCat = new PreferenceCategory(this); inlinePrefCat.setTitle(R.string.inline_preferences); root.addPreference(inlinePrefCat); // Checkbox preference CheckBoxPreference checkboxPref = new CheckBoxPreference(this); checkboxPref.setKey("checkbox_preference"); checkboxPref.setTitle(R.string.title_checkbox_preference); checkboxPref.setSummary(R.string.summary_checkbox_preference); inlinePrefCat.addPreference(checkboxPref); // Switch preference SwitchPreference switchPref = new SwitchPreference(this); switchPref.setKey("switch_preference"); switchPref.setTitle(R.string.title_switch_preference); switchPref.setSummary(R.string.summary_switch_preference); inlinePrefCat.addPreference(switchPref); // Dialog based preferences PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this); dialogBasedPrefCat.setTitle(R.string.dialog_based_preferences); root.addPreference(dialogBasedPrefCat); // Edit text preference EditTextPreference editTextPref = new EditTextPreference(this); editTextPref.setDialogTitle(R.string.dialog_title_edittext_preference); editTextPref.setKey("edittext_preference"); editTextPref.setTitle(R.string.title_edittext_preference); editTextPref.setSummary(R.string.summary_edittext_preference); dialogBasedPrefCat.addPreference(editTextPref); // List preference ListPreference listPref = new ListPreference(this); listPref.setEntries(R.array.entries_list_preference); listPref.setEntryValues(R.array.entryvalues_list_preference); listPref.setDialogTitle(R.string.dialog_title_list_preference); listPref.setKey("list_preference"); listPref.setTitle(R.string.title_list_preference); listPref.setSummary(R.string.summary_list_preference); dialogBasedPrefCat.addPreference(listPref); // Launch preferences PreferenceCategory launchPrefCat = new PreferenceCategory(this); launchPrefCat.setTitle(R.string.launch_preferences); root.addPreference(launchPrefCat); /* * The Preferences screenPref serves as a screen break (similar to page * break in word processing). Like for other preference types, we assign * a key here so that it is able to save and restore its instance state. */ // Screen preference PreferenceScreen screenPref = getPreferenceManager().createPreferenceScreen(this); screenPref.setKey("screen_preference"); screenPref.setTitle(R.string.title_screen_preference); screenPref.setSummary(R.string.summary_screen_preference); launchPrefCat.addPreference(screenPref); /* * You can add more preferences to screenPref that will be shown on the * next screen. */ // Example of next screen toggle preference CheckBoxPreference nextScreenCheckBoxPref = new CheckBoxPreference(this); nextScreenCheckBoxPref.setKey("next_screen_toggle_preference"); nextScreenCheckBoxPref.setTitle(R.string.title_next_screen_toggle_preference); nextScreenCheckBoxPref.setSummary(R.string.summary_next_screen_toggle_preference); screenPref.addPreference(nextScreenCheckBoxPref); // Intent preference PreferenceScreen intentPref = getPreferenceManager().createPreferenceScreen(this); intentPref .setIntent(new Intent().setAction(Intent.ACTION_VIEW).setData(Uri.parse("http://www.android.com"))); intentPref.setTitle(R.string.title_intent_preference); intentPref.setSummary(R.string.summary_intent_preference); launchPrefCat.addPreference(intentPref); // Preference attributes PreferenceCategory prefAttrsCat = new PreferenceCategory(this); prefAttrsCat.setTitle(R.string.preference_attributes); root.addPreference(prefAttrsCat); // Visual parent toggle preference CheckBoxPreference parentCheckBoxPref = new CheckBoxPreference(this); parentCheckBoxPref.setTitle(R.string.title_parent_preference); parentCheckBoxPref.setSummary(R.string.summary_parent_preference); prefAttrsCat.addPreference(parentCheckBoxPref); // Visual child toggle preference // See res/values/attrs.xml for the <declare-styleable> that defines // TogglePrefAttrs. TypedArray a = obtainStyledAttributes(R.styleable.TogglePrefAttrs); CheckBoxPreference childCheckBoxPref = new CheckBoxPreference(this); childCheckBoxPref.setTitle(R.string.title_child_preference); childCheckBoxPref.setSummary(R.string.summary_child_preference); childCheckBoxPref .setLayoutResource(a.getResourceId(R.styleable.TogglePrefAttrs_android_preferenceLayoutChild, 0)); prefAttrsCat.addPreference(childCheckBoxPref); a.recycle(); return root; }
From source file:com.forrestguice.suntimeswidget.AlarmDialog.java
private void initColors(Context context) { int[] colorAttrs = { android.R.attr.textColorPrimary }; TypedArray typedArray = context.obtainStyledAttributes(colorAttrs); int def = Color.WHITE; color_textTimeDelta = ContextCompat.getColor(context, typedArray.getResourceId(0, def)); typedArray.recycle();/*from w ww.jav a 2s. c o m*/ }
From source file:com.hippo.vectorold.drawable.AnimatedVectorDrawable.java
public void inflate(Context context, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { Resources res = context.getResources(); int eventType = parser.getEventType(); float pathErrorScale = 1; while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { final String tagName = parser.getName(); if (ANIMATED_VECTOR.equals(tagName)) { final TypedArray a = res.obtainAttributes(attrs, R.styleable.AnimatedVectorDrawable); int drawableRes = a.getResourceId(R.styleable.AnimatedVectorDrawable_drawable, 0); if (drawableRes != 0) { VectorDrawable vectorDrawable = (VectorDrawable) res.getDrawable(drawableRes).mutate(); vectorDrawable.setAllowCaching(false); pathErrorScale = vectorDrawable.getPixelSize(); mAnimatedVectorState.mVectorDrawable = vectorDrawable; }// w w w.j ava 2s. c o m a.recycle(); } else if (TARGET.equals(tagName)) { final TypedArray a = res.obtainAttributes(attrs, R.styleable.AnimatedVectorDrawableTarget); final String target = a.getString(R.styleable.AnimatedVectorDrawableTarget_name); int id = a.getResourceId(R.styleable.AnimatedVectorDrawableTarget_animation, 0); if (id != 0) { Animator objectAnimator = AnimatorInflater.loadAnimator(context, id, pathErrorScale); setupAnimatorsForTarget(target, objectAnimator); } a.recycle(); } } eventType = parser.next(); } }
From source file:com.hamsik2046.password.view.SingleInputFormActivity.java
private void loadTheme() { /* Default values */ mButtonNextIcon = getResources().getDrawable(R.drawable.ic_action_next_item); mButtonFinishIcon = getResources().getDrawable(R.drawable.ic_action_accept); mTextFieldBackgroundColor = getResources().getColor(R.color.default_text_field_background_color); mProgressBackgroundColor = getResources().getColor(R.color.default_progress_background_color); mTitleTextColor = getResources().getColor(R.color.default_title_text_color); mDetailsTextColor = getResources().getColor(R.color.default_details_text_color); mErrorTextColor = getResources().getColor(R.color.default_error_text_color); int themeResId = 0; try {/*from w w w.ja va 2 s .co m*/ String packageName = getClass().getPackage().getName(); PackageManager packageManager = getPackageManager(); if (packageManager != null) { PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA); ApplicationInfo applicationInfo = packageInfo.applicationInfo; if (applicationInfo != null) { themeResId = applicationInfo.theme; } } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } /* Custom values */ int[] attrs = { R.attr.sifStyle }; TypedArray array = obtainStyledAttributes(themeResId, attrs); if (array != null) { TypedArray styleArray = obtainStyledAttributes(array.getResourceId(0, 0), R.styleable.SingleInputFormStyle); if (styleArray != null) { Drawable buttonNextIcon = styleArray .getDrawable(R.styleable.SingleInputFormStyle_sifButtonNextIcon); if (buttonNextIcon != null) { mButtonNextIcon = buttonNextIcon; } Drawable buttonFinishIcon = styleArray .getDrawable(R.styleable.SingleInputFormStyle_sifButtonFinishIcon); if (buttonFinishIcon != null) { mButtonFinishIcon = buttonFinishIcon; } mTextFieldBackgroundColor = styleArray.getColor( R.styleable.SingleInputFormStyle_sifTextFieldBackgroundColor, mTextFieldBackgroundColor); mProgressBackgroundColor = styleArray.getColor( R.styleable.SingleInputFormStyle_sifProgressBackgroundColor, mProgressBackgroundColor); mTitleTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifTitleTextColor, mTitleTextColor); mDetailsTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifDetailsTextColor, mDetailsTextColor); mErrorTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifErrorTextColor, mErrorTextColor); } } }
From source file:com.android.calculator3.Calculator2.java
@Override public void onCreate(Bundle state) { super.onCreate(state); // Disable IME for this application???? getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); setContentView(R.layout.main);/*w w w. j av a 2s . c o m*/ //??????????sin?cos //ViewPager????? mPager = (ViewPager) findViewById(R.id.panelswitch); if (mPager != null) { mPager.setAdapter(new PageAdapter(mPager)); } else { // Single page UI final TypedArray buttons = getResources().obtainTypedArray(R.array.buttons); for (int i = 0; i < buttons.length(); i++) { setOnClickListener(null, buttons.getResourceId(i, 0)); } buttons.recycle(); } if (mClearButton == null) { mClearButton = findViewById(R.id.clear); mClearButton.setOnClickListener(mListener); mClearButton.setOnLongClickListener(mListener); } if (mBackspaceButton == null) { mBackspaceButton = findViewById(R.id.del); mBackspaceButton.setOnClickListener(mListener); mBackspaceButton.setOnLongClickListener(mListener); } //? mPersist = new Persist(this); mPersist.load(); //?? mHistory = mPersist.history; mDisplay = (CalculatorDisplay) findViewById(R.id.display); //? mLogic = new Logic(this, mHistory, mDisplay); mLogic.setListener(this); //?? mLogic.setDeleteMode(mPersist.getDeleteMode()); mLogic.setLineLength(mDisplay.getMaxDigits()); //??? HistoryAdapter historyAdapter = new HistoryAdapter(this, mHistory, mLogic); mHistory.setObserver(historyAdapter); //?? if (mPager != null) { mPager.setCurrentItem(state == null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0)); } //?? mListener.setHandler(mLogic, mPager); //? mDisplay.setOnKeyListener(mListener); if (!ViewConfiguration.get(this).hasPermanentMenuKey()) { //?? createFakeMenu(); } //?? mLogic.resumeWithHistory(); // updateDeleteMode(); }
From source file:com.cc.signalinfo.fragments.SignalFragment.java
/** * Gets the TextViews that map to the signal info data in the code for binding. * * @param sigInfoIds - the array containing the IDs to the TextView resources * @param refreshMap - should we recreate the map or reuse it? (in case we some reason added some, somehow) * @return map of the Signal data enumeration types (keys) and corresponding TextViews (values) *///from w ww . j av a2 s. c o m public Map<Signal, TextView> getSignalTextViewMap(TypedArray sigInfoIds, boolean refreshMap) { // no reason to do this over and over if it's already filled (we keep the same text stuff if (signalTextViewMap.isEmpty() || refreshMap) { Signal[] values = Signal.values(); for (int i = 0; i <= sigInfoIds.length(); ++i) { int id = sigInfoIds.getResourceId(i, -1); if (id != -1) { TextView currentView = (TextView) rootView.findViewById(id); signalTextViewMap.put(values[i], currentView); } } } return Collections.unmodifiableMap(signalTextViewMap); }
From source file:com.github.andrewlord1990.snackbarbuilder.SnackbarBuilder.java
private void loadParentViewId(TypedArray attrs) { parentViewId = attrs.getResourceId(R.styleable.SnackbarBuilderStyle_snackbarBuilder_parentViewId, 0); }
From source file:com.example.administrator.myapplication.recycler_swipe.swpie.SwipeMenuLayout.java
public SwipeMenuLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwipeMenuLayout); mLeftViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_leftViewId, mLeftViewId); mContentViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_contentViewId, mContentViewId); mRightViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_rightViewId, mRightViewId); typedArray.recycle();//from www . j a v a 2 s.co m ViewConfiguration configuration = ViewConfiguration.get(getContext()); mScaledTouchSlop = configuration.getScaledTouchSlop(); mScaledMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mScaledMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity(); mScroller = new OverScroller(getContext()); }