List of usage examples for android.content.res TypedArray getDrawable
@Nullable public Drawable getDrawable(@StyleableRes int index)
From source file:com.github.andrewlord1990.materialandroid.component.list.ListItemView.java
private void loadAvatar(TypedArray typedAttrs) { Drawable avatar = typedAttrs.getDrawable(R.styleable.MDListItemView_md_list_avatar); setAvatar(avatar); }
From source file:com.tevinjeffrey.njitct.ui.utils.TintImageView.java
public TintImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = getContext().obtainStyledAttributes(attrs, TINT_ATTRS, defStyleAttr, 0); color = fetchAccentColor();// ww w. java 2 s . c o m Drawable drawable; if (a.length() > 0) { if (a.hasValue(2)) { color = a.getColor(2, 0); } if (a.hasValue(0)) { drawable = a.getDrawable(0); tintDrawable(drawable, color); setBackgroundDrawable(drawable); } if (a.hasValue(1)) { drawable = a.getDrawable(1); tintDrawable(drawable, color); setImageDrawable(drawable); } } a.recycle(); }
From source file:android.support.v7.preference.PreferenceGroupAdapter.java
@Override public PreferenceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final PreferenceLayout pl = mPreferenceLayouts.get(viewType); final LayoutInflater inflater = LayoutInflater.from(parent.getContext()); TypedArray a = parent.getContext().obtainStyledAttributes(null, R.styleable.BackgroundStyle); Drawable background = a.getDrawable(R.styleable.BackgroundStyle_android_selectableItemBackground); if (background == null) { background = parent.getContext().getResources() .getDrawable(android.R.drawable.list_selector_background); }/*www. j a v a2s . c om*/ a.recycle(); final View view = inflater.inflate(pl.resId, parent, false); if (view.getBackground() == null) { ViewCompat.setBackground(view, background); } final ViewGroup widgetFrame = (ViewGroup) view.findViewById(android.R.id.widget_frame); if (widgetFrame != null) { if (pl.widgetResId != 0) { inflater.inflate(pl.widgetResId, widgetFrame); } else { widgetFrame.setVisibility(View.GONE); } } return new PreferenceViewHolder(view); }
From source file:com.freshdigitable.udonroad.ffab.IndicatableFFAB.java
public IndicatableFFAB(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final View v = View.inflate(context, R.layout.view_indicatable_ffab, this); indicator = (ActionIndicatorView) v.findViewById(R.id.iffab_indicator); ffab = (FlingableFAB) v.findViewById(R.id.iffab_ffab); ViewCompat.setElevation(indicator, ffab.getCompatElevation()); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IndicatableFFAB, defStyleAttr, R.style.Widget_FFAB_IndicatableFFAB); try {//from w w w . j av a 2 s. c om final Drawable fabIcon = a.getDrawable(R.styleable.IndicatableFFAB_fabIcon); ffab.setImageDrawable(fabIcon); final int fabTint = a.getColor(R.styleable.IndicatableFFAB_fabTint, NO_ID); if (fabTint != NO_ID) { ViewCompat.setBackgroundTintList(ffab, ColorStateList.valueOf(fabTint)); } final int indicatorTint = a.getColor(R.styleable.IndicatableFFAB_indicatorTint, 0); indicator.setBackgroundColor(indicatorTint); indicatorMargin = a.getDimensionPixelSize(R.styleable.IndicatableFFAB_marginFabToIndicator, 0); } finally { a.recycle(); } ffab.setOnTouchListener(new OnTouchListener() { private MotionEvent old; @Override public boolean onTouch(View view, MotionEvent motionEvent) { final int action = motionEvent.getAction(); if (action == MotionEvent.ACTION_DOWN) { old = MotionEvent.obtain(motionEvent); onStart(); return false; } final Direction direction = Direction.getDirection(old, motionEvent); if (action == MotionEvent.ACTION_MOVE) { onMoving(direction); } else if (action == MotionEvent.ACTION_UP) { old.recycle(); onFling(view.getHandler()); } return false; } private Direction prevSelected = Direction.UNDEFINED; public void onStart() { indicator.onActionLeave(prevSelected); prevSelected = Direction.UNDEFINED; indicator.setVisibility(View.VISIBLE); } public void onMoving(Direction direction) { if (prevSelected == direction) { return; } indicator.onActionLeave(prevSelected); if (isDirectionEnabled(direction)) { indicator.onActionSelected(direction); } prevSelected = direction; } private boolean isDirectionEnabled(Direction direction) { for (Direction d : enableDirections) { if (d == direction) { return true; } } return false; } public void onFling(Handler handler) { handler.postDelayed(new Runnable() { @Override public void run() { indicator.setVisibility(View.INVISIBLE); } }, 200); } }); if (isInEditMode()) { indicator.setVisibility(VISIBLE); } }
From source file:com.aprz.easy_iosched.ui.widget.CustomRatingBar.java
public CustomRatingBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomRatingBar, 0, 0); try {//from w w w. j av a2 s. c o m mMaxRating = typedArray.getInt(R.styleable.CustomRatingBar_maxRating, DEFAULT_MAX_RATING); mFilledDrawable = typedArray.getDrawable(R.styleable.CustomRatingBar_filledDrawable); if (mFilledDrawable == null) { mFilledDrawable = ResourcesCompat.getDrawable(getResources(), DEFAULT_FILLED_DRAWABLE_ID, null); } mUnfilledDrawable = typedArray.getDrawable(R.styleable.CustomRatingBar_unfilledDrawable); if (mUnfilledDrawable == null) { mUnfilledDrawable = ResourcesCompat.getDrawable(getResources(), DEFAULT_UNFILLED_DRAWABLE_ID, null); } } finally { typedArray.recycle(); } setSaveEnabled(true); }
From source file:android.support.design.widget.NavigationDrawerView.java
public NavigationDrawerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // Custom attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavigationDrawerView, defStyleAttr, R.style.Widget_Design_NavigationDrawerView); //noinspection deprecation setBackgroundDrawable(a.getDrawable(R.styleable.NavigationDrawerView_android_background)); ViewCompat.setElevation(this, a.getDimensionPixelSize(R.styleable.NavigationDrawerView_android_elevation, 0)); ViewCompat.setFitsSystemWindows(this, a.getBoolean(R.styleable.NavigationDrawerView_android_fitsSystemWindows, false)); mMaxWidth = a.getDimensionPixelSize(R.styleable.NavigationDrawerView_android_maxWidth, 0); a.recycle();//w w w. j a v a2 s . com // Set up the menu mMenu = new MenuBuilder(context); mMenu.setCallback(new MenuBuilder.Callback() { @Override public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { return mListener != null && mListener.onNavigationItemSelected(item); } @Override public void onMenuModeChange(MenuBuilder menu) { } }); mPresenter = new NavigationMenuPresenter(); mPresenter.setId(PRESENTER_NAVIGATION_DRAWER_VIEW); mPresenter.initForMenu(context, mMenu); mMenu.addMenuPresenter(mPresenter); addView((View) mPresenter.getMenuView(this)); }
From source file:com.lee.sdk.widget.viewpager.DrawablePageIndicator.java
@SuppressWarnings("deprecation") public DrawablePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;// www. j a v a 2 s . c o m //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawablePageIndicator, defStyle, 0); Drawable background = a.getDrawable(R.styleable.DrawablePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } mShadowLeft = a.getDimension(R.styleable.DrawablePageIndicator_shadow_left, 0.0f); mShadowRight = a.getDimension(R.styleable.DrawablePageIndicator_shadow_right, 0.0f); mDrawable = a.getDrawable(R.styleable.DrawablePageIndicator_android_src); if (mDrawable == null) { mDrawable = new ColorDrawable(Color.WHITE); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.kryten2k35.otaupdater.activities.AvailableActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mContext = this; setTheme(Preferences.getTheme(mContext)); super.onCreate(savedInstanceState); setContentView(R.layout.updater_available); setupActionBar();//from ww w .j a v a2s . co m mConnectivity = new Connectivity(mContext); remoteFileInfo = UpdaterApplication.getRemoteFileInfo(); int[] attrs = { R.attr.alertIcon }; TypedArray ta = this.obtainStyledAttributes(attrs); mAlert = new AlertDialog.Builder(this); mAlert.setIcon(ta.getDrawable(0)); mAlert.setPositiveButton(getString(R.string.ok), null); mAlert.setTitle("Attention"); ta.recycle(); // View finding TextView updateName = (TextView) findViewById(R.id.updater_update_available); TextView changeLogContent = (TextView) findViewById(R.id.updater_update_changelog_content); progressBar = (ProgressBar) findViewById(R.id.update_download_progress_bar); progressCounter = (TextView) findViewById(R.id.updater_download_progress_counter); downloadButton = (Button) findViewById(R.id.updater_download_update_button); md5Button = (Button) findViewById(R.id.updater_check_md5_button); md5Text = (TextView) findViewById(R.id.updater_update_md5); // Remote file information remoteVersion = remoteFileInfo.getVersion(); remoteCodename = remoteFileInfo.getCodename(); remoteChangelog = remoteFileInfo.getChangelog(); remoteMd5 = remoteFileInfo.getMd5(); remoteDirectUrl = remoteFileInfo.getDirectUrl(); remoteHttpUrl = remoteFileInfo.getHttpUrl(); remoteFileSize = remoteFileInfo.getRemoteFileSize(); remoteFilename = remoteFileInfo.getFilename(); // Are we using a HTTP download? isHttpDownload = !remoteHttpUrl.isEmpty() && remoteDirectUrl.isEmpty(); if (!isHttpDownload) { // Filename File file = new File(Preferences.getDownloadLocation(mContext) + remoteFilename); if (DEBUGGING) Log.d(TAG, "Local file " + file.toString()); // Does the file already exist? Did we download it already? if (file.length() == remoteFileSize) { Log.d(TAG, "Local filesize" + file.length() + " and remote filesize " + remoteFileSize); onDownloadFinished(); } else { progressCounter.setText(Utils.formatDataFromBytes(remoteFileSize)); md5Button.setEnabled(false); } } else { progressCounter.setText(getString(R.string.http_download)); md5Button.setEnabled(false); UpdaterApplication.DOWNLOAD_STATE = DOWNLOAD_IS_HTTP; } setUpDownloadButton(); // Setup MD5 checker button md5Button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new MD5Check(AvailableActivity.this).execute(remoteFilename, remoteMd5); } }); // Set the update name updateName.setText(remoteFileInfo.getUpdateName()); // MD5 information md5Text.setText(remoteMd5); // Changelog String[] changeLogStr = remoteChangelog.split(";"); changeLogContent.setText(Utils.getBulletList(remoteCodename + " " + remoteVersion, changeLogStr)); }
From source file:com.cooltechworks.views.ScratchImageView.java
public ScratchImageView(Context context, AttributeSet set) { super(context, set); TypedArray array = context.obtainStyledAttributes(set, R.styleable.ScratchImageView); mCustomScrachView = array.getDrawable(R.styleable.ScratchImageView_customScrach); init();/*from w w w.j a va 2 s . c om*/ }
From source file:com.cooltechworks.views.ScratchImageView.java
public ScratchImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ScratchImageView); mCustomScrachView = array.getDrawable(R.styleable.ScratchImageView_customScrach); init();//from www.j a v a 2 s . co m }