!14624 [MS][Lite]remove some copy codes

From: @sishuikang
Reviewed-by: @zhanghaibo5,@zhanghaibo5,@hangangqiang
Signed-off-by: @zhanghaibo5
pull/14624/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit f328ecd300

@ -15,9 +15,10 @@
*/
package com.mindspore.himindspore.bean;
import com.mindspore.customview.tablayout.listener.CustomTabEntity;
public class TabEntity implements CustomTabEntity {
import com.mindspore.himindspore.ui.view.MSTabEntity;
public class TabEntity implements MSTabEntity {
public String title;
public int selectedIcon;
@ -30,17 +31,17 @@ public class TabEntity implements CustomTabEntity {
}
@Override
public String getTabTitle() {
public String getMSTabTitle() {
return title;
}
@Override
public int getTabSelectedIcon() {
public int getMSTabIconChecked() {
return selectedIcon;
}
@Override
public int getTabUnselectedIcon() {
public int getMSTabIconUnchecked() {
return unSelectedIcon;
}
}

@ -40,7 +40,7 @@ import androidx.appcompat.app.AlertDialog;
import com.mindspore.common.sp.Preferences;
import com.mindspore.common.utils.Utils;
import com.mindspore.customview.countdown.CountDownView;
import com.mindspore.customview.countdown.MSCountDownView;
import com.mindspore.himindspore.R;
import com.mindspore.himindspore.base.BaseActivity;
import com.mindspore.himindspore.ui.main.MainActivity;
@ -63,7 +63,7 @@ public class SplashActivity extends BaseActivity implements EasyPermissions.Perm
private SharedPreferences prefs;
private CountDownView cdvTime;
private MSCountDownView cdvTime;
private boolean isCheckPrivacy = false;
private View mContentView;

@ -24,22 +24,25 @@ import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import com.mindspore.common.base.adapter.BasePagerAdapter;
import com.mindspore.customview.dialog.UpdateDialog;
import com.mindspore.customview.tablayout.CommonTabLayout;
import com.mindspore.customview.tablayout.listener.CustomTabEntity;
import com.mindspore.customview.tablayout.listener.OnTabSelectListener;
import com.mindspore.himindspore.R;
import com.mindspore.himindspore.base.BaseActivity;
import com.mindspore.himindspore.comment.FragmentFactory;
import com.mindspore.himindspore.net.FileDownLoadObserver;
import com.mindspore.himindspore.net.UpdateInfoBean;
import com.mindspore.himindspore.ui.view.MSTabEntity;
import java.io.File;
import java.util.ArrayList;
@ -49,16 +52,18 @@ public class MainActivity extends BaseActivity<MainPresenter> implements MainCon
private static final String TAG = "MainActivity";
private ViewPager mVpHome;
private CommonTabLayout mCtlTable;
private TabLayout mTabLayout;
private int now_version;
private ProgressDialog progressDialog;
private List<MSTabEntity> mTabEntities;
@Override
protected void init() {
presenter = new MainPresenter(this);
mVpHome = findViewById(R.id.vp_home);
mCtlTable = findViewById(R.id.ctl_table);
mTabLayout = findViewById(R.id.tab_layout);
showPackaeInfo();
initTabLayout();
initViewPager();
@ -82,19 +87,68 @@ public class MainActivity extends BaseActivity<MainPresenter> implements MainCon
}
private void initTabLayout() {
ArrayList<CustomTabEntity> mTabEntities = presenter.getTabEntity();
mCtlTable.setTabData(mTabEntities);
mCtlTable.setOnTabSelectListener(new OnTabSelectListener() {
mTabEntities = presenter.getTabEntity();
for (int i = 0; i < mTabEntities.size(); i++) {
mTabLayout.addTab(mTabLayout.newTab().setCustomView(getTabView(mTabEntities.get(i))));
}
chooseFirst();
mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelect(int position) {
mVpHome.setCurrentItem(position);
public void onTabSelected(TabLayout.Tab tab) {
Log.e(TAG, "onTabSelected: " + tab.getPosition());
mVpHome.setCurrentItem(tab.getPosition(),true);
recoverItem();
View view =tab.getCustomView();
ImageView imageView = view.findViewById(R.id.tab_icon);
TextView textView = view.findViewById(R.id.tab_title);
imageView.setImageResource(mTabEntities.get(tab.getPosition()).getMSTabIconChecked());
textView.setTextColor(getResources().getColor(R.color.main_tab_text_checked));
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselect(int position) {
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
public View getTabView(MSTabEntity tabEntity) {
View view = LayoutInflater.from(this).inflate(R.layout.layout_tab_top, null);
ImageView tabIcon = view.findViewById(R.id.tab_icon);
tabIcon.setImageResource(tabEntity.getMSTabIconUnchecked());
TextView tabText = view.findViewById(R.id.tab_title);
tabText.setText(tabEntity.getMSTabTitle());
tabText.setTextColor(getResources().getColor(R.color.main_tab_text_uncheck));
return view;
}
private void chooseFirst() {
TabLayout.Tab tabAt = mTabLayout.getTabAt(0);
View view = tabAt.getCustomView();
ImageView imageView = view.findViewById(R.id.tab_icon);
TextView textView = view.findViewById(R.id.tab_title);
imageView.setImageResource(mTabEntities.get(0).getMSTabIconChecked());
textView.setTextColor(getResources().getColor(R.color.main_tab_text_checked));
}
private void recoverItem() {
for (int i = 0; i < mTabEntities.size(); i++) {
TabLayout.Tab tabAt = mTabLayout.getTabAt(i);
View view = tabAt.getCustomView();
ImageView imageView = view.findViewById(R.id.tab_icon);
TextView textView = view.findViewById(R.id.tab_title);
imageView.setImageResource(mTabEntities.get(i).getMSTabIconUnchecked());
textView.setTextColor(getResources().getColor(R.color.main_tab_text_uncheck));
}
}
private void initViewPager() {
@ -104,23 +158,7 @@ public class MainActivity extends BaseActivity<MainPresenter> implements MainCon
fragments.add(FragmentFactory.getInstance().getMeFragment());
BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager(), fragments);
mVpHome.setAdapter(adapter);
mVpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
if (position >= 0) {
mCtlTable.setCurrentTab(position);
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
mVpHome.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
mVpHome.setOffscreenPageLimit(3);
mVpHome.setCurrentItem(0);
}
@ -171,7 +209,7 @@ public class MainActivity extends BaseActivity<MainPresenter> implements MainCon
public void showUpdate(final UpdateInfoBean updateInfo) {
if (now_version != updateInfo.getVersionCode()) {
UpdateDialog updateDialog= new UpdateDialog(this);
UpdateDialog updateDialog = new UpdateDialog(this);
updateDialog.setTitleString(getResources().getString(R.string.app_update_lastest) + updateInfo.getVersionName());
updateDialog.setContentString(updateInfo.getMessage());
updateDialog.setYesOnclickListener(() -> downFile());
@ -201,12 +239,9 @@ public class MainActivity extends BaseActivity<MainPresenter> implements MainCon
@Override
public void onProgress(final int progress, final long total) {
runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.setMax((int) total / 1024 / 1024);
progressDialog.setProgress(progress);
}
runOnUiThread(() -> {
progressDialog.setMax((int) total / 1024 / 1024);
progressDialog.setProgress(progress);
});
}

@ -15,12 +15,12 @@
*/
package com.mindspore.himindspore.ui.main;
import com.mindspore.customview.tablayout.listener.CustomTabEntity;
import com.mindspore.himindspore.net.FileDownLoadObserver;
import com.mindspore.himindspore.net.UpdateInfoBean;
import com.mindspore.himindspore.ui.view.MSTabEntity;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public interface MainContract {
@ -31,7 +31,7 @@ public interface MainContract {
}
interface Presenter {
ArrayList<CustomTabEntity> getTabEntity();
List<MSTabEntity> getTabEntity();
void getUpdateInfo();

@ -19,13 +19,13 @@ import android.content.res.TypedArray;
import android.util.Log;
import com.mindspore.common.utils.Utils;
import com.mindspore.customview.tablayout.listener.CustomTabEntity;
import com.mindspore.himindspore.R;
import com.mindspore.himindspore.base.BasePresenter;
import com.mindspore.himindspore.bean.TabEntity;
import com.mindspore.himindspore.net.FileDownLoadObserver;
import com.mindspore.himindspore.net.RetrofitHelper;
import com.mindspore.himindspore.net.UpdateInfoBean;
import com.mindspore.himindspore.ui.view.MSTabEntity;
import java.io.File;
import java.util.ArrayList;
@ -51,15 +51,15 @@ public class MainPresenter extends BasePresenter<MainActivity> implements MainCo
@Override
public ArrayList<CustomTabEntity> getTabEntity() {
ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
public ArrayList<MSTabEntity> getTabEntity() {
ArrayList<MSTabEntity> mTabEntities = new ArrayList<>();
TypedArray mIconUnSelectIds = Utils.getApp().getResources().obtainTypedArray(R.array.main_tab_un_select);
TypedArray mIconSelectIds = Utils.getApp().getResources().obtainTypedArray(R.array.main_tab_select);
String[] mainTitles = Utils.getApp().getResources().getStringArray(R.array.main_tab_title);
for (int i = 0; i < mainTitles.length; i++) {
int unSelectId = mIconUnSelectIds.getResourceId(i, R.drawable.experience_uncheck);
int selectId = mIconSelectIds.getResourceId(i, R.drawable.experience_checked);
mTabEntities.add(new TabEntity(mainTitles[i],selectId , unSelectId));
mTabEntities.add(new TabEntity(mainTitles[i], selectId, unSelectId));
}
mIconUnSelectIds.recycle();
mIconSelectIds.recycle();

@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mindspore.customview.tablayout.listener;
package com.mindspore.himindspore.ui.view;
import androidx.annotation.DrawableRes;
public interface CustomTabEntity {
String getTabTitle();
public interface MSTabEntity {
String getMSTabTitle();
@DrawableRes
int getTabSelectedIcon();
int getMSTabIconChecked();
@DrawableRes
int getTabUnselectedIcon();
int getMSTabIconUnchecked();
}

@ -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>

@ -7,7 +7,6 @@
android:background="@color/white"
tools:context=".ui.guide.SplashActivity">
<ImageView
android:id="@+id/image_logo"
android:layout_width="160dp"
@ -48,23 +47,23 @@
app:layout_constraintTop_toBottomOf="@+id/title" />
<com.mindspore.customview.countdown.CountDownView
<com.mindspore.customview.countdown.MSCountDownView
android:id="@+id/cdv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="40dp"
android:layout_marginEnd="20dp"
app:cd_animator_time="3"
app:cd_animator_time_unit="@string/splash_count_down"
app:cd_arc_color="@color/btn_small_checked"
app:cd_arc_width="2dp"
app:cd_bg_color="@color/gray_light"
app:cd_circle_radius="20dp"
app:cd_location="top"
app:cd_retreat_type="forward"
app:cd_text_color="@color/black"
app:cd_text_size="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:ms_cd_animator_time="3"
app:ms_cd_animator_time_unit="@string/splash_count_down"
app:ms_cd_arc_color="@color/btn_small_checked"
app:ms_cd_arc_width="2dp"
app:ms_cd_bg_color="@color/gray_light"
app:ms_cd_circle_radius="20dp"
app:ms_cd_location="top"
app:ms_cd_retreat_type="forward"
app:ms_cd_text_color="@color/black"
app:ms_cd_text_size="12sp" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -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>

@ -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();
}
}

@ -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>

@ -1,163 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="tl_divider_color" format="color" />
<attr name="tl_divider_padding" format="dimension" />
<attr name="tl_divider_width" format="dimension" />
<attr name="tl_indicator_anim_duration" format="integer" />
<attr name="tl_indicator_anim_enable" format="boolean" />
<attr name="tl_indicator_bounce_enable" format="boolean" />
<attr name="tl_indicator_color" format="color" />
<attr name="tl_indicator_corner_radius" format="dimension" />
<attr name="tl_indicator_gravity" format="enum">
<enum name="TOP" value="48" />
<enum name="BOTTOM" value="80" />
</attr>
<attr name="tl_indicator_height" format="dimension" />
<attr name="tl_indicator_margin_bottom" format="dimension" />
<attr name="tl_indicator_margin_left" format="dimension" />
<attr name="tl_indicator_margin_right" format="dimension" />
<attr name="tl_indicator_margin_top" format="dimension" />
<attr name="tl_indicator_style" format="enum">
<enum name="NORMAL" value="0" />
<enum name="TRIANGLE" value="1" />
<enum name="BLOCK" value="2" />
</attr>
<attr name="tl_indicator_width" format="dimension" />
<attr name="tl_indicator_width_equal_title" format="boolean" />
<attr name="tl_tab_padding" format="dimension" />
<attr name="tl_tab_space_equal" format="boolean" />
<attr name="tl_tab_width" format="dimension" />
<attr name="tl_textAllCaps" format="boolean" />
<attr name="tl_textBold" format="enum">
<enum name="NONE" value="0" />
<enum name="SELECT" value="1" />
<enum name="BOTH" value="2" />
</attr>
<attr name="tl_textSelectColor" format="color" />
<attr name="tl_textUnselectColor" format="color" />
<attr name="tl_textsize" format="dimension" />
<attr name="tl_underline_color" format="color" />
<attr name="tl_underline_gravity" format="enum">
<enum name="TOP" value="48" />
<enum name="BOTTOM" value="80" />
</attr>
<attr name="tl_underline_height" format="dimension" />
<declare-styleable name="CommonTabLayout">
<attr name="tl_indicator_color" />
<attr name="tl_indicator_height" />
<attr name="tl_indicator_width" />
<attr name="tl_indicator_margin_left" />
<attr name="tl_indicator_margin_top" />
<attr name="tl_indicator_margin_right" />
<attr name="tl_indicator_margin_bottom" />
<attr name="tl_indicator_corner_radius" />
<attr name="tl_indicator_gravity" />
<attr name="tl_indicator_style" />
<attr name="tl_indicator_anim_enable" />
<attr name="tl_indicator_anim_duration" />
<attr name="tl_indicator_bounce_enable" />
<attr name="tl_underline_color" />
<attr name="tl_underline_height" />
<attr name="tl_underline_gravity" />
<attr name="tl_divider_color" />
<attr name="tl_divider_width" />
<attr name="tl_divider_padding" />
<attr name="tl_tab_padding" />
<attr name="tl_tab_space_equal" />
<attr name="tl_tab_width" />
<attr name="tl_textsize" />
<attr name="tl_textSelectColor" />
<attr name="tl_textUnselectColor" />
<attr name="tl_textBold" />
<attr name="tl_textAllCaps" />
<attr name="tl_iconWidth" format="dimension" />
<attr name="tl_iconHeight" format="dimension" />
<attr name="tl_iconVisible" format="boolean" />
<attr name="tl_iconGravity" format="enum">
<enum name="LEFT" value="3" />
<enum name="TOP" value="48" />
<enum name="RIGHT" value="5" />
<enum name="BOTTOM" value="80" />
</attr>
<attr name="tl_iconMargin" format="dimension" />
</declare-styleable>
<declare-styleable name="MsgView">
<attr name="mv_backgroundColor" format="color" />
<attr name="mv_cornerRadius" format="dimension" />
<attr name="mv_strokeWidth" format="dimension" />
<attr name="mv_strokeColor" format="color" />
<attr name="mv_isRadiusHalfHeight" format="boolean" />
<attr name="mv_isWidthHeightEqual" format="boolean" />
</declare-styleable>
<declare-styleable name="SegmentTabLayout">
<attr name="tl_indicator_color" />
<attr name="tl_indicator_height" />
<attr name="tl_indicator_margin_left" />
<attr name="tl_indicator_margin_top" />
<attr name="tl_indicator_margin_right" />
<attr name="tl_indicator_margin_bottom" />
<attr name="tl_indicator_corner_radius" />
<attr name="tl_indicator_anim_enable" />
<attr name="tl_indicator_anim_duration" />
<attr name="tl_indicator_bounce_enable" />
<attr name="tl_divider_color" />
<attr name="tl_divider_width" />
<attr name="tl_divider_padding" />
<attr name="tl_tab_padding" />
<attr name="tl_tab_space_equal" />
<attr name="tl_tab_width" />
<attr name="tl_textsize" />
<attr name="tl_textSelectColor" />
<attr name="tl_textUnselectColor" />
<attr name="tl_textBold" />
<attr name="tl_textAllCaps" />
<attr name="tl_bar_color" format="color" />
<attr name="tl_bar_stroke_color" format="color" />
<attr name="tl_bar_stroke_width" format="dimension" />
</declare-styleable>
<declare-styleable name="SlidingTabLayout">
<attr name="tl_indicator_color" />
<attr name="tl_indicator_height" />
<attr name="tl_indicator_width" />
<attr name="tl_indicator_margin_left" />
<attr name="tl_indicator_margin_top" />
<attr name="tl_indicator_margin_right" />
<attr name="tl_indicator_margin_bottom" />
<attr name="tl_indicator_corner_radius" />
<attr name="tl_indicator_gravity" />
<attr name="tl_indicator_style" />
<attr name="tl_indicator_width_equal_title" />
<attr name="tl_underline_color" />
<attr name="tl_underline_height" />
<attr name="tl_underline_gravity" />
<attr name="tl_divider_color" />
<attr name="tl_divider_width" />
<attr name="tl_divider_padding" />
<attr name="tl_tab_padding" />
<attr name="tl_tab_space_equal" />
<attr name="tl_tab_width" />
<attr name="tl_textsize" />
<attr name="tl_textSelectColor" />
<attr name="tl_textUnselectColor" />
<attr name="tl_textBold" />
<attr name="tl_textAllCaps" />
</declare-styleable>
<declare-styleable name="CountDownView">
<attr name="cd_circle_radius" format="dimension" />
<attr name="cd_arc_width" format="dimension" />
<attr name="cd_arc_color" format="color" />
<attr name="cd_bg_color" format="color" />
<attr name="cd_text_color" format="color" />
<attr name="cd_text_size" format="dimension" />
<attr name="cd_animator_time" format="integer" />
<attr name="cd_animator_time_unit" format="string" />
<attr name="cd_retreat_type" format="enum">
<declare-styleable name="MSCountDownView">
<attr name="ms_cd_circle_radius" format="dimension" />
<attr name="ms_cd_arc_width" format="dimension" />
<attr name="ms_cd_arc_color" format="color" />
<attr name="ms_cd_bg_color" format="color" />
<attr name="ms_cd_text_color" format="color" />
<attr name="ms_cd_text_size" format="dimension" />
<attr name="ms_cd_animator_time" format="integer" />
<attr name="ms_cd_animator_time_unit" format="string" />
<attr name="ms_cd_retreat_type" format="enum">
<enum name="forward" value="1" />
<enum name="back" value="2" />
</attr>
<attr name="cd_location" format="enum">
<attr name="ms_cd_location" format="enum">
<enum name="left" value="1" />
<enum name="top" value="2" />
<enum name="right" value="3" />

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save