List of usage examples for android.graphics.drawable LayerDrawable LayerDrawable
public LayerDrawable(@NonNull Drawable[] layers)
From source file:com.pendtium.base.fragments.BaseFragment.java
protected void changeActionBarColor(int color) { Drawable colorDrawable = new ColorDrawable(color); Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { // ld.setCallback(drawableCallback); // } else { activity.getSupportActionBar().setBackgroundDrawable(ld); // } } else {/*ww w.java2 s . c o m*/ TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); // workaround for broken ActionBarContainer drawable handling on // pre-API 17 builds // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { activity.getSupportActionBar().setBackgroundDrawable(td); } td.startTransition(200); } oldBackground = ld; }
From source file:cn.psvmc.demo.MainActivity.java
private void changeColor(int newColor) { tabs.setIndicatorColor(newColor);// w w w. j av a 2 s. c o m ActionBar actionbar = getActionBar(); if (actionbar == null) { return; } // change ActionBar color just if an ActionBar is available if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { ld.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(ld); } } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(td); } td.startTransition(200); } oldBackground = ld; // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler getActionBar().setDisplayShowTitleEnabled(false); getActionBar().setDisplayShowTitleEnabled(true); } currentColor = newColor; }
From source file:com.android.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java
public ExpandedAlarmViewHolder(View itemView, boolean hasVibrator) { super(itemView); final Context context = itemView.getContext(); mHasVibrator = hasVibrator;/* w w w. j av a 2 s. com*/ mDayOrder = DayOrderUtils.getDayOrder(context); final Resources.Theme theme = context.getTheme(); int[] attrs = new int[] { android.R.attr.selectableItemBackground }; final TypedArray typedArray = theme.obtainStyledAttributes(attrs); final LayerDrawable background = new LayerDrawable( new Drawable[] { ContextCompat.getDrawable(context, R.drawable.alarm_background_expanded), typedArray.getDrawable(0) }); itemView.setBackground(background); typedArray.recycle(); final int firstDay = Utils.getZeroIndexedFirstDayOfWeek(context); delete = (ImageButton) itemView.findViewById(R.id.delete); repeat = (CheckBox) itemView.findViewById(R.id.repeat_onoff); vibrate = (CheckBox) itemView.findViewById(R.id.vibrate_onoff); ringtone = (TextView) itemView.findViewById(R.id.choose_ringtone); editLabel = (TextView) itemView.findViewById(R.id.edit_label); repeatDays = (LinearLayout) itemView.findViewById(R.id.repeat_days); // Build button for each day. LayoutInflater mInflater = LayoutInflater.from(context); for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final CompoundButton dayButton = (CompoundButton) mInflater.inflate(R.layout.day_button, repeatDays, false /* attachToRoot */); dayButton.setText(Utils.getShortWeekday(i, firstDay)); dayButton.setContentDescription(Utils.getLongWeekday(i, firstDay)); repeatDays.addView(dayButton); dayButtons[i] = dayButton; } // Collapse handler itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getItemHolder().collapse(); } }); arrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getItemHolder().collapse(); } }); // Edit time handler clock.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().onClockClicked(getItemHolder().item); } }); // Edit label handler editLabel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getAlarmTimeClickHandler().onEditLabelClicked(getItemHolder().item); } }); // Vibrator checkbox handler vibrate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().setAlarmVibrationEnabled(getItemHolder().item, ((CheckBox) v).isChecked()); } }); // Ringtone editor handler ringtone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getAlarmTimeClickHandler().onRingtoneClicked(getItemHolder().item); } }); // Delete alarm handler delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().onDeleteClicked(getItemHolder().item); v.announceForAccessibility(context.getString(R.string.alarm_deleted)); } }); // Repeat checkbox handler repeat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean checked = ((CheckBox) view).isChecked(); getAlarmTimeClickHandler().setAlarmRepeatEnabled(getItemHolder().item, checked); } }); // Day buttons handler for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final int buttonIndex = i; dayButtons[i].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean isChecked = ((CompoundButton) view).isChecked(); getAlarmTimeClickHandler().setDayOfWeekEnabled(getItemHolder().item, isChecked, buttonIndex); } }); } }
From source file:com.wizardsofm.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java
public ExpandedAlarmViewHolder(View itemView, boolean hasVibrator) { super(itemView); final Context context = itemView.getContext(); mHasVibrator = hasVibrator;/*from w w w . j ava 2 s.c o m*/ mDayOrder = DayOrderUtils.getDayOrder(context); final Resources.Theme theme = context.getTheme(); int[] attrs = new int[] { android.R.attr.selectableItemBackground }; final TypedArray typedArray = theme.obtainStyledAttributes(attrs); final LayerDrawable background = new LayerDrawable(new Drawable[] { ContextCompat.getDrawable(context, com.wizardsofm.deskclock.R.drawable.alarm_background_expanded), typedArray.getDrawable(0) }); itemView.setBackground(background); typedArray.recycle(); final int firstDay = Utils.getZeroIndexedFirstDayOfWeek(context); delete = (ImageButton) itemView.findViewById(com.wizardsofm.deskclock.R.id.delete); repeat = (CheckBox) itemView.findViewById(com.wizardsofm.deskclock.R.id.repeat_onoff); vibrate = (CheckBox) itemView.findViewById(com.wizardsofm.deskclock.R.id.vibrate_onoff); ringtone = (TextView) itemView.findViewById(com.wizardsofm.deskclock.R.id.choose_ringtone); editLabel = (TextView) itemView.findViewById(com.wizardsofm.deskclock.R.id.edit_label); repeatDays = (LinearLayout) itemView.findViewById(com.wizardsofm.deskclock.R.id.repeat_days); // Build button for each day. LayoutInflater mInflater = LayoutInflater.from(context); for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final CompoundButton dayButton = (CompoundButton) mInflater .inflate(com.wizardsofm.deskclock.R.layout.day_button, repeatDays, false /* attachToRoot */); dayButton.setText(Utils.getShortWeekday(i, firstDay)); dayButton.setContentDescription(Utils.getLongWeekday(i, firstDay)); repeatDays.addView(dayButton); dayButtons[i] = dayButton; } // Collapse handler itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getItemHolder().collapse(); } }); arrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getItemHolder().collapse(); } }); // Edit time handler clock.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().onClockClicked(getItemHolder().item); } }); // Edit label handler editLabel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getAlarmTimeClickHandler().onEditLabelClicked(getItemHolder().item); } }); // Vibrator checkbox handler vibrate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().setAlarmVibrationEnabled(getItemHolder().item, ((CheckBox) v).isChecked()); } }); // Ringtone editor handler ringtone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getAlarmTimeClickHandler().onRingtoneClicked(getItemHolder().item); } }); // Delete alarm handler delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().onDeleteClicked(getItemHolder().item); v.announceForAccessibility(context.getString(com.wizardsofm.deskclock.R.string.alarm_deleted)); } }); // Repeat checkbox handler repeat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean checked = ((CheckBox) view).isChecked(); getAlarmTimeClickHandler().setAlarmRepeatEnabled(getItemHolder().item, checked); } }); // Day buttons handler for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final int buttonIndex = i; dayButtons[i].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean isChecked = ((CompoundButton) view).isChecked(); getAlarmTimeClickHandler().setDayOfWeekEnabled(getItemHolder().item, isChecked, buttonIndex); } }); } }
From source file:mj.com.myapplication.MainActivity.java
private void changeColor(int newColor) { tabs.setIndicatorColor(newColor);/*from ww w . j a va 2 s. c om*/ // change ActionBar color just if an ActionBar is available if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { ld.setCallback(drawableCallback); } else { //getActionBar().setBackgroundDrawable(ld); } } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); // workaround for broken ActionBarContainer drawable handling on // pre-API 17 builds // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { //getActionBar().setBackgroundDrawable(td); } td.startTransition(200); } oldBackground = ld; // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler //getActionBar().setDisplayShowTitleEnabled(false); //getActionBar().setDisplayShowTitleEnabled(true); } currentColor = newColor; }
From source file:com.example.pagerslidingtabstrip.MainActivity.java
private void changeColor(int newColor) { tabs.setIndicatorColor(newColor);//from w ww. ja v a 2 s . c o m // change ActionBar color just if an ActionBar is available if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { ld.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(ld); } } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); // workaround for broken ActionBarContainer drawable handling on // pre-API 17 builds // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(td); } td.startTransition(200); } oldBackground = ld; // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler } currentColor = newColor; }
From source file:com.zoe.viewpager.MainActivity.java
private void changeColor(int newColor) { tabs.setIndicatorColor(newColor);//from ww w. j a v a 2 s .c o m // ActionBarActionBar if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { ld.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(ld); } } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); // workaround for broken ActionBarContainer drawable handling on // pre-API 17 builds // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(td); } td.startTransition(200); } oldBackground = ld; getActionBar().setDisplayShowTitleEnabled(false); getActionBar().setDisplayShowTitleEnabled(true); } currentColor = newColor; }
From source file:android.support.v7.widget.AppCompatProgressBarHelper.java
/** * Converts a drawable to a tiled version of itself. It will recursively * traverse layer and state list drawables. *///w ww. j ava 2 s . co m private Drawable tileify(Drawable drawable, boolean clip) { if (drawable instanceof DrawableWrapper) { Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable(); if (inner != null) { inner = tileify(inner, clip); ((DrawableWrapper) drawable).setWrappedDrawable(inner); } } else if (drawable instanceof LayerDrawable) { LayerDrawable background = (LayerDrawable) drawable; final int N = background.getNumberOfLayers(); Drawable[] outDrawables = new Drawable[N]; for (int i = 0; i < N; i++) { int id = background.getId(i); outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress)); } LayerDrawable newBg = new LayerDrawable(outDrawables); for (int i = 0; i < N; i++) { newBg.setId(i, background.getId(i)); } return newBg; } else if (drawable instanceof BitmapDrawable) { final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; final Bitmap tileBitmap = bitmapDrawable.getBitmap(); if (mSampleTile == null) { mSampleTile = tileBitmap; } final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape()); final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); shapeDrawable.getPaint().setShader(bitmapShader); shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter()); return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable; } return drawable; }
From source file:com.duguang.baseanimation.ui.tab.PagerTabStrip.PagerTabMainActivity.java
private void changeColor(int newColor) { tabs.setIndicatorColor(newColor);/* w ww .j ava2s. c o m*/ // change ActionBar color just if an ActionBar is available if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = getResources().getDrawable(R.drawable.tab_pagertab_actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { ld.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(ld); } } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); // workaround for broken ActionBarContainer drawable handling on // pre-API 17 builds // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(td); } td.startTransition(200); } oldBackground = ld; // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler getActionBar().setDisplayShowTitleEnabled(false); getActionBar().setDisplayShowTitleEnabled(true); } currentColor = newColor; }
From source file:com.marshalchen.common.demoofui.viewpagerSlidingTab.ViewpagerSlidingTabsActivity.java
private void changeColor(int newColor) { tabs.setIndicatorColor(newColor);/*from w ww. j a va 2s . co m*/ // change ActionBar color just if an ActionBar is available if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = getResources().getDrawable(R.drawable.view_sliding_tab_actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { ld.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(ld); } } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); // workaround for broken ActionBarContainer drawable handling on // pre-API 17 builds // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(td); } td.startTransition(200); } oldBackground = ld; // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler getActionBar().setDisplayShowTitleEnabled(false); getActionBar().setDisplayShowTitleEnabled(true); } currentColor = newColor; }