Skip to content

Commit

Permalink
qmui demo skin
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Oct 20, 2019
1 parent 5a92c31 commit d04b83a
Show file tree
Hide file tree
Showing 81 changed files with 749 additions and 474 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Tencent is pleased to support the open source community by making QMUI_Android available.
*
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://opensource.org/licenses/MIT
*
* 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.qmuiteam.qmui.skin;

import android.content.res.Resources;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public interface IQMUISkinHandlerSpan {

void handle(View view, QMUISkinManager manager, int skinIndex, Resources.Theme theme);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ protected void getSkinValueFromAttributeSet(View view, AttributeSet attrs, QMUIS
builder.textColor(id);
} else if (attr == R.styleable.QMUISkinDef_qmui_skin_second_text_color) {
builder.secondTextColor(id);
} else if (attr == R.styleable.QMUISkinDef_qmui_skin_btn_text_color) {
builder.btnTextColor(id);
} else if (attr == R.styleable.QMUISkinDef_qmui_skin_src) {
builder.src(id);
} else if (attr == R.styleable.QMUISkinDef_qmui_skin_tint_color) {
Expand All @@ -131,6 +129,8 @@ protected void getSkinValueFromAttributeSet(View view, AttributeSet attrs, QMUIS
builder.leftSeparator(id);
}else if(attr == R.styleable.QMUISkinDef_qmui_skin_bg_tint_color) {
builder.bgTintColor(id);
}else if(attr == R.styleable.QMUISkinDef_qmui_skin_progress_color){
builder.progressColor(id);
}
}
a.recycle();
Expand Down
28 changes: 25 additions & 3 deletions qmui/src/main/java/com/qmuiteam/qmui/skin/QMUISkinManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@
import android.content.res.Resources;
import android.os.Build;
import android.os.Trace;
import android.text.Spanned;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;

import com.qmuiteam.qmui.BuildConfig;
import com.qmuiteam.qmui.QMUILog;
import com.qmuiteam.qmui.R;
import com.qmuiteam.qmui.qqface.QMUIQQFaceView;
import com.qmuiteam.qmui.skin.annotation.QMUISkinListenWithHierarchyChange;
import com.qmuiteam.qmui.skin.defaultAttr.IQMUISkinDefaultAttrProvider;
import com.qmuiteam.qmui.skin.handler.IQMUISkinRuleHandler;
import com.qmuiteam.qmui.skin.handler.QMUISkinRuleAlphaHandler;
import com.qmuiteam.qmui.skin.handler.QMUISkinRuleBackgroundHandler;
import com.qmuiteam.qmui.skin.handler.QMUISkinRuleBgTintColorHandler;
import com.qmuiteam.qmui.skin.handler.QMUISkinRuleBorderHandler;
import com.qmuiteam.qmui.skin.handler.QMUISkinRuleProgressColorHandler;
import com.qmuiteam.qmui.skin.handler.QMUISkinRuleSeparatorHandler;
import com.qmuiteam.qmui.skin.handler.QMUISkinRuleSrcHandler;
import com.qmuiteam.qmui.skin.handler.QMUISkinRuleTextColorHandler;
Expand Down Expand Up @@ -140,6 +144,8 @@ private QMUISkinManager(Resources resources, String packageName) {
mRuleHandlers.put(QMUISkinValueBuilder.TINT_COLOR, new QMUISkinRuleTintColorHandler());
mRuleHandlers.put(QMUISkinValueBuilder.ALPHA, new QMUISkinRuleAlphaHandler());
mRuleHandlers.put(QMUISkinValueBuilder.BG_TINT_COLOR, new QMUISkinRuleBgTintColorHandler());
mRuleHandlers.put(QMUISkinValueBuilder.PROGRESS_COLOR, new QMUISkinRuleProgressColorHandler());

}

@Nullable
Expand Down Expand Up @@ -226,6 +232,22 @@ private void runDispatch(@NonNull View view, int skinIndex, Resources.Theme them
}
}
}
} else if ((view instanceof TextView) || (view instanceof QMUIQQFaceView)) {
CharSequence text;
if (view instanceof TextView) {
text = ((TextView) view).getText();
} else {
text = ((QMUIQQFaceView) view).getText();
}
if (text instanceof Spanned) {
IQMUISkinHandlerSpan[] spans = ((Spanned) text).getSpans(0, text.length(), IQMUISkinHandlerSpan.class);
if (spans != null) {
for (int i = 0; i < spans.length; i++) {
spans[i].handle(view, this, skinIndex, theme);
}
}
view.invalidate();
}
}
}

