!14624 [MS][Lite]remove some copy codes
From: @sishuikang Reviewed-by: @zhanghaibo5,@zhanghaibo5,@hangangqiang Signed-off-by: @zhanghaibo5pull/14624/MERGE
commit
f328ecd300
@ -1,43 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<com.mindspore.customview.tablayout.CommonTabLayout
|
||||
android:layout_alignParentBottom="true"
|
||||
android:id="@+id/ctl_table"
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/vp_home"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:background="@color/white"
|
||||
app:tl_iconHeight="23dp"
|
||||
app:tl_iconWidth="23dp"
|
||||
app:tl_indicator_color="#2C97DE"
|
||||
app:tl_indicator_height="0dp"
|
||||
app:tl_textSelectColor="@color/main_tab_text_checked"
|
||||
app:tl_textUnselectColor="@color/main_tab_text_uncheck"
|
||||
app:tl_textsize="12sp"
|
||||
app:tl_underline_color="#DDDDDD"
|
||||
app:tl_underline_height="1dp" />
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@color/white" />
|
||||
|
||||
<View
|
||||
android:id="@+id/lineView"
|
||||
android:layout_above="@+id/ctl_table"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider_gray" />
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:layout_above="@+id/lineView"
|
||||
android:id="@+id/vp_home"
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white" />
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
android:layout_height="55dp"
|
||||
android:background="@color/white"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorFullWidth="false"
|
||||
app:tabIndicatorGravity="center"
|
||||
app:tabIndicatorHeight="0dp"
|
||||
app:tabMaxWidth="0dp"
|
||||
app:tabMode="fixed"
|
||||
app:tabRippleColor="@android:color/transparent"
|
||||
app:tabSelectedTextColor="@color/main_tab_text_checked"
|
||||
app:tabTextColor="@color/main_tab_text_uncheck" />
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_tap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tab_icon"
|
||||
android:layout_width="23dp"
|
||||
android:layout_height="23dp"/>
|
||||
|
||||
<TextView
|
||||
android:textSize="12sp"
|
||||
android:id="@+id/tab_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,227 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.mindspore.customview.countdown;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.mindspore.common.utils.DisplayUtil;
|
||||
import com.mindspore.customview.R;
|
||||
|
||||
public class MSCountDownView extends View {
|
||||
|
||||
private static final int HALF = 2;
|
||||
private Context mContext;
|
||||
private Paint mPaintBackGround, mPaintArc, mPaintText;
|
||||
|
||||
private int mRetreatType;
|
||||
private float mPaintArcWidth;
|
||||
private int mCircleRadius;
|
||||
private int mPaintArcColor = Color.RED;
|
||||
private int mPaintBackGroundColor = Color.BLUE;
|
||||
private int mLoadingTime;
|
||||
private String mLoadingTimeUnit = "";
|
||||
private int mTextColor = Color.BLACK;
|
||||
private int mTextSize;
|
||||
private int location;
|
||||
private float startAngle, mmSweepAngleStart, mmSweepAngleEnd, mSweepAngle;
|
||||
|
||||
private String mText = "";
|
||||
private int mWidth, mHeight;
|
||||
private AnimatorSet set;
|
||||
|
||||
public MSCountDownView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public MSCountDownView(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public MSCountDownView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
mContext = context;
|
||||
init(attrs);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void init(AttributeSet attrs) {
|
||||
TypedArray array = mContext.obtainStyledAttributes(attrs, R.styleable.MSCountDownView);
|
||||
mRetreatType = array.getInt(R.styleable.MSCountDownView_ms_cd_retreat_type, 1);
|
||||
location = array.getInt(R.styleable.MSCountDownView_ms_cd_location, 1);
|
||||
mCircleRadius = (int) array.getDimension(R.styleable.MSCountDownView_ms_cd_circle_radius, DisplayUtil.dp2px(mContext, 25));
|
||||
mPaintArcWidth = array.getDimension(R.styleable.MSCountDownView_ms_cd_arc_width, DisplayUtil.dp2px(mContext, 3));
|
||||
mPaintArcColor = array.getColor(R.styleable.MSCountDownView_ms_cd_arc_color, mPaintArcColor);
|
||||
mTextSize = (int) array.getDimension(R.styleable.MSCountDownView_ms_cd_text_size, DisplayUtil.dp2px(mContext, 14));
|
||||
mTextColor = array.getColor(R.styleable.MSCountDownView_ms_cd_text_color, mTextColor);
|
||||
mPaintBackGroundColor = array.getColor(R.styleable.MSCountDownView_ms_cd_bg_color, mPaintBackGroundColor);
|
||||
mLoadingTime = array.getInteger(R.styleable.MSCountDownView_ms_cd_animator_time, 3);
|
||||
mLoadingTimeUnit = array.getString(R.styleable.MSCountDownView_ms_cd_animator_time_unit);
|
||||
if (TextUtils.isEmpty(mLoadingTimeUnit)) {
|
||||
mLoadingTimeUnit = "";
|
||||
}
|
||||
array.recycle();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
private void initView() {
|
||||
this.setBackground(ContextCompat.getDrawable(mContext, android.R.color.transparent));
|
||||
mPaintBackGround = new Paint();
|
||||
mPaintBackGround.setAntiAlias(true);
|
||||
mPaintBackGround.setStyle(Paint.Style.FILL);
|
||||
mPaintBackGround.setColor(mPaintBackGroundColor);
|
||||
|
||||
mPaintArc = new Paint();
|
||||
mPaintArc.setAntiAlias(true);
|
||||
mPaintArc.setStyle(Paint.Style.STROKE);
|
||||
mPaintArc.setColor(mPaintArcColor);
|
||||
mPaintArc.setStrokeWidth(mPaintArcWidth);
|
||||
|
||||
mPaintText = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mPaintText.setAntiAlias(true);
|
||||
mPaintText.setStyle(Paint.Style.STROKE);
|
||||
mPaintText.setStyle(Paint.Style.FILL);
|
||||
mPaintText.setColor(mTextColor);
|
||||
mPaintText.setTextSize(mTextSize);
|
||||
|
||||
if (mLoadingTime < 0) {
|
||||
mLoadingTime = 3;
|
||||
}
|
||||
switch (location) {
|
||||
case 1:
|
||||
startAngle = -180;
|
||||
break;
|
||||
case 2:
|
||||
startAngle = -90;
|
||||
break;
|
||||
case 3:
|
||||
startAngle = 0;
|
||||
break;
|
||||
case 4:
|
||||
startAngle = 90;
|
||||
break;
|
||||
}
|
||||
|
||||
if (mRetreatType == 1) {
|
||||
mmSweepAngleStart = 0f;
|
||||
mmSweepAngleEnd = 360f;
|
||||
} else {
|
||||
mmSweepAngleStart = 360f;
|
||||
mmSweepAngleEnd = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
setMeasuredDimension(mCircleRadius * HALF, mCircleRadius * HALF);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
canvas.drawCircle(mWidth / HALF, mHeight / HALF, mWidth / HALF - mPaintArcWidth, mPaintBackGround);
|
||||
RectF rectF = new RectF( mPaintArcWidth / HALF, mPaintArcWidth / HALF, mWidth - mPaintArcWidth / HALF, mHeight - mPaintArcWidth / HALF);
|
||||
canvas.drawArc(rectF, startAngle, mSweepAngle, false, mPaintArc);
|
||||
float mTextWidth = mPaintText.measureText(mText, 0, mText.length());
|
||||
float dx = mWidth / HALF - mTextWidth / HALF;
|
||||
Paint.FontMetricsInt fontMetricsInt = mPaintText.getFontMetricsInt();
|
||||
float dy = (fontMetricsInt.bottom - fontMetricsInt.top) / HALF - fontMetricsInt.bottom;
|
||||
float baseLine = mHeight / HALF + dy;
|
||||
canvas.drawText(mText, dx, baseLine, mPaintText);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
ValueAnimator viewAnimator = ValueAnimator.ofFloat(mmSweepAngleStart, mmSweepAngleEnd);
|
||||
viewAnimator.setInterpolator(new LinearInterpolator());
|
||||
viewAnimator.addUpdateListener(valueAnimator -> {
|
||||
mSweepAngle = (float) valueAnimator.getAnimatedValue();
|
||||
invalidate();
|
||||
});
|
||||
ValueAnimator textAnimator = ValueAnimator.ofInt(mLoadingTime, 0);
|
||||
textAnimator.setInterpolator(new LinearInterpolator());
|
||||
textAnimator.addUpdateListener(valueAnimator -> {
|
||||
int time = (int) valueAnimator.getAnimatedValue();
|
||||
mText = time + mLoadingTimeUnit;
|
||||
});
|
||||
set = new AnimatorSet();
|
||||
set.setDuration(mLoadingTime * 1000);
|
||||
set.playTogether(viewAnimator, textAnimator);
|
||||
set.setInterpolator(new LinearInterpolator());
|
||||
set.start();
|
||||
set.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
super.onAnimationEnd(animation);
|
||||
clearAnimation();
|
||||
if (onCountDownFinishListener != null) {
|
||||
onCountDownFinishListener.finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
onCountDownFinishListener = null;
|
||||
if (set != null && set.isRunning()) {
|
||||
set.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTime(int time) {
|
||||
mLoadingTime = time;
|
||||
}
|
||||
|
||||
private OnCountDownFinishListener onCountDownFinishListener;
|
||||
|
||||
public void setOnLoadingFinishListener(OnCountDownFinishListener listener) {
|
||||
this.onCountDownFinishListener = listener;
|
||||
}
|
||||
|
||||
public interface OnCountDownFinishListener {
|
||||
void finish();
|
||||
}
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.mindspore.customview.tablayout.listener;
|
||||
|
||||
public interface OnTabSelectListener {
|
||||
void onTabSelect(int position);
|
||||
void onTabReselect(int position);
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.mindspore.customview.tablayout.utils;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FragmentChangeManager {
|
||||
private FragmentManager mFragmentManager;
|
||||
private int mContainerViewId;
|
||||
|
||||
private ArrayList<Fragment> mFragments;
|
||||
|
||||
private int mCurrentTab;
|
||||
|
||||
public FragmentChangeManager(FragmentManager fm, int containerViewId, ArrayList<Fragment> fragments) {
|
||||
this.mFragmentManager = fm;
|
||||
this.mContainerViewId = containerViewId;
|
||||
this.mFragments = fragments;
|
||||
initFragments();
|
||||
}
|
||||
|
||||
private void initFragments() {
|
||||
for (Fragment fragment : mFragments) {
|
||||
mFragmentManager.beginTransaction().add(mContainerViewId, fragment).hide(fragment).commit();
|
||||
}
|
||||
|
||||
setFragments(0);
|
||||
}
|
||||
|
||||
|
||||
public void setFragments(int index) {
|
||||
for (int i = 0; i < mFragments.size(); i++) {
|
||||
FragmentTransaction ft = mFragmentManager.beginTransaction();
|
||||
Fragment fragment = mFragments.get(i);
|
||||
if (i == index) {
|
||||
ft.show(fragment);
|
||||
} else {
|
||||
ft.hide(fragment);
|
||||
}
|
||||
ft.commit();
|
||||
}
|
||||
mCurrentTab = index;
|
||||
}
|
||||
|
||||
public int getCurrentTab() {
|
||||
return mCurrentTab;
|
||||
}
|
||||
|
||||
public Fragment getCurrentFragment() {
|
||||
return mFragments.get(mCurrentTab);
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.mindspore.customview.tablayout.utils;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.mindspore.customview.tablayout.widget.MsgView;
|
||||
|
||||
public class UnreadMsgUtils {
|
||||
public static void show(MsgView msgView, int num) {
|
||||
if (msgView == null) {
|
||||
return;
|
||||
}
|
||||
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) msgView.getLayoutParams();
|
||||
DisplayMetrics dm = msgView.getResources().getDisplayMetrics();
|
||||
msgView.setVisibility(View.VISIBLE);
|
||||
if (num <= 0) {//圆点,设置默认宽高
|
||||
msgView.setStrokeWidth(0);
|
||||
msgView.setText("");
|
||||
|
||||
lp.width = (int) (5 * dm.density);
|
||||
lp.height = (int) (5 * dm.density);
|
||||
msgView.setLayoutParams(lp);
|
||||
} else {
|
||||
lp.height = (int) (18 * dm.density);
|
||||
if (num > 0 && num < 10) {
|
||||
lp.width = (int) (18 * dm.density);
|
||||
msgView.setText(num + "");
|
||||
} else if (num > 9 && num < 100) {
|
||||
lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
|
||||
msgView.setPadding((int) (6 * dm.density), 0, (int) (6 * dm.density), 0);
|
||||
msgView.setText(num + "");
|
||||
} else {
|
||||
lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
|
||||
msgView.setPadding((int) (6 * dm.density), 0, (int) (6 * dm.density), 0);
|
||||
msgView.setText("99+");
|
||||
}
|
||||
msgView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSize(MsgView rtv, int size) {
|
||||
if (rtv == null) {
|
||||
return;
|
||||
}
|
||||
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) rtv.getLayoutParams();
|
||||
lp.width = size;
|
||||
lp.height = size;
|
||||
rtv.setLayoutParams(lp);
|
||||
}
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
package com.mindspore.customview.tablayout.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.StateListDrawable;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mindspore.common.utils.DisplayUtil;
|
||||
import com.mindspore.customview.R;
|
||||
|
||||
@SuppressLint("AppCompatCustomView")
|
||||
public class MsgView extends TextView {
|
||||
private Context context;
|
||||
private GradientDrawable gd_background = new GradientDrawable();
|
||||
private int backgroundColor;
|
||||
private int cornerRadius;
|
||||
private int strokeWidth;
|
||||
private int strokeColor;
|
||||
private boolean isRadiusHalfHeight;
|
||||
private boolean isWidthHeightEqual;
|
||||
|
||||
public MsgView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public MsgView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public MsgView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
this.context = context;
|
||||
obtainAttributes(context, attrs);
|
||||
}
|
||||
|
||||
private void obtainAttributes(Context context, AttributeSet attrs) {
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MsgView);
|
||||
backgroundColor = ta.getColor(R.styleable.MsgView_mv_backgroundColor, Color.TRANSPARENT);
|
||||
cornerRadius = ta.getDimensionPixelSize(R.styleable.MsgView_mv_cornerRadius, 0);
|
||||
strokeWidth = ta.getDimensionPixelSize(R.styleable.MsgView_mv_strokeWidth, 0);
|
||||
strokeColor = ta.getColor(R.styleable.MsgView_mv_strokeColor, Color.TRANSPARENT);
|
||||
isRadiusHalfHeight = ta.getBoolean(R.styleable.MsgView_mv_isRadiusHalfHeight, false);
|
||||
isWidthHeightEqual = ta.getBoolean(R.styleable.MsgView_mv_isWidthHeightEqual, false);
|
||||
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
if (isWidthHeightEqual() && getWidth() > 0 && getHeight() > 0) {
|
||||
int max = Math.max(getWidth(), getHeight());
|
||||
int measureSpec = MeasureSpec.makeMeasureSpec(max, MeasureSpec.EXACTLY);
|
||||
super.onMeasure(measureSpec, measureSpec);
|
||||
return;
|
||||
}
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
if (isRadiusHalfHeight()) {
|
||||
setCornerRadius(getHeight() / 2);
|
||||
} else {
|
||||
setBgSelector();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setBackgroundColor(int backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
setBgSelector();
|
||||
}
|
||||
|
||||
public void setCornerRadius(int cornerRadius) {
|
||||
this.cornerRadius = DisplayUtil.dp2px(context, cornerRadius);
|
||||
setBgSelector();
|
||||
}
|
||||
|
||||
public void setStrokeWidth(int strokeWidth) {
|
||||
this.strokeWidth = DisplayUtil.dp2px(context, strokeWidth);
|
||||
setBgSelector();
|
||||
}
|
||||
|
||||
public void setStrokeColor(int strokeColor) {
|
||||
this.strokeColor = strokeColor;
|
||||
setBgSelector();
|
||||
}
|
||||
|
||||
public void setIsRadiusHalfHeight(boolean isRadiusHalfHeight) {
|
||||
this.isRadiusHalfHeight = isRadiusHalfHeight;
|
||||
setBgSelector();
|
||||
}
|
||||
|
||||
public void setIsWidthHeightEqual(boolean isWidthHeightEqual) {
|
||||
this.isWidthHeightEqual = isWidthHeightEqual;
|
||||
setBgSelector();
|
||||
}
|
||||
|
||||
public int getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public int getCornerRadius() {
|
||||
return cornerRadius;
|
||||
}
|
||||
|
||||
public int getStrokeWidth() {
|
||||
return strokeWidth;
|
||||
}
|
||||
|
||||
public int getStrokeColor() {
|
||||
return strokeColor;
|
||||
}
|
||||
|
||||
public boolean isRadiusHalfHeight() {
|
||||
return isRadiusHalfHeight;
|
||||
}
|
||||
|
||||
public boolean isWidthHeightEqual() {
|
||||
return isWidthHeightEqual;
|
||||
}
|
||||
|
||||
|
||||
private void setDrawable(GradientDrawable gd, int color, int strokeColor) {
|
||||
gd.setColor(color);
|
||||
gd.setCornerRadius(cornerRadius);
|
||||
gd.setStroke(strokeWidth, strokeColor);
|
||||
}
|
||||
|
||||
public void setBgSelector() {
|
||||
StateListDrawable bg = new StateListDrawable();
|
||||
|
||||
setDrawable(gd_background, backgroundColor, strokeColor);
|
||||
bg.addState(new int[]{-android.R.attr.state_pressed}, gd_background);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {//16
|
||||
setBackground(bg);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
setBackgroundDrawable(bg);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tab_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:singleLine="true"/>
|
||||
|
||||
<com.mindspore.customview.tablayout.widget.MsgView
|
||||
android:id="@+id/rtv_msg_tip"
|
||||
xmlns:mv="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="11.5sp"
|
||||
android:visibility="gone"
|
||||
mv:mv_backgroundColor="#FD481F"
|
||||
mv:mv_isRadiusHalfHeight="true"
|
||||
mv:mv_strokeColor="#ffffff"
|
||||
mv:mv_strokeWidth="1dp"/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_tap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tab_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_tab_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.mindspore.customview.tablayout.widget.MsgView
|
||||
android:id="@+id/rtv_msg_tip"
|
||||
xmlns:mv="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@+id/ll_tap"
|
||||
android:gravity="center"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="11.5sp"
|
||||
android:visibility="gone"
|
||||
mv:mv_backgroundColor="#FD481F"
|
||||
mv:mv_isRadiusHalfHeight="true"
|
||||
mv:mv_strokeColor="#ffffff"
|
||||
mv:mv_strokeWidth="1dp"/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,44 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_tap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_tab_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tab_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"/>
|
||||
</LinearLayout>
|
||||
|
||||
<com.mindspore.customview.tablayout.widget.MsgView
|
||||
android:layout_toRightOf="@+id/ll_tap"
|
||||
android:id="@+id/rtv_msg_tip"
|
||||
xmlns:mv="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="11.5sp"
|
||||
android:visibility="gone"
|
||||
mv:mv_backgroundColor="#FD481F"
|
||||
mv:mv_isRadiusHalfHeight="true"
|
||||
mv:mv_strokeColor="#ffffff"
|
||||
mv:mv_strokeWidth="1dp"/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_tap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tab_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_tab_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.mindspore.customview.tablayout.widget.MsgView
|
||||
android:id="@+id/rtv_msg_tip"
|
||||
xmlns:mv="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@+id/ll_tap"
|
||||
android:gravity="center"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="11.5sp"
|
||||
android:visibility="gone"
|
||||
mv:mv_backgroundColor="#FD481F"
|
||||
mv:mv_isRadiusHalfHeight="true"
|
||||
mv:mv_strokeColor="#ffffff"
|
||||
mv:mv_strokeWidth="1dp"/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_tap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tab_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"/>
|
||||
</LinearLayout>
|
||||
|
||||
<com.mindspore.customview.tablayout.widget.MsgView
|
||||
android:layout_toRightOf="@+id/ll_tap"
|
||||
android:id="@+id/rtv_msg_tip"
|
||||
xmlns:mv="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="11.5sp"
|
||||
android:visibility="gone"
|
||||
mv:mv_backgroundColor="#FD481F"
|
||||
mv:mv_isRadiusHalfHeight="true"
|
||||
mv:mv_strokeColor="#ffffff"
|
||||
mv:mv_strokeWidth="1dp"/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,44 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_tap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_tab_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tab_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"/>
|
||||
</LinearLayout>
|
||||
|
||||
<com.mindspore.customview.tablayout.widget.MsgView
|
||||
android:id="@+id/rtv_msg_tip"
|
||||
xmlns:mv="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@+id/ll_tap"
|
||||
android:gravity="center"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="11.5sp"
|
||||
android:visibility="gone"
|
||||
mv:mv_backgroundColor="#FD481F"
|
||||
mv:mv_isRadiusHalfHeight="true"
|
||||
mv:mv_strokeColor="#ffffff"
|
||||
mv:mv_strokeWidth="1dp"/>
|
||||
|
||||
</RelativeLayout>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue