Example usage for android.graphics.drawable LayerDrawable LayerDrawable

List of usage examples for android.graphics.drawable LayerDrawable LayerDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable LayerDrawable LayerDrawable.

Prototype

public LayerDrawable(@NonNull Drawable[] layers) 

Source Link

Document

Creates a new layer drawable with the list of specified layers.

Usage

From source file:com.arta.lib.demo.widget.pagerslidingtabstrip.PagerSlidingTabStripMainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);/*from www  .j  a v  a  2 s .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.pagerslidingtabstrip_actionbar_bottom);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

        if (oldBackground == null) {

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
                //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.HONEYCOMB_MR2) {
                //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.romelapj.appvercine.activity.MainActivity.java

private void changeColor(int newColor) {
    tabs.setBackgroundColor(newColor);// w w w  . ja  va 2 s .  c om
    mTintManager.setTintColor(newColor);
    Drawable colorDrawable = new ColorDrawable(newColor);
    Drawable bottomDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });
    if (oldBackground == null) {
        getSupportActionBar().setBackgroundDrawable(ld);
    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        getSupportActionBar().setBackgroundDrawable(td);
        td.startTransition(200);
    }

}

From source file:beihua.example.com.kouding_app.MainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);/*from   www .java2 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
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);

    }

    currentColor = newColor;

}

From source file:com.jia.blossom.viewpageindicator.MainActivity.java

private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);/*  w w  w  .  j  a v a2  s .c o m*/
    if (Build.VERSION.SDK_INT >= 11) {
        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 < 17) {
                Log.e("lintest", Build.VERSION.SDK_INT + " < 17");
                ld.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(ld);
            }
        } else {
            // TransitionDrawableDrawable?drawable?
            TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
            if (Build.VERSION.SDK_INT < 17) {
                td.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(td);
            }
            td.startTransition(3000);
        }
        oldBackground = ld;
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);
    }
    currentColor = newColor;
}

From source file:sse.tf141.suncore.MainActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);/*from  w  w  w  . ja  v a2  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
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);
    }
    currentColor = newColor;
}

From source file:com.haoxue.zixueplayer.MainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//from ww w.j  a  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) {

            getActionBar().setBackgroundDrawable(ld);

        } else {

            TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });

            getActionBar().setBackgroundDrawable(td);

            td.startTransition(200);

        }

        oldBackground = ld;

        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);

    }

}

From source file:com.charjack.charjackplayer.MainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);// w w w.  j  a v  a  2s. c  o m

    // change ActionBar color just if an ActionBar is available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        System.out.println("------------1-----");
        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

        if (oldBackground == null) {
            System.out.println("------------2-----");
            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:android.support.v7.internal.widget.TintRatingBar.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *///from  ww  w . j a  v  a 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 Bitmap tileBitmap = ((BitmapDrawable) drawable).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);
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}

From source file:com.pdftron.pdf.utils.IconPickerGridViewAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;/*from  w ww.j  av  a2s .c  o  m*/
    if (convertView == null) {
        // if it's not recycled, initialize some attributes
        convertView = LayoutInflater.from(mContext).inflate(R.layout.tools_gridview_icon_picker, null);

        RelativeLayout layout = (RelativeLayout) convertView.findViewById(R.id.cell_layout);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.icon_image_view);

        holder = new ViewHolder();
        holder.mIconLayout = layout;
        holder.mIconImage = imageView;
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    final String iconOutline = Tool.ANNOTATION_NOTE_ICON_FILE_PREFIX + mSource.get(position).toLowerCase()
            + Tool.ANNOTATION_NOTE_ICON_FILE_POSTFIX_OUTLINE;
    final String iconFill = Tool.ANNOTATION_NOTE_ICON_FILE_PREFIX + mSource.get(position).toLowerCase()
            + Tool.ANNOTATION_NOTE_ICON_FILE_POSTFIX_FILL;

    int iconOutlineID = mContext.getResources().getIdentifier(iconOutline, "drawable",
            mContext.getPackageName());
    int iconFillID = mContext.getResources().getIdentifier(iconFill, "drawable", mContext.getPackageName());

    // set selected icon
    if (!mSelected.equals("")) {
        if (mSelected.equals(getItem(position))) {
            Drawable[] layers = new Drawable[2];
            layers[0] = ContextCompat.getDrawable(mContext, iconFillID);
            layers[0].setColorFilter(mIconColor, PorterDuff.Mode.SRC_ATOP);
            layers[1] = ContextCompat.getDrawable(mContext, iconOutlineID);
            LayerDrawable layerDrawable = new LayerDrawable(layers);
            holder.mIconImage.setImageDrawable(layerDrawable);
        } else {
            holder.mIconImage.setImageDrawable(mContext.getResources().getDrawable(iconOutlineID));
        }
    }
    return convertView;
}

From source file:com.androidinspain.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java

private ExpandedAlarmViewHolder(View itemView, boolean hasVibrator) {
    super(itemView);

    mHasVibrator = hasVibrator;/*from  w  ww .  ja  va2  s  .c o m*/

    delete = (TextView) 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);
    hairLine = itemView.findViewById(R.id.hairline);

    final Context context = itemView.getContext();
    itemView.setBackground(new LayerDrawable(
            new Drawable[] { ContextCompat.getDrawable(context, R.drawable.alarm_background_expanded),
                    ThemeUtils.resolveDrawable(context, R.attr.selectableItemBackground) }));

    // Build button for each day.
    final LayoutInflater inflater = LayoutInflater.from(context);
    final List<Integer> weekdays = DataModel.getDataModel().getWeekdayOrder().getCalendarDays();
    for (int i = 0; i < 7; i++) {
        final View dayButtonFrame = inflater.inflate(R.layout.day_button, repeatDays, false /* attachToRoot */);
        final CompoundButton dayButton = (CompoundButton) dayButtonFrame.findViewById(R.id.day_button_box);
        final int weekday = weekdays.get(i);
        dayButton.setText(UiDataModel.getUiDataModel().getShortWeekday(weekday));
        dayButton.setContentDescription(UiDataModel.getUiDataModel().getLongWeekday(weekday));
        repeatDays.addView(dayButtonFrame);
        dayButtons[i] = dayButton;
    }

    // Cannot set in xml since we need compat functionality for API < 21
    final Drawable labelIcon = Utils.getVectorDrawable(context, R.drawable.ic_label);
    editLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(labelIcon, null, null, null);
    final Drawable deleteIcon = Utils.getVectorDrawable(context, R.drawable.ic_delete_small);
    delete.setCompoundDrawablesRelativeWithIntrinsicBounds(deleteIcon, null, null, null);

    // Collapse handler
    itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Events.sendAlarmEvent(R.string.action_collapse_implied, R.string.label_deskclock);
            getItemHolder().collapse();
        }
    });
    arrow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Events.sendAlarmEvent(R.string.action_collapse, R.string.label_deskclock);
            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(context, getItemHolder().item);
        }
    });
    // Delete alarm handler
    delete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getAlarmTimeClickHandler().onDeleteClicked(getItemHolder());
            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);
            getItemHolder().notifyItemChanged(ANIMATE_REPEAT_DAYS);
        }
    });
    // Day buttons handler
    for (int i = 0; i < dayButtons.length; 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);
            }
        });
    }

    itemView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
}