Java Code Examples for android.support.graphics.drawable.VectorDrawableCompat#create()
The following examples show how to use
android.support.graphics.drawable.VectorDrawableCompat#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FingerprintIconView.java From BiometricPromptCompat with Apache License 2.0 | 6 votes |
public void setState(State state, boolean animate) { if (state == this.state) return; @DrawableRes int resId = getDrawable(this.state, state, animate); if (resId == 0) { setImageDrawable(null); } else { Drawable icon = null; if (animate) { icon = AnimatedVectorDrawableCompat.create(getContext(), resId); } if (icon == null) { icon = VectorDrawableCompat.create(getResources(), resId, getContext().getTheme()); } setImageDrawable(icon); if (icon instanceof Animatable) { ((Animatable) icon).start(); } } this.state = state; }
Example 2
Source File: PickerBitmapView.java From 365browser with Apache License 2.0 | 6 votes |
/** * Initialization for the special tiles (camera/gallery icon). * @param bitmapDetails The details about the bitmap represented by this PickerBitmapView. */ public void initializeSpecialTile(PickerBitmap bitmapDetails) { int labelStringId; Drawable image; Resources resources = mContext.getResources(); if (isCameraTile()) { image = ApiCompatibilityUtils.getDrawable(resources, R.drawable.ic_photo_camera); labelStringId = R.string.photo_picker_camera; } else { image = VectorDrawableCompat.create( resources, R.drawable.ic_collections_grey, mContext.getTheme()); labelStringId = R.string.photo_picker_browse; } mSpecialTileIcon.setImageDrawable(image); mSpecialTileLabel.setText(labelStringId); // Reset visibility, since #initialize() sets mSpecialTile visibility to GONE. mSpecialTile.setVisibility(View.VISIBLE); mSpecialTileIcon.setVisibility(View.VISIBLE); mSpecialTileLabel.setVisibility(View.VISIBLE); }
Example 3
Source File: VideoViewHolder.java From Camera-Roll-Android-App with Apache License 2.0 | 6 votes |
@Override public void onSharedElementEnter() { final View view = itemView.findViewById(R.id.image); Resources res = itemView.getContext().getResources(); final Drawable playOverlay = VectorDrawableCompat.create(res, R.drawable.play_indicator, itemView.getContext().getTheme()); if (playOverlay == null) { return; } view.post(new Runnable() { @Override public void run() { int dimen = (int) view.getContext().getResources() .getDimension(R.dimen.twenty_four_dp) * 2; int left = view.getWidth() / 2 - dimen / 2; int top = view.getHeight() / 2 - dimen / 2; playOverlay.setBounds(left, top, left + dimen, top + dimen); view.getOverlay().add(playOverlay); } }); }
Example 4
Source File: MdVectorDrawableCompat.java From android-md-core with Apache License 2.0 | 5 votes |
@Nullable public static VectorDrawableCompat create(@NonNull Context context, @DrawableRes int resId) { Resources res = context.getResources(); Resources.Theme theme = context.getTheme(); VectorDrawableCompat drawable = VectorDrawableCompat.create(res, resId, theme); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { try { XmlPullParser parser = res.getXml(resId); AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } TypedArray a = theme.obtainStyledAttributes(attrs, new int[]{ android.R.attr.tint }, 0, 0); int tintId = a.getResourceId(0, 0); a.recycle(); drawable.setTintList(MdCompat.getColorStateList(context, tintId)); } catch (Exception e) { Ln.d(e); } } return drawable; }
Example 5
Source File: VectorDrawableInflateImpl.java From MagicaSakura with Apache License 2.0 | 5 votes |
@Override public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException { ColorStateList colorFilter = getTintColorList(context, attrs, android.R.attr.tint); Drawable d; if (resId == 0) { d = VectorDrawableCompat.createFromXmlInner(context.getResources(), parser, attrs); } else { d = VectorDrawableCompat.create(context.getResources(), resId, context.getTheme()); } if (d != null && colorFilter != null) { DrawableCompat.setTintList(d, colorFilter); } return d; }
Example 6
Source File: VectorDrawableInflateImpl.java From timecat with Apache License 2.0 | 5 votes |
@Override public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException { ColorStateList colorFilter = getTintColorList(context, attrs, android.R.attr.tint); Drawable d; if (resId == 0) { d = VectorDrawableCompat.createFromXmlInner(context.getResources(), parser, attrs); } else { d = VectorDrawableCompat.create(context.getResources(), resId, context.getTheme()); } if (d != null && colorFilter != null) { DrawableCompat.setTintList(d, colorFilter); } return d; }
Example 7
Source File: ImageUtils.java From Pasta-Music with Apache License 2.0 | 5 votes |
public static Drawable getVectorDrawable(Context context, int resId) { VectorDrawableCompat drawable; try { drawable = VectorDrawableCompat.create(context.getResources(), resId, context.getTheme()); } catch (Exception e) { e.printStackTrace(); return new ColorDrawable(Color.TRANSPARENT); } if (drawable != null) return drawable.getCurrent(); else return new ColorDrawable(Color.TRANSPARENT); }
Example 8
Source File: VectorDrawableUtils.java From Timeline with Apache License 2.0 | 5 votes |
public static Drawable getDrawable(Context context, int drawableResId) { Drawable drawable; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { drawable = context.getResources().getDrawable(drawableResId, context.getTheme()); } else { drawable = VectorDrawableCompat.create(context.getResources(), drawableResId, context.getTheme()); } return drawable; }
Example 9
Source File: SettingsFragment.java From Anti-recall with GNU Affero General Public License v3.0 | 5 votes |
private Bitmap getBitmap(int drawableRes) { Drawable drawable = VectorDrawableCompat.create(getResources(), drawableRes, null); Canvas canvas = new Canvas(); Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); canvas.setBitmap(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; }
Example 10
Source File: Theme.java From APlayer with GNU General Public License v3.0 | 5 votes |
public static Drawable getVectorDrawable(@NonNull Resources res, @DrawableRes int resId, @Nullable Resources.Theme theme) { if (Build.VERSION.SDK_INT >= 21) { return res.getDrawable(resId, theme); } return VectorDrawableCompat.create(res, resId, theme); }
Example 11
Source File: DrawableUtils.java From ChangeTabLayout with Apache License 2.0 | 5 votes |
static Drawable getDrawable(Context context, int drawableResId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return context.getDrawable(drawableResId); } else { try { return VectorDrawableCompat.create(context.getResources(), drawableResId, null); }catch (Resources.NotFoundException e){ return ContextCompat.getDrawable(context, drawableResId); } } }
Example 12
Source File: ImageUtils.java From Pasta-for-Spotify with Apache License 2.0 | 5 votes |
public static Drawable getVectorDrawable(Context context, int resId) { VectorDrawableCompat drawable; try { drawable = VectorDrawableCompat.create(context.getResources(), resId, context.getTheme()); } catch (Exception e) { e.printStackTrace(); return new ColorDrawable(Color.TRANSPARENT); } if (drawable != null) return drawable.getCurrent(); else return new ColorDrawable(Color.TRANSPARENT); }
Example 13
Source File: Utils.java From FireFiles with Apache License 2.0 | 5 votes |
public static Bitmap getVector2Bitmap(Context context, int id) { VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(context.getResources(), id, context.getTheme()); Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); vectorDrawable.draw(canvas); return bitmap; }
Example 14
Source File: Utils.java From FireFiles with Apache License 2.0 | 5 votes |
public static Bitmap getVector2Bitmap(Context context, int id) { VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(context.getResources(), id, context.getTheme()); Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); vectorDrawable.draw(canvas); return bitmap; }
Example 15
Source File: BluetoothChooserDialog.java From 365browser with Apache License 2.0 | 5 votes |
private Drawable getIconWithRowIconColorStateList(int icon) { Resources res = mActivity.getResources(); Drawable drawable = VectorDrawableCompat.create(res, icon, mActivity.getTheme()); DrawableCompat.setTintList(drawable, ApiCompatibilityUtils.getColorStateList(res, R.color.item_chooser_row_icon_color)); return drawable; }
Example 16
Source File: BindingSetters.java From materialup with Apache License 2.0 | 4 votes |
@BindingAdapter({"app:vd"}) public static void setVectorDrawable(ImageView view, @DrawableRes int id) { VectorDrawableCompat drawableCompat = VectorDrawableCompat.create(view.getResources(), id, view.getContext().getTheme()); view.setImageResource(id); }
Example 17
Source File: Util.java From Orin with GNU General Public License v3.0 | 4 votes |
public static Drawable getVectorDrawable(@NonNull Resources res, @DrawableRes int resId, @Nullable Resources.Theme theme) { if (Build.VERSION.SDK_INT >= 21) { return res.getDrawable(resId, theme); } return VectorDrawableCompat.create(res, resId, theme); }
Example 18
Source File: MainActivity.java From android-design-library with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Adding Toolbar to Main screen Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Setting ViewPager for each Tabs ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); // Set Tabs inside Toolbar TabLayout tabs = (TabLayout) findViewById(R.id.tabs); tabs.setupWithViewPager(viewPager); // Create Navigation drawer and inlfate layout NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); // Adding menu icon to Toolbar ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme()); indicator.setTint(ResourcesCompat.getColor(getResources(),R.color.white,getTheme())); supportActionBar.setHomeAsUpIndicator(indicator); supportActionBar.setDisplayHomeAsUpEnabled(true); } // Set behavior of Navigation drawer navigationView.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { // Set item in checked state menuItem.setChecked(true); // TODO: handle navigation // Closing drawer on item click mDrawerLayout.closeDrawers(); return true; } }); // Adding Floating Action Button to bottom right of main view FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.make(v, "Hello Snackbar!", Snackbar.LENGTH_LONG).show(); } }); }
Example 19
Source File: MainActivity.java From android-design-library with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Adding Toolbar to Main screen Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Setting ViewPager for each Tabs ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); // Set Tabs inside Toolbar TabLayout tabs = (TabLayout) findViewById(R.id.tabs); tabs.setupWithViewPager(viewPager); // Create Navigation drawer and inlfate layout NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); // Adding menu icon to Toolbar ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme()); indicator.setTint(ResourcesCompat.getColor(getResources(),R.color.white,getTheme())); supportActionBar.setHomeAsUpIndicator(indicator); supportActionBar.setDisplayHomeAsUpEnabled(true); } // Set behavior of Navigation drawer navigationView.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { // Set item in checked state menuItem.setChecked(true); // TODO: handle navigation // Closing drawer on item click mDrawerLayout.closeDrawers(); return true; } }); // Adding Floating Action Button to bottom right of main view FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.make(v, "Hello Snackbar!", Snackbar.LENGTH_LONG).show(); } }); }
Example 20
Source File: IndicatorView.java From TriangularCustomView with MIT License | 4 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mRect.right = getWidth(); canvas.drawRect(mRect,mRectPaint); Log.d("No of tabs=",""+noOfTabs); Log.d("X-axis value=",""+(2/(float)noOfTabs)); Log.d("midptx value=",""+midpt.x); midpt.y = 180; leftpt.x=midpt.x-40; leftpt.y=140; rightpt.x=midpt.x+40; rightpt.y=140; triangle.moveTo(leftpt.x, leftpt.y); // Top triangle.lineTo(midpt.x, midpt.y); // Bottom left triangle.lineTo(rightpt.x ,rightpt.y); // Bottom right triangle.lineTo(leftpt.x, leftpt.y); // Back to Top triangle.close(); canvas.drawPath(triangle,mRectPaint); for(int i =0; i<resources.length; i++) { vds[i] = VectorDrawableCompat.create(getContext().getResources(), resources[i], null); } for(int i=0; i<resources.length; i++) { //imgRes[i] = BitmapFactory.decodeResource(getResources(),resources[i]); //Use for png images imgRes[i] = getBitmap(vds[i]); } // canvas.drawBitmap(imgRes[0],); canvas.drawBitmap(imgRes[0],(getWidth()/noOfTabs)/2-(imgRes[0].getWidth()/2),70-(imgRes[0].getHeight())/2,null); for(int i =1; i<noOfTabs; i++) { canvas.drawBitmap(imgRes[i],(i / (float) noOfTabs) * getWidth()+(getWidth()/noOfTabs)/2-(imgRes[i].getWidth()/2),70-(imgRes[i].getHeight())/2,null); } }