张波

添加basefragment。后续业务待梳理,拆解

Showing 44 changed files with 2937 additions and 2 deletions

Too many changes to show.

To preserve performance only 44 of 44+ files are displayed.

... ... @@ -44,8 +44,10 @@ android {
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.wd:log:1.0.0'
implementation 'com.wd:wdkitcore:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.wd:log:1.0.1'
implementation 'com.wd:wdkitcore:1.0.5'
implementation 'com.airbnb.android:lottie:5.2.0'
}
uploadArchives {
... ...
package com.wd.foundation.wdkit.animator;
import android.view.View;
import com.airbnb.lottie.LottieAnimationView;
import com.airbnb.lottie.LottieComposition;
import com.wd.foundation.wdkitcore.tools.AppContext;
public class AnimUtil {
/**
* 从本地查找lottie动画
*
* @param interactCode 特效name
*/
public static void showLocalLottieEffects(LottieAnimationView animationView, String interactCode,
boolean needpaly) {
try {
// json文件的路径根据具体需求修改
LottieComposition composition =
LottieComposition.Factory.fromFileSync(AppContext.getContext(), interactCode);
animationView.cancelAnimation();
animationView.setProgress(0);
animationView.setComposition(composition);
if (needpaly) {
animationView.playAnimation();
}
animationView.setVisibility(View.VISIBLE);
} catch (Exception e) {
}
}
}
... ...
package com.wd.foundation.wdkit.base;
import java.util.List;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProviders;
import com.wd.base.log.Logger;
import com.wd.foundation.wdkit.R;
import com.wd.foundation.wdkit.dialog.DialogUtils;
import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum;
import com.wd.foundation.wdkit.utils.ToolsUtil;
import com.wd.foundation.wdkit.widget.DefaultView;
/**
* fragment基类<BR>
*
* @author baozhaoxin
* @version [V1.0.0, 2023/1/28]
* @since V1.0.0
*/
public abstract class BaseFragment extends Fragment {
private boolean isUserVisible = true;
private boolean isViewCreated = false;
private Dialog mLoadingDialog;
protected Activity activity;
/**
* true java布局,false xml布局
*/
private boolean isjava;
private Activity mActivity;
FrameLayout layout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.perCreate();
View rootView;
if (isjava) {
rootView = getJavaLayout();
} else {
rootView = inflater.inflate(getLayout(), container, false);
}
mActivity = getActivity();
initView(rootView);
return rootView;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
isViewCreated = true;
}
/**
* 获取指定类型的VM实例<BR>
* 获取Activity对象的vm
*
* @param viewModelClazz VM的类实例
* @param <T> VM类型
* @return VM对象
*/
protected <T extends ViewModel> T getViewModel(Class<T> viewModelClazz) {
if (null != getActivity()) {
return ViewModelProviders.of(getActivity()).get(viewModelClazz);
} else {
return ViewModelProviders.of(this).get(viewModelClazz);
}
}
/**
* 获取指定类型的VM实例<BR>
* 获取fragment自己的vm
*
* @param viewModelClazz VM的类实例
* @param <T> VM类型
* @return VM对象
*/
protected <T extends ViewModel> T getViewModelThis(Class<T> viewModelClazz) {
return ViewModelProviders.of(this).get(viewModelClazz);
}
@Override
public void onDestroy() {
super.onDestroy();
// 在fragment destroy的时候重置isUserVisible
isUserVisible = true;
}
/**
* 获取日志tag
*
* @return 日志tag
*/
protected abstract String getLogTag();
/**
* 获取当前Fragment布局
*
* @return 布局文件
*/
protected abstract int getLayout();
/**
* 初始化View<BR>
* 不要有耗时操作,否则页面加载慢
*
* @param rootView 布局根视图
*/
protected abstract void initView(View rootView);
/**
* onKeyDown回调<BR>
* 需要Activity主动触发
*
* @param keyCode 按键类型
* @param event 按键事件
* @return 是否消费事件
*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
/**
* onKeyUp 回调<BR>
* 需要Activity主动触发
*
* @param keyCode 按键类型
* @param event 按键事件
* @return 是否消费事件
*/
public boolean onKeyUp(int keyCode, KeyEvent event) {
return false;
}
// 标记onResume是否被刚刚调用
private boolean mResume = false;
/**
* 用于判断fragment真实展现,不要用其提供的isVisible()方法
*
* @return true 可见 false不可见
*/
public boolean isRealVisible() {
return getUserVisibleHint() && mResume;
}
@Override
public void onResume() {
super.onResume();
mResume = true;
}
@Override
public void onPause() {
super.onPause();
mResume = false;
}
@Override
public void onStop() {
super.onStop();
mResume = false;
}
/**
* 判断是否对用户可见
*/
public boolean isUserVisible() {
return /* isVisible() */ isAdded() && getUserVisibleHint() && isUserVisible && parentUserVisible(this);
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (!isViewCreated) {
isUserVisible = isVisibleToUser;
return;
}
if (isVisibleToUser) {
userVisible(false);
} else {
userInvisible(false);
}
Log.d("BaseFragment", this.getClass().getName());
}
/**
* 判断父Fragment是否可见
*/
private static boolean parentUserVisible(Fragment fragment) {
Fragment f = fragment.getParentFragment();
if (f instanceof BaseFragment) {
return ((BaseFragment) f).isUserVisible();
}
while (f != null) {
if (!f.isVisible() || !f.getUserVisibleHint()) {
return false;
}
f = f.getParentFragment();
}
return true;
}
void userVisible(boolean fromActivity) {
// 父Fragment不可见则不做处理
if (isUserVisible || (fromActivity && (!getUserVisibleHint() || !parentUserVisible(this)))) {
return;
}
isUserVisible = true;
FragmentManager fragmentManager;
try {
fragmentManager = getChildFragmentManager();
} catch (Exception e) {
onUserVisible(fromActivity);
return;
}
List<Fragment> fragments = fragmentManager.getFragments();
if (fragments == null || fragments.isEmpty()) {
onUserVisible(fromActivity);
return;
}
for (Fragment f : fragments) {
/*
* if (!f.isVisible()) {
* continue;
* }
*/
if (!(f instanceof BaseFragment)) {
if (f.getUserVisibleHint() || (fromActivity && parentUserVisible(f))) {
f.setUserVisibleHint(true);
}
continue;
}
BaseFragment lazy = (BaseFragment) f;
// 忽略子fragment中有对用户不可见的fragment
if (!lazy.getUserVisibleHint()) {
continue;
}
lazy.userVisible(fromActivity);
}
onUserVisible(fromActivity);
}
void userInvisible(boolean fromActivity) {
// 已经不可见则无需再调用
if (!isUserVisible) {
return;
}
isUserVisible = false;
FragmentManager fragmentManager;
try {
fragmentManager = getChildFragmentManager();
} catch (Exception e) {
onUserInvisible(getUserVisibleHint(), fromActivity);
return;
}
List<Fragment> fragments = fragmentManager.getFragments();
if (fragments == null || fragments.isEmpty()) {
onUserInvisible(getUserVisibleHint(), fromActivity);
return;
}
for (Fragment f : fragments) {
/*
* if (!f.isVisible()) {
* continue;
* }
*/
if (!(f instanceof BaseFragment)) {
f.setUserVisibleHint(false);
continue;
}
BaseFragment lazy = (BaseFragment) f;
// 忽略子fragment中有对用户不可见的fragment
if (!lazy.getUserVisibleHint()) {
continue;
}
lazy.userInvisible(fromActivity);
}
onUserInvisible(getUserVisibleHint(), fromActivity);
}
/**
* 进入用户可见壮状态
*
* @param callFromActivity 是否是从activity层调用
*/
protected void onUserVisible(boolean callFromActivity) {
if (getLogTag() == null) {
Logger.d("onUserVisible");
} else {
Logger.t(getLogTag()).d("onUserVisible");
}
}
/**
* 进入用户不可见状态, app进入后台,或者新的activity被启动时
*
* @param userVisibleHint 表示在进入不可见状态时,是否是对用户可见状态,一般情况下在ViewPager里才起作用
* @param callFromActivity 是否是从activity层调用
*/
protected void onUserInvisible(boolean userVisibleHint, boolean callFromActivity) {
if (getLogTag() == null) {
Logger.d("onUserInvisible");
} else {
Logger.t(getLogTag()).d("onUserInvisible");
}
}
/**
* loading 按返回键loading默认消失
*/
public void startLoading() {
startLoading(true);
}
/**
* loading
*
* @param allowCancel 按返回键loading是否消失
*/
protected void startLoading(boolean allowCancel) {
if (mActivity == null || mActivity.isFinishing() || mActivity.isDestroyed()) {
return;
}
if (mLoadingDialog == null) {
createLoadingDialog(allowCancel);
}
if (mLoadingDialog != null && !mLoadingDialog.isShowing()) {
mLoadingDialog.show();
}
}
protected void stopLoading() {
if (mActivity == null || mActivity.isFinishing() || mActivity.isDestroyed()) {
return;
}
if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
mLoadingDialog.dismiss();
}
}
private void createLoadingDialog(boolean allowCancel) {
mLoadingDialog = DialogUtils.creatRequestDialog(mActivity, allowCancel);
}
/**
* 增加空布局
*/
protected View addEmptyView(int emptyType) {
return addEmptyView(emptyType, null);
}
/**
* 增加空布局
*
* @return
*/
protected View addEmptyView(int type, DefaultView.RetryClickListener listener) {
return addEmptyViewWithWeight(type, null, listener);
}
/**
* 增加空布局
*
* @return
*/
protected View addEmptyViewWithWeight(int type, Integer[] weight, DefaultView.RetryClickListener listener) {
View emptyView = LayoutInflater.from(getContext()).inflate(R.layout.wdkit_empty_view_layout, null);
DefaultView mDefaultView = emptyView.findViewById(R.id.default_view);
if (listener != null) {
mDefaultView.setRetryBtnClickListener(listener);
}
if (weight == null || weight.length != 2) {
mDefaultView.show(type);
} else {
mDefaultView.showWithWeight(type, weight[0], weight[1]);
}
return emptyView;
}
@SuppressWarnings({"deprecation"})
@Override
public void onAttach(@NonNull Activity activity) {
super.onAttach(activity);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
this.activity = activity;
}
}
@TargetApi(23)
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (context instanceof Activity) {
this.activity = (Activity) context;
}
}
public void setStatusBarStyle(@NonNull StatusBarStyleEnum statusBarStyle) {
ToolsUtil.setStatusBarStyle(statusBarStyle, getActivity());
}
protected void perCreate() {
}
protected View getJavaLayout() {
return null;
}
/**
* 设置java布局标识
*/
public void setIsjava(boolean isjava) {
this.isjava = isjava;
}
public void onUserLeaveHint() {
}
}
\ No newline at end of file
... ...
package com.wd.foundation.wdkit.base;
import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum;
import com.wd.foundation.wdkit.widget.DefaultView;
/**
* 懒加载fragment
*
* @author baozhaoxin
* @version [V1.0.0, 2023/1/28]
* @since V1.0.0
*/
public abstract class BaseLazyFragment extends BaseFragment {
/**
* 记录开启页面时间
*/
private long startTime;
/**
* 浏览时长
*/
public int duration;
/**
* 是否第一次加载
*/
protected boolean isFirstLoad = true;
/**
* 页面id
*/
public String mPageId;
// 记录当前页面的原头信息的objectType,目前只用在专题中
public int objectType = 0;
/**
* 国殇标记(true:开启了国殇)
*/
public boolean contryGrayFlag = false;
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
}
@Override
public void onDestroyView() {
super.onDestroyView();
isFirstLoad = true;
long endTime = System.currentTimeMillis();
duration = (int) (endTime - startTime);
}
@Override
public void onResume() {
super.onResume();
if (isFirstLoad) {
startTime = System.currentTimeMillis();
lazyLoadData();
isFirstLoad = false;
}
}
@Override
public void onDestroy() {
super.onDestroy();
long endTime = System.currentTimeMillis();
duration = (int) (endTime - startTime);
}
/**
* viewModel 进入页面加载数据
*/
protected abstract void lazyLoadData();
/**
* 修改手机顶部状态,只支持白色和黑色
* @param isWhite
*/
public void changePhoneStatusBarWhiteOrBlack(boolean isWhite){
if(isWhite){
setStatusBarStyle(StatusBarStyleEnum.FULLSCREEN_LIGHT_ENUM);
}else {
setStatusBarStyle(StatusBarStyleEnum.FULLSCREEN_DARK_ENUM);
}
}
public String getmPageId() {
return mPageId;
}
protected void showDefaultView(int type, DefaultView.RetryClickListener listener) {
addEmptyView(type, listener);
}
}
... ...
package com.wd.foundation.wdkit.constant;
/**
* 缺省页常量
*
* @author baozhaoxin
* @version [V1.0.0, 2023/4/3]
* @since V1.0.0
*/
public class DefaultViewConstant {
/**
* 页面接口报错,用于列表类及其他页面(带重试按钮)
*/
public static final int TYPE_GET_CONTENT_ERROR = 1;
/**
* 内容获取失败,用于内容详情页(带重试按钮)
*/
public static final int TYPE_GET_CONTENT_FAILED = 2;
/**
* 暂无网络(带重试按钮)
*/
public static final int TYPE_NO_NETWORK = 3;
/**
* 暂无内容
*/
public static final int TYPE_NO_CONTENT = 4;
/**
* 暂无收藏内容
*/
public static final int TYPE_NO_COLLECTED = 5;
/**
* 暂无消息
*/
public static final int TYPE_NO_RECORDS_MESSAGE = 6;
/**
* 暂无浏览历史
*/
public static final int TYPE_NO_RECORDS_BROWSE = 7;
/**
* 没有找到相关内容
*/
public static final int TYPE_NO_CONTENT_FOUND = 8;
/**
* 直播结束
*/
public static final int TYPE_LIVE_END = 10;
/**
* 暂无评论
*/
public static final int TYPE_NO_COMMENT = 11;
/**
* 暂无作品
*/
public static final int TYPE_NO_WORKS = 12;
/**
* 暂无预约
*/
public static final int TYPE_NO_RESERVATION = 13;
/**
* 限流
*/
public static final int TYPE_CURRENT_LIMITING = 14;
/**
* 该号主暂时无法访问
* */
public static final int TYPE_NO_PERMISSION = 15;
/**
* 主播暂时离开,马上回来
* */
public static final int TYPE_ANCHOR_LEAVING = 16;
public static final int TYPE_NO_RELEVANT_CONTENT_FOUND = 17;
/**
* 号主页-暂无作品
*/
public static final int TYPE_PERSONAL_CENTER_WORKS = 18;
/**
* 号主页-暂无评论
*/
public static final int TYPE_PERSONAL_CENTER_COMMENT = 19;
/**
* 关注列表-暂无关注
*/
public static final int TYPE_PERSONAL_CENTER_FOCUS = 20;
/**
* 内容获取失败,用于视频详情页(带重试按钮)
*/
public static final int TYPE_GET_CONTENT_FAILED_VIDEO = 21;
/**
* 号主页-暂无关注-有更多点击
*/
public static final int TYPE_PERSONAL_CENTER_FOCUS_TOP_VIEW = 22;
}
... ...
/*
* Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved.
*/
package com.wd.foundation.wdkit.dialog;
import android.app.Dialog;
import android.content.Context;
import android.view.Window;
import android.view.WindowManager;
import com.airbnb.lottie.LottieAnimationView;
import com.wd.foundation.wdkit.R;
import com.wd.foundation.wdkit.widget.progress.PageLoadingView;
/**
* @author yzm
* @date 2022/6/27
* @time 9:34.
*/
public class DialogUtils {
/**
* 构造方法
* @param context
* @return Dialog
*/
public static Dialog creatRequestDialog(final Context context) {
return creatRequestDialog(context, true);
}
/**
* 创建请求弹窗
* @param context
* @param allowCancel
* @return Dialog
*/
public static Dialog creatRequestDialog(final Context context, boolean allowCancel) {
final Dialog dialog = new Dialog(context, R.style.CustomDialog);
dialog.setContentView(R.layout.wdkit_pdialog_layout);
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
int width = context.getResources().getDisplayMetrics().widthPixels;
final double scaleFlag = 0.5;
lp.width = (int) (scaleFlag * width);
dialog.setCanceledOnTouchOutside(allowCancel);
dialog.setCancelable(allowCancel);
PageLoadingView loadingView = (PageLoadingView) dialog.findViewById(R.id.channelSmallLoading);
loadingView.showLoading();
// dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
// @Override
// public void onDismiss(DialogInterface dialogInterface) {
// loadingView.stopLoading();
// }
// });
return dialog;
}
/**
* 一键登录的loading
* @param context
* @param allowCancel
* @return Dialog
*/
public static Dialog createOneKeyAuthLoading(final Context context, boolean allowCancel) {
final Dialog dialog = new Dialog(context, R.style.CustomDialog);
dialog.setContentView(R.layout.wdkit_one_key_auth_login_loading);
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
int width = context.getResources().getDisplayMetrics().widthPixels;
int height = context.getResources().getDisplayMetrics().heightPixels;
lp.width = width;
lp.height = height;
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(allowCancel);
// RelativeLayout loadingBtn = dialog.findViewById(R.id.loading_btn);
// RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) loadingBtn.getLayoutParams();
// layoutParams.topMargin = UiUtils.dp2px(295);
LottieAnimationView loadingView = dialog.findViewById(R.id.one_key_loading);
loadingView.setAnimation("login_loading.json");
loadingView.playAnimation();
return dialog;
}
public interface DialogOneButtonClickListener {
/**
* 确定
*/
void okButtonClick();
}
}
... ...
/*
* Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved.
*/
package com.wd.foundation.wdkit.statusbar;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import androidx.core.content.ContextCompat;
import com.wd.foundation.wdkit.R;
import com.wd.foundation.wdkitcore.tools.ResUtils;
/**
* description:状态栏工具类
*
* @author lvjinhui
* @version [V1.0.0, 2022/5/10]
* @since V1.0.0
*/
public class StatusBarCompat {
public static final int NOMENU = -20221114;
private static final int MIUI = 1;
private static final int FLYME = 2;
private static final int ANDROID_M = 3;
private static boolean labelIsBlack = true;
private static int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
private StatusBarCompat() {
}
/**
* Activity全屏显示,但是状态栏不会被覆盖掉,而是正常显示,只是Activity顶端布局会被状态栏覆盖
*
* @param activity Activity页面
* @param statusBarColor 状态栏颜色
* @param blackLabel 是否深色
*/
public static void fullScreenStatusBar(Activity activity, int statusBarColor, boolean... blackLabel) {
if (blackLabel != null && blackLabel.length > 0) {
labelIsBlack = blackLabel[0];
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setStatusBarLollipop(activity, false, statusBarColor);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setStatusBarKitkat(activity, false, statusBarColor);
}
}
/**
* Activity全屏显示,但是状态栏不会被覆盖掉,而是正常显示,只是Activity顶端布局会被状态栏覆盖
*
* @param activity Activity页面
*/
public static void fullScreenNoStatusBar(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setStatusBarLollipop(activity, false, NOMENU);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setStatusBarKitkat(activity, false, NOMENU);
}
}
/**
* 设置状态栏全透明
*
* @param activity 需要设置的activity
*/
public static void setTransparent(Activity activity) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
transparentStatusBar(activity);
setRootView(activity);
}
/**
* 使状态栏透明
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void transparentStatusBar(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 需要设置这个flag contentView才能延伸到状态栏
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
// 状态栏覆盖在contentView上面,设置透明使contentView的背景透出来
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
// 让contentView延伸到状态栏并且设置状态栏颜色透明
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
/**
* 设置根布局参数
*/
private static void setRootView(Activity activity) {
ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
for (int i = 0, count = parent.getChildCount(); i < count; i++) {
View childView = parent.getChildAt(i);
if (childView instanceof ViewGroup) {
childView.setFitsSystemWindows(true);
((ViewGroup) childView).setClipToPadding(true);
}
}
}
/**
* 状态栏和Activity共存,Activity不全屏显示,应用平常的显示画面
* 4.4以上可以设置状态栏颜色
*
* @param activity Activity页面
* @param statusBarColor 状态栏颜色
* @param blackLabel 是否深色
*/
public static void normalStatusBar(Activity activity, int statusBarColor, boolean... blackLabel) {
if (blackLabel != null && blackLabel.length > 0) {
labelIsBlack = blackLabel[0];
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setStatusBarLollipop(activity, true, statusBarColor);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setStatusBarKitkat(activity, true, statusBarColor);
}
}
/**
* 获取状态栏高度
*
* @param activity Activity页面
* @return 状态栏高度
*/
public static int getStatusBarHeight(Activity activity) {
int statusBarHeight = 0;
int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
// 根据资源ID获取响应的尺寸值
statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
}
if (statusBarHeight == 0) {
statusBarHeight = (int) ResUtils.getDimension(R.dimen.wdkit_dp25);
}
return statusBarHeight;
}
/**
* 获取状态栏高度
* 兼容Android 12及其以上
*
* @param activity Activity页面
* @return 状态栏高度
*/
public static int getStatusBarHeightNew(Activity activity) {
int statusBarHeight = 0;
try {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object object = c.newInstance();
Field field = c.getField("status_bar_height");
int x = (Integer) field.get(object);
statusBarHeight = activity.getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
return statusBarHeight;
}
/**
* 获取状态栏高度
*
* @param context 上下文
* @return 状态栏高度
*/
public static int getStatusBarHeight(Context context) {
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
int height = resources.getDimensionPixelSize(resourceId);
return height;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void setStatusBarLollipop(Activity activity, boolean isNormalMode, int statusBarColor) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// isNormalMode 不是全屏
if (isNormalMode) {
window.setStatusBarColor(statusBarColor);
if (labelIsBlack) {
// 文字黑色
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
// 文字白色
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (NOMENU == statusBarColor) {
// 全屏无状态栏
window.getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
} else {
window.setStatusBarColor(statusBarColor);
if (labelIsBlack) {
// 全屏、文字黑色
window.getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
} else {
// 全屏、文字白色
window.getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}
}
}
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void setStatusBarKitkat(Activity activity, boolean isNormalMode, int statusBarColor) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
if (isNormalMode) {
contentView.setPadding(0, getStatusBarHeight(activity), 0, 0);
} else {
contentView.setPadding(0, 0, 0, 0);
}
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
View statusBarView = decorView.findViewById(R.id.status_view);
if (statusBarView != null) {
decorView.removeView(statusBarView);
}
statusBarView = new View(activity);
ViewGroup.LayoutParams lp =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
statusBarView.setBackgroundColor(statusBarColor);
statusBarView.setId(R.id.status_view);
decorView.addView(statusBarView, lp);
}
/**
* 状态栏亮色模式,设置状态栏黑色文字、图标,
* 适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
*
* @param activity Activity页面
* @return 1:MIUUI 2:Flyme 3:android6.0
*/
public static int setStatusBarLightMode(Activity activity) {
int result = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow()
.getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
result = ANDROID_M;
} else if (flymeSetStatusBarLightMode(activity.getWindow(), true)) {
result = FLYME;
} else if (miuiSetStatusBarLightMode(activity, true)) {
result = MIUI;
}
}
return result;
}
/**
* 状态栏暗色模式,清除MIUI、flyme或6.0以上版本状态栏黑色文字、图标
*
* @param activity Activity页面
* @return 1:MIUUI 2:Flyme 3:android6.0
*/
public static int setStatusBarDarkMode(Activity activity) {
int result = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
result = ANDROID_M;
} else if (flymeSetStatusBarLightMode(activity.getWindow(), false)) {
result = FLYME;
} else if (miuiSetStatusBarLightMode(activity, false)) {
result = MIUI;
}
}
return result;
}
/**
* 已知系统类型时,设置状态栏黑色文字、图标。
* 适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
*
* @param activity Activity页面
* @param type 1:MIUUI 2:Flyme 3:android6.0
*/
public static void setStatusBarLightMode(Activity activity, int type) {
if (type == MIUI) {
miuiSetStatusBarLightMode(activity, true);
} else if (type == FLYME) {
flymeSetStatusBarLightMode(activity.getWindow(), true);
} else if (type == ANDROID_M) {
activity.getWindow()
.getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
/**
* 状态栏暗色模式,清除MIUI、flyme或6.0以上版本状态栏黑色文字、图标
*
* @param activity Activity页面
* @param type 手机类型,这里区分小米、魅族和通用android M版本以上
*/
public static void setStatusBarDarkMode(Activity activity, int type) {
if (type == MIUI) {
miuiSetStatusBarLightMode(activity, false);
} else if (type == FLYME) {
flymeSetStatusBarLightMode(activity.getWindow(), false);
} else if (type == ANDROID_M) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
/**
* 设置状态栏图标为深色和魅族特定的文字风格
* 可以用来判断是否为Flyme用户
*
* @param window 需要设置的窗口
* @param dark 是否把状态栏文字及图标颜色设置为深色
* @return boolean 成功执行返回true
*/
private static boolean flymeSetStatusBarLightMode(Window window, boolean dark) {
boolean result = false;
if (window != null) {
try {
WindowManager.LayoutParams lp = window.getAttributes();
Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
darkFlag.setAccessible(true);
meizuFlags.setAccessible(true);
int bit = darkFlag.getInt(null);
int value = meizuFlags.getInt(lp);
if (dark) {
value |= bit;
} else {
value &= ~bit;
}
meizuFlags.setInt(lp, value);
window.setAttributes(lp);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
/**
* 需要MIUIV6以上
*
* @param dark 是否把状态栏文字及图标颜色设置为深色
* @return boolean 成功执行返回true
*/
private static boolean miuiSetStatusBarLightMode(Activity activity, boolean dark) {
boolean result = false;
Window window = activity.getWindow();
if (window != null) {
Class clazz = window.getClass();
try {
int darkModeFlag = 0;
Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
darkModeFlag = field.getInt(layoutParams);
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
if (dark) {
/**
* 状态栏透明且黑色字体
*/
extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
} else {
/**
* 清除黑色字体
*/
extraFlagField.invoke(window, 0, darkModeFlag);
}
result = true;
/**
* 开发版 7.7.13 及以后版本采用了系统API,旧方法无效但不会报错,所以两个方式都要加上
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (dark) {
activity.getWindow()
.getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
/**
* 设置状态栏背景
*
* @param activity Activity页面
* @param state 状态栏值,如{@link View#SYSTEM_UI_FLAG_LIGHT_STATUS_BAR}
* @param colorId 背景颜色资源id
*/
public static void setStatusBar(Activity activity, int state, int colorId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window mWindow = activity.getWindow();
mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
mWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
mWindow.setStatusBarColor(Color.TRANSPARENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
}
activity.getWindow().getDecorView().setSystemUiVisibility(flags);
// 设置暗色,文字为深色背景透明View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
// 设置亮色,文字为白色背景透明View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
setUiVisibility(mWindow, state);
setColor(mWindow, ContextCompat.getColor(activity, colorId));
}
}
private static void setColor(Window mWindow, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mWindow == null) {
return;
}
mWindow.setStatusBarColor(color);
}
}
private static void setUiVisibility(Window mWindow, int statue) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWindow.getDecorView().setSystemUiVisibility(statue);
}
}
/**
* 设置状态栏背景
*
* @param activity Activity页面
* @param state 状态栏值,如{@link View#SYSTEM_UI_FLAG_LIGHT_STATUS_BAR}
* @param color 背景颜色
*/
public static void setStatusBar(Activity activity, int state, String color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window mWindow = activity.getWindow();
mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
mWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
mWindow.setStatusBarColor(Color.TRANSPARENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
}
activity.getWindow().getDecorView().setSystemUiVisibility(flags);
// 设置暗色,文字为深色背景透明View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
// 设置亮色,文字为白色背景透明View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
setUiVisibility(mWindow, state);
setColor(mWindow, color);
}
}
private static void setColor(Window mWindow, String color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mWindow == null) {
return;
}
mWindow.setStatusBarColor(Color.parseColor(color));
}
}
// 获取状态栏高度
public static int getStatusBarHeight2(Context context) {
Class<?> c = null;
Object obj = null;
Field field = null;
int x = 0, statusBarHeight = 0;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
statusBarHeight = context.getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
e1.printStackTrace();
}
return statusBarHeight;
}
}
... ...
/*
* Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved.
*/
package com.wd.foundation.wdkit.statusbar;
import com.wd.foundation.wdkit.R;
/**
* 状态栏类型枚举值<BR>
*
* @author zhangbo
* @version [V1.0.0, 2022/5/10]
* @since V1.0.0
*/
public enum StatusBarStyleEnum {
/**
* 默认值
*/
NONE(0, false, false),
/**
* 正常状态栏,黑色背景,白字
*/
NORMAL_BLACK_LIGHT_ENUM(R.color.color_000000, false, false),
/**
* 正常状态栏,黑色背景,白字
*/
NORMAL_161827_LIGHT_ENUM(R.color.color_161827, false, false),
/**
* 正常状态栏,白色背景,黑字
*/
NORMAL_WHITE_DARK_ENUM(R.color.color_ffffff, true, false),
/**
* 正常状态栏,F9F9F9背景,黑字
*/
NORMAL_F9F9F9_DARK_ENUM(R.color.color_F9F9F9, true, false),
/**
* 全屏,透明,黑字
*/
FULLSCREEN_DARK_ENUM(0, true, true),
/**
* 全屏,透明,白字
*/
FULLSCREEN_LIGHT_ENUM(0, false, true),
/**
* 全屏,透明
*/
FULLSCREEN_NO_ENUM(-1, false, true);
private final int colorId;
private final boolean labelIsBlack;
private final boolean fullScreen;
/**
* 构造函数
*
* @param colorId 背景颜色资源id
* @param labelIsBlack 状态栏文字是否深色(否,则是白色)
* @param fullScreen 是否沉浸式状态栏
*/
StatusBarStyleEnum(int colorId, boolean labelIsBlack, boolean fullScreen) {
this.colorId = colorId;
this.labelIsBlack = labelIsBlack;
this.fullScreen = fullScreen;
}
public int getColorId() {
return colorId;
}
public boolean isLabelIsBlack() {
return labelIsBlack;
}
public boolean isFullScreen() {
return fullScreen;
}
}
... ...
/*
* Copyright (c) Wondertek Technologies Co., Ltd. 2021-2022. All rights reserved.
*/
package com.wd.foundation.wdkit.utils;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import androidx.annotation.NonNull;
import com.wd.foundation.wdkit.statusbar.StatusBarCompat;
import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum;
//import top.zibin.luban.OnCompressListener;
/**
* 工具类
*
* @author lvjinhui
*/
public class ToolsUtil {
private static final String IMAGE_DIR = "people_daily_client";
private static final String CROP_DIR = "crop_image";
private static final int CROP_IMG_SIZE = 1024;
/**
* 默认一次选择最多的数量
*/
private static int maxNum = 6;
private static final float SCALE = 0.85f;
private static final int MAX_ORIGINAL_SIZE = 10;
private ToolsUtil() {
}
public static void setMaxNum(int num) {
maxNum = num;
}
// /**
// * onActivityResult 接收选择的图片和视频
// *
// * @param activity activity or fragment
// * @param mItemList 可以同时选择图片和视频
// * @param requestCode
// */
// public static void selectPicsAndVideo(Activity activity, List<Item> mItemList, int requestCode) {
// Matisse.from(activity)
// .choose(MimeType.ofAll(), false)
// .countable(true)
// // .capture(true)
// // .captureStrategy(new CaptureStrategy(true, FileUtils.FILEPROVIDER, IMAGE_DIR))
// .maxSelectable(maxNum)
// .setSelectionItems(mItemList)
// .gridExpectedSize(activity.getResources().getDimensionPixelSize(R.dimen.rmrb_dp88))
// .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
// .thumbnailScale(SCALE)
// .imageEngine(new Glide4Engine())
// .originalEnable(true)
// .maxOriginalSize(MAX_ORIGINAL_SIZE)
// .autoHideToolbarOnSingleTap(true)
// .setSelType(SelectionSpec.SEL_TYPE_ALL)
// .forResult(requestCode);
//
// }
//
// /**
// * 选择多张图片或单个视频
// * @param activity
// * @param mItemList
// * @param requestCode
// */
// public static void selectPicsOrVideo(Activity activity, List<Item> mItemList, int requestCode) {
// Matisse.from(activity)
// .choose(MimeType.ofAll(), true)
// .countable(true)
//// .maxSelectable(maxNum)
// .maxSelectablePerMediaType(maxNum,1)
// .setSelectionItems(mItemList)
// .gridExpectedSize(activity.getResources().getDimensionPixelSize(R.dimen.rmrb_dp88))
// .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
// .thumbnailScale(SCALE)
// //这两行要连用 是否在选择图片中展示照相 和适配安卓7.0 FileProvider
// .capture(true)
// .isVideoAndPic(true)
// .captureStrategy(new CaptureStrategy(true, BaseConstants.FILE_PROVIDER))
// .imageEngine(new Glide4Engine())
// .originalEnable(true)
// .autoHideToolbarOnSingleTap(true)
// .showSingleMediaType(true)
// .setSelType(SelectionSpec.SEL_TYPE_ALL)
// .forResult(requestCode);
// }
//
// /**
// * 选择照片
// *
// * @param activity
// * @param mItemList
// * @param requestCode
// */
// public static void selectPhotos(Activity activity, List<Item> mItemList, int requestCode) {
// Matisse.from(activity)
// .choose(EnumSet.of(MimeType.JPEG, MimeType.PNG, MimeType.GIF, MimeType.BMP), true)
// .countable(true)
// .maxSelectable(maxNum)
// .setSelectionItems(mItemList)
// .gridExpectedSize(activity.getResources().getDimensionPixelSize(R.dimen.rmrb_dp88))
// .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
// .thumbnailScale(SCALE)
// .imageEngine(new Glide4Engine())
// .originalEnable(true)
// .maxOriginalSize(MAX_ORIGINAL_SIZE)
// .autoHideToolbarOnSingleTap(true)
// .showSingleMediaType(true)
// .setSelType(SelectionSpec.SEL_TYPE_IMG)
// .forResult(requestCode);
// }
//
// /**
// * 仅选择视频,多个
// *
// * @param activity
// * @param mItemList
// * @param requestCode
// */
// public static void selectVideos(Activity activity, List<Item> mItemList, int requestCode) {
// Matisse.from(activity)
// .choose(MimeType.ofVideo(), true)
// .countable(true)
// .maxSelectable(maxNum)
// .setSelectionItems(mItemList)
// .gridExpectedSize(activity.getResources().getDimensionPixelSize(R.dimen.rmrb_dp88))
// .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
// .thumbnailScale(SCALE)
// .imageEngine(new Glide4Engine())
// .originalEnable(true)
// .maxOriginalSize(MAX_ORIGINAL_SIZE)
// .autoHideToolbarOnSingleTap(true)
// .showSingleMediaType(true)
// .setSelType(SelectionSpec.SEL_TYPE_VOD)
// .forResult(requestCode);
//
// }
//
// /**
// * 相机
// *
// * @param activity
// * @param requestCode
// * @return 拍照保存的路径
// */
// public static String openCamera(Activity activity, int requestCode) {
// Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// PackageManager pm = activity.getPackageManager();
// // Ensure that there's a camera activity to handle the intent
// if (takePictureIntent.resolveActivity(pm) != null) {
// // Create the File where the photo should go
// File photoFile = null;
// try {
// photoFile = createImageFile(activity);
// } catch (IOException ex) {
// // Error occurred while creating the File
// }
// // Continue only if the File was successfully created
// if (photoFile != null) {
// Uri photoURI;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// photoURI = FileProvider.getUriForFile(activity, BaseConstants.FILE_PROVIDER, photoFile);
// } else {
// photoURI = Uri.fromFile(photoFile);
// }
// takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
// activity.startActivityForResult(takePictureIntent, requestCode);
// return photoFile.getAbsolutePath();
// }
// }
//
// return "";
// }
//
// /**
// * 图片裁剪
// *
// * @param activity
// * @param file 要裁剪的图片
// */
// public static void photoCrop(Activity activity, File file) {
// File cropFile = MyFileUtils.createFileInDownload(CROP_DIR, MyFileUtils.getFileNameByTime("IMG", "jpg"));
// String pickCropPath = cropFile.getAbsolutePath();
// UCrop.Options options = new UCrop.Options();
// options.setShowCropGrid(false);
// // 隐藏底部工具
// options.setHideBottomControls(true);
// options.setToolbarColor(ContextCompat.getColor(activity, R.color.res_color_common_C9));
// options.setStatusBarColor(ContextCompat.getColor(activity, R.color.res_color_common_C9));
//// options.setActiveWidgetColor(ContextCompat.getColor(activity, R.color.res_color_common_C9));
// options.setToolbarWidgetColor(ContextCompat.getColor(activity, R.color.res_color_common_C8));
// // 设置图片压缩质量
// options.setCompressionQuality(100);
// UCrop.of(Uri.fromFile(file), Uri.parse(pickCropPath))
// .withMaxResultSize(CROP_IMG_SIZE, CROP_IMG_SIZE)
// .withAspectRatio(1, 1)
// .withOptions(options)
// .start(activity);
// }
//
// /**
// * 图片裁剪 Options 定义
// *
// * @param activity
// * @param file 要裁剪的图片
// */
// public static void photoCropCustom(Activity activity, File file, boolean type) {
// File cropFile = MyFileUtils.createFileInDownload(CROP_DIR, MyFileUtils.getFileNameByTime("IMG", "jpg"));
// String pickCropPath = cropFile.getAbsolutePath();
//
// UCrop.Options options = new UCrop.Options();
// // 修改标题栏颜色
// options.setToolbarColor(ContextCompat.getColor(activity, R.color.color_000000));
// // 修改状态栏颜色
// options.setStatusBarColor(ContextCompat.getColor(activity, R.color.color_000000));
// // 隐藏底部工具
// options.setHideBottomControls(true);
// // 图片格式
// // options.setCompressionFormat(Bitmap.CompressFormat.JPEG);
// // 设置图片压缩质量
// options.setCompressionQuality(100);
// // 是否让用户调整范围(默认false),如果开启,可能会造成剪切的图片的长宽比不是设定的
// // 如果不开启,用户不能拖动选框,只能缩放图片
// // options.setFreeStyleCropEnabled(true);
// // 圆
// // options.setCircleDimmedLayer(true);
// // 不显示网格线
// // options.setShowCropGrid(false);
//
// // FileUtils.createOrExistsDir(Config.SAVE_REAL_PATH);
//
// UCrop of = UCrop.of(Uri.fromFile(file), Uri.parse(pickCropPath));
// if (type) {
// of.withMaxResultSize(525, 294).withAspectRatio(16, 9);
// } else {
// of.withMaxResultSize(525, 700).withAspectRatio(3, 4);
// }
//
// of.withOptions(options).start(activity);
//
// }
//
// /**
// * 图片裁剪
// * @param activity
// * @param file
// * @param ratioType 1-1:1,2-16:9,3-3:4
// */
// public static void pictureCrop(Activity activity, File file, int ratioType) {
// pictureCrop(activity,file,ratioType, ResUtils.getString(R.string.res_str_crop));
// }
//
// /**
// * 图片裁剪
// * @param activity
// * @param file
// * @param ratioType 1-1:1,2-16:9,3-3:4,4-3:2
// * @param title 标题
// */
// public static void pictureCrop(Activity activity, File file, int ratioType , String title) {
// File cropFile = MyFileUtils.createFileInDownload(CROP_DIR, MyFileUtils.getFileNameByTime("IMG", "jpg"));
// String pickCropPath = cropFile.getAbsolutePath();
// UCrop.Options options = new UCrop.Options();
// // 不显示网格线
// options.setShowCropGrid(false);
// // 隐藏底部工具
// options.setHideBottomControls(true);
// options.setToolbarColor(ContextCompat.getColor(activity, R.color.res_color_common_C9));
// options.setStatusBarColor(ContextCompat.getColor(activity, R.color.res_color_common_C9));
// options.setToolbarWidgetColor(ContextCompat.getColor(activity, R.color.res_color_general_000000));
// // 设置图片压缩质量
// options.setCompressionQuality(100);
// options.setToolbarTitle(title);
// // 是否让用户调整范围(默认false),如果开启,可能会造成剪切的图片的长宽比不是设定的
// // 如果不开启,用户不能拖动选框,只能缩放图片
// options.setFreeStyleCropEnabled(false);
// UCrop of = UCrop.of(Uri.fromFile(file), Uri.parse(pickCropPath));
// if (ratioType == 1) {
// of.withMaxResultSize(CROP_IMG_SIZE, CROP_IMG_SIZE).withAspectRatio(1, 1);
// } else if (ratioType == 2){
// of.withMaxResultSize(CROP_IMG_SIZE, CROP_IMG_SIZE).withAspectRatio(16, 9);
// }else if (ratioType == 3){
// of.withMaxResultSize(CROP_IMG_SIZE, CROP_IMG_SIZE).withAspectRatio(3, 4);
// }else if (ratioType == 4){
// of.withMaxResultSize(CROP_IMG_SIZE, CROP_IMG_SIZE).withAspectRatio(3, 2);
// }
// of.withOptions(options).startPicCropActivity(activity);
// }
//
// /**
// * 拍照保存的图片
// *
// * @param context
// * @return image File
// * @throws IOException
// */
// public static File createImageFile(Context context) throws IOException {
// // Create an image file name
// String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
// String imageFileName = "JPEG_" + timeStamp + "_";
// File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
// File image = File.createTempFile(imageFileName, ".jpg", storageDir);
// return image;
// }
//
// public static boolean isStrangePhone() {
// boolean strangePhone = "mx5".equalsIgnoreCase(Build.DEVICE) || "Redmi Note2".equalsIgnoreCase(Build.DEVICE)
// || "Z00A_1".equalsIgnoreCase(Build.DEVICE) || "hwH60-L02".equalsIgnoreCase(Build.DEVICE)
// || "hermes".equalsIgnoreCase(Build.DEVICE)
// || ("V4".equalsIgnoreCase(Build.DEVICE) && "Meitu".equalsIgnoreCase(Build.MANUFACTURER))
// || ("m1metal".equalsIgnoreCase(Build.DEVICE) && "Meizu".equalsIgnoreCase(Build.MANUFACTURER));
//
// return strangePhone;
// }
//
// /**
// * 提供精确的除法运算
// *
// * @param v1 被除数
// * @param v2 除数
// * @return 两个参数的商
// */
// public static double divNum(double v1, double v2) {
// try {
// int v1IntValue = (int) Math.round(v1);
// int v2IntValue = (int) Math.round(v2);
// if (0 == v1IntValue || 0 == v2IntValue) {
// return 0;
// }
// BigDecimal b1 = BigDecimal.valueOf(v1);
// BigDecimal b2 = BigDecimal.valueOf(v2);
// return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// }
// return 0;
// }
//
// /**
// * 单个图片压缩,替换原图
// *
// * @param context
// * @param photo
// * @param ignoreBy 小于该值不压缩 KB
// * @param zipListener 回调
// */
// public static void luBanZip(Context context, File photo, int ignoreBy, ILuBanZipListener zipListener) {
// if (photo != null && photo.exists()) {
// ThreadPoolUtils.submit(new Runnable() {
// @Override
// public void run() {
// try {
// if (zipListener != null) {
// zipListener.onStart();
// }
//
// Bitmap image = BitmapFactory.decodeFile(photo.getAbsolutePath());
// int degree = FileZipUtils.readPictureDegree(photo.getAbsolutePath());// 读取照片旋转角度
// if (degree > 0) {
// image = FileZipUtils.rotateBitmap(image, degree); // 旋转照片
// }
// Bitmap bitmap = FileZipUtils.compressScale(image, ignoreBy);
// File directory = new File(context.getFilesDir() + File.separator + Environment.DIRECTORY_PICTURES);
// File file = new File(directory, SystemClock.uptimeMillis() + ".jpg");
// if (!directory.exists()) {
// directory.mkdirs();
// }
// FileOutputStream fileOutputStream = new FileOutputStream(file);
// Bitmap.CompressFormat compressFormat = Bitmap.CompressFormat.JPEG;
// bitmap.compress(compressFormat, 100, fileOutputStream);
// fileOutputStream.flush();
// fileOutputStream.close();
// if (zipListener != null) {
// zipListener.onSuccess(file);
// }
// Logger.t("ToolsUtil").e("压缩图片~");
// } catch (Exception e) {
// if (zipListener != null) {
// zipListener.onError(e.getMessage());
// }
// }
//
// }
// });
// } else {
// if (zipListener != null) {
// zipListener.onError("原始文件不存在");
// }
// }
//
// }
public static void setStatusBarStyle(@NonNull StatusBarStyleEnum statusBarStyle, Activity activity) {
if (statusBarStyle.isFullScreen()) {
if (-1 == statusBarStyle.getColorId()) {
// 全屏,即,沉浸式状态栏。需要自己处理好页面内容,因为部分内容会顶到状态栏底部
StatusBarCompat.fullScreenNoStatusBar(activity);
} else {
// 全屏,即,沉浸式状态栏。需要自己处理好页面内容,因为部分内容会顶到状态栏底部
StatusBarCompat.fullScreenStatusBar(activity, Color.TRANSPARENT, statusBarStyle.isLabelIsBlack());
}
} else {
// 修改状态栏背景色,非全屏
int state = statusBarStyle.isLabelIsBlack() ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
: View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
StatusBarCompat.setStatusBar(activity, state, statusBarStyle.getColorId());
}
}
// /**
// * 直播间点赞样式数据转换
// * 获取点赞样式
// * love爱心型 thumb点赞手势 pray 祈福 mourning默哀
// * 默认爱心
// * @param likeStyle
// */
// public static int dealLiveRoomLikeStyle(String likeStyle) {
// if (StringUtils.isEqual(Constants.STRING_EMPTY, likeStyle)) {
// return -1;
// } else if (StringUtils.isEqual(Constants.STRING_PRAY, likeStyle)) {
// return R.mipmap.icon_like_selected_pray;
// } else if (StringUtils.isEqual(Constants.STRING_MOURNING, likeStyle)) {
// return R.mipmap.icon_like_selected_candle;
// } else {
// return R.mipmap.icon_like_selected_redheart;
// }
// }
//
// /**
// * 点赞样式库
// * @param likeStyle 点赞样式 1(默认):红心(点赞) 2:大拇指(祈福) 3:蜡烛(默哀) 4:置空 5视频详情页
// * @param mode 背景色深浅,0浅色用于评论弹框等白色背景的(默认)、1深色用于视频等黑色背景的、2动态详情页等专属 3视频详情专属 4评论点赞专属
// * @param selected 点赞状态 false未点赞、true已点赞
// * */
// public static int getLikeStyle(int likeStyle, int mode, boolean selected){
// // 点赞样式 1:红心(点赞) 2:大拇指(祈福) 3:蜡烛(默哀) 4:置空
// if (2 == likeStyle) {
// //已点赞 深浅色用同一套图标
// if(selected){
// return R.mipmap.icon_like_selected_pray;
// } else{
// if(1 == mode) {
// return R.mipmap.icon_like_unselect_night_pray;
// } else if(2 == mode) {
// return R.mipmap.icon_like_unselect_grey_pray;
// }else if(3 == mode){
// return R.mipmap.icon_like_unselect_video_pray;
// }else{
// return R.mipmap.icon_like_unselect_light_pray;
// }
// }
// }else if (3 == likeStyle) {
// //已点赞 深浅色用同一套图标
// if (selected) {
// return R.mipmap.icon_like_selected_candle;
// } else {
// if (1 == mode) {
// return R.mipmap.icon_like_unselect_night_candle;
// } else if (2 == mode) {
// return R.mipmap.icon_like_unselect_grey_candle;
// }else if(3 == mode){
// return R.mipmap.icon_like_unselect_video_candle;
// } else {
// return R.mipmap.icon_like_unselect_light_candle;
// }
// }
// }else if(4 == likeStyle) {
// return -1;
// }else{
// //已点赞 深浅色用同一套图标
// if(selected){
// return R.mipmap.icon_like_selected_redheart;
// }else{
// if(1 == mode) {
// return R.mipmap.icon_like_unselect_night_redheart;
// } else if(2 == mode) {
// return R.mipmap.icon_like_unselect_grey_redheart;
// }else if(3 == mode) {
// return R.mipmap.icon_like_unselect_video_redheart;
// }else if(4 == mode){
// return R.mipmap.icon_like_unselect_grey_redheart_comment;
// }else{
// return R.mipmap.icon_like_unselect_light_redheart;
// }
// }
// }
// }
//
// /**
// * 带圈的点赞样式库
// * @param likeStyle 点赞样式 1:红心(点赞) 2:大拇指(祈福) 3:蜡烛(默哀) 4:置空
// * @param selected 点赞状态 false未点赞、true已点赞
// * */
// public static int getCircleLikeStyle(int likeStyle, boolean selected){
// if (2 == likeStyle) {
// if(selected){
// return R.mipmap.icon_like_selected_light_pray_circle;
// }else{
// return R.mipmap.icon_like_unselect_light_pray_circle;
// }
// }else if (3 == likeStyle) {
// if(selected){
// return R.mipmap.icon_like_selected_light_candle_circle;
// }else{
// return R.mipmap.icon_like_unselect_light_candle_circle;
// }
// }else {
// if(selected){
// return R.mipmap.icon_like_selected_light_redheart_circle;
// }else{
// return R.mipmap.icon_like_unselect_light_redheart_circle;
// }
// }
// }
//
// /**
// * 获取分享点赞名称
// * @param likeStyle
// * @return
// */
// public static int getCircleLikeName(int likeStyle){
// if (2 == likeStyle) {
// //祈祷
// return R.string.share_to_like_pray;
// }else if (3 == likeStyle) {
// //默哀
// return R.string.share_to_like_silent;
// }else {
// //点赞
// return R.string.share_to_like;
// }
// }
//
// /**
// * 收藏样式库
// * 设置收藏图标
// * @param mode 背景色深浅,0浅色用于评论弹框等白色背景的(默认)、1深色用于视频等黑色背景的、2分享弹窗里面的收藏(带圈)、 3视频详情页
// */
// public static int getCollectStyle(int mode, boolean selected) {
// if (selected) {
// if(mode == 2){
// return R.mipmap.ic_share_collected;
// }else{
// return R.mipmap.icon_collect_select;
// }
// }else {
// if(mode == 1) {
// return R.mipmap.icon_collect_unselect_night;
// }else if(mode == 2) {
// return R.mipmap.ic__collect_unselect_pop;
// }else if(mode == 3){
// return R.mipmap.ic_collect_unselected_video;
// }else{
// return R.mipmap.icon_collect_unselect_light;
// }
// }
// }
//
// /**
// * 点赞动效库
// * */
// public static String getLikeStyleAnimation(int likeStyle){
// // 点赞样式 1:红心(点赞) 2:大拇指(祈福) 3:蜡烛(默哀) 4:置空
// String selRes = "";
// if (1 == likeStyle) {
// selRes = "like_article.json";
// }else if (2 == likeStyle) {
// selRes = "like_pray_40.json";
// }else if (3 == likeStyle) {
// selRes = "like_candle_40.json";
// }
// return selRes;
// }
//
// /**
// * 收藏成功
// */
// public static void showAddCollectLabelDialog(Context context,
// List<CollectContentBean> contentList
// , AddFavoriteLabelCallback addFavoriteLabelCallback) {
// if(context == null)
// {
// return;
// }
//
// if(context instanceof Activity)
// {
// if(((Activity) context).isFinishing() || ((Activity) context).isDestroyed())
// {
// return;
// }
// }
// CollectDialog.createDialog(context, contentList,addFavoriteLabelCallback).show();
// }
}
... ...
package com.wd.foundation.wdkit.viewclick;
import java.util.Calendar;
import android.view.View;
/**
* 防止快速点击
*
* @author baozhaoxin
* @version [V1.0.0, 2023/2/7]
* @since V1.0.0
*/
public abstract class BaseClickListener implements View.OnClickListener {
/**
* 点击事件间隔 这里设置不能少于多长时间
*/
public static final int MIN_CLICK_DELAY_TIME = 800;
private long lastClickTime = 0;
/**
* 连续点击控制
*
* @param v
*/
protected abstract void onNoDoubleClick(View v);
@Override
public void onClick(View v) {
long currentTime = Calendar.getInstance().getTimeInMillis();
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
lastClickTime = currentTime;
onNoDoubleClick(v);
}
}
}
\ No newline at end of file
... ...
package com.wd.foundation.wdkit.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.wd.foundation.wdkit.R;
import com.wd.foundation.wdkit.constant.DefaultViewConstant;
import com.wd.foundation.wdkit.viewclick.BaseClickListener;
import com.wd.foundation.wdkitcore.tools.ResUtils;
/**
* 缺省页
* TODO 待拆,往上层业务抛
* @author baozhaoxin
* @version [V1.0.0, 2023/3/31]
* @since V1.0.0
*/
public class DefaultView extends LinearLayout {
/**
* 根view
*/
private View rootView;
/**
* View 距离top高度
*/
private View topView, btmView;
/**
* 根布局
*/
private LinearLayout defaultRootLayout;
/**
* 内容布局
*/
private LinearLayout defaultLayout;
/**
* 图标
*/
private ImageView defaultImg;
private ConstraintLayout topMenuView;
/**
* 文案
*/
private TextView defaultTv;
/**
* 重试按钮
*/
private TextView defaultBtn;
/**
* 上下文环境
*/
private Context mContext;
/**
* 1.页面接口报错,用于列表类及其他页面(带重试按钮):Loading failed, please try again!
* 2.内容获取失败,用于内容详情页(带重试按钮):An error occurred. Please try again later.
* 3.暂无网络(带重试按钮):网络出小差了,请检查网络后重试!
* 4.暂无内容:No content
* 5.暂无收藏内容:You haven't collected anything yet. Go to the home page.
* 6.暂无消息:No records
* 7.暂无浏览历史:No records
* 8.暂无搜索结果:No content found
*/
private int mType = -1;// DefaultViewConstant.TYPE_GET_CONTENT_ERROR;
/**
* 重试按钮点击监听
*/
private RetryClickListener retryClickListener;
/**
* 缺省页面布局,true:用带NestedScrollView布局;false:不带带NestedScrollView布局
*/
private boolean nestedScrollView = false;
public DefaultView(Context context) {
this(context, null);
}
public DefaultView(Context context, boolean nestedScrollView) {
super(context);
this.nestedScrollView = nestedScrollView;
initView(context);
}
public DefaultView(Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public DefaultView(Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
// 获取定义的一些属性
TypedArray styleAttrs =
context.getTheme().obtainStyledAttributes(attrs, R.styleable.DefaultView, defStyleAttr, 0);
// 数一数有多少个属性呢
int indexCount = styleAttrs.getIndexCount();
// 循环遍历的方式,找到我们所定义的一些属性
for (int i = 0; i < indexCount; i++) {
// 属性的索引值
int attrIndex = styleAttrs.getIndex(i);
// 根据索引值给java代码中的成员变量赋值
if (attrIndex == R.styleable.DefaultView_default_view_type) {
mType = styleAttrs.getInteger(attrIndex, -1);
}
}
// 资源文件中的属性回收
styleAttrs.recycle();
initView(context);
}
/**
* 初始化view
*
* @param context
*/
private void initView(Context context) {
mContext = context;
if (rootView == null) {
if (nestedScrollView) {
rootView = LayoutInflater.from(context).inflate(R.layout.wdkit_default_layout_nested_sc, this);
} else {
rootView = LayoutInflater.from(context).inflate(R.layout.wdkit_default_layout, this);
}
}
if (rootView != null) {
defaultRootLayout = rootView.findViewById(R.id.default_root_layout);
topView = rootView.findViewById(R.id.top_View);
btmView = rootView.findViewById(R.id.btmspaceview);
defaultLayout = rootView.findViewById(R.id.default_content_layout);
defaultImg = rootView.findViewById(R.id.default_img);
topMenuView = rootView.findViewById(R.id.layout_follow_more_creator);
defaultTv = rootView.findViewById(R.id.default_tv);
defaultBtn = rootView.findViewById(R.id.default_btn);
defaultBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (retryClickListener != null) {
retryClickListener.onRetryClick();
}
}
});
}
// 显示默认缺省页面
show(mType);
// defaultRootLayout.setVisibility(GONE);
}
public void show(int type) {
show(type, false, false);
}
/**
* 展示布局,同时设置顶部底部比例
*/
public void showWithWeight(int type, int topWeight, int btmWeight) {
setTopBtmWeight(topWeight, btmWeight);
show(type, false, false);
}
/**
* 展示布局,设置top和btm距离,适合容器是wrap_parent
*/
public void setTopBtmHeight(int type, int topWeight, int btmWeight) {
setTopBtmHeight(topWeight, btmWeight);
show(type, false, false);
}
/**
* 显示缺省页
*
* @param type 1.页面接口报错,用于列表类及其他页面(带重试按钮):Loading failed, please try again!
* 2.内容获取失败,用于内容详情页(带重试按钮):An error occurred. Please try again later.
* 3.暂无网络(带重试按钮):网络出小差了,请检查网络后重试!
* 4.暂无内容:No content
* 5.暂无收藏内容:You haven't collected anything yet. Go to the home page.
* 6.暂无消息:No records
* 7.暂无浏览历史:No records
* 8.暂无搜索结果:No content found
* 9.确认提交
* 10.直播结束
* 11.没有找到相关内容(2023/11/6 新增 )DefaultViewConstant.TYPE_NO_RELEVANT_CONTENT_FOUND
* @param hasTry true带重试按钮、false不带重试按钮
* @param isDark true黑模式、false正常模式
*/
public void show(int type, boolean hasTry, boolean isDark) {
if (type == -1) {
return;
}
mType = type;
if (isDark) {
// 黑色样式
setDarkMode();
}
// 点击重试按钮
defaultBtn.setVisibility(hasTry ? VISIBLE : GONE);
topMenuView.setVisibility(GONE);
if (type == DefaultViewConstant.TYPE_GET_CONTENT_FAILED) {
// 内容获取失败,用于内容详情页
if (isDark) {
// 灰粉:直播间、视频
defaultImg.setBackgroundResource(R.mipmap.wdkit_icon_default_get_content_failed_greypink);
} else {
// 白粉:通用
defaultImg.setBackgroundResource(R.mipmap.wdkit_icon_default_get_content_failed_whitepink);
}
defaultTv.setText(ResUtils.getString(R.string.default_get_content_failed));
} else if (type == DefaultViewConstant.TYPE_GET_CONTENT_ERROR) {
// 内容获取失败,用于内容详情页
if (isDark) {
// 灰粉:直播间、视频
defaultImg.setBackgroundResource(R.mipmap.wdkit_icon_default_get_content_failed_greypink);
} else {
// 白粉:通用
defaultImg.setBackgroundResource(R.mipmap.wdkit_icon_default_get_content_failed_whitepink);
}
defaultTv.setText(ResUtils.getString(R.string.default_get_content_failed));
defaultBtn.setVisibility(VISIBLE);
} else if (type == DefaultViewConstant.TYPE_NO_NETWORK) {
// 暂无网络
defaultImg.setBackgroundResource(R.mipmap.icon_default_no_network);
defaultTv.setText(ResUtils.getString(R.string.default_no_network));
} else if (type == DefaultViewConstant.TYPE_NO_COLLECTED) {
// 暂无收藏
defaultImg.setBackgroundResource(R.mipmap.icon_default_no_collected);
defaultTv.setText(ResUtils.getString(R.string.no_collection));
} else if (type == DefaultViewConstant.TYPE_NO_RECORDS_MESSAGE) {
// 暂无消息
defaultImg.setBackgroundResource(R.mipmap.icon_default_no_records_message);
defaultTv.setText(ResUtils.getString(R.string.default_no_records));
} else if (type == DefaultViewConstant.TYPE_NO_RECORDS_BROWSE) {
// 暂无浏览历史
defaultImg.setBackgroundResource(R.mipmap.icon_default_noworkorreservation);
defaultTv.setText(ResUtils.getString(R.string.no_browsing_history));
} else if (type == DefaultViewConstant.TYPE_NO_CONTENT_FOUND) {
// 没有找到相关内容(搜索)
defaultImg.setBackgroundResource(R.mipmap.icon_default_no_search_result);
defaultTv.setText(ResUtils.getString(R.string.default_no_content_found));
} else if (type == DefaultViewConstant.TYPE_LIVE_END) {
// 直播结束
defaultImg.setBackgroundResource(R.mipmap.icon_default_live_end);
defaultTv.setText(ResUtils.getString(R.string.tips_end_of_live_broadcast));
} else if (type == DefaultViewConstant.TYPE_NO_COMMENT) {
// 暂无评论
defaultImg.setBackgroundResource(R.mipmap.icon_default_nocomment);
defaultTv.setText(ResUtils.getString(R.string.nocomment));
} else if (type == DefaultViewConstant.TYPE_NO_WORKS || type == DefaultViewConstant.TYPE_NO_RESERVATION
|| type == DefaultViewConstant.TYPE_NO_CONTENT) {
// 暂无预约、暂无作品、暂无内容
defaultImg.setBackgroundResource(R.mipmap.icon_default_noworkorreservation);
if (type == DefaultViewConstant.TYPE_NO_WORKS) {
defaultTv.setText(ResUtils.getString(R.string.noworks));
} else if (type == DefaultViewConstant.TYPE_NO_RESERVATION) {
defaultTv.setText(ResUtils.getString(R.string.noreservation));
} else if (type == DefaultViewConstant.TYPE_NO_CONTENT) {
defaultTv.setText(ResUtils.getString(R.string.default_no_content));
}
} else if (type == DefaultViewConstant.TYPE_CURRENT_LIMITING) {
// 限流
defaultImg.setBackgroundResource(R.mipmap.icon_currentlimiting);
defaultTv.setText(ResUtils.getString(R.string.currentlimiting) + "(10s)");
} else if (type == DefaultViewConstant.TYPE_NO_PERMISSION) {
// 该号主暂时无法访问
defaultImg.setBackgroundResource(R.mipmap.icon_no_permission);
defaultTv.setText(ResUtils.getString(R.string.nopermission));
} else if (type == DefaultViewConstant.TYPE_ANCHOR_LEAVING) {
// 主播暂时离开,马上回来
defaultImg.setBackgroundResource(R.mipmap.icon_anchor_leaving);
defaultTv.setText(ResUtils.getString(R.string.anchor_leaving));
} else if (type == DefaultViewConstant.TYPE_NO_RELEVANT_CONTENT_FOUND) {
// 没有找到相关内容
defaultImg.setBackgroundResource(R.mipmap.wdkit_icon_no_relevant_content_found);
defaultTv.setText(ResUtils.getString(R.string.no_relevant_content_found));
defaultImg.getLayoutParams().height = (int) mContext.getResources().getDimension(R.dimen.wdkit_dp139);
defaultImg.getLayoutParams().width = (int) mContext.getResources().getDimension(R.dimen.wdkit_dp200);
} else if (type == DefaultViewConstant.TYPE_PERSONAL_CENTER_WORKS) {
// 号主页-暂无作品
defaultImg.setBackgroundResource(R.mipmap.ic_no_works_yet);
defaultTv.setText(ResUtils.getString(R.string.no_works_yet));
} else if (type == DefaultViewConstant.TYPE_PERSONAL_CENTER_COMMENT) {
// 号主页-暂无评论
defaultImg.setBackgroundResource(R.mipmap.ic_no_comment_yet);
defaultTv.setText(ResUtils.getString(R.string.no_comment_yet));
} else if (type == DefaultViewConstant.TYPE_PERSONAL_CENTER_FOCUS) {
// 号主页-暂无关注
defaultImg.setBackgroundResource(R.mipmap.ic_no_focus_yet);
defaultTv.setText(ResUtils.getString(R.string.no_focus_yet));
} else if (type == DefaultViewConstant.TYPE_PERSONAL_CENTER_FOCUS_TOP_VIEW) {
defaultImg.setBackgroundResource(R.mipmap.ic_no_focus_yet);
defaultTv.setText(ResUtils.getString(R.string.no_focus_yet));
setTopMenuViewShow();
} else if (type == DefaultViewConstant.TYPE_GET_CONTENT_FAILED_VIDEO) {
// 内容获取失败,用于视频详情页(带重试按钮)
defaultImg.setBackgroundResource(R.mipmap.icon_default_get_content_failed_video);
defaultTv.setText(ResUtils.getString(R.string.default_get_content_failed));
defaultBtn.setTextColor(ResUtils.getColor(R.color.color_CCCCCC));
} else {
// 页面接口报错,用于列表类及其他页面(带重试按钮)
defaultImg.setBackgroundResource(R.mipmap.wdkit_icon_default_get_content_failed_whitepink);
defaultTv.setText(ResUtils.getString(R.string.default_get_content_failed));
}
defaultRootLayout.setVisibility(VISIBLE);
}
/**
* 隐藏缺省页
*/
public void hide() {
defaultRootLayout.setVisibility(GONE);
}
public int getmType() {
return mType;
}
public void setmType(int mType) {
this.mType = mType;
}
/**
* 设置暗模式
*/
public void setDarkMode() {
// 黑色
defaultRootLayout.setBackgroundColor(0xff000000);
defaultTv.setTextColor(0xffB0B0B0);
defaultBtn.setTextColor(0xffCCCCCC);
defaultBtn.setBackground(ResUtils.getDrawable(R.drawable.wdkit_bg_text_networkerror_reload_dark));
}
/**
* 设置topView 距离top高度
*/
public void setTopViewHeight(int height) {
ViewGroup.LayoutParams params = topView.getLayoutParams();
params.height = height;
topView.setLayoutParams(params);
}
/**
* 在ColumnFragment上设置背景色
*/
public void setColumnFragmentBackgroundColor() {
defaultRootLayout.setBackgroundResource(R.drawable.wdkit_shape_square_page_top_radius);
LayoutParams defaultViewLp = (LayoutParams) defaultRootLayout.getLayoutParams();
defaultViewLp.rightMargin = (int) mContext.getResources().getDimension(R.dimen.wdkit_dp6);
defaultViewLp.leftMargin = (int) mContext.getResources().getDimension(R.dimen.wdkit_dp6);
defaultRootLayout.setLayoutParams(defaultViewLp);
}
/**
* 设置重试按钮点击监听
*
* @param retryClickListener
*/
public void setRetryBtnClickListener(RetryClickListener retryClickListener) {
this.retryClickListener = retryClickListener;
}
public interface RetryClickListener {
void onRetryClick();
}
/**
* 设置顶部、底部比例
*/
public void setTopBtmWeight(int topWeight, int btmWeight) {
if (topView != null) {
// 设置顶部比例
LayoutParams topParams = (LayoutParams) topView.getLayoutParams();
topParams.weight = topWeight;
topView.setLayoutParams(topParams);
}
if (btmView != null) {
// 设置底部比例
LayoutParams btmParams = (LayoutParams) btmView.getLayoutParams();
btmParams.weight = btmWeight;
btmView.setLayoutParams(btmParams);
}
}
public void showOnlySpace(int type) {
if (btmView != null) {
btmView.setVisibility(GONE);
}
show(type);
}
/**
* 设置顶部、底部高度
*/
public void setTopBtmHeight(int topWeight, int btmWeight) {
if (topView != null) {
// 设置顶部比例
LayoutParams topParams = (LayoutParams) topView.getLayoutParams();
topParams.height = topWeight;
topParams.weight = 0;
topView.setLayoutParams(topParams);
}
if (btmView != null) {
// 设置底部比例
LayoutParams btmParams = (LayoutParams) btmView.getLayoutParams();
btmParams.height = btmWeight;
btmParams.weight = 0;
btmView.setLayoutParams(btmParams);
}
}
public void setTipTextStyle(int color, float textsize) {
if (defaultTv != null) {
defaultTv.setTextColor(color);
defaultTv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textsize);
}
}
public void setTopMenuViewShow() {
if (topMenuView != null) {
topMenuView.setVisibility(VISIBLE);
}
}
public void setTopMenuViewClickListen(BaseClickListener clickListen) {
if (topMenuView != null) {
topMenuView.setOnClickListener(clickListen);
}
}
}
... ...
package com.wd.foundation.wdkit.widget.progress;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import com.airbnb.lottie.LottieAnimationView;
import com.wd.foundation.wdkit.R;
import com.wd.foundation.wdkit.animator.AnimUtil;
/**
* 第一次 视频详情 请求接口 loading 效果
*
* @author xujiawei
*/
public class PageLoadingView extends LinearLayout {
/**
* 延迟0.5秒展示loading,如果0.5秒内结束了,则不展示loading
*/
private boolean needShow;
private Handler handler;
private LottieAnimationView animationView;
private Context context;
public PageLoadingView(Context context) {
this(context, null);
}
public PageLoadingView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public PageLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
init();
}
private void init() {
View view = LayoutInflater.from(context).inflate(R.layout.wdkit_small_white_black_loading_view, this, true);
animationView = view.findViewById(R.id.animation_view);
handler = new Handler(Looper.getMainLooper());
}
/**
* loading
*/
public void showLoading() {
// 需要展示loading
needShow = true;
// 延时展示loading
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (needShow) {
needShow = false;
AnimUtil.showLocalLottieEffects(animationView, "refreshing_common_loading.json", true);
}
}
}, 500);
}
public void stopLoading() {
// 已经结束,不需要再展示loading
needShow = false;
animationView.pauseAnimation();
}
}
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="@dimen/wdkit_dp0_5" android:color="@color/res_color_common_C6" />
<corners android:radius="@dimen/wdkit_dp3"/>
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="@dimen/wdkit_dp0_5" android:color="@color/res_color_common_C2" />
<corners android:radius="@dimen/wdkit_dp3"/>
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/res_color_common_C7" />
<stroke android:width="@dimen/wdkit_dp0_5" android:color="@color/res_color_common_C6"/>
<corners android:radius="@dimen/wdkit_dp4"/>
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:topLeftRadius="@dimen/rmrb_dp6"
android:topRightRadius="@dimen/rmrb_dp6" />
<solid android:color="@color/res_color_common_C8" />
</shape>
\ No newline at end of file
... ...
<!-- 纯内容布局,中间内容模块 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/default_content_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/default_img"
android:layout_width="@dimen/wdkit_dp160"
android:layout_height="@dimen/wdkit_dp112"
android:scaleType="fitXY"
tools:src="@mipmap/wdkit_icon_no_relevant_content_found"
/>
<TextView
android:id="@+id/default_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/wdkit_dp6"
android:gravity="center"
android:textColor="@color/res_color_common_C3"
android:textSize="@dimen/wdkit_dp14"
tools:text="没有找到相关内容"
/>
<TextView
android:id="@+id/default_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/wdkit_dp16"
android:background="@drawable/wdkit_bg_text_networkerror_reload"
android:gravity="center"
android:paddingLeft="@dimen/wdkit_dp16"
android:paddingTop="@dimen/wdkit_dp4"
android:paddingRight="@dimen/wdkit_dp16"
android:paddingBottom="@dimen/wdkit_dp4"
android:text="@string/clickretry"
android:textColor="@color/res_color_common_C2"
android:textSize="@dimen/wdkit_dp12"
android:textStyle="bold"
/>
</LinearLayout>
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/default_root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_follow_more_creator"
android:layout_width="match_parent"
android:layout_height="@dimen/wdkit_dp36"
android:layout_marginHorizontal="@dimen/wdkit_dp16"
android:layout_marginTop="@dimen/wdkit_dp10"
android:layout_marginBottom="@dimen/wdkit_dp2"
android:background="@drawable/wdkit_shape_follow_header_bg"
android:visibility="gone">
<TextView
android:id="@+id/tv_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/res_attention_more"
android:textColor="@color/res_color_common_C1"
android:textSize="@dimen/wdkit_dp14"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/iv_more"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iv_more"
android:layout_width="@dimen/wdkit_dp15"
android:layout_height="@dimen/wdkit_dp15"
android:scaleType="centerCrop"
android:src="@drawable/wdkit_icon_setting_arrow"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_more"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:id="@+id/top_View"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="180" />
<include
layout="@layout/wdkit_default_item_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<View
android:id="@+id/btmspaceview"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="366" />
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/default_root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_follow_more_creator"
android:layout_width="match_parent"
android:layout_height="@dimen/wdkit_dp36"
android:layout_marginHorizontal="@dimen/wdkit_dp16"
android:layout_marginTop="@dimen/wdkit_dp10"
android:layout_marginBottom="@dimen/wdkit_dp2"
android:background="@drawable/wdkit_shape_follow_header_bg"
android:visibility="gone">
<TextView
android:id="@+id/tv_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/res_attention_more"
android:textColor="@color/res_color_common_C1"
android:textSize="@dimen/wdkit_dp14"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/iv_more"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iv_more"
android:layout_width="@dimen/wdkit_dp15"
android:layout_height="@dimen/wdkit_dp15"
android:scaleType="centerCrop"
android:src="@drawable/wdkit_icon_setting_arrow"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_more"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:id="@+id/top_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="7" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<include
layout="@layout/wdkit_default_item_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_noData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>
<com.wd.foundation.wdkit.widget.DefaultView
android:id="@+id/default_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
... ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<RelativeLayout
android:id="@+id/loading_btn"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="324dp"
android:layout_marginHorizontal="25dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:enabled="false"
android:scaleType="fitXY"
android:src="@drawable/login_tv_bg_s" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/one_key_loading"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_centerInParent="true"
app:lottie_autoPlay="true"
app:lottie_loop="true" />
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="@dimen/rmrb_dp44"
android:layout_marginBottom="@dimen/rmrb_dp44"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<com.wd.foundation.wdkit.widget.progress.PageLoadingView
android:id="@+id/channelSmallLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<!-- 全局区域动画(全域动画)加载动画 refreshing_common_loading.pag -->
<FrameLayout 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="wrap_content"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="@dimen/rmrb_dp100"
android:layout_height="@dimen/rmrb_dp100"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="@dimen/rmrb_dp72"
android:layout_height="@dimen/rmrb_dp72"
app:lottie_autoPlay="false"
app:lottie_loop="true"
android:layout_gravity="center_horizontal"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/rmrb_dp10"
android:text="@string/loading_text"
android:textColor="#E6FFFFFF"
android:textSize="@dimen/rmrb_dp14"
android:visibility="gone" />
</LinearLayout>
</FrameLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="btmlogo_dimen">107dp</dimen>
<dimen name="btmjump_dimen">128dp</dimen>
<dimen name="btmjump_dimensmall">23dp</dimen>
</resources>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="btmlogo_dimen">121dp</dimen>
<dimen name="btmjump_dimen">142dp</dimen>
<dimen name="btmjump_dimensmall">33dp</dimen>
</resources>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="btmlogo_dimen">130dp</dimen>
<dimen name="btmjump_dimen">156dp</dimen>
<dimen name="btmjump_dimensmall">52dp</dimen>
</resources>
\ No newline at end of file
... ...