Expand All @@ -245,14 +267,14 @@ private void applyTheme(@NonNull View view, int skinIndex, Resources.Theme theme
}
}

public void refreshTheme(@NonNull View view){
public void refreshTheme(@NonNull View view) {
Integer skinIndex = (Integer) view.getTag(R.id.qmui_skin_current_index);
if(skinIndex == null || skinIndex <= 0){
if (skinIndex == null || skinIndex <= 0) {
return;
}

SkinItem skinItem = mSkins.get(skinIndex);
if(skinItem != null){
if (skinItem != null) {
applyTheme(view, skinIndex, skinItem.theme);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class QMUISkinValueBuilder {
public static final String BACKGROUND = "background";
public static final String TEXT_COLOR = "textColor";
public static final String SECOND_TEXT_COLOR = "secondTextColor";
public static final String BTN_TEXT_COLOR = "btnTextColor";
public static final String SRC = "src";
public static final String BORDER = "border";
public static final String TOP_SEPARATOR = "topSeparator";
Expand All @@ -31,6 +30,7 @@ public class QMUISkinValueBuilder {
public static final String ALPHA = "alpha";
public static final String TINT_COLOR = "tintColor";
public static final String BG_TINT_COLOR = "bgTintColor";
public static final String PROGRESS_COLOR = "progressColor";

private HashMap<String, String> mValues = new HashMap<>();

Expand All @@ -54,13 +54,13 @@ public QMUISkinValueBuilder textColor(String attrName) {
return this;
}

public QMUISkinValueBuilder btnTextColor(int attr) {
mValues.put(BTN_TEXT_COLOR, String.valueOf(attr));
public QMUISkinValueBuilder progressColor(int attr){
mValues.put(PROGRESS_COLOR, String.valueOf(attr));
return this;
}

public QMUISkinValueBuilder btnTextColor(String attrName) {
mValues.put(BTN_TEXT_COLOR, attrName);
public QMUISkinValueBuilder progressColor(String attrName){
mValues.put(PROGRESS_COLOR, attrName);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.qmuiteam.qmui.skin.QMUISkinManager;
import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.util.QMUIViewHelper;
import com.qmuiteam.qmui.widget.QMUIProgressBar;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

public class QMUISkinRuleBackgroundHandler implements IQMUISkinRuleHandler {
Expand All @@ -31,6 +32,8 @@ public void handle(QMUISkinManager skinManager, View view, Resources.Theme theme
if(view instanceof QMUIRoundButton){
((QMUIRoundButton)view).setBgData(
QMUIResHelper.getAttrColorStateList(view.getContext(), theme, attr));
}else if(view instanceof QMUIProgressBar){
view.setBackgroundColor(QMUIResHelper.getAttrColor(theme, attr));
}else{
QMUIViewHelper.setBackgroundKeepingPadding(view,
QMUIResHelper.getAttrDrawable(view.getContext(), theme, attr));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Tencent is pleased to support the open source community by making QMUI_Android available.
*
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://opensource.org/licenses/MIT
*
* 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.qmuiteam.qmui.skin.handler;

import android.view.View;

import com.qmuiteam.qmui.widget.QMUIProgressBar;

public class QMUISkinRuleProgressColorHandler extends QMUISkinRuleColorHandler {

@Override
void handle(View view, String name, int color) {
if (view instanceof QMUIProgressBar) {
((QMUIProgressBar) view).setProgressColor(color);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.widget.TextView;

import com.qmuiteam.qmui.qqface.QMUIQQFaceView;
import com.qmuiteam.qmui.widget.QMUIProgressBar;

public class QMUISkinRuleTextColorHandler extends QMUISkinRuleColorStateListHandler {

Expand All @@ -29,6 +30,8 @@ void handle(View view, String name, ColorStateList colorStateList) {
((TextView) view).setTextColor(colorStateList);
} else if (view instanceof QMUIQQFaceView) {
((QMUIQQFaceView) view).setTextColor(colorStateList.getDefaultColor());
}else if(view instanceof QMUIProgressBar){
((QMUIProgressBar) view).setTextColor(colorStateList.getDefaultColor());
}
}
}
67 changes: 63 additions & 4 deletions qmui/src/main/java/com/qmuiteam/qmui/span/QMUITouchableSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,40 @@

package com.qmuiteam.qmui.span;

import androidx.annotation.ColorInt;
import androidx.core.view.ViewCompat;
import android.content.res.Resources;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;

import com.qmuiteam.qmui.QMUILog;
import com.qmuiteam.qmui.link.ITouchableSpan;
import com.qmuiteam.qmui.skin.IQMUISkinHandlerSpan;
import com.qmuiteam.qmui.skin.QMUISkinHelper;
import com.qmuiteam.qmui.skin.QMUISkinManager;
import com.qmuiteam.qmui.util.QMUIResHelper;

import androidx.annotation.ColorInt;
import androidx.core.view.ViewCompat;

/**
* 可 Touch 的 Span,在 {@link #setPressed(boolean)} 后根据是否 pressed 来触发不同的UI状态
* <p>
* 提供设置 span 的文字颜色和背景颜色的功能, 在构造时传入
* </p>
*/
public abstract class QMUITouchableSpan extends ClickableSpan implements ITouchableSpan {
public abstract class QMUITouchableSpan extends ClickableSpan implements ITouchableSpan, IQMUISkinHandlerSpan {
private static final String TAG = "QMUITouchableSpan";
private boolean mIsPressed;
@ColorInt private int mNormalBackgroundColor;
@ColorInt private int mPressedBackgroundColor;
@ColorInt private int mNormalTextColor;
@ColorInt private int mPressedTextColor;

private int mNormalBgAttr;
private int mPressedBgAttr;
private int mNormalTextColorAttr;
private int mPressedTextColorAttr;

private boolean mIsNeedUnderline = false;

public abstract void onSpanClick(View widget);
Expand All @@ -59,6 +72,27 @@ public QMUITouchableSpan(@ColorInt int normalTextColor,
mPressedBackgroundColor = pressedBackgroundColor;
}

public QMUITouchableSpan(View initFollowSkinView,
int normalTextColorAttr, int pressedTextColorAttr,
int normalBgAttr, int pressedBgAttr) {
mNormalBgAttr = normalBgAttr;
mPressedBgAttr = pressedBgAttr;
mNormalTextColorAttr = normalTextColorAttr;
mPressedTextColorAttr = pressedTextColorAttr;
if (normalTextColorAttr != 0) {
mNormalTextColor = QMUISkinHelper.getSkinColor(initFollowSkinView, normalTextColorAttr);
}
if (pressedTextColorAttr != 0) {
mPressedTextColor = QMUISkinHelper.getSkinColor(initFollowSkinView, pressedTextColorAttr);
}
if (normalBgAttr != 0) {
mNormalBackgroundColor = QMUISkinHelper.getSkinColor(initFollowSkinView, normalBgAttr);
}
if (pressedBgAttr != 0) {
mPressedBackgroundColor = QMUISkinHelper.getSkinColor(initFollowSkinView, pressedBgAttr);
}
}

public int getNormalBackgroundColor() {
return mNormalBackgroundColor;
}
Expand All @@ -82,7 +116,7 @@ public int getPressedBackgroundColor() {
public int getPressedTextColor() {
return mPressedTextColor;
}

public void setPressed(boolean isSelected) {
mIsPressed = isSelected;
}
Expand All @@ -102,4 +136,29 @@ public void updateDrawState(TextPaint ds) {
: mNormalBackgroundColor;
ds.setUnderlineText(mIsNeedUnderline);
}

@Override
public void handle(View view, QMUISkinManager manager, int skinIndex, Resources.Theme theme) {
boolean noAttrExist = true;
if (mNormalTextColorAttr != 0) {
mNormalTextColor = QMUIResHelper.getAttrColor(theme, mNormalTextColorAttr);
noAttrExist = false;
}
if (mPressedTextColorAttr != 0) {
mPressedTextColor = QMUIResHelper.getAttrColor(theme, mPressedTextColorAttr);
noAttrExist = false;
}
if (mNormalBgAttr != 0) {
mNormalBackgroundColor = QMUIResHelper.getAttrColor(theme, mNormalBgAttr);
noAttrExist = false;
}
if (mPressedBgAttr != 0) {
mPressedBackgroundColor = QMUIResHelper.getAttrColor(theme, mPressedBgAttr);
noAttrExist = false;
}

if (noAttrExist) {
QMUILog.w(TAG, "There are no attrs for skin. Please use constructor with 5 parameters");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
Expand Down Expand Up @@ -69,6 +70,7 @@
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.qmuiteam.qmui.QMUIInterpolatorStaticHolder;
import com.qmuiteam.qmui.R;
import com.qmuiteam.qmui.skin.IQMUISkinDispatchInterceptor;
import com.qmuiteam.qmui.util.QMUICollapsingTextHelper;
import com.qmuiteam.qmui.util.QMUILangHelper;
import com.qmuiteam.qmui.util.QMUIViewHelper;
Expand All @@ -86,7 +88,7 @@
* @date 2017-09-02
*/

public class QMUICollapsingTopBarLayout extends FrameLayout implements IWindowInsetLayout {
public class QMUICollapsingTopBarLayout extends FrameLayout implements IWindowInsetLayout, IQMUISkinDispatchInterceptor {

private static final int DEFAULT_SCRIM_ANIMATION_DURATION = 600;

Expand Down Expand Up @@ -1266,4 +1268,9 @@ public void onOffsetChanged(AppBarLayout layout, int verticalOffset) {
Math.abs(verticalOffset) / (float) expandRange);
}
}

@Override
public boolean intercept(int skinIndex, Resources.Theme theme) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class QMUILoadingView extends View implements IQMUISkinDefaultAttrProvide

static {
sDefaultAttrs = new SimpleArrayMap<>();
sDefaultAttrs.put(QMUISkinValueBuilder.TINT_COLOR, R.attr.qmui_loading_color);
sDefaultAttrs.put(QMUISkinValueBuilder.TINT_COLOR, R.attr.qmui_skin_support_loading_color);
}

public QMUILoadingView(Context context) {
Expand Down
13 changes: 13 additions & 0 deletions qmui/src/main/java/com/qmuiteam/qmui/widget/QMUIProgressBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ public void setBarColor(int backgroundColor, int progressColor) {
invalidate();
}

@Override
public void setBackgroundColor(int backgroundColor) {
mBackgroundColor = backgroundColor;
mBackgroundPaint.setColor(mBackgroundColor);
invalidate();
}

public void setProgressColor(int progressColor) {
mProgressColor = progressColor;
mPaint.setColor(mProgressColor);
invalidate();
}

/**
* 设置进度文案的文字大小
*
Expand Down
Loading

0 comments on commit d04b83a

Please sign in to comment.