/* * Copyright (C) 2016 Bilibili * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.bilibili.magicasakura.widgets; import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.v7.widget.Toolbar; import android.util.AttributeSet; import com.bilibili.magicasakura.utils.TintManager; import com.wm.remusic.R; /** * @author xyczero617@gmail.com * @time 15/10/19 */ public class TintToolbar extends Toolbar implements Tintable, AppCompatBackgroundHelper.BackgroundExtensible { private AppCompatBackgroundHelper mBackgroundHelper; public TintToolbar(Context context) { this(context, null); } public TintToolbar(Context context, AttributeSet attrs) { this(context, attrs, R.attr.toolbarStyle); } public TintToolbar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (isInEditMode()) { return; } TintManager mTintManager = TintManager.get(getContext()); mBackgroundHelper = new AppCompatBackgroundHelper(this, mTintManager); mBackgroundHelper.loadFromAttribute(attrs, defStyleAttr); } @Override public void setBackgroundDrawable(Drawable background) { super.setBackgroundDrawable(background); if (mBackgroundHelper != null) { mBackgroundHelper.setBackgroundDrawableExternal(background); } } @Override public void setBackgroundResource(int resId) { if (mBackgroundHelper != null) { mBackgroundHelper.setBackgroundResId(resId); } else { super.setBackgroundResource(resId); } } @Override public void setBackgroundColor(int color) { super.setBackgroundColor(color); if (mBackgroundHelper != null) { mBackgroundHelper.setBackgroundColor(color); } } @Override public void setBackgroundTintList(int resId) { if (mBackgroundHelper != null) { mBackgroundHelper.setBackgroundTintList(resId, null); } } @Override public void setBackgroundTintList(int resId, PorterDuff.Mode mode) { if (mBackgroundHelper != null) { mBackgroundHelper.setBackgroundTintList(resId, mode); } } @Override public void tint() { if (mBackgroundHelper != null) { mBackgroundHelper.tint(); } } }