@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.tv_transition).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { TransitionDrawable drawable = (TransitionDrawable) v.getBackground(); drawable.startTransition(3000); } }); ScaleDrawable scaleDrawable = (ScaleDrawable) findViewById(R.id.v_scale).getBackground(); scaleDrawable.setLevel(10); //lever默认为0,无法显示。level范围为0~10000。level越大,显示的越大 ClipDrawable clipDrawable = (ClipDrawable) findViewById(R.id.v_clip).getBackground(); clipDrawable.setLevel(5000); View vCustom = findViewById(R.id.v_custom); CustomDrawable customDrawable = new CustomDrawable(getResources().getColor(R.color.colorAccent)); vCustom.setBackground(customDrawable); }
public static void assertEquals(ScaleDrawable a,ScaleDrawable b) { assertEqualsDrawableWrapper(a, b); assertEquals(a.isStateful(), b.isStateful()); Drawable.ConstantState a_state = a.getConstantState(); Drawable.ConstantState b_state = b.getConstantState(); Class classScaleState = TestUtil.resolveClass(ScaleDrawable.class.getName() + "$ScaleState"); assertEquals((Float) TestUtil.getField(a_state, classScaleState, "mScaleWidth"), (Float) TestUtil.getField(b_state, classScaleState, "mScaleWidth")); assertEquals((Float) TestUtil.getField(a_state, classScaleState, "mScaleHeight"), (Float) TestUtil.getField(b_state, classScaleState, "mScaleHeight")); assertEquals((Integer) TestUtil.getField(a_state, classScaleState, "mGravity"), (Integer) TestUtil.getField(b_state, classScaleState, "mGravity")); // android:drawable if (Build.VERSION.SDK_INT < TestUtil.MARSHMALLOW) // 23 { assertEquals((Drawable) TestUtil.getField(a_state, classScaleState, "mDrawable"), (Drawable) TestUtil.getField(b_state, classScaleState, "mDrawable")); } }
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { // test transition View v = findViewById(R.id.test_transition); TransitionDrawable drawable = (TransitionDrawable) v.getBackground(); drawable.startTransition(1000); // test scale View testScale = findViewById(R.id.test_scale); ScaleDrawable testScaleDrawable = (ScaleDrawable) testScale.getBackground(); testScaleDrawable.setLevel(10); // test clip ImageView testClip = (ImageView) findViewById(R.id.test_clip); ClipDrawable testClipDrawable = (ClipDrawable) testClip.getDrawable(); testClipDrawable.setLevel(8000); // test custom drawable View testCustomDrawable = findViewById(R.id.test_custom_drawable); CustomDrawable customDrawable = new CustomDrawable(Color.parseColor("#0ac39e")); testCustomDrawable.setBackgroundDrawable(customDrawable); } }
/** * Applies current thumb tint from {@link Decorator#mTintInfo} to the current thumb drawable. * <p> * <b>Note</b>, that for post {@link android.os.Build.VERSION_CODES#LOLLIPOP LOLLIPOP} this * method does nothing. */ @SuppressWarnings("ConstantConditions") private void applyThumbTint() { this.ensureDecorator(); if (UiConfig.MATERIALIZED || mThumb == null || !mDecorator.hasTintInfo()) { return; } final Drawable thumb = mThumb instanceof ScaleDrawable ? ((ScaleDrawable) mThumb).getDrawable() : mThumb; final SeekBarTintInfo tintInfo = mDecorator.getTintInfo(); if ((!tintInfo.hasTintList && !tintInfo.hasTintMode)) { return; } final boolean isTintDrawable = thumb instanceof TintDrawable; final TintDrawable tintDrawable = isTintDrawable ? (TintDrawable) thumb : new TintDrawable(thumb); if (tintInfo.hasTintList) { tintDrawable.setTintList(tintInfo.tintList); } if (tintInfo.hasTintMode) { tintDrawable.setTintMode(tintInfo.tintMode); } if (tintDrawable.isStateful()) { tintDrawable.setState(getDrawableState()); } if (isTintDrawable) { return; } final int thumbOffset = getThumbOffset(); this.mThumb = mDecorator.hasPrivateFlag(PFLAG_DISCRETE) ? mAnimations.makeThumbScaleable(tintDrawable, Gravity.CENTER) : tintDrawable; super.setThumb(mThumb); tintDrawable.attachCallback(); setThumbOffset(thumbOffset); }
/** * Updates a scale level of the thumb's drawable. * * @param scale The scale value from the range {@code [0.0, 1.0]}. */ @SuppressWarnings("Range") void setThumbScale(float scale) { if (view.mThumb instanceof ScaleDrawable) { final int scaleLevel = Math.round(scale * MAX_LEVEL); view.mThumb.setLevel(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN ? scaleLevel : // Correct scale level for pre JELLY_BEAN Android versions. // scaleLevel(10000) = scale(1.0) [expected scale(1.0)] // scaleLevel(5000) = scale(0.0) [expected scale(0.5)] // scaleLevel(0) = scale(1.0) [expected scale(0.0)] scaleLevel + (int) ((10000 - scaleLevel) / 10000f * 5000) ); } }
private void setupDrawables() { parts = new ArrayList<>(); parts.add(ContextCompat.getDrawable(getContext(), R.drawable.carriage_part1)); parts.add(ContextCompat.getDrawable(getContext(), R.drawable.carriage_part2)); parts.add(ContextCompat.getDrawable(getContext(), R.drawable.carriage_part3)); carriageOffset = (int) getContext().getResources().getDimension(R.dimen.carriage_offset); pageOffset = (int) getContext().getResources().getDimension(R.dimen.page_offset); offset = (int) getContext().getResources().getDimension(R.dimen.offset); button = ContextCompat.getDrawable(getContext(), R.drawable.button); buttonPressed = ContextCompat.getDrawable(getContext(), R.drawable.button_pressed); page = new ScaleDrawable(ContextCompat.getDrawable(getContext(), R.drawable.page), TOP, -1, 1); page.setLevel(10000); pageBack = new ScaleDrawable(ContextCompat.getDrawable(getContext(), R.drawable.page_revers), TOP, -1, 1); pageBack.setLevel(0); keyboard = ContextCompat.getDrawable(getContext(), R.drawable.keyboard_bg); typewriter = ContextCompat.getDrawable(getContext(), R.drawable.machine); space = ContextCompat.getDrawable(getContext(), R.drawable.space); spacePressed = ContextCompat.getDrawable(getContext(), R.drawable.space_pressed); letter = ContextCompat.getDrawable(getContext(), R.drawable.letter); }
/** * Some drawable implementations have problems with mutation. This method returns false if * there is a known issue in the given drawable's implementation. */ public static boolean canSafelyMutateDrawable(@NonNull Drawable drawable) { if (Build.VERSION.SDK_INT < 15 && drawable instanceof InsetDrawable) { return false; } else if (Build.VERSION.SDK_INT < 15 && drawable instanceof GradientDrawable) { // GradientDrawable has a bug pre-ICS which results in mutate() resulting // in loss of color return false; } else if (Build.VERSION.SDK_INT < 17 && drawable instanceof LayerDrawable) { return false; } if (drawable instanceof DrawableContainer) { // If we have a DrawableContainer, let's traverse its child array final Drawable.ConstantState state = drawable.getConstantState(); if (state instanceof DrawableContainer.DrawableContainerState) { final DrawableContainer.DrawableContainerState containerState = (DrawableContainer.DrawableContainerState) state; for (final Drawable child : containerState.getChildren()) { if (!canSafelyMutateDrawable(child)) { return false; } } } } else if (drawable instanceof android.support.v4.graphics.drawable.DrawableWrapper) { return canSafelyMutateDrawable( ((android.support.v4.graphics.drawable.DrawableWrapper) drawable) .getWrappedDrawable()); } /*else if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) { return canSafelyMutateDrawable( ((android.support.v7.graphics.drawable.DrawableWrapper) drawable) .getWrappedDrawable()); }*/ else if (drawable instanceof ScaleDrawable) { return canSafelyMutateDrawable(((ScaleDrawable) drawable).getDrawable()); } return true; }
public void setEventsIcon(@DrawableRes int drawableRes) { Drawable drawable = ContextCompat.getDrawable(getContext(), drawableRes); int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); drawable.setBounds(0, 0, width / 2, height / 2); ScaleDrawable sd = new ScaleDrawable(drawable, Gravity.CENTER, 0.6f, 0.6f); sd.setLevel(8000); ViewHelper.tintDrawable(drawable, ViewHelper.getTertiaryTextColor(getContext())); setCompoundDrawablesWithIntrinsicBounds(sd, null, null, null); }
private void setSeekBarBg(){ try { int progressColor = CustomAttrValueUtil.getAttrColorValue(R.attr.colorPrimary,R.color.colorAccent,this); LayerDrawable layerDrawable = (LayerDrawable) seekBar.getProgressDrawable(); ScaleDrawable scaleDrawable = (ScaleDrawable)layerDrawable.findDrawableByLayerId(android.R.id.progress); GradientDrawable drawable = (GradientDrawable) scaleDrawable.getDrawable(); drawable.setColor(progressColor); }catch (Exception e){ e.printStackTrace(); } }
/** * Some drawable implementations have problems with mutation. This method returns false if * there is a known issue in the given drawable's implementation. */ public static boolean canSafelyMutateDrawable(@NonNull Drawable drawable) { if (Build.VERSION.SDK_INT < 15 && drawable instanceof InsetDrawable) { return false; } else if (Build.VERSION.SDK_INT < 15 && drawable instanceof GradientDrawable) { // GradientDrawable has a bug pre-ICS which results in mutate() resulting // in loss of color return false; } else if (Build.VERSION.SDK_INT < 17 && drawable instanceof LayerDrawable) { return false; } if (drawable instanceof DrawableContainer) { // If we have a DrawableContainer, let's traverse it's child array final Drawable.ConstantState state = drawable.getConstantState(); if (state instanceof DrawableContainer.DrawableContainerState) { final DrawableContainer.DrawableContainerState containerState = (DrawableContainer.DrawableContainerState) state; for (final Drawable child : containerState.getChildren()) { if (!canSafelyMutateDrawable(child)) { return false; } } } } else if (drawable instanceof android.support.v4.graphics.drawable.DrawableWrapper) { return canSafelyMutateDrawable( ((android.support.v4.graphics.drawable.DrawableWrapper) drawable) .getWrappedDrawable()); } else if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) { return canSafelyMutateDrawable( ((android.support.v7.graphics.drawable.DrawableWrapper) drawable) .getWrappedDrawable()); } else if (drawable instanceof ScaleDrawable) { return canSafelyMutateDrawable(((ScaleDrawable) drawable).getDrawable()); } return true; }
public static boolean m2634b(Drawable drawable) { if (drawable instanceof LayerDrawable) { return VERSION.SDK_INT >= 16; } else if (drawable instanceof InsetDrawable) { return VERSION.SDK_INT >= 14; } else { if (drawable instanceof StateListDrawable) { return VERSION.SDK_INT >= 8; } else { if (drawable instanceof GradientDrawable) { return VERSION.SDK_INT >= 14; } else { if (!(drawable instanceof DrawableContainer)) { return drawable instanceof C0063q ? m2634b(((C0063q) drawable).m469a()) : drawable instanceof C0244a ? m2634b(((C0244a) drawable).m1984a()) : drawable instanceof ScaleDrawable ? m2634b(((ScaleDrawable) drawable).getDrawable()) : true; } else { ConstantState constantState = drawable.getConstantState(); if (!(constantState instanceof DrawableContainerState)) { return true; } for (Drawable b : ((DrawableContainerState) constantState).getChildren()) { if (!m2634b(b)) { return false; } } return true; } } } } }
/*** * Method called from APIs below 21 to setup Progress Color */ private void setupProgressColor() { //load up the drawable and apply color LayerDrawable ld = (LayerDrawable) getProgressDrawable(); ScaleDrawable shape = (ScaleDrawable) (ld.findDrawableByLayerId(android.R.id.progress)); shape.setColorFilter(mProgressColor, PorterDuff.Mode.SRC_IN); //set the background to transparent NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) (ld.findDrawableByLayerId(android.R.id.background)); ninePatchDrawable.setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN); }
@Override public void setEnabled(final boolean enabled) { mIsEnabled = enabled; triggerMethodOnceViewIsDisplayed(this, new Callable<Void>() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public Void call() throws Exception { if (!lollipopAndAbove()) { gradientDrawable = new GradientDrawable(); gradientDrawable.setShape(GradientDrawable.OVAL); gradientDrawable.setSize(mOriginalThumbHeight / 3, mOriginalThumbHeight / 3); gradientDrawable.setColor(mIsEnabled ? mThumbColor : Color.LTGRAY); gradientDrawable.setDither(true); gradientDrawable.setAlpha(mThumbAlpha); setThumb(gradientDrawable); //load up the drawable and apply color LayerDrawable ld = (LayerDrawable) getProgressDrawable(); ScaleDrawable shape = (ScaleDrawable) (ld.findDrawableByLayerId(android.R.id.progress)); shape.setColorFilter(mIsEnabled ? mProgressColor : Color.LTGRAY, PorterDuff.Mode.SRC_IN); //set the background to transparent NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) (ld.findDrawableByLayerId(android.R.id.background)); ninePatchDrawable.setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN); //background //load up the drawable and apply color SeekBarBackgroundDrawable seekBarBackgroundDrawable = new SeekBarBackgroundDrawable(getContext(), mIsEnabled ? mProgressBackgroundColor : Color.LTGRAY, mActualBackgroundColor, getPaddingLeft(), getPaddingRight()); if (belowJellybean()) setBackgroundDrawable(seekBarBackgroundDrawable); else setBackground(seekBarBackgroundDrawable); } SeekBarCompat.super.setEnabled(enabled); return null; } }); }
/*** * Method called from APIs below 21 to setup Progress Color */ private void setupProgressColor() { try { //load up the drawable and apply color LayerDrawable ld = (LayerDrawable) getProgressDrawable(); ScaleDrawable shape = (ScaleDrawable) (ld.findDrawableByLayerId(android.R.id.progress)); shape.setColorFilter(mProgressColor, PorterDuff.Mode.SRC_IN); //set the background to transparent NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) (ld.findDrawableByLayerId(android.R.id.background)); ninePatchDrawable.setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN); } catch (NullPointerException e) { //TODO: Handle exception } }
/*** * Enables or disables the whole seekBar! * * @param enabled */ @Override public void setEnabled(final boolean enabled) { mIsEnabled = enabled; triggerMethodOnceViewIsDisplayed(this, new Callable<Void>() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public Void call() throws Exception { if (!lollipopAndAbove()) { gradientDrawable = new GradientDrawable(); gradientDrawable.setShape(GradientDrawable.OVAL); gradientDrawable.setSize(mOriginalThumbHeight / 3, mOriginalThumbHeight / 3); gradientDrawable.setColor(mIsEnabled ? mThumbColor : Color.LTGRAY); gradientDrawable.setDither(true); gradientDrawable.setAlpha(mThumbAlpha); setThumb(gradientDrawable); //load up the drawable and apply color LayerDrawable ld = (LayerDrawable) getProgressDrawable(); ScaleDrawable shape = (ScaleDrawable) (ld.findDrawableByLayerId(android.R.id.progress)); shape.setColorFilter(mIsEnabled ? mProgressColor : Color.LTGRAY, PorterDuff.Mode.SRC_IN); //set the background to transparent NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) (ld.findDrawableByLayerId(android.R.id.background)); ninePatchDrawable.setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN); //background //load up the drawable and apply color SeekBarBackgroundDrawable seekBarBackgroundDrawable = new SeekBarBackgroundDrawable(getContext(), mIsEnabled ? mProgressBackgroundColor : Color.LTGRAY, mActualBackgroundColor, getPaddingLeft(), getPaddingRight()); if (belowJellybean()) setBackgroundDrawable(seekBarBackgroundDrawable); else setBackground(seekBarBackgroundDrawable); } SeekBarCompat.super.setEnabled(enabled); return null; } }); }
@Override public boolean isAttributeIgnored(ScaleDrawable resource, String namespaceURI, String name) { if (super.isAttributeIgnored(resource,namespaceURI,name)) return true; if (NamespaceUtil.XMLNS_ANDROID.equals(namespaceURI)) { // Se usan en tiempo de construcción return ("drawable".equals(name) || "scaleGravity".equals(name) || "scaleHeight".equals(name) || "scaleWidth".equals(name)); } return false; }
private Drawable tileifyProgressDrawable(Drawable wrapped) { if (wrapped instanceof LayerDrawable) { LayerDrawable drawable = (LayerDrawable) wrapped; final int N = drawable.getNumberOfLayers(); Drawable[] outDrawables = new Drawable[N]; for (int i = 0; i < N; i++) { final int id = drawable.getId(i); Drawable childDrawable = drawable.getDrawable(i); if (id == android.R.id.background) { outDrawables[i] = new NumberBGDrawable(childDrawable); } else if (id == android.R.id.progress) { if (childDrawable instanceof ScaleDrawable) { outDrawables[i] = tileifyScaleDrawable((ScaleDrawable) childDrawable); } else if (childDrawable instanceof ClipDrawable) { outDrawables[i] = tileifyClipDrawable((ClipDrawable) childDrawable); } else { outDrawables[i] = childDrawable; } } else { outDrawables[i] = childDrawable; } } LayerDrawable newDrawable = new NumberLayerDrawable(outDrawables); return newDrawable; } return wrapped; }
/** * Applies current discrete indicator tint from {@link Decorator#mTintInfo} to the current discrete * indicator's drawable. */ @SuppressLint("NewApi") @SuppressWarnings("ConstantConditions") private void applyDiscreteIndicatorTint() { this.ensureDecorator(); if (mDiscreteIndicator == null || !mDecorator.hasTintInfo()) { return; } final Drawable indicator = mDiscreteIndicator instanceof ScaleDrawable ? ((ScaleDrawable) mDiscreteIndicator).getDrawable() : mDiscreteIndicator; final SeekBarTintInfo tintInfo = mDecorator.getTintInfo(); if ((!tintInfo.hasDiscreteIndicatorTintList && !tintInfo.hasDiscreteIndicatorTintMode)) { return; } if (UiConfig.MATERIALIZED) { this.mDiscreteIndicator = mDiscreteIndicator.mutate(); if (tintInfo.hasDiscreteIndicatorTintList) { mDiscreteIndicator.setTintList(tintInfo.discreteIndicatorTintList); } if (tintInfo.hasDiscreteIndicatorTintMode) { mDiscreteIndicator.setTintMode(tintInfo.discreteIndicatorTintMode); } if (mDiscreteIndicator.isStateful()) { mDiscreteIndicator.setState(getDrawableState()); } return; } final boolean isTintDrawable = indicator instanceof TintDrawable; final TintDrawable tintDrawable = isTintDrawable ? (TintDrawable) indicator : new TintDrawable(indicator); if (tintInfo.hasDiscreteIndicatorTintList) { tintDrawable.setTintList(tintInfo.discreteIndicatorTintList); } if (tintInfo.hasDiscreteIndicatorTintMode) { tintDrawable.setTintMode(tintInfo.discreteIndicatorTintMode); } if (isTintDrawable) { return; } this.mDiscreteIndicator = mDecorator.hasPrivateFlag(PFLAG_DISCRETE) ? mAnimations.makeDiscreteIndicatorScaleable(tintDrawable, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL) : tintDrawable; mDiscreteIndicator.setCallback(this); updateDiscreteIndicatorState(getDrawableState(), false); }
private void clickBarOn(FrameLayout frameLayout) { pins.get((int) frameLayout.getTag()).setVisibility(View.VISIBLE); isOldBarClicked = true; int childCount = frameLayout.getChildCount(); for (int i = 0; i < childCount; i++) { View childView = frameLayout.getChildAt(i); if (childView instanceof LinearLayout) { LinearLayout linearLayout = (LinearLayout) childView; Bar bar = (Bar) linearLayout.getChildAt(0); TextView titleTxtView = (TextView) linearLayout.getChildAt(1); LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable(); layerDrawable.mutate(); ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1); GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable(); if (mPinBackgroundColor != 0) { if (progressLayer != null) { progressLayer.setColor(ContextCompat.getColor(mContext, mProgressClickColor)); } } else { if (progressLayer != null) { progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.holo_green_dark)); } } if (mBarTitleSelectedColor > 0) { titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleSelectedColor)); } else { titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.holo_green_dark)); } } } }
public void disableBar(int index) { final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount(); for (int i = 0; i < barsCount; i++) { FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i); int rootChildCount = rootFrame.getChildCount(); for (int j = 0; j < rootChildCount; j++) { if ((int) rootFrame.getTag() != index) continue; rootFrame.setEnabled(false); rootFrame.setClickable(false); View childView = rootFrame.getChildAt(j); if (childView instanceof LinearLayout) { //bar LinearLayout barContainerLinear = ((LinearLayout) childView); int barContainerCount = barContainerLinear.getChildCount(); for (int k = 0; k < barContainerCount; k++) { View view = barContainerLinear.getChildAt(k); if (view instanceof Bar) { Bar bar = (Bar) view; LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable(); layerDrawable.mutate(); ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1); GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable(); if (progressLayer != null) { if (mProgressDisableColor > 0) progressLayer.setColor(ContextCompat.getColor(mContext, mProgressDisableColor)); else progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray)); } } else { TextView titleTxtView = (TextView) view; if (mProgressDisableColor > 0) titleTxtView.setTextColor(ContextCompat.getColor(mContext, mProgressDisableColor)); else titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray)); } } } } } }
public void enableBar(int index) { final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount(); for (int i = 0; i < barsCount; i++) { FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i); int rootChildCount = rootFrame.getChildCount(); for (int j = 0; j < rootChildCount; j++) { if ((int) rootFrame.getTag() != index) continue; rootFrame.setEnabled(true); rootFrame.setClickable(true); View childView = rootFrame.getChildAt(j); if (childView instanceof LinearLayout) { //bar LinearLayout barContainerLinear = ((LinearLayout) childView); int barContainerCount = barContainerLinear.getChildCount(); for (int k = 0; k < barContainerCount; k++) { View view = barContainerLinear.getChildAt(k); if (view instanceof Bar) { Bar bar = (Bar) view; LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable(); layerDrawable.mutate(); ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1); GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable(); if (progressLayer != null) { if (mProgressColor > 0) progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor)); else progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray)); } } else { TextView titleTxtView = (TextView) view; if (mProgressDisableColor > 0) titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor)); else titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray)); } } } } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); Resources res = getResources(); TabHost tabHost = getTabHost(); // Profiles tab ScaleDrawable sd = new ScaleDrawable(res.getDrawable(R.drawable.quadiconlow), 0, 10f, 10f); Intent intentWindows = new Intent().setClass(this, Profile.class); TabHost.TabSpec tabSpecWindows = tabHost .newTabSpec("Windows") .setIndicator("", sd.getDrawable()) .setContent(intentWindows); ScaleDrawable sd2 = new ScaleDrawable(res.getDrawable(R.drawable.routeslow), 0, 10f, 10f); Intent intentWindows2 = new Intent().setClass(this, Profile.class); TabHost.TabSpec tabSpecWindows2 = tabHost .newTabSpec("Windows") .setIndicator("", sd2.getDrawable()) .setContent(intentWindows); ScaleDrawable sd3 = new ScaleDrawable(res.getDrawable(R.drawable.waveslow), 0, 10f, 10f); Intent intentWindows3 = new Intent().setClass(this, Profile.class); TabHost.TabSpec tabSpecWindows3 = tabHost .newTabSpec("Windows") .setIndicator("", sd3.getDrawable()) .setContent(intentWindows); ScaleDrawable sd4 = new ScaleDrawable(res.getDrawable(R.drawable.controllow), 0, 10f, 10f); Intent intentWindows4 = new Intent().setClass(this, Profile.class); TabHost.TabSpec tabSpecWindows4 = tabHost .newTabSpec("Windows") .setIndicator("", sd4.getDrawable()) .setContent(intentWindows); /*ScaleDrawable sd5 = new ScaleDrawable(res.getDrawable(R.drawable.aboutlow), 0, 10f, 10f); Intent intentWindows5 = new Intent().setClass(this, Profile.class); TabHost.TabSpec tabSpecWindows5 = tabHost .newTabSpec("Windows") .setIndicator("", sd5.getDrawable()) .setContent(intentWindows); ScaleDrawable sd6 = new ScaleDrawable(res.getDrawable(R.drawable.donatelow), 0, 10f, 10f); Intent intentWindows6 = new Intent().setClass(this, Profile.class); TabHost.TabSpec tabSpecWindows6 = tabHost .newTabSpec("Windows") .setIndicator("", sd4.getDrawable()) .setContent(intentWindows);*/ // add all tabs tabHost.addTab(tabSpecWindows); tabHost.addTab(tabSpecWindows2); tabHost.addTab(tabSpecWindows3); tabHost.addTab(tabSpecWindows4); //tabHost.addTab(tabSpecWindows5); //tabHost.addTab(tabSpecWindows6); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pre_file_selector); toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); toolbar.setTitleTextColor(getResources().getColor(R.color.fs_colorAccent)); getSupportActionBar().setDisplayShowTitleEnabled(false); } Drawable drawableMyFiles = getResources().getDrawable(R.drawable.my_files_icon_sequencing_com_color); drawableMyFiles.setBounds(0, 0, (int)(drawableMyFiles.getIntrinsicWidth()*0.65), (int)(drawableMyFiles.getIntrinsicHeight()*0.65)); ScaleDrawable sdMyFiles = new ScaleDrawable(drawableMyFiles, 0, 50, 50); Drawable drawableSampleFiles = getResources().getDrawable(R.drawable.sample_files_icon_sequencing_com_blue); drawableSampleFiles.setBounds(0, 0, (int) (drawableSampleFiles.getIntrinsicWidth() * 0.6), (int) (drawableSampleFiles.getIntrinsicHeight() * 0.6)); ScaleDrawable sdSampleFiles = new ScaleDrawable(drawableSampleFiles, 0, 50, 50); videoView = (CVideoView) findViewById(R.id.video_view); btnMyFiles = (Button) findViewById(R.id.btnMyFiles); btnMyFiles.setCompoundDrawables(sdMyFiles.getDrawable(), null, null, null); tvTextTitle = (TextView) findViewById(R.id.tvTextTitle); tvText = (TextView) findViewById(R.id.tvText); btnSampleFiles = (Button) findViewById(R.id.btnSampleFiles); btnSampleFiles.setCompoundDrawables(sdSampleFiles.getDrawable(), null, null, null); btnMyFiles.setOnClickListener(this); btnSampleFiles.setOnClickListener(this); fabInfo = (FloatingActionButton) findViewById(R.id.fab); fabInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(toolTipView != null){ toolTipView.remove(); toolTipView = null; } else { displayInfo(); } } }); fileSelectorIntent = new Intent(getBaseContext(), FileSelectorActivity.class); fileSelectorIntent.putExtra("serverResponse", getIntent().getStringExtra("serverResponse")); fileSelectorIntent.putExtra("fileId", getIntent().getStringExtra("fileId")); fileSelectorIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); }
public ClassDescScaleDrawable(ClassDescDrawableMgr classMgr,ClassDescElementDrawableBased<? super ScaleDrawable> parent) { super(classMgr,"scale",parent); }
@Override public Class<ScaleDrawable> getDrawableOrElementDrawableClass() { return ScaleDrawable.class; }
public static void assertEquals(Drawable a,Drawable b) { if (!a.getClass().equals(b.getClass())) throw new ItsNatDroidException("Not equal: \"" + a + "\" - \"" + b + "\""); if (a instanceof AnimationDrawable) { assertEquals((AnimationDrawable) a, (AnimationDrawable) b); } else if (a instanceof BitmapDrawable) { assertEquals((BitmapDrawable)a,(BitmapDrawable)b); } else if (a instanceof ClipDrawable) { assertEquals((ClipDrawable)a,(ClipDrawable)b); } else if (a instanceof ColorDrawable) { assertEquals(((ColorDrawable) a).getColor(), ((ColorDrawable) b).getColor()); } else if (a instanceof GradientDrawable) { assertEquals((GradientDrawable)a,(GradientDrawable)b); } else if (a instanceof InsetDrawable) { assertEquals((InsetDrawable)a,(InsetDrawable)b); } else if (a instanceof LayerDrawable) { assertEquals((LayerDrawable)a,(LayerDrawable)b); } else if (a instanceof LevelListDrawable) { assertEquals((LevelListDrawable)a,(LevelListDrawable)b); } else if (a instanceof NinePatchDrawable) { assertEquals((NinePatchDrawable)a,(NinePatchDrawable)b); } else if (a instanceof RotateDrawable) { assertEquals((RotateDrawable)a,(RotateDrawable)b); } else if (a instanceof ScaleDrawable) { assertEquals((ScaleDrawable)a,(ScaleDrawable)b); } else if (a instanceof StateListDrawable) { assertEquals((StateListDrawable)a,(StateListDrawable)b); } else if (a instanceof TransitionDrawable) { assertEquals((TransitionDrawable)a,(TransitionDrawable)b); } else throw new ItsNatDroidException("Cannot test drawable " + a); }
/** * Returns the current discrete indicator's drawable. * <p> * <b>Note, that on pre {@link android.os.Build.VERSION_CODES#LOLLIPOP LOLLIPOP} Android versions * this method will return an instance of {@link TintDrawable TintDrawable} if tint has been applied * via {@link #setDiscreteIndicatorTintList(ColorStateList)}.</b> * <p> * The original wrapped indicator drawable can be obtained via {@link TintDrawable#getDrawable()}. * * @return Discrete indicator's drawable. * @see #setDiscreteIndicator(android.graphics.drawable.Drawable) */ @Nullable public Drawable getDiscreteIndicator() { if (mDiscreteIndicator instanceof ScaleDrawable) return ((ScaleDrawable) mDiscreteIndicator).getDrawable(); else return mDiscreteIndicator; }
/** * Wraps the given <var>drawable</var> into instance of {@link ScaleDrawable} if it is valid * and not ScaleDrawable yet. * * @param drawable The drawable to wrap and make scaleable. * @param gravity The gravity determining a pivot along which can be the given drawable scaled. * @return Instance of ScaleDrawable with the specified drawable wrapped or {@code null} * if the given drawable was also {@code null}. */ static Drawable makeDrawableScaleable(Drawable drawable, int gravity) { if (drawable == null || drawable instanceof ScaleDrawable) return drawable; final ScaleDrawable scaleDrawable = new ScaleDrawable(drawable, gravity, 1f, 1f); scaleDrawable.setLevel(MAX_LEVEL); return scaleDrawable; }
private void clickBarOff(FrameLayout frameLayout) { pins.get((int) frameLayout.getTag()).setVisibility(View.INVISIBLE); isOldBarClicked = false; int childCount = frameLayout.getChildCount(); for (int i = 0; i < childCount; i++) { View childView = frameLayout.getChildAt(i); if (childView instanceof LinearLayout) { LinearLayout linearLayout = (LinearLayout) childView; Bar bar = (Bar) linearLayout.getChildAt(0); TextView titleTxtView = (TextView) linearLayout.getChildAt(1); LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable(); layerDrawable.mutate(); ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1); GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable(); if (progressLayer != null) { progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor)); } titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor)); } } }
public static MaterialProgressDrawable create(@NonNull Context context) { Drawable[] layers = new Drawable[3]; layers[0] = new ColorDrawable(ThemeUtils.getDisabledThemeAttrColor(context, R.attr.colorControlNormal)); Drawable secondaryProgress = new ColorDrawable(ThemeUtils.getDisabledThemeAttrColor(context, R.attr.colorControlActivated)); layers[1] = new ScaleDrawable(secondaryProgress, Gravity.START, 1f, -1f); Drawable progress = new ColorDrawable(ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated)); layers[2] = new ScaleDrawable(progress, Gravity.START, 1f, -1f); return new MaterialProgressDrawable(layers); }
@Override public ElementDrawableChildRoot createElementDrawableChildRoot(DOMElemDrawable rootElem, AttrDrawableContext attrCtx) { ElementDrawableChildRoot elementDrawableRoot = new ElementDrawableChildRoot(); XMLInflaterContext xmlInflaterContext = attrCtx.getXMLInflaterContext(); XMLInflaterDrawable xmlInflaterDrawable = attrCtx.getXMLInflaterDrawable(); xmlInflaterDrawable.processChildElements(rootElem, elementDrawableRoot,attrCtx); ArrayList<ElementDrawableChildBase> childList = elementDrawableRoot.getElementDrawableChildList(); Drawable childDrawable = getDrawableChild("drawable", rootElem, xmlInflaterContext, childList); XMLInflaterRegistry xmlInflaterRegistry = classMgr.getXMLInflaterRegistry(); DOMAttr attrGravity = rootElem.getDOMAttribute(NamespaceUtil.XMLNS_ANDROID, "scaleGravity"); int gravity = attrGravity != null ? AttrDesc.parseMultipleName(attrGravity.getValue(), GravityUtil.nameValueMap) : Gravity.LEFT; // Valor concreto no puede ser un recurso DOMAttr attrScaleHeight = rootElem.getDOMAttribute(NamespaceUtil.XMLNS_ANDROID, "scaleHeight"); float scaleHeight = attrScaleHeight != null ? getPercent(xmlInflaterRegistry.getDimensionOrString(attrScaleHeight.getResourceDesc(), xmlInflaterContext)) : -1; // Se puede poner en un values/ como un <string> o como un <dimen> (aunque luego se procese como un String) DOMAttr attrScaleWidth = rootElem.getDOMAttribute(NamespaceUtil.XMLNS_ANDROID, "scaleWidth"); float scaleWidth = attrScaleWidth != null ? getPercent(xmlInflaterRegistry.getDimensionOrString(attrScaleWidth.getResourceDesc(),xmlInflaterContext)) : -1; ScaleDrawable drawable = new ScaleDrawable(childDrawable,gravity,scaleWidth,scaleHeight); setCallback(childDrawable,drawable); elementDrawableRoot.setDrawable(drawable); return elementDrawableRoot; }
/** * <b>Note, that on pre {@link android.os.Build.VERSION_CODES#LOLLIPOP LOLLIPOP} Android versions * this method will return an instance of {@link TintDrawable TintDrawable} if tint has been applied * via {@link #setThumbTintList(ColorStateList)}.</b> * <p> * The original wrapped drawable can be obtained via {@link TintDrawable#getDrawable()}. */ @Override public Drawable getThumb() { if (mThumb instanceof ScaleDrawable) return ((ScaleDrawable) mThumb).getDrawable(); return mThumb; }
/** * Updates a scale level of the given <var>drawable</var> according to the specified scale * value. * * @param drawable The drawable of which scale level to update. * @param scale The scale value from the range {@code [0.0, 1.0]}. */ private void updateDrawableScale(Drawable drawable, float scale) { if (drawable instanceof ScaleDrawable) drawable.setLevel(Math.round(scale * MAX_LEVEL)); }