初始化代码
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.qxcm.moduleutil;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.qxcm.moduleutil.test", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
7
moduleUtil/src/main/AndroidManifest.xml
Normal file
7
moduleUtil/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application
|
||||
android:allowBackup="true">
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.qxcm.moduleutil.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
|
||||
import com.blankj.utilcode.util.BarUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.utils.LanguageUtil;
|
||||
|
||||
public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends AppCompatActivity {
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(LanguageUtil.attachBaseContext(newBase));
|
||||
}
|
||||
protected VDB mBinding;
|
||||
|
||||
// private LoadingDialog mLoadingDialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().getDecorView().setBackgroundResource(R.mipmap.log_bj);
|
||||
setContentView(getLayoutId());
|
||||
mBinding = DataBindingUtil.setContentView(this, getLayoutId());
|
||||
mBinding.setLifecycleOwner(this);
|
||||
BarUtils.setStatusBarLightMode(this, isLightMode());
|
||||
BarUtils.transparentStatusBar(this);
|
||||
initView();
|
||||
initData();
|
||||
initCompleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resources getResources() {//禁止app字体大小跟随系统字体大小调节
|
||||
Resources resources = super.getResources();
|
||||
if (resources != null && resources.getConfiguration().fontScale != 1.0f) {
|
||||
android.content.res.Configuration configuration = resources.getConfiguration();
|
||||
configuration.fontScale = 1.0f;
|
||||
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
public boolean isLightMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void initData();
|
||||
|
||||
protected abstract void initView();
|
||||
|
||||
protected void initCompleted() {}
|
||||
|
||||
protected abstract int getLayoutId();
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (mBinding != null) {
|
||||
mBinding.unbind();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public void showLoading(String content) {
|
||||
// if (mLoadingDialog == null) {
|
||||
// mLoadingDialog = new LoadingDialog(this);
|
||||
// }
|
||||
// if (!mLoadingDialog.isShowing()) {
|
||||
// mLoadingDialog.show();
|
||||
// }
|
||||
}
|
||||
|
||||
public void showLoading() {
|
||||
// if (mLoadingDialog == null) {
|
||||
// mLoadingDialog = new LoadingDialog(this);
|
||||
// }
|
||||
// if (!mLoadingDialog.isShowing()) {
|
||||
// mLoadingDialog.show();
|
||||
// }
|
||||
}
|
||||
|
||||
public void disLoading() {
|
||||
// if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
|
||||
// mLoadingDialog.dismiss();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
View view = getCurrentFocus();
|
||||
if (isShouldHideInput(view, ev)) {
|
||||
InputMethodManager Object = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (Object != null) {
|
||||
Object.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
return super.dispatchTouchEvent(ev);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//判断是否隐藏键盘
|
||||
public boolean isShouldHideInput(View v, MotionEvent event) {
|
||||
if (v != null && (v instanceof EditText)) {
|
||||
int[] leftTop = {0, 0};
|
||||
//获取输入框当前的location位置
|
||||
v.getLocationInWindow(leftTop);
|
||||
int left = leftTop[0];
|
||||
int top = leftTop[1];
|
||||
int bottom = top + v.getHeight();
|
||||
int right = left + v.getWidth();
|
||||
if (event.getX() > left && event.getX() < right
|
||||
&& event.getY() > top && event.getY() < bottom) {
|
||||
// 点击的是输入框区域,保留点击EditText的事件
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.qxcm.moduleutil.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
|
||||
import com.qxcm.moduleutil.utils.LanguageUtil;
|
||||
|
||||
public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewDataBinding> extends BaseAppCompatActivity<VDB> implements IView<Activity> {
|
||||
|
||||
protected P MvpPre;
|
||||
|
||||
protected abstract P bindPresenter();
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
MvpPre = bindPresenter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLoadings() {
|
||||
// showLoading("加载中");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLoadings(String content) {
|
||||
// showLoading(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disLoadings() {
|
||||
// disLoading();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (MvpPre != null) {
|
||||
MvpPre.detachView();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getSelfActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(LanguageUtil.attachBaseContext(newBase));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.qxcm.moduleutil.activity;
|
||||
|
||||
public interface IPresenter {
|
||||
void detachView();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.qxcm.moduleutil.activity;
|
||||
|
||||
public interface IView<T> {
|
||||
T getSelfActivity();
|
||||
|
||||
void showLoadings();
|
||||
|
||||
void showLoadings(String content);
|
||||
|
||||
void disLoadings();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.qxcm.moduleutil.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.blankj.utilcode.util.ConvertUtils;
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.bean.HeavenGiftBean;
|
||||
import com.qxcm.moduleutil.utils.ImageUtils;
|
||||
|
||||
public class GiftAdapter extends BaseQuickAdapter<HeavenGiftBean, BaseViewHolder> {
|
||||
//类型 1:金币,2:礼物,3:坐骑,4:头像框":
|
||||
private final int COIN_TYPE = 1;
|
||||
private final int GIFT_TYPE = 2;
|
||||
private final int MOUNT_TYPE = 3;
|
||||
private final int HEAD_TYPE = 4;
|
||||
|
||||
public GiftAdapter() {
|
||||
super(R.layout.item_gift);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, HeavenGiftBean item) {
|
||||
ImageUtils.loadHeadCC(item.getPicture(), helper.getView(R.id.iv_head));
|
||||
helper.getView(R.id.im_jb).setVisibility(View.VISIBLE);
|
||||
if (item.getType() == COIN_TYPE) {
|
||||
helper.setText(R.id.tv_gift_time, String.format("%s", item.getGold()));
|
||||
} else if (item.getType() == GIFT_TYPE) {
|
||||
helper.getView(R.id.im_jb).setVisibility(View.GONE);
|
||||
helper.setText(R.id.tv_gift_time, String.format("*%s", item.getQuantity()));
|
||||
} else {
|
||||
helper.getView(R.id.im_jb).setVisibility(View.GONE);
|
||||
helper.setText(R.id.tv_gift_time, String.format("%s天", item.getDays()));
|
||||
}
|
||||
helper.setText(R.id.tv_head_name, item.getTitle());
|
||||
ViewGroup.LayoutParams layoutParams = helper.itemView.getLayoutParams();
|
||||
layoutParams.width = ((ScreenUtils.getScreenWidth() - ConvertUtils.dp2px(140)) / 4);
|
||||
layoutParams.height = 259;
|
||||
helper.itemView.setLayoutParams(layoutParams);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.qxcm.moduleutil.adapter;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.bean.BaseListData;
|
||||
import com.qxcm.moduleutil.bean.HeatedBean;
|
||||
import com.qxcm.moduleutil.bean.HeavenGiftBean;
|
||||
import com.zhpan.bannerview.BaseBannerAdapter;
|
||||
import com.zhpan.bannerview.BaseViewHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HeavenGiftAdapter extends BaseBannerAdapter<BaseListData> {
|
||||
List<HeavenGiftBean> list;
|
||||
private OnItemClickListener onItemClickListener;
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.onItemClickListener = listener;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void bindData(BaseViewHolder<BaseListData> holder, BaseListData data, int position, int pageSize) {
|
||||
GiftAdapter adapter = new GiftAdapter();
|
||||
RecyclerView recyclerView = holder.itemView.findViewById(R.id.recyclerView);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(holder.itemView.getContext(), 4));
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.setNewData(data.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId(int viewType) {
|
||||
return R.layout.ietm_heaven_gift;
|
||||
}
|
||||
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(View view, HeavenGiftBean data, int position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.qxcm.moduleutil.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* listview的adapter基类
|
||||
*/
|
||||
public class MyBaseAdapter<T> extends BaseAdapter {
|
||||
|
||||
public List<T> list_adapter;
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return list_adapter == null ? 0 : list_adapter.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return list_adapter.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<T> getList_adapter() {
|
||||
if (list_adapter == null)
|
||||
list_adapter = new ArrayList<>();
|
||||
return list_adapter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.qxcm.moduleutil.adapter;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
|
||||
private List<Fragment> fragmentList;
|
||||
|
||||
public MyFragmentPagerAdapter(List<Fragment> list, FragmentManager fm) {
|
||||
super(fm);
|
||||
this.fragmentList = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
return fragmentList.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fragmentList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
// super.destroyItem(container, position, object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.qxcm.moduleutil.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.makeramen.roundedimageview.RoundedImageView;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.utils.ImageUtils;
|
||||
|
||||
public class OneImageYuanJiaoAdapter extends MyBaseAdapter<String> {
|
||||
private Context context;
|
||||
|
||||
// public OneImageYuanJiaoAdapter(Context context) {
|
||||
// this.context = context;
|
||||
// }
|
||||
|
||||
public OneImageYuanJiaoAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// protected void convert(BaseViewHolder helper, String item) {
|
||||
// helper.addOnClickListener(R.id.fiv);
|
||||
//
|
||||
// helper.setVisible(R.id.ll_del, false);
|
||||
// QMUIRadiusImageView image = helper.getView(R.id.fiv);
|
||||
// RequestOptions options = new RequestOptions()
|
||||
// .centerCrop()
|
||||
// .placeholder(R.color.white)
|
||||
// .diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// Glide.with(mContext)
|
||||
// .load(item)
|
||||
// .apply(options)
|
||||
// .into(image);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder VH;
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(context).inflate(R.layout.gv_filter_image, null);
|
||||
VH = new ViewHolder(convertView);
|
||||
convertView.setTag(VH);
|
||||
} else {
|
||||
VH = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
VH.iv_del.setVisibility(View.GONE);
|
||||
|
||||
if (!TextUtils.isEmpty(list_adapter.get(position))) {
|
||||
|
||||
ImageUtils.loadHeadCC(list_adapter.get(position),VH.tv_title);
|
||||
}
|
||||
//
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
public static class ViewHolder {
|
||||
RoundedImageView tv_title;
|
||||
ImageView iv_del;
|
||||
RelativeLayout layoutImg;
|
||||
|
||||
public ViewHolder(View convertView) {
|
||||
tv_title = convertView.findViewById(R.id.fiv);
|
||||
iv_del = convertView.findViewById(R.id.iv_del);
|
||||
// layoutImg = convertView.findViewById(R.id.layout_img);
|
||||
//
|
||||
// int screenWidth = QMUIDisplayHelper.getScreenWidth(BaseApplication.mApplication) - QMUIDisplayHelper.dp2px(BaseApplication.mApplication, 24);
|
||||
//
|
||||
// int imgWidth = screenWidth*1/3-QMUIDisplayHelper.dp2px(BaseApplication.mApplication, 10);
|
||||
//
|
||||
// RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) layoutImg.getLayoutParams();
|
||||
// params.width = imgWidth;
|
||||
// params.height = imgWidth;
|
||||
// layoutImg.setLayoutParams(params);
|
||||
//
|
||||
// params = (RelativeLayout.LayoutParams) tv_title.getLayoutParams();
|
||||
// params.width = imgWidth;
|
||||
// params.height = imgWidth;
|
||||
// tv_title.setLayoutParams(params);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.qxcm.moduleutil.base;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
public class BaseApplication extends Application {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.qxcm.moduleutil.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.qxcm.moduleutil.activity.BaseAppCompatActivity;
|
||||
|
||||
public abstract class BaseFragment<VDB extends ViewDataBinding> extends Fragment {
|
||||
protected VDB mBinding;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
mBinding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false);
|
||||
mBinding.setLifecycleOwner(this);
|
||||
return mBinding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
initArgs(getArguments());
|
||||
}
|
||||
initView();
|
||||
initData();
|
||||
initListener();
|
||||
}
|
||||
|
||||
public void initArgs(Bundle arguments) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (mBinding != null) {
|
||||
mBinding.unbind();
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
protected void initListener() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected abstract void initData();
|
||||
|
||||
protected abstract void initView();
|
||||
|
||||
protected abstract int getLayoutId();
|
||||
|
||||
|
||||
public void showLoading(String content) {
|
||||
if (!isAdded() || getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
if (getActivity() instanceof BaseAppCompatActivity) {
|
||||
((BaseAppCompatActivity) getActivity()).showLoading(content);
|
||||
}
|
||||
}
|
||||
|
||||
public void disLoading() {
|
||||
if (getActivity() instanceof BaseAppCompatActivity) {
|
||||
((BaseAppCompatActivity) getActivity()).disLoading();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.qxcm.moduleutil.base;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.qxcm.moduleutil.activity.IPresenter;
|
||||
import com.qxcm.moduleutil.activity.IView;
|
||||
|
||||
|
||||
public abstract class BaseMvpFragment<P extends IPresenter, VDB extends ViewDataBinding> extends BaseFragment<VDB> implements IView<Activity> {
|
||||
protected P MvpPre;
|
||||
|
||||
protected abstract P bindPresenter();
|
||||
|
||||
@Override
|
||||
public FragmentActivity getSelfActivity() {
|
||||
return getActivity();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
MvpPre = bindPresenter();
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (MvpPre != null) {
|
||||
MvpPre.detachView();
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLoadings() {
|
||||
// showLoading("加载中...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLoadings(String content) {
|
||||
// showLoading(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disLoadings() {
|
||||
// disLoading();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BaseListData<T> {
|
||||
private List<T> data;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CircleListBean {
|
||||
private String id;
|
||||
private String userNickName;
|
||||
private String userAvatar;
|
||||
private String time;
|
||||
private String content;
|
||||
private List<String> images;
|
||||
private String type;
|
||||
private String comment;
|
||||
private String like;
|
||||
private String isShare;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/8/5.
|
||||
*/
|
||||
|
||||
public class ConfigBean {
|
||||
private String version;//Android apk安装包 版本号
|
||||
private String downloadApkUrl;//Android apk安装包 下载地址
|
||||
private String updateDes;//版本更新描述
|
||||
private String liveWxShareUrl;//直播间微信分享地址
|
||||
private String liveShareTitle;//直播间分享标题
|
||||
private String liveShareDes;//直播间分享描述
|
||||
private String videoShareTitle;//短视频分享标题
|
||||
private String videoShareDes;//短视频分享描述
|
||||
private int videoAuditSwitch;//短视频审核是否开启
|
||||
private int videoCloudType;//短视频云储存类型 1七牛云 2腾讯云
|
||||
private String videoQiNiuHost;//短视频七牛云域名
|
||||
private String txCosAppId;//腾讯云存储appId
|
||||
private String txCosRegion;//腾讯云存储区域
|
||||
private String txCosBucketName;//腾讯云存储桶名字
|
||||
private String txCosVideoPath;//腾讯云存储视频文件夹
|
||||
private String txCosImagePath;//腾讯云存储图片文件夹
|
||||
private String coinName;//钻石名称
|
||||
private String votesName;//映票名称
|
||||
private String scoreName;//积分名称
|
||||
private String[] liveTimeCoin;//直播间计时收费规则
|
||||
private String[] loginType;//三方登录类型
|
||||
private String[][] liveType;//直播间开播类型
|
||||
private String[] shareType;//分享类型
|
||||
// private List<LiveClassBean> liveClass;//直播分类
|
||||
private String videoClass;//短视频分类
|
||||
private int maintainSwitch;//维护开关
|
||||
private String maintainTips;//维护提示
|
||||
private String mAdInfo;//引导页 广告信息
|
||||
private int priMsgSwitch;//私信开关
|
||||
private int forceUpdate;//强制更新
|
||||
private String mWaterMarkUrl;//水印
|
||||
private String mShopSystemName;//商店名称
|
||||
|
||||
private String beautyAppId;//美颜鉴权AppId
|
||||
private String beautyKey;//美颜鉴权AppKey
|
||||
private int mOpenInstallSwitch;
|
||||
private String teenager_des;
|
||||
private int leaderboard_switch;
|
||||
private String mAgoraAppId;//声网appId
|
||||
|
||||
|
||||
@JSONField(name = "apk_ver")
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@JSONField(name = "apk_ver")
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@JSONField(name = "apk_url")
|
||||
public String getDownloadApkUrl() {
|
||||
return downloadApkUrl;
|
||||
}
|
||||
|
||||
@JSONField(name = "apk_url")
|
||||
public void setDownloadApkUrl(String downloadApkUrl) {
|
||||
this.downloadApkUrl = downloadApkUrl;
|
||||
}
|
||||
|
||||
@JSONField(name = "apk_des")
|
||||
public String getUpdateDes() {
|
||||
return updateDes;
|
||||
}
|
||||
|
||||
@JSONField(name = "apk_des")
|
||||
public void setUpdateDes(String updateDes) {
|
||||
this.updateDes = updateDes;
|
||||
}
|
||||
|
||||
@JSONField(name = "wx_siteurl")
|
||||
public void setLiveWxShareUrl(String liveWxShareUrl) {
|
||||
this.liveWxShareUrl = liveWxShareUrl;
|
||||
}
|
||||
|
||||
@JSONField(name = "wx_siteurl")
|
||||
public String getLiveWxShareUrl() {
|
||||
return liveWxShareUrl;
|
||||
}
|
||||
|
||||
@JSONField(name = "share_title")
|
||||
public String getLiveShareTitle() {
|
||||
return liveShareTitle;
|
||||
}
|
||||
|
||||
@JSONField(name = "share_title")
|
||||
public void setLiveShareTitle(String liveShareTitle) {
|
||||
this.liveShareTitle = liveShareTitle;
|
||||
}
|
||||
|
||||
@JSONField(name = "share_des")
|
||||
public String getLiveShareDes() {
|
||||
return liveShareDes;
|
||||
}
|
||||
|
||||
@JSONField(name = "share_des")
|
||||
public void setLiveShareDes(String liveShareDes) {
|
||||
this.liveShareDes = liveShareDes;
|
||||
}
|
||||
|
||||
@JSONField(name = "name_coin")
|
||||
public String getCoinName() {
|
||||
return coinName;
|
||||
}
|
||||
|
||||
@JSONField(name = "name_coin")
|
||||
public void setCoinName(String coinName) {
|
||||
this.coinName = coinName;
|
||||
}
|
||||
|
||||
@JSONField(name = "name_score")
|
||||
public String getScoreName() {
|
||||
return scoreName;
|
||||
}
|
||||
@JSONField(name = "name_score")
|
||||
public void setScoreName(String scoreName) {
|
||||
this.scoreName = scoreName;
|
||||
}
|
||||
|
||||
@JSONField(name = "name_votes")
|
||||
public String getVotesName() {
|
||||
return votesName;
|
||||
}
|
||||
|
||||
@JSONField(name = "name_votes")
|
||||
public void setVotesName(String votesName) {
|
||||
this.votesName = votesName;
|
||||
}
|
||||
|
||||
@JSONField(name = "live_time_coin")
|
||||
public String[] getLiveTimeCoin() {
|
||||
return liveTimeCoin;
|
||||
}
|
||||
|
||||
@JSONField(name = "live_time_coin")
|
||||
public void setLiveTimeCoin(String[] liveTimeCoin) {
|
||||
this.liveTimeCoin = liveTimeCoin;
|
||||
}
|
||||
|
||||
@JSONField(name = "login_type")
|
||||
public String[] getLoginType() {
|
||||
return loginType;
|
||||
}
|
||||
|
||||
@JSONField(name = "login_type")
|
||||
public void setLoginType(String[] loginType) {
|
||||
this.loginType = loginType;
|
||||
}
|
||||
|
||||
@JSONField(name = "live_type")
|
||||
public String[][] getLiveType() {
|
||||
return liveType;
|
||||
}
|
||||
|
||||
@JSONField(name = "live_type")
|
||||
public void setLiveType(String[][] liveType) {
|
||||
this.liveType = liveType;
|
||||
}
|
||||
|
||||
@JSONField(name = "share_type")
|
||||
public String[] getShareType() {
|
||||
return shareType;
|
||||
}
|
||||
|
||||
@JSONField(name = "share_type")
|
||||
public void setShareType(String[] shareType) {
|
||||
this.shareType = shareType;
|
||||
}
|
||||
|
||||
// @JSONField(name = "liveclass")
|
||||
// public List<LiveClassBean> getLiveClass() {
|
||||
// return liveClass;
|
||||
// }
|
||||
//
|
||||
// @JSONField(name = "liveclass")
|
||||
// public void setLiveClass(List<LiveClassBean> liveClass) {
|
||||
// this.liveClass = liveClass;
|
||||
// }
|
||||
|
||||
|
||||
@JSONField(name = "videoclass")
|
||||
public String getVideoClass() {
|
||||
return videoClass;
|
||||
}
|
||||
|
||||
@JSONField(name = "videoclass")
|
||||
public void setVideoClass(String videoClass) {
|
||||
this.videoClass = videoClass;
|
||||
}
|
||||
|
||||
@JSONField(name = "maintain_switch")
|
||||
public int getMaintainSwitch() {
|
||||
return maintainSwitch;
|
||||
}
|
||||
|
||||
@JSONField(name = "maintain_switch")
|
||||
public void setMaintainSwitch(int maintainSwitch) {
|
||||
this.maintainSwitch = maintainSwitch;
|
||||
}
|
||||
|
||||
@JSONField(name = "maintain_tips")
|
||||
public String getMaintainTips() {
|
||||
return maintainTips;
|
||||
}
|
||||
|
||||
@JSONField(name = "maintain_tips")
|
||||
public void setMaintainTips(String maintainTips) {
|
||||
this.maintainTips = maintainTips;
|
||||
}
|
||||
|
||||
@JSONField(name = "sprout_appid")
|
||||
public String getBeautyAppId() {
|
||||
return beautyAppId;
|
||||
}
|
||||
@JSONField(name = "sprout_appid")
|
||||
public void setBeautyAppId(String beautyAppId) {
|
||||
this.beautyAppId = beautyAppId;
|
||||
}
|
||||
|
||||
@JSONField(name = "sprout_key")
|
||||
public String getBeautyKey() {
|
||||
return beautyKey;
|
||||
}
|
||||
|
||||
@JSONField(name = "sprout_key")
|
||||
public void setBeautyKey(String beautyKey) {
|
||||
this.beautyKey = beautyKey;
|
||||
}
|
||||
|
||||
|
||||
public String[] getVideoShareTypes() {
|
||||
return shareType;
|
||||
}
|
||||
|
||||
@JSONField(name = "video_share_title")
|
||||
public String getVideoShareTitle() {
|
||||
return videoShareTitle;
|
||||
}
|
||||
|
||||
@JSONField(name = "video_share_title")
|
||||
public void setVideoShareTitle(String videoShareTitle) {
|
||||
this.videoShareTitle = videoShareTitle;
|
||||
}
|
||||
|
||||
@JSONField(name = "video_share_des")
|
||||
public String getVideoShareDes() {
|
||||
return videoShareDes;
|
||||
}
|
||||
|
||||
@JSONField(name = "video_share_des")
|
||||
public void setVideoShareDes(String videoShareDes) {
|
||||
this.videoShareDes = videoShareDes;
|
||||
}
|
||||
|
||||
@JSONField(name = "video_audit_switch")
|
||||
public int getVideoAuditSwitch() {
|
||||
return videoAuditSwitch;
|
||||
}
|
||||
|
||||
@JSONField(name = "video_audit_switch")
|
||||
public void setVideoAuditSwitch(int videoAuditSwitch) {
|
||||
this.videoAuditSwitch = videoAuditSwitch;
|
||||
}
|
||||
|
||||
@JSONField(name = "cloudtype")
|
||||
public int getVideoCloudType() {
|
||||
return videoCloudType;
|
||||
}
|
||||
|
||||
@JSONField(name = "cloudtype")
|
||||
public void setVideoCloudType(int videoCloudType) {
|
||||
this.videoCloudType = videoCloudType;
|
||||
}
|
||||
|
||||
@JSONField(name = "qiniu_domain")
|
||||
public String getVideoQiNiuHost() {
|
||||
return videoQiNiuHost;
|
||||
}
|
||||
|
||||
@JSONField(name = "qiniu_domain")
|
||||
public void setVideoQiNiuHost(String videoQiNiuHost) {
|
||||
this.videoQiNiuHost = videoQiNiuHost;
|
||||
}
|
||||
|
||||
@JSONField(name = "txcloud_appid")
|
||||
public String getTxCosAppId() {
|
||||
return txCosAppId;
|
||||
}
|
||||
|
||||
@JSONField(name = "txcloud_appid")
|
||||
public void setTxCosAppId(String txCosAppId) {
|
||||
this.txCosAppId = txCosAppId;
|
||||
}
|
||||
|
||||
@JSONField(name = "txcloud_region")
|
||||
public String getTxCosRegion() {
|
||||
return txCosRegion;
|
||||
}
|
||||
|
||||
@JSONField(name = "txcloud_region")
|
||||
public void setTxCosRegion(String txCosRegion) {
|
||||
this.txCosRegion = txCosRegion;
|
||||
}
|
||||
|
||||
@JSONField(name = "txcloud_bucket")
|
||||
public String getTxCosBucketName() {
|
||||
return txCosBucketName;
|
||||
}
|
||||
|
||||
@JSONField(name = "txcloud_bucket")
|
||||
public void setTxCosBucketName(String txCosBucketName) {
|
||||
this.txCosBucketName = txCosBucketName;
|
||||
}
|
||||
|
||||
@JSONField(name = "video_watermark")
|
||||
public String getWaterMarkUrl() {
|
||||
return mWaterMarkUrl;
|
||||
}
|
||||
|
||||
@JSONField(name = "video_watermark")
|
||||
public void setWaterMarkUrl(String waterMarkUrl) {
|
||||
mWaterMarkUrl = waterMarkUrl;
|
||||
}
|
||||
|
||||
@JSONField(name = "txvideofolder")
|
||||
public String getTxCosVideoPath() {
|
||||
return txCosVideoPath;
|
||||
}
|
||||
|
||||
@JSONField(name = "txvideofolder")
|
||||
public void setTxCosVideoPath(String txCosVideoPath) {
|
||||
this.txCosVideoPath = txCosVideoPath;
|
||||
}
|
||||
|
||||
@JSONField(name = "tximgfolder")
|
||||
public String getTxCosImagePath() {
|
||||
return txCosImagePath;
|
||||
}
|
||||
|
||||
@JSONField(name = "tximgfolder")
|
||||
public void setTxCosImagePath(String txCosImagePath) {
|
||||
this.txCosImagePath = txCosImagePath;
|
||||
}
|
||||
|
||||
@JSONField(name = "guide")
|
||||
public String getAdInfo() {
|
||||
return mAdInfo;
|
||||
}
|
||||
|
||||
@JSONField(name = "guide")
|
||||
public void setAdInfo(String adInfo) {
|
||||
mAdInfo = adInfo;
|
||||
}
|
||||
|
||||
@JSONField(name = "letter_switch")
|
||||
public int getPriMsgSwitch() {
|
||||
return priMsgSwitch;
|
||||
}
|
||||
|
||||
@JSONField(name = "letter_switch")
|
||||
public void setPriMsgSwitch(int priMsgSwitch) {
|
||||
this.priMsgSwitch = priMsgSwitch;
|
||||
}
|
||||
|
||||
@JSONField(name = "isup")
|
||||
public int getForceUpdate() {
|
||||
return forceUpdate;
|
||||
}
|
||||
|
||||
@JSONField(name = "isup")
|
||||
public void setForceUpdate(int forceUpdate) {
|
||||
this.forceUpdate = forceUpdate;
|
||||
}
|
||||
|
||||
|
||||
@JSONField(name = "shop_system_name")
|
||||
public String getShopSystemName() {
|
||||
return mShopSystemName;
|
||||
}
|
||||
@JSONField(name = "shop_system_name")
|
||||
public void setShopSystemName(String shopSystemName) {
|
||||
mShopSystemName = shopSystemName;
|
||||
}
|
||||
|
||||
@JSONField(name = "openinstall_switch")
|
||||
public int getOpenInstallSwitch() {
|
||||
return mOpenInstallSwitch;
|
||||
}
|
||||
@JSONField(name = "openinstall_switch")
|
||||
public void setOpenInstallSwitch(int openInstallSwitch) {
|
||||
mOpenInstallSwitch = openInstallSwitch;
|
||||
}
|
||||
|
||||
|
||||
public String getTeenager_des() {
|
||||
return teenager_des;
|
||||
}
|
||||
|
||||
public void setTeenager_des(String teenager_des) {
|
||||
this.teenager_des = teenager_des;
|
||||
}
|
||||
|
||||
public int getLeaderboard_switch() {
|
||||
return leaderboard_switch;
|
||||
}
|
||||
|
||||
public void setLeaderboard_switch(int leaderboard_switch) {
|
||||
this.leaderboard_switch = leaderboard_switch;
|
||||
}
|
||||
@JSONField(name = "sw_app_id")
|
||||
public String getAgoraAppId() {
|
||||
return mAgoraAppId;
|
||||
}
|
||||
@JSONField(name = "sw_app_id")
|
||||
public void setAgoraAppId(String agoraAppId) {
|
||||
mAgoraAppId = agoraAppId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ConfigThemeBean {
|
||||
// 普通字体黑色 default is # 000000
|
||||
private String textColor;
|
||||
// 主题色 default is # 0dffb9
|
||||
private String themeColor;
|
||||
// 提示字体颜色 default is #9b9b9b
|
||||
private String placehoulderTextColor;
|
||||
// 按钮字体颜色 default is #333333
|
||||
private String btnTextColor;
|
||||
// 背景图片 default is green
|
||||
private String backgroundImage;
|
||||
// 底部工具栏
|
||||
// @property (nonatomic,strong)NSArray <QXTabbarModel*>*tabbarArray;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
|
||||
import com.qxcm.moduleutil.widget.picker.PickerView;
|
||||
|
||||
public class DateBean implements PickerView.PickerItem {
|
||||
|
||||
private String text;
|
||||
private int date;
|
||||
|
||||
public DateBean(String text, int date) {
|
||||
this.text = text;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public int getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(int date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DateBean{" +
|
||||
"text='" + text + '\'' +
|
||||
", date=" + date +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HeatedBean {
|
||||
private String title;
|
||||
private String title_pictrue;
|
||||
private String type;
|
||||
private String title_content;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HeavenGiftBean {
|
||||
private String title;
|
||||
private String picture;
|
||||
private int type;
|
||||
private String quantity;
|
||||
private String gold;
|
||||
private String days;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import com.chad.library.adapter.base.entity.MultiItemEntity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HomeBean implements MultiItemEntity {
|
||||
private int itemViewType = 2;
|
||||
private String user_id;
|
||||
private String head_picture;
|
||||
private String nickname;
|
||||
private String sex;
|
||||
private String signature;
|
||||
private String constellation;
|
||||
private String birthday;
|
||||
private String intro_voice;
|
||||
private String intro_voice_time;
|
||||
private String offline_time;
|
||||
private int age;
|
||||
private int is_online;
|
||||
@Override
|
||||
public int getItemType() {
|
||||
return itemViewType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import com.chad.library.adapter.base.entity.SectionEntity;
|
||||
|
||||
public class RecordSection extends SectionEntity<String> {
|
||||
|
||||
public RecordSection(boolean isHeader, String header) {
|
||||
super(isHeader, header);
|
||||
}
|
||||
|
||||
public RecordSection(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
365
moduleUtil/src/main/java/com/qxcm/moduleutil/bean/RoomModel.java
Normal file
365
moduleUtil/src/main/java/com/qxcm/moduleutil/bean/RoomModel.java
Normal file
@@ -0,0 +1,365 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.chad.library.adapter.base.entity.MultiItemEntity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
public class RoomModel implements Serializable, MultiItemEntity {
|
||||
|
||||
|
||||
/**
|
||||
* room_id : 843
|
||||
* room_code : 20777
|
||||
* user_id : 548120
|
||||
* room_name : 须尽欢女神🌙宝藏女孩零
|
||||
* label_id : 25
|
||||
* type_id : 0
|
||||
* popularity : 1175
|
||||
* label_name : 女神
|
||||
* owner_picture : https://gudao-prod.oss-cn-hangzhou.aliyuncs.com/ios_images/2019-12-23/BDDC0E6A-E90B-4935-8334-A2DDC690030E.png
|
||||
* owner_sex : 2
|
||||
* holder : 548996
|
||||
* holder_picture : https://gudao-prod.oss-cn-hangzhou.aliyuncs.com/android_images/548996/20191224190037_1577185235767.jpg
|
||||
* holder_sex : 2
|
||||
* owner_nickname : 收🎁秒结🌙须尽欢
|
||||
* holder_nickname : 兔兔🌙
|
||||
* is_owner : 0
|
||||
* have_password : 0
|
||||
* last_join : {"nickname":"忘川","head_picture":"https://gudao-prod.oss-cn-hangzhou.aliyuncs.com/ios_images/2019-12-06/3A29FB55-E55B-46EB-B4F0-C65A40C9200B.png"}
|
||||
*/
|
||||
private int itemViewType = 1;
|
||||
private String id;
|
||||
private String room_id;
|
||||
private String room_code;
|
||||
private String user_id;
|
||||
private String room_name;
|
||||
private String label_id;
|
||||
private String voice;//开麦状态
|
||||
private String on_line; //在线状态
|
||||
private String chatrooms;
|
||||
private String type_id;
|
||||
private String popularity;
|
||||
private String label_name;
|
||||
private String label_icon;
|
||||
private String owner_picture;
|
||||
private String owner_sex;
|
||||
private String holder;
|
||||
private String holder_picture;
|
||||
private String holder_sex;
|
||||
private String owner_nickname;
|
||||
private String holder_nickname;
|
||||
private int is_owner;
|
||||
private int locked;
|
||||
private LastJoinBean last_join;
|
||||
private String favorite;
|
||||
private int week_star_recommend; //周星推荐 1是0否
|
||||
private String on_line_count;
|
||||
private String special_flag_big;
|
||||
private String special_flag_small;
|
||||
private String special_flag_small_color;
|
||||
private String cover_picture;
|
||||
private String special_frame_big;//大边框
|
||||
private String special_frame_small;//小边框
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getVoice() {
|
||||
return voice;
|
||||
}
|
||||
|
||||
public void setVoice(String voice) {
|
||||
this.voice = voice;
|
||||
}
|
||||
|
||||
public String getOn_line() {
|
||||
return on_line;
|
||||
}
|
||||
|
||||
public void setOn_line(String on_line) {
|
||||
this.on_line = on_line;
|
||||
}
|
||||
|
||||
public String getChatrooms() {
|
||||
return chatrooms;
|
||||
}
|
||||
|
||||
public void setChatrooms(String chatrooms) {
|
||||
this.chatrooms = chatrooms;
|
||||
}
|
||||
|
||||
public String getSpecial_frame_big() {
|
||||
return special_frame_big;
|
||||
}
|
||||
|
||||
public void setSpecial_frame_big(String special_frame_big) {
|
||||
this.special_frame_big = special_frame_big;
|
||||
}
|
||||
|
||||
public String getSpecial_frame_small() {
|
||||
return special_frame_small;
|
||||
}
|
||||
|
||||
public void setSpecial_frame_small(String special_frame_small) {
|
||||
this.special_frame_small = special_frame_small;
|
||||
}
|
||||
|
||||
public String getRoomPicture() {
|
||||
if (!TextUtils.isEmpty(cover_picture)) {
|
||||
return cover_picture;
|
||||
}
|
||||
return owner_picture;
|
||||
}
|
||||
|
||||
public String getCover_picture() {
|
||||
return cover_picture;
|
||||
}
|
||||
|
||||
public void setCover_picture(String cover_picture) {
|
||||
this.cover_picture = cover_picture;
|
||||
}
|
||||
|
||||
public String getSpecial_flag_small_color() {
|
||||
return special_flag_small_color;
|
||||
}
|
||||
|
||||
public void setSpecial_flag_small_color(String special_flag_small_color) {
|
||||
this.special_flag_small_color = special_flag_small_color;
|
||||
}
|
||||
|
||||
public String getSpecial_flag_big() {
|
||||
return special_flag_big;
|
||||
}
|
||||
|
||||
public void setSpecial_flag_big(String special_flag_big) {
|
||||
this.special_flag_big = special_flag_big;
|
||||
}
|
||||
|
||||
public String getSpecial_flag_small() {
|
||||
return special_flag_small;
|
||||
}
|
||||
|
||||
public void setSpecial_flag_small(String special_flag_small) {
|
||||
this.special_flag_small = special_flag_small;
|
||||
}
|
||||
|
||||
public String getOn_line_count() {
|
||||
return on_line_count;
|
||||
}
|
||||
|
||||
public void setOn_line_count(String on_line_count) {
|
||||
this.on_line_count = on_line_count;
|
||||
}
|
||||
|
||||
public String getLabel_icon() {
|
||||
return label_icon;
|
||||
}
|
||||
|
||||
public void setLabel_icon(String label_icon) {
|
||||
this.label_icon = label_icon;
|
||||
}
|
||||
|
||||
public int getWeek_star_recommend() {
|
||||
return week_star_recommend;
|
||||
}
|
||||
|
||||
public void setWeek_star_recommend(int week_star_recommend) {
|
||||
this.week_star_recommend = week_star_recommend;
|
||||
}
|
||||
|
||||
public String getFavorite() {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
public void setFavorite(String favorite) {
|
||||
this.favorite = favorite;
|
||||
}
|
||||
|
||||
public String getRoom_id() {
|
||||
return room_id;
|
||||
}
|
||||
|
||||
public void setRoom_id(String room_id) {
|
||||
this.room_id = room_id;
|
||||
}
|
||||
|
||||
public String getRoom_code() {
|
||||
return room_code;
|
||||
}
|
||||
|
||||
public void setRoom_code(String room_code) {
|
||||
this.room_code = room_code;
|
||||
}
|
||||
|
||||
public String getUser_id() {
|
||||
return user_id;
|
||||
}
|
||||
|
||||
public void setUser_id(String user_id) {
|
||||
this.user_id = user_id;
|
||||
}
|
||||
|
||||
public String getRoom_name() {
|
||||
return room_name;
|
||||
}
|
||||
|
||||
public void setRoom_name(String room_name) {
|
||||
this.room_name = room_name;
|
||||
}
|
||||
|
||||
public String getLabel_id() {
|
||||
return label_id;
|
||||
}
|
||||
|
||||
public void setLabel_id(String label_id) {
|
||||
this.label_id = label_id;
|
||||
}
|
||||
|
||||
public String getType_id() {
|
||||
return type_id;
|
||||
}
|
||||
|
||||
public void setType_id(String type_id) {
|
||||
this.type_id = type_id;
|
||||
}
|
||||
|
||||
public String getPopularity() {
|
||||
return popularity;
|
||||
}
|
||||
|
||||
public void setPopularity(String popularity) {
|
||||
this.popularity = popularity;
|
||||
}
|
||||
|
||||
public String getLabel_name() {
|
||||
return label_name;
|
||||
}
|
||||
|
||||
public void setLabel_name(String label_name) {
|
||||
this.label_name = label_name;
|
||||
}
|
||||
|
||||
public String getOwner_picture() {
|
||||
return owner_picture;
|
||||
}
|
||||
|
||||
public void setOwner_picture(String owner_picture) {
|
||||
this.owner_picture = owner_picture;
|
||||
}
|
||||
|
||||
public String getOwner_sex() {
|
||||
return owner_sex;
|
||||
}
|
||||
|
||||
public void setOwner_sex(String owner_sex) {
|
||||
this.owner_sex = owner_sex;
|
||||
}
|
||||
|
||||
public String getHolder() {
|
||||
return holder;
|
||||
}
|
||||
|
||||
public void setHolder(String holder) {
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
public String getHolder_picture() {
|
||||
return holder_picture;
|
||||
}
|
||||
|
||||
public void setHolder_picture(String holder_picture) {
|
||||
this.holder_picture = holder_picture;
|
||||
}
|
||||
|
||||
public String getHolder_sex() {
|
||||
return holder_sex;
|
||||
}
|
||||
|
||||
public void setHolder_sex(String holder_sex) {
|
||||
this.holder_sex = holder_sex;
|
||||
}
|
||||
|
||||
public String getOwner_nickname() {
|
||||
return owner_nickname;
|
||||
}
|
||||
|
||||
public void setOwner_nickname(String owner_nickname) {
|
||||
this.owner_nickname = owner_nickname;
|
||||
}
|
||||
|
||||
public String getHolder_nickname() {
|
||||
return holder_nickname;
|
||||
}
|
||||
|
||||
public void setHolder_nickname(String holder_nickname) {
|
||||
this.holder_nickname = holder_nickname;
|
||||
}
|
||||
|
||||
public int getIs_owner() {
|
||||
return is_owner;
|
||||
}
|
||||
|
||||
public void setIs_owner(int is_owner) {
|
||||
this.is_owner = is_owner;
|
||||
}
|
||||
|
||||
public int getLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(int locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public LastJoinBean getLast_join() {
|
||||
return last_join;
|
||||
}
|
||||
|
||||
public void setLast_join(LastJoinBean last_join) {
|
||||
this.last_join = last_join;
|
||||
}
|
||||
|
||||
public void setItemViewType(int itemViewType) {
|
||||
this.itemViewType = itemViewType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemType() {
|
||||
return itemViewType;
|
||||
}
|
||||
|
||||
public static class LastJoinBean implements Serializable {
|
||||
/**
|
||||
* nickname : 忘川
|
||||
* head_picture : https://gudao-prod.oss-cn-hangzhou.aliyuncs.com/ios_images/2019-12-06/3A29FB55-E55B-46EB-B4F0-C65A40C9200B.png
|
||||
*/
|
||||
|
||||
private String nickname;
|
||||
private String head_picture;
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getHead_picture() {
|
||||
return head_picture;
|
||||
}
|
||||
|
||||
public void setHead_picture(String head_picture) {
|
||||
this.head_picture = head_picture;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RoomResultResp {
|
||||
|
||||
private int count;
|
||||
private List<RoomResultInfo> list;
|
||||
|
||||
public static class RoomResultInfo {
|
||||
private String room_id;
|
||||
private String room_code;
|
||||
private String room_name;
|
||||
private String label_name;
|
||||
private String popularity;
|
||||
private String is_password;
|
||||
private String nickname;
|
||||
private String cover_picture;
|
||||
private String label_icon;
|
||||
private int locked;
|
||||
|
||||
public int getLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(int locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public String getLabel_icon() {
|
||||
return label_icon;
|
||||
}
|
||||
|
||||
public void setLabel_icon(String label_icon) {
|
||||
this.label_icon = label_icon;
|
||||
}
|
||||
|
||||
public String getRoom_id() {
|
||||
return room_id;
|
||||
}
|
||||
|
||||
public void setRoom_id(String room_id) {
|
||||
this.room_id = room_id;
|
||||
}
|
||||
|
||||
public String getRoom_code() {
|
||||
return room_code;
|
||||
}
|
||||
|
||||
public void setRoom_code(String room_code) {
|
||||
this.room_code = room_code;
|
||||
}
|
||||
|
||||
public String getRoom_name() {
|
||||
return room_name;
|
||||
}
|
||||
|
||||
public void setRoom_name(String room_name) {
|
||||
this.room_name = room_name;
|
||||
}
|
||||
|
||||
public String getLabel_name() {
|
||||
return label_name;
|
||||
}
|
||||
|
||||
public void setLabel_name(String label_name) {
|
||||
this.label_name = label_name;
|
||||
}
|
||||
|
||||
public String getPopularity() {
|
||||
return popularity;
|
||||
}
|
||||
|
||||
public void setPopularity(String popularity) {
|
||||
this.popularity = popularity;
|
||||
}
|
||||
|
||||
public String getIs_password() {
|
||||
return is_password;
|
||||
}
|
||||
|
||||
public void setIs_password(String is_password) {
|
||||
this.is_password = is_password;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getCover_picture() {
|
||||
return cover_picture;
|
||||
}
|
||||
|
||||
public void setCover_picture(String cover_picture) {
|
||||
this.cover_picture = cover_picture;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public List<RoomResultInfo> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<RoomResultInfo> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
public class RoomTypeModel {
|
||||
|
||||
|
||||
/**
|
||||
* id :
|
||||
* name :
|
||||
* type :
|
||||
* sort :
|
||||
*/
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String type;
|
||||
private String sort;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(String sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SearchResp {
|
||||
|
||||
|
||||
private List<UserResultResp> user_result;
|
||||
private RoomResultResp room_result;
|
||||
|
||||
public List<UserResultResp> getUser_result() {
|
||||
return user_result;
|
||||
}
|
||||
|
||||
public void setUser_result(List<UserResultResp> user_result) {
|
||||
this.user_result = user_result;
|
||||
}
|
||||
|
||||
public RoomResultResp getRoom_result() {
|
||||
return room_result;
|
||||
}
|
||||
|
||||
public void setRoom_result(RoomResultResp room_result) {
|
||||
this.room_result = room_result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TeenagerInfo {
|
||||
// "status 是否开启青少年模式1开启2关闭": 2,
|
||||
// "today_pop 今日是否已经弹窗过 1是0否": 1,
|
||||
// "had_password 是否已经设置密码 1是0否": 1
|
||||
|
||||
private int status;
|
||||
private int today_pop;
|
||||
private int had_password;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TopRoom {
|
||||
|
||||
private String id;
|
||||
private String user_id;
|
||||
private String room_name;
|
||||
private String label_id;
|
||||
private String cover_picture;
|
||||
private String voice;
|
||||
private String on_line;
|
||||
private String chatrooms;
|
||||
private String popularity;
|
||||
private String room_id;
|
||||
private String user_count;
|
||||
private List<UserList> user_list;
|
||||
|
||||
@Data
|
||||
public static class UserList {
|
||||
private String head_picture;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
public class UserPictrue {
|
||||
private String sex;
|
||||
private String defaultAvatar;
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getDefaultAvatar() {
|
||||
return defaultAvatar;
|
||||
}
|
||||
|
||||
public void setDefaultAvatar(String defaultAvatar) {
|
||||
this.defaultAvatar = defaultAvatar;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.qxcm.moduleutil.bean;
|
||||
|
||||
public class UserResultResp {
|
||||
|
||||
|
||||
private String user_id;
|
||||
private String user_code;
|
||||
private String nickname;
|
||||
private String head_picture;
|
||||
private String sex;
|
||||
private String follow;
|
||||
private String fans_count;
|
||||
private String online_text;
|
||||
private String good_number;
|
||||
private String id_color;
|
||||
|
||||
public String getUser_id() {
|
||||
return user_id;
|
||||
}
|
||||
|
||||
public void setUser_id(String user_id) {
|
||||
this.user_id = user_id;
|
||||
}
|
||||
|
||||
public String getUser_code() {
|
||||
return user_code;
|
||||
}
|
||||
|
||||
public void setUser_code(String user_code) {
|
||||
this.user_code = user_code;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getHead_picture() {
|
||||
return head_picture;
|
||||
}
|
||||
|
||||
public void setHead_picture(String head_picture) {
|
||||
this.head_picture = head_picture;
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getFollow() {
|
||||
return follow;
|
||||
}
|
||||
|
||||
public void setFollow(String follow) {
|
||||
this.follow = follow;
|
||||
}
|
||||
|
||||
public String getFans_count() {
|
||||
return fans_count;
|
||||
}
|
||||
|
||||
public void setFans_count(String fans_count) {
|
||||
this.fans_count = fans_count;
|
||||
}
|
||||
|
||||
public String getOnline_text() {
|
||||
return online_text;
|
||||
}
|
||||
|
||||
public void setOnline_text(String online_text) {
|
||||
this.online_text = online_text;
|
||||
}
|
||||
|
||||
public String getGood_number() {
|
||||
return good_number;
|
||||
}
|
||||
|
||||
public void setGood_number(String good_number) {
|
||||
this.good_number = good_number;
|
||||
}
|
||||
|
||||
public String getId_color() {
|
||||
return id_color;
|
||||
}
|
||||
|
||||
public void setId_color(String id_color) {
|
||||
this.id_color = id_color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.qxcm.moduleutil.custon;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
|
||||
/**
|
||||
* Created by cxf on 2019/4/27.
|
||||
*/
|
||||
|
||||
public class CircleProgress extends View {
|
||||
|
||||
private float mStrokeWidth;
|
||||
private float mR;
|
||||
private int mBgColor;
|
||||
private int mFgColor;
|
||||
private float mMaxProgress;
|
||||
private float mCurProgress;
|
||||
private Paint mBgPaint;
|
||||
private Paint mFgPaint;
|
||||
private float mX;
|
||||
private RectF mRectF;
|
||||
|
||||
public CircleProgress(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public CircleProgress(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public CircleProgress(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CircleProgress);
|
||||
mBgColor = ta.getColor(R.styleable.CircleProgress_cp_bg_color, 0);
|
||||
mFgColor = ta.getColor(R.styleable.CircleProgress_cp_fg_color, 0);
|
||||
mStrokeWidth = ta.getDimension(R.styleable.CircleProgress_cp_stroke_width, 0);
|
||||
mMaxProgress = ta.getFloat(R.styleable.CircleProgress_cp_max_progress, 0);
|
||||
mCurProgress = ta.getFloat(R.styleable.CircleProgress_cp_cur_progress, 0);
|
||||
ta.recycle();
|
||||
initPaint();
|
||||
}
|
||||
|
||||
private void initPaint() {
|
||||
mBgPaint = new Paint();
|
||||
mBgPaint.setAntiAlias(true);
|
||||
mBgPaint.setDither(true);
|
||||
mBgPaint.setColor(mBgColor);
|
||||
mBgPaint.setStyle(Paint.Style.STROKE);
|
||||
mBgPaint.setStrokeWidth(mStrokeWidth);
|
||||
|
||||
mFgPaint = new Paint();
|
||||
mFgPaint.setAntiAlias(true);
|
||||
mFgPaint.setDither(true);
|
||||
mFgPaint.setColor(mFgColor);
|
||||
mFgPaint.setStyle(Paint.Style.STROKE);
|
||||
mFgPaint.setStrokeWidth(mStrokeWidth);
|
||||
mRectF = new RectF();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
float offset = mStrokeWidth / 2;
|
||||
mX = w / 2;
|
||||
mR = mX - offset;
|
||||
mRectF = new RectF();
|
||||
mRectF.left = offset;
|
||||
mRectF.top = offset;
|
||||
mRectF.right = w - offset;
|
||||
mRectF.bottom = mRectF.right;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
canvas.drawCircle(mX, mX, mR, mBgPaint);
|
||||
if (mMaxProgress > 0 && mCurProgress > 0) {
|
||||
canvas.drawArc(mRectF, -90, mCurProgress / mMaxProgress * 360, false, mFgPaint);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxProgress(float maxProgress) {
|
||||
mMaxProgress = maxProgress;
|
||||
}
|
||||
|
||||
public void setCurProgress(float curProgress) {
|
||||
mCurProgress = curProgress;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.qxcm.moduleutil.dialog;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Paint;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.adapter.GiftAdapter;
|
||||
import com.qxcm.moduleutil.adapter.HeavenGiftAdapter;
|
||||
import com.qxcm.moduleutil.bean.BaseListData;
|
||||
import com.qxcm.moduleutil.bean.HeatedBean;
|
||||
import com.qxcm.moduleutil.bean.HeavenGiftBean;
|
||||
import com.qxcm.moduleutil.databinding.DialogFirstChargeBinding;
|
||||
import com.qxcm.moduleutil.databinding.DialogHeavenGiftBinding;
|
||||
import com.qxcm.moduleutil.widget.dialog.BaseDialog;
|
||||
import com.zhpan.bannerview.indicator.DrawableIndicator;
|
||||
import com.zhpan.indicator.base.IIndicator;
|
||||
import com.zhpan.indicator.enums.IndicatorSlideMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*@author
|
||||
*@data
|
||||
*@description: 首充好礼
|
||||
*/
|
||||
public class FirstChargeDialog extends BaseDialog<DialogFirstChargeBinding> {
|
||||
|
||||
GiftAdapter giftAdapter;
|
||||
HeavenGiftAdapter heavenGiftAdapter;
|
||||
public FirstChargeDialog(@NonNull Context context) {
|
||||
super(context, R.style.BaseDialogStyleH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_first_charge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(false);
|
||||
setCanceledOnTouchOutside(false);
|
||||
Window window = getWindow();
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 375.f / 375), WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
mBinding.ivClose.setOnClickListener(v -> dismiss());
|
||||
// giftAdapter=new GiftAdapter();
|
||||
// LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
// linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
// mBinding.rvHead.setLayoutManager(linearLayoutManager);
|
||||
// mBinding.rvHead.setAdapter(giftAdapter);
|
||||
mBinding.tvTitle2.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
heavenGiftAdapter=new HeavenGiftAdapter();
|
||||
mBinding.bannerViewPager
|
||||
.setPageMargin(15)
|
||||
.setAutoPlay(false)
|
||||
.setRevealWidth(0, 0)
|
||||
.setIndicatorVisibility(View.VISIBLE)
|
||||
.setIndicatorView(getVectorDrawableIndicator())
|
||||
.setIndicatorSlideMode(IndicatorSlideMode.NORMAL)
|
||||
.setAdapter(heavenGiftAdapter)
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
List<HeavenGiftBean> list=new ArrayList<>();
|
||||
for (int i = 0; i < 7; i++){
|
||||
HeavenGiftBean bean=new HeavenGiftBean();
|
||||
bean.setTitle("礼物"+i);
|
||||
bean.setPicture("");
|
||||
bean.setType(1);
|
||||
bean.setQuantity("x"+i);
|
||||
bean.setGold(i+"");
|
||||
bean.setDays(i+"天");
|
||||
list.add(bean);
|
||||
}
|
||||
mBinding.bannerViewPager.create(baseListData(list,4));
|
||||
|
||||
}
|
||||
private List<BaseListData<HeavenGiftBean>> baseListData(List<HeavenGiftBean> list, int chunkSize){
|
||||
List<BaseListData<HeavenGiftBean>> baseListData = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i += chunkSize) {
|
||||
BaseListData<HeavenGiftBean> baseListData1 = new BaseListData<>();
|
||||
baseListData1.setData(list.subList(i, Math.min(i + chunkSize, list.size())));
|
||||
baseListData.add(baseListData1);
|
||||
}
|
||||
return baseListData;
|
||||
}
|
||||
private IIndicator getVectorDrawableIndicator() {
|
||||
int dp6 = getResources().getDimensionPixelOffset(com.qxcm.moduleutil.R.dimen.dp_6);
|
||||
return new DrawableIndicator(getContext())
|
||||
.setIndicatorGap(getResources().getDimensionPixelOffset(com.qxcm.moduleutil.R.dimen.dp_2_5))
|
||||
.setIndicatorDrawable(com.qxcm.moduleutil.R.drawable.banner_indicator_nornal, com.qxcm.moduleutil.R.drawable.banner_indicator_focus)
|
||||
.setIndicatorSize(getResources().getDimensionPixelOffset(com.qxcm.moduleutil.R.dimen.dp_13), dp6, getResources().getDimensionPixelOffset(com.qxcm.moduleutil.R.dimen.dp_13), dp6);
|
||||
}
|
||||
|
||||
private Resources getResources() {
|
||||
return getContext().getResources();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.qxcm.moduleutil.dialog;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.adapter.GiftAdapter;
|
||||
import com.qxcm.moduleutil.adapter.HeavenGiftAdapter;
|
||||
import com.qxcm.moduleutil.bean.BaseListData;
|
||||
import com.qxcm.moduleutil.bean.HeavenGiftBean;
|
||||
import com.qxcm.moduleutil.databinding.DialogHeavenGiftBinding;
|
||||
import com.qxcm.moduleutil.widget.dialog.BaseDialog;
|
||||
import com.zhpan.bannerview.indicator.DrawableIndicator;
|
||||
import com.zhpan.indicator.base.IIndicator;
|
||||
import com.zhpan.indicator.enums.IndicatorSlideMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/**
|
||||
*@author
|
||||
*@data
|
||||
*@description: 天降好礼
|
||||
*/
|
||||
public class HeavenGiftDialog extends BaseDialog<DialogHeavenGiftBinding> {
|
||||
|
||||
GiftAdapter giftAdapter;
|
||||
HeavenGiftAdapter heavenGiftAdapter;
|
||||
public HeavenGiftDialog(@NonNull Context context) {
|
||||
super(context,R.style.BaseDialogStyleH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_heaven_gift;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(false);
|
||||
setCanceledOnTouchOutside(false);
|
||||
Window window = getWindow();
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 375.f / 375), WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
mBinding.ivClose.setOnClickListener(v -> dismiss());
|
||||
// giftAdapter=new GiftAdapter();
|
||||
// LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
// linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
// mBinding.rvHead.setLayoutManager(linearLayoutManager);
|
||||
// mBinding.rvHead.setAdapter(giftAdapter);
|
||||
|
||||
heavenGiftAdapter=new HeavenGiftAdapter();
|
||||
mBinding.bannerViewPager
|
||||
.setPageMargin(15)
|
||||
.setAutoPlay(false)
|
||||
.setRevealWidth(0, 0)
|
||||
.setIndicatorVisibility(View.VISIBLE)
|
||||
.setIndicatorView(getVectorDrawableIndicator())
|
||||
.setIndicatorSlideMode(IndicatorSlideMode.NORMAL)
|
||||
.setAdapter(heavenGiftAdapter)
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
List<HeavenGiftBean> list=new ArrayList<>();
|
||||
for (int i = 0; i < 7; i++){
|
||||
HeavenGiftBean bean=new HeavenGiftBean();
|
||||
bean.setTitle("礼物"+i);
|
||||
bean.setPicture("");
|
||||
bean.setType(1);
|
||||
bean.setQuantity("x"+i);
|
||||
bean.setGold(i+"");
|
||||
bean.setDays(i+"天");
|
||||
list.add(bean);
|
||||
}
|
||||
// giftAdapter.setNewData(list);
|
||||
mBinding.bannerViewPager.create(baseListData(list,4));
|
||||
}
|
||||
|
||||
private List<BaseListData<HeavenGiftBean>> baseListData(List<HeavenGiftBean> list, int chunkSize){
|
||||
List<BaseListData<HeavenGiftBean>> baseListData = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i += chunkSize) {
|
||||
BaseListData<HeavenGiftBean> baseListData1 = new BaseListData<>();
|
||||
baseListData1.setData(list.subList(i, Math.min(i + chunkSize, list.size())));
|
||||
baseListData.add(baseListData1);
|
||||
}
|
||||
return baseListData;
|
||||
}
|
||||
private IIndicator getVectorDrawableIndicator() {
|
||||
int dp6 = getResources().getDimensionPixelOffset(com.qxcm.moduleutil.R.dimen.dp_6);
|
||||
return new DrawableIndicator(getContext())
|
||||
.setIndicatorGap(getResources().getDimensionPixelOffset(com.qxcm.moduleutil.R.dimen.dp_2_5))
|
||||
.setIndicatorDrawable(com.qxcm.moduleutil.R.drawable.banner_indicator_nornal, com.qxcm.moduleutil.R.drawable.banner_indicator_focus)
|
||||
.setIndicatorSize(getResources().getDimensionPixelOffset(com.qxcm.moduleutil.R.dimen.dp_13), dp6, getResources().getDimensionPixelOffset(com.qxcm.moduleutil.R.dimen.dp_13), dp6);
|
||||
}
|
||||
|
||||
private Resources getResources() {
|
||||
return getContext().getResources();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.qxcm.moduleutil.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.databinding.DialogInviteBinding;
|
||||
import com.qxcm.moduleutil.widget.dialog.BaseDialog;
|
||||
/**
|
||||
*@author lxj
|
||||
*@data 2025年5月14日
|
||||
*@description: 房间邀请弹窗
|
||||
*/
|
||||
public class InviteDialog extends BaseDialog<DialogInviteBinding> {
|
||||
public InviteDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_invite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(false);
|
||||
setCanceledOnTouchOutside(false);
|
||||
Window window = getWindow();
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 315.f / 375), WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
mBinding.ivClose.setOnClickListener(v -> dismiss());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.qxcm.moduleutil.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.text.TextPaint;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.blankj.utilcode.util.SpanUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.databinding.DialogPolicBinding;
|
||||
|
||||
/**
|
||||
* 隐私协议
|
||||
*/
|
||||
public class PolicyDialog extends Dialog {
|
||||
private final DialogPolicBinding policBinding;
|
||||
private PolicyClickListener mPolicyClickListener;
|
||||
|
||||
public PolicyDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
policBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_polic, null, false);
|
||||
policBinding.setClick(new PolicyClickProxy());
|
||||
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
setContentView(policBinding.getRoot());
|
||||
setCanceledOnTouchOutside(false);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
SpanUtils spanUtils = new SpanUtils();
|
||||
ClickableSpan clickSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
// ARouter.getInstance().build(ARouters.H5).withString("url", Constant.URL.URL_USER_YHXY).navigation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDrawState(@NonNull TextPaint ds) {
|
||||
ds.setColor(Color.parseColor("#FFFFD6A2"));
|
||||
ds.setUnderlineText(true);
|
||||
}
|
||||
};
|
||||
ClickableSpan ysClickSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
// ARouter.getInstance().build(ARouters.H5).withString("url", Constant.URL.URL_USER_YSXY).navigation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDrawState(@NonNull TextPaint ds) {
|
||||
ds.setColor(Color.parseColor("#FFFFD6A2"));
|
||||
ds.setUnderlineText(true);
|
||||
}
|
||||
};
|
||||
spanUtils.append("欢迎使用初梦!\n").append("在使用我们的产品和服务之前,请您先阅读并了解").append("《用户协议》").setClickSpan(clickSpan).append("和").append("《隐私协议》").setClickSpan(ysClickSpan).append("。我们将严格按照上述协议为" +
|
||||
"您提供服务,保护您的信息安全,点" +
|
||||
"击“同意”即表示您已阅读并同意全部" +
|
||||
"条款,可以继续使用我们的产品和服" +
|
||||
"务。");
|
||||
policBinding.tvText.setText(spanUtils.create());
|
||||
policBinding.tvText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public void setPolicyClickListener(PolicyClickListener policyClickListener) {
|
||||
this.mPolicyClickListener = policyClickListener;
|
||||
}
|
||||
|
||||
public class PolicyClickProxy {
|
||||
public void onAgreeClick() {
|
||||
if (mPolicyClickListener != null) {
|
||||
mPolicyClickListener.policyAgree();
|
||||
}
|
||||
}
|
||||
|
||||
public void onExit() {
|
||||
if (mPolicyClickListener != null) {
|
||||
mPolicyClickListener.policyExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface PolicyClickListener {
|
||||
void policyAgree();
|
||||
|
||||
void policyExit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.qxcm.moduleutil.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.bean.TeenagerInfo;
|
||||
import com.qxcm.moduleutil.databinding.DialogRealNameBinding;
|
||||
import com.qxcm.moduleutil.databinding.IndexDialogYouthModelBinding;
|
||||
import com.qxcm.moduleutil.widget.dialog.BaseDialog;
|
||||
/**
|
||||
*@author
|
||||
*@data
|
||||
*@description:实名认账弹窗
|
||||
*/
|
||||
public class RealNameDialog extends BaseDialog<DialogRealNameBinding> {
|
||||
|
||||
public RealNameDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_real_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(false);
|
||||
setCanceledOnTouchOutside(false);
|
||||
Window window = getWindow();
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 315.f / 375), WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
mBinding.tvIKnow.setOnClickListener(v -> dismiss());
|
||||
mBinding.ivClose.setOnClickListener(v -> dismiss());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.qxcm.moduleutil.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.bean.TeenagerInfo;
|
||||
import com.qxcm.moduleutil.databinding.IndexDialogYouthModelBinding;
|
||||
import com.qxcm.moduleutil.widget.dialog.BaseDialog;
|
||||
|
||||
/**
|
||||
* 描述 describe 青少年模式弹窗
|
||||
*/
|
||||
public class YouthModelDialog extends BaseDialog<IndexDialogYouthModelBinding> {
|
||||
private TeenagerInfo teenagerInfo;
|
||||
|
||||
public YouthModelDialog(@NonNull Context context, TeenagerInfo teenagerInfo) {
|
||||
super(context);
|
||||
this.teenagerInfo = teenagerInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.index_dialog_youth_model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(false);
|
||||
setCanceledOnTouchOutside(false);
|
||||
Window window = getWindow();
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 315.f / 375), WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
mBinding.ivClose.setOnClickListener(v -> dismiss());
|
||||
mBinding.tvIKnow.setOnClickListener(v -> dismiss());
|
||||
mBinding.tvOpen.setOnClickListener(v -> {
|
||||
if (teenagerInfo.getHad_password() == 1) {
|
||||
// ARouter.getInstance().build(ARouteConstants.SET_YOUTH_PWD_ACTIVITY).withInt("type", SetYouthPasswordActivity.TYPE_OPEN).navigation();
|
||||
} else {
|
||||
// ARouter.getInstance().build(ARouteConstants.SET_YOUTH_PWD_ACTIVITY).withInt("type", SetYouthPasswordActivity.SET_TYPE).navigation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
public void setTeenagerInfo(TeenagerInfo teenagerInfo) {
|
||||
this.teenagerInfo = teenagerInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.qxcm.moduleutil.event;
|
||||
|
||||
/**
|
||||
* Created by http://www.yunbaokj.com on 2022/7/12.
|
||||
*/
|
||||
public class AppLifecycleEvent {
|
||||
|
||||
private boolean mFrontGround;
|
||||
|
||||
public AppLifecycleEvent(boolean frontGround) {
|
||||
mFrontGround = frontGround;
|
||||
}
|
||||
|
||||
public boolean isFrontGround() {
|
||||
return mFrontGround;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.qxcm.moduleutil.event;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/7/18.
|
||||
*/
|
||||
|
||||
public class LocationCityEvent {
|
||||
private final String city;
|
||||
|
||||
public LocationCityEvent(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.qxcm.moduleutil.event;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/7/18.
|
||||
*/
|
||||
|
||||
public class LocationEvent {
|
||||
private double lng;
|
||||
private double lat;
|
||||
|
||||
public LocationEvent(double lng, double lat) {
|
||||
this.lng = lng;
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public double getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.qxcm.moduleutil.event;
|
||||
|
||||
public class LogOutEvent {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.qxcm.moduleutil.http;
|
||||
|
||||
|
||||
public class APIException extends RuntimeException {
|
||||
private int code;
|
||||
|
||||
|
||||
public APIException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public APIException(int code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.qxcm.moduleutil.http;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class BaseModel<T> implements Parcelable {
|
||||
private int status;
|
||||
private T data;
|
||||
private String info;
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getInfo() {
|
||||
return info;
|
||||
}
|
||||
|
||||
public void setInfo(String info) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public BaseModel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(this.status);
|
||||
dest.writeString(this.info);
|
||||
}
|
||||
|
||||
protected BaseModel(Parcel in) {
|
||||
this.status = in.readInt();
|
||||
this.info = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<BaseModel> CREATOR = new Creator<BaseModel>() {
|
||||
@Override
|
||||
public BaseModel createFromParcel(Parcel source) {
|
||||
return new BaseModel(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseModel[] newArray(int size) {
|
||||
return new BaseModel[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.qxcm.moduleutil.http;
|
||||
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.blankj.utilcode.util.ThreadUtils;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.qxcm.moduleutil.event.LogOutEvent;
|
||||
import com.qxcm.moduleutil.utils.DialogUtils;
|
||||
import com.qxcm.moduleutil.utils.logger.Logger;
|
||||
|
||||
import org.apache.http.conn.ConnectTimeoutException;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2017/11/22.
|
||||
*/
|
||||
|
||||
public abstract class BaseObserver<T> implements Observer<T> {
|
||||
|
||||
private boolean showErrMsg;
|
||||
|
||||
public BaseObserver() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public BaseObserver(boolean showErrMsg) {
|
||||
this.showErrMsg = showErrMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if (e instanceof SocketTimeoutException) {
|
||||
ToastUtils.show("网络中断,请检查您的网络状态");
|
||||
} else if (e instanceof ConnectException) {
|
||||
ToastUtils.show("网络中断,请检查您的网络状态");
|
||||
} else if (e instanceof ConnectTimeoutException) {
|
||||
ToastUtils.show("网络中断,请检查您的网络状态");
|
||||
} else if (e instanceof UnknownHostException) {
|
||||
ToastUtils.show("网络中断,请检查您的网络状态");
|
||||
} else if (e instanceof IllegalStateException) {
|
||||
ToastUtils.show("解析失败");
|
||||
} else if (e instanceof APIException) {
|
||||
APIException apiException = (APIException) e;
|
||||
if (apiException.getCode() == -1) {
|
||||
EventBus.getDefault().post(new LogOutEvent());
|
||||
}
|
||||
if (showErrMsg && !TextUtils.isEmpty(apiException.getMessage())) {
|
||||
ToastUtils.show(apiException.getMessage());
|
||||
}
|
||||
} else if (e instanceof APIException) {
|
||||
APIException apiException = (APIException) e;
|
||||
if (showErrMsg && !TextUtils.isEmpty(apiException.getMessage())) {
|
||||
ToastUtils.show(apiException.getMessage());
|
||||
}
|
||||
} else if (e instanceof JsonSyntaxException) {
|
||||
ToastUtils.show("网络请求错误……");
|
||||
} else {
|
||||
ToastUtils.show(e.getMessage());
|
||||
// CrashReport.postCatchedException(e); //bugly收集错误信息
|
||||
}
|
||||
e.printStackTrace();
|
||||
onComplete();
|
||||
}
|
||||
|
||||
public void onErrorCode(int code) {
|
||||
Logger.e("onErrorCode", code);
|
||||
if (code == 2) {
|
||||
ThreadUtils.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DialogUtils.showNoBalance();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void onComplete() {
|
||||
Logger.i("onComplete");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.qxcm.moduleutil.http;
|
||||
|
||||
import android.app.Dialog;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/8/7.
|
||||
*/
|
||||
|
||||
public abstract class HttpCallback {
|
||||
|
||||
private Dialog mLoadingDialog;
|
||||
|
||||
public abstract void onSuccess(int code, String msg, String[] info);
|
||||
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录过期
|
||||
*/
|
||||
public void onLoginInvalid() {
|
||||
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
try {
|
||||
if (showLoadingDialog()) {
|
||||
if (mLoadingDialog == null) {
|
||||
mLoadingDialog = createLoadingDialog();
|
||||
}
|
||||
mLoadingDialog.show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
if (showLoadingDialog() && mLoadingDialog != null) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
public Dialog createLoadingDialog() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean showLoadingDialog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isUseLoginInvalid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.qxcm.moduleutil.interfaces;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AppLifecycleUtil {
|
||||
|
||||
private static final List<LifecycleCallback> sList;
|
||||
|
||||
static {
|
||||
sList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static void addLifecycleCallback(LifecycleCallback callback) {
|
||||
if (sList != null) {
|
||||
sList.add(callback);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeLifecycleCallback(LifecycleCallback callback) {
|
||||
if (sList != null) {
|
||||
sList.remove(callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处于前台
|
||||
*/
|
||||
public static void onAppFrontGround() {
|
||||
if (sList != null && sList.size() > 0) {
|
||||
for (LifecycleCallback callback : sList) {
|
||||
callback.onAppFrontGround();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处于后台
|
||||
*/
|
||||
public static void onAppBackGround() {
|
||||
if (sList != null && sList.size() > 0) {
|
||||
for (LifecycleCallback callback : sList) {
|
||||
callback.onAppBackGround();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface LifecycleCallback {
|
||||
|
||||
/**
|
||||
* 处于前台
|
||||
*/
|
||||
void onAppFrontGround();
|
||||
|
||||
/**
|
||||
* 处于后台
|
||||
*/
|
||||
void onAppBackGround();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.qxcm.moduleutil.interfaces;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/8/11.
|
||||
*/
|
||||
|
||||
public abstract class CommonCallback<T> {
|
||||
public abstract void callback(T bean);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.qxcm.moduleutil.presenter;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
|
||||
import com.qxcm.moduleutil.activity.IPresenter;
|
||||
import com.qxcm.moduleutil.activity.IView;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
public abstract class BasePresenter<V extends IView> implements IPresenter {
|
||||
protected CompositeDisposable mDisposables = new CompositeDisposable();
|
||||
// private RemoteDataSource api;
|
||||
protected Reference<V> MvpRef;
|
||||
protected Context mContext;
|
||||
|
||||
@Deprecated
|
||||
public BasePresenter(V view) {
|
||||
attachView(view);
|
||||
}
|
||||
|
||||
public BasePresenter(V view, Context context) {
|
||||
attachView(view);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
private void attachView(V view) {
|
||||
MvpRef = new WeakReference<V>(view);
|
||||
}
|
||||
|
||||
protected V getView() {
|
||||
if (MvpRef != null) {
|
||||
return MvpRef.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// protected RemoteDataSource getApi() {
|
||||
// if (api == null) {
|
||||
// api = RemoteDataSource.getInstance();
|
||||
// }
|
||||
// return api;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 主要用于判断IView的生命周期是否结束,防止出现内存泄露状况
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isViewAttach() {
|
||||
return MvpRef != null && MvpRef.get() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
cancelRequest();
|
||||
if (MvpRef != null) {
|
||||
MvpRef.clear();
|
||||
MvpRef = null;
|
||||
}
|
||||
// if (api != null) {
|
||||
// api = null;
|
||||
// }
|
||||
unBindView();
|
||||
}
|
||||
|
||||
|
||||
public void unBindView() {
|
||||
if (MvpRef != null) {
|
||||
MvpRef.clear();
|
||||
}
|
||||
mContext=null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入订阅对象
|
||||
*
|
||||
* @param disposable
|
||||
*/
|
||||
public void addDisposable(Disposable disposable) {
|
||||
mDisposables.add(disposable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除订阅对象
|
||||
*
|
||||
* @param disposable
|
||||
*/
|
||||
public void removeDisposable(Disposable disposable) {
|
||||
mDisposables.remove(disposable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消所有请求
|
||||
*/
|
||||
public void cancelRequest() {
|
||||
if (mDisposables != null) {
|
||||
mDisposables.clear(); // clear时网络请求会随即cancel
|
||||
mDisposables = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
578
moduleUtil/src/main/java/com/qxcm/moduleutil/utils/BarUtils.java
Normal file
578
moduleUtil/src/main/java/com/qxcm/moduleutil/utils/BarUtils.java
Normal file
@@ -0,0 +1,578 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
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.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.MarginLayoutParams;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
|
||||
import com.blankj.utilcode.util.Utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* author: Blankj
|
||||
* blog : http://blankj.com
|
||||
* time : 2016/09/23
|
||||
* desc : 栏相关工具类
|
||||
* </pre>
|
||||
*/
|
||||
public final class BarUtils {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// status bar
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private static final int DEFAULT_ALPHA = 112;
|
||||
private static final String TAG_COLOR = "TAG_COLOR";
|
||||
private static final String TAG_ALPHA = "TAG_ALPHA";
|
||||
private static final int TAG_OFFSET = -123;
|
||||
|
||||
private BarUtils() {
|
||||
throw new UnsupportedOperationException("u can't instantiate me...");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态栏高度(单位:px)
|
||||
*
|
||||
* @return 状态栏高度(单位:px)
|
||||
*/
|
||||
public static int getStatusBarHeight() {
|
||||
Resources resources = Utils.getApp().getResources();
|
||||
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
|
||||
return resources.getDimensionPixelSize(resourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏是否可见
|
||||
*
|
||||
* @param activity activity
|
||||
* @param isVisible {@code true}: 可见<br>{@code false}: 不可见
|
||||
*/
|
||||
public static void setStatusBarVisibility(final Activity activity, final boolean isVisible) {
|
||||
if (isVisible) {
|
||||
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
} else {
|
||||
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断状态栏是否可见
|
||||
*
|
||||
* @param activity activity
|
||||
* @return {@code true}: 可见<br>{@code false}: 不可见
|
||||
*/
|
||||
public static boolean isStatusBarVisible(final Activity activity) {
|
||||
int flags = activity.getWindow().getAttributes().flags;
|
||||
return (flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 view 增加 MarginTop 为状态栏高度
|
||||
*
|
||||
* @param view view
|
||||
*/
|
||||
public static void addMarginTopEqualStatusBarHeight(@NonNull View view) {
|
||||
Object haveSetOffset = view.getTag(TAG_OFFSET);
|
||||
if (haveSetOffset != null && (Boolean) haveSetOffset) return;
|
||||
MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();
|
||||
layoutParams.setMargins(layoutParams.leftMargin,
|
||||
layoutParams.topMargin + getStatusBarHeight(),
|
||||
layoutParams.rightMargin,
|
||||
layoutParams.bottomMargin);
|
||||
view.setTag(TAG_OFFSET, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 view 减少 MarginTop 为状态栏高度
|
||||
*
|
||||
* @param view view
|
||||
*/
|
||||
public static void subtractMarginTopEqualStatusBarHeight(@NonNull View view) {
|
||||
Object haveSetOffset = view.getTag(TAG_OFFSET);
|
||||
if (haveSetOffset == null || !(Boolean) haveSetOffset) return;
|
||||
MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();
|
||||
layoutParams.setMargins(layoutParams.leftMargin,
|
||||
layoutParams.topMargin - getStatusBarHeight(),
|
||||
layoutParams.rightMargin,
|
||||
layoutParams.bottomMargin);
|
||||
view.setTag(TAG_OFFSET, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏颜色
|
||||
*
|
||||
* @param activity activity
|
||||
* @param color 状态栏颜色值
|
||||
*/
|
||||
public static void setStatusBarColor(@NonNull final Activity activity,
|
||||
@ColorInt final int color) {
|
||||
setStatusBarColor(activity, color, DEFAULT_ALPHA, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏颜色
|
||||
*
|
||||
* @param activity activity
|
||||
* @param color 状态栏颜色值
|
||||
* @param alpha 状态栏透明度,此透明度并非颜色中的透明度
|
||||
*/
|
||||
public static void setStatusBarColor(@NonNull final Activity activity,
|
||||
@ColorInt final int color,
|
||||
@IntRange(from = 0, to = 255) final int alpha) {
|
||||
setStatusBarColor(activity, color, alpha, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏颜色
|
||||
*
|
||||
* @param activity activity
|
||||
* @param color 状态栏颜色值
|
||||
* @param alpha 状态栏透明度,此透明度并非颜色中的透明度
|
||||
* @param isDecor {@code true}: 设置在 DecorView 中<br>
|
||||
* {@code false}: 设置在 ContentView 中
|
||||
*/
|
||||
public static void setStatusBarColor(@NonNull final Activity activity,
|
||||
@ColorInt final int color,
|
||||
@IntRange(from = 0, to = 255) final int alpha,
|
||||
final boolean isDecor) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
hideAlphaView(activity);
|
||||
transparentStatusBar(activity);
|
||||
addStatusBarColor(activity, color, alpha, isDecor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏透明度
|
||||
*
|
||||
* @param activity activity
|
||||
*/
|
||||
public static void setStatusBarAlpha(@NonNull final Activity activity) {
|
||||
setStatusBarAlpha(activity, DEFAULT_ALPHA, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏透明度
|
||||
*
|
||||
* @param activity activity
|
||||
*/
|
||||
public static void setStatusBarAlpha(@NonNull final Activity activity,
|
||||
@IntRange(from = 0, to = 255) final int alpha) {
|
||||
setStatusBarAlpha(activity, alpha, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏透明度
|
||||
*
|
||||
* @param activity activity
|
||||
* @param alpha 状态栏透明度
|
||||
* @param isDecor {@code true}: 设置在 DecorView 中<br>
|
||||
* {@code false}: 设置在 ContentView 中
|
||||
*/
|
||||
public static void setStatusBarAlpha(@NonNull final Activity activity,
|
||||
@IntRange(from = 0, to = 255) final int alpha,
|
||||
final boolean isDecor) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
hideColorView(activity);
|
||||
transparentStatusBar(activity);
|
||||
addStatusBarAlpha(activity, alpha, isDecor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏颜色
|
||||
*
|
||||
* @param fakeStatusBar 伪造状态栏
|
||||
* @param color 状态栏颜色值
|
||||
*/
|
||||
public static void setStatusBarColor(@NonNull final View fakeStatusBar,
|
||||
@ColorInt final int color) {
|
||||
setStatusBarColor(fakeStatusBar, color, DEFAULT_ALPHA);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏颜色
|
||||
*
|
||||
* @param fakeStatusBar 伪造状态栏
|
||||
* @param color 状态栏颜色值
|
||||
* @param alpha 状态栏透明度,此透明度并非颜色中的透明度
|
||||
*/
|
||||
public static void setStatusBarColor(@NonNull final View fakeStatusBar,
|
||||
@ColorInt final int color,
|
||||
@IntRange(from = 0, to = 255) final int alpha) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
fakeStatusBar.setVisibility(View.VISIBLE);
|
||||
transparentStatusBar((Activity) fakeStatusBar.getContext());
|
||||
ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
|
||||
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = BarUtils.getStatusBarHeight();
|
||||
fakeStatusBar.setBackgroundColor(getStatusBarColor(color, alpha));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏透明度
|
||||
*
|
||||
* @param fakeStatusBar 伪造状态栏
|
||||
*/
|
||||
public static void setStatusBarAlpha(@NonNull final View fakeStatusBar) {
|
||||
setStatusBarAlpha(fakeStatusBar, DEFAULT_ALPHA);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态栏透明度
|
||||
*
|
||||
* @param fakeStatusBar 伪造状态栏
|
||||
* @param alpha 状态栏透明度
|
||||
*/
|
||||
public static void setStatusBarAlpha(@NonNull final View fakeStatusBar,
|
||||
@IntRange(from = 0, to = 255) final int alpha) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
fakeStatusBar.setVisibility(View.VISIBLE);
|
||||
transparentStatusBar((Activity) fakeStatusBar.getContext());
|
||||
ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
|
||||
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = BarUtils.getStatusBarHeight();
|
||||
fakeStatusBar.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 DrawerLayout 设置状态栏颜色
|
||||
* <p>DrawLayout 需设置 {@code android:fitsSystemWindows="true"}</p>
|
||||
*
|
||||
* @param activity activity
|
||||
* @param drawer drawerLayout
|
||||
* @param fakeStatusBar 伪造状态栏
|
||||
* @param color 状态栏颜色值
|
||||
* @param isTop drawerLayout 是否在顶层
|
||||
*/
|
||||
public static void setStatusBarColor4Drawer(@NonNull final Activity activity,
|
||||
@NonNull final DrawerLayout drawer,
|
||||
@NonNull final View fakeStatusBar,
|
||||
@ColorInt final int color,
|
||||
final boolean isTop) {
|
||||
setStatusBarColor4Drawer(activity, drawer, fakeStatusBar, color, DEFAULT_ALPHA, isTop);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 DrawerLayout 设置状态栏颜色
|
||||
* <p>DrawLayout 需设置 {@code android:fitsSystemWindows="true"}</p>
|
||||
*
|
||||
* @param activity activity
|
||||
* @param drawer drawerLayout
|
||||
* @param fakeStatusBar 伪造状态栏
|
||||
* @param color 状态栏颜色值
|
||||
* @param alpha 状态栏透明度,此透明度并非颜色中的透明度
|
||||
* @param isTop drawerLayout 是否在顶层
|
||||
*/
|
||||
public static void setStatusBarColor4Drawer(@NonNull final Activity activity,
|
||||
@NonNull final DrawerLayout drawer,
|
||||
@NonNull final View fakeStatusBar,
|
||||
@ColorInt final int color,
|
||||
@IntRange(from = 0, to = 255) final int alpha,
|
||||
final boolean isTop) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
drawer.setFitsSystemWindows(false);
|
||||
transparentStatusBar(activity);
|
||||
setStatusBarColor(fakeStatusBar, color, isTop ? alpha : 0);
|
||||
for (int i = 0, len = drawer.getChildCount(); i < len; i++) {
|
||||
drawer.getChildAt(i).setFitsSystemWindows(false);
|
||||
}
|
||||
if (isTop) {
|
||||
hideAlphaView(activity);
|
||||
} else {
|
||||
addStatusBarAlpha(activity, alpha, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 DrawerLayout 设置状态栏透明度
|
||||
* <p>DrawLayout 需设置 {@code android:fitsSystemWindows="true"}</p>
|
||||
*
|
||||
* @param activity activity
|
||||
* @param drawer drawerLayout
|
||||
* @param fakeStatusBar 伪造状态栏
|
||||
* @param isTop drawerLayout 是否在顶层
|
||||
*/
|
||||
public static void setStatusBarAlpha4Drawer(@NonNull final Activity activity,
|
||||
@NonNull final DrawerLayout drawer,
|
||||
@NonNull final View fakeStatusBar,
|
||||
final boolean isTop) {
|
||||
setStatusBarAlpha4Drawer(activity, drawer, fakeStatusBar, DEFAULT_ALPHA, isTop);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 DrawerLayout 设置状态栏透明度
|
||||
* <p>DrawLayout 需设置 {@code android:fitsSystemWindows="true"}</p>
|
||||
*
|
||||
* @param activity activity
|
||||
* @param drawer drawerLayout
|
||||
* @param fakeStatusBar 伪造状态栏
|
||||
* @param alpha 状态栏透明度
|
||||
* @param isTop drawerLayout 是否在顶层
|
||||
*/
|
||||
public static void setStatusBarAlpha4Drawer(@NonNull final Activity activity,
|
||||
@NonNull final DrawerLayout drawer,
|
||||
@NonNull final View fakeStatusBar,
|
||||
@IntRange(from = 0, to = 255) final int alpha,
|
||||
final boolean isTop) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
drawer.setFitsSystemWindows(false);
|
||||
transparentStatusBar(activity);
|
||||
setStatusBarAlpha(fakeStatusBar, isTop ? alpha : 0);
|
||||
for (int i = 0, len = drawer.getChildCount(); i < len; i++) {
|
||||
drawer.getChildAt(i).setFitsSystemWindows(false);
|
||||
}
|
||||
if (isTop) {
|
||||
hideAlphaView(activity);
|
||||
} else {
|
||||
addStatusBarAlpha(activity, alpha, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addStatusBarColor(final Activity activity,
|
||||
final int color,
|
||||
final int alpha,
|
||||
boolean isDecor) {
|
||||
ViewGroup parent = isDecor ?
|
||||
(ViewGroup) activity.getWindow().getDecorView() :
|
||||
(ViewGroup) activity.findViewById(android.R.id.content);
|
||||
View fakeStatusBarView = parent.findViewWithTag(TAG_COLOR);
|
||||
if (fakeStatusBarView != null) {
|
||||
if (fakeStatusBarView.getVisibility() == View.GONE) {
|
||||
fakeStatusBarView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
fakeStatusBarView.setBackgroundColor(getStatusBarColor(color, alpha));
|
||||
} else {
|
||||
parent.addView(createColorStatusBarView(parent.getContext(), color, alpha));
|
||||
}
|
||||
}
|
||||
|
||||
private static void addStatusBarAlpha(final Activity activity,
|
||||
final int alpha,
|
||||
boolean isDecor) {
|
||||
ViewGroup parent = isDecor ?
|
||||
(ViewGroup) activity.getWindow().getDecorView() :
|
||||
(ViewGroup) activity.findViewById(android.R.id.content);
|
||||
View fakeStatusBarView = parent.findViewWithTag(TAG_ALPHA);
|
||||
if (fakeStatusBarView != null) {
|
||||
if (fakeStatusBarView.getVisibility() == View.GONE) {
|
||||
fakeStatusBarView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
fakeStatusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
|
||||
} else {
|
||||
parent.addView(createAlphaStatusBarView(parent.getContext(), alpha));
|
||||
}
|
||||
}
|
||||
|
||||
private static void hideColorView(final Activity activity) {
|
||||
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
|
||||
View fakeStatusBarView = decorView.findViewWithTag(TAG_COLOR);
|
||||
if (fakeStatusBarView == null) return;
|
||||
fakeStatusBarView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private static void hideAlphaView(final Activity activity) {
|
||||
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
|
||||
View fakeStatusBarView = decorView.findViewWithTag(TAG_ALPHA);
|
||||
if (fakeStatusBarView == null) return;
|
||||
fakeStatusBarView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private static int getStatusBarColor(final int color, final int alpha) {
|
||||
if (alpha == 0) return color;
|
||||
float a = 1 - alpha / 255f;
|
||||
int red = (color >> 16) & 0xff;
|
||||
int green = (color >> 8) & 0xff;
|
||||
int blue = color & 0xff;
|
||||
red = (int) (red * a + 0.5);
|
||||
green = (int) (green * a + 0.5);
|
||||
blue = (int) (blue * a + 0.5);
|
||||
return Color.argb(255, red, green, blue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制一个和状态栏一样高的颜色矩形
|
||||
*/
|
||||
private static View createColorStatusBarView(final Context context,
|
||||
final int color,
|
||||
final int alpha) {
|
||||
View statusBarView = new View(context);
|
||||
statusBarView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight()));
|
||||
statusBarView.setBackgroundColor(getStatusBarColor(color, alpha));
|
||||
statusBarView.setTag(TAG_COLOR);
|
||||
return statusBarView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制一个和状态栏一样高的黑色透明度矩形
|
||||
*/
|
||||
private static View createAlphaStatusBarView(final Context context, final int alpha) {
|
||||
View statusBarView = new View(context);
|
||||
statusBarView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight()));
|
||||
statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
|
||||
statusBarView.setTag(TAG_ALPHA);
|
||||
return statusBarView;
|
||||
}
|
||||
|
||||
private static void transparentStatusBar(final Activity activity) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
Window window = activity.getWindow();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
int option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
||||
window.getDecorView().setSystemUiVisibility(option);
|
||||
window.setStatusBarColor(Color.TRANSPARENT);
|
||||
} else {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// action bar
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 获取 ActionBar 高度
|
||||
*
|
||||
* @param activity activity
|
||||
* @return ActionBar 高度
|
||||
*/
|
||||
public static int getActionBarHeight(@NonNull final Activity activity) {
|
||||
TypedValue tv = new TypedValue();
|
||||
if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
|
||||
return TypedValue.complexToDimensionPixelSize(
|
||||
tv.data, activity.getResources().getDisplayMetrics()
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// notification bar
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 设置通知栏是否可见
|
||||
* <p>需添加权限
|
||||
* {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />}</p>
|
||||
*
|
||||
* @param isVisible {@code true}: 可见<br>{@code false}: 关闭
|
||||
*/
|
||||
public static void setNotificationBarVisibility(final boolean isVisible) {
|
||||
String methodName;
|
||||
if (isVisible) {
|
||||
methodName = (Build.VERSION.SDK_INT <= 16) ? "expand" : "expandNotificationsPanel";
|
||||
} else {
|
||||
methodName = (Build.VERSION.SDK_INT <= 16) ? "collapse" : "collapsePanels";
|
||||
}
|
||||
invokePanels(methodName);
|
||||
}
|
||||
|
||||
private static void invokePanels(final String methodName) {
|
||||
try {
|
||||
@SuppressLint("WrongConstant")
|
||||
Object service = Utils.getApp().getSystemService("statusbar");
|
||||
@SuppressLint("PrivateApi")
|
||||
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
|
||||
Method expand = statusBarManager.getMethod(methodName);
|
||||
expand.invoke(service);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// navigation bar
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 获取导航栏高度
|
||||
*
|
||||
* @return 导航栏高度
|
||||
*/
|
||||
public static int getNavBarHeight() {
|
||||
Resources res = Utils.getApp().getResources();
|
||||
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (resourceId != 0) {
|
||||
return res.getDimensionPixelSize(resourceId);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置导航栏是否可见
|
||||
*
|
||||
* @param activity activity
|
||||
* @param isVisible {@code true}: 可见<br>{@code false}: 不可见
|
||||
*/
|
||||
public static void setNavBarVisibility(final Activity activity, boolean isVisible) {
|
||||
if (isVisible) {
|
||||
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
} else {
|
||||
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
View decorView = activity.getWindow().getDecorView();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
int visibility = decorView.getSystemUiVisibility();
|
||||
decorView.setSystemUiVisibility(visibility & ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置导航栏沉浸式
|
||||
*
|
||||
* @param activity activity
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public static void setNavBarImmersive(final Activity activity) {
|
||||
View decorView = activity.getWindow().getDecorView();
|
||||
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
decorView.setSystemUiVisibility(uiOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断导航栏是否可见
|
||||
*
|
||||
* @param activity activity
|
||||
* @return {@code true}: 可见<br>{@code false}: 不可见
|
||||
*/
|
||||
public static boolean isNavBarVisible(final Activity activity) {
|
||||
boolean isNoLimits = (activity.getWindow().getAttributes().flags
|
||||
& WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) != 0;
|
||||
if (isNoLimits) return false;
|
||||
View decorView = activity.getWindow().getDecorView();
|
||||
int visibility = decorView.getSystemUiVisibility();
|
||||
return (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
|
||||
}
|
||||
|
||||
public static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {
|
||||
View decor = activity.getWindow().getDecorView();
|
||||
if (dark) {
|
||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
} else {
|
||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
|
||||
|
||||
public abstract class BaseBottomSheetDialog<VDM extends ViewDataBinding> extends BottomSheetDialog {
|
||||
|
||||
public Context mContext;
|
||||
private Object object;
|
||||
protected VDM mBinding;
|
||||
|
||||
public BaseBottomSheetDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
this.mContext = context;
|
||||
mBinding = DataBindingUtil.bind(LayoutInflater.from(context).inflate(getLayout(), null, false));
|
||||
if (mBinding != null) {
|
||||
setContentView(mBinding.getRoot());
|
||||
((View) mBinding.getRoot().getParent()).setBackgroundColor(Color.parseColor("#00000000"));
|
||||
}
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
public abstract int getLayout();
|
||||
|
||||
public abstract void initView();
|
||||
|
||||
public abstract void initData();
|
||||
|
||||
public void setTag(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public Object getTag() {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/7/19.
|
||||
*/
|
||||
|
||||
public class DateFormatUtil {
|
||||
|
||||
private static SimpleDateFormat sFormat;
|
||||
private static SimpleDateFormat sFormat2;
|
||||
private static SimpleDateFormat sFormat3;
|
||||
private static SimpleDateFormat sFormat4;
|
||||
|
||||
static {
|
||||
sFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||
sFormat2 = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
|
||||
sFormat3 = new SimpleDateFormat("MM.dd-HH:mm:ss");
|
||||
sFormat4=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
|
||||
public static String getCurTimeString() {
|
||||
return sFormat.format(new Date());
|
||||
}
|
||||
|
||||
public static String getVideoCurTimeString() {
|
||||
return sFormat2.format(new Date());
|
||||
}
|
||||
|
||||
public static String getCurTimeString2() {
|
||||
return sFormat3.format(new Date());
|
||||
}
|
||||
public static String getCurTimeString3() {
|
||||
return sFormat4.format(new Date());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.bean.DateBean;
|
||||
import com.qxcm.moduleutil.databinding.MeDialogDateSelectBinding;
|
||||
import com.qxcm.moduleutil.widget.picker.PickerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 日期选择
|
||||
*/
|
||||
public class DateSelectDialog extends BaseBottomSheetDialog<MeDialogDateSelectBinding> {
|
||||
|
||||
|
||||
|
||||
|
||||
private int year = 0;
|
||||
private int month = 0;
|
||||
private OnSelectDate mOnSelectDate;
|
||||
private List<DateBean> yearList;
|
||||
private List<DateBean> monthList;
|
||||
private List<DateBean> dayList;
|
||||
|
||||
public DateSelectDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayout() {
|
||||
return R.layout.me_dialog_date_select;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
this.setCancelable(false);
|
||||
this.setCanceledOnTouchOutside(false);
|
||||
mBinding.tvCancel.setOnClickListener(this::onClick);
|
||||
mBinding.tvConfirm.setOnClickListener(this::onClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
setYear();
|
||||
mBinding.pickerViewYear.setSelectedItemPosition(yearList.size());
|
||||
setMonth(TimeUtils.getYear());
|
||||
mBinding.pickerViewMonth.setSelectedItemPosition(monthList.size());
|
||||
setDay(TimeUtils.getYear(), TimeUtils.getMonth());
|
||||
mBinding.pickerViewDay.setSelectedItemPosition(dayList.size());
|
||||
}
|
||||
|
||||
public void setData(String y, String m, String d) {
|
||||
int yIndex = 0;
|
||||
for (int i = 0; i < yearList.size(); i++) {
|
||||
DateBean dateBean = yearList.get(i);
|
||||
if (dateBean.getText().equals(y)) {
|
||||
yIndex = i;
|
||||
}
|
||||
}
|
||||
mBinding.pickerViewYear.setSelectedItemPosition(yIndex);
|
||||
monthList = getMonth(Integer.parseInt(y));
|
||||
int mIndex = 0;
|
||||
for (int i = 0; i < monthList.size(); i++) {
|
||||
DateBean dateBean = monthList.get(i);
|
||||
if (dateBean.getText().equals(m)) {
|
||||
mIndex = i;
|
||||
}
|
||||
}
|
||||
mBinding.pickerViewMonth.setSelectedItemPosition(mIndex);
|
||||
dayList = getDay(Integer.parseInt(y), Integer.parseInt(m));
|
||||
int dIndex = 0;
|
||||
for (int i = 0; i < dayList.size(); i++) {
|
||||
DateBean dateBean = dayList.get(i);
|
||||
if (dateBean.getText().equals(d)) {
|
||||
dIndex = i;
|
||||
}
|
||||
}
|
||||
mBinding.pickerViewDay.setSelectedItemPosition(dIndex);
|
||||
}
|
||||
|
||||
|
||||
private void setDay(int year, int month) {
|
||||
dayList = getDay(year, month);
|
||||
mBinding.pickerViewDay.setItems(dayList, new PickerView.OnItemSelectedListener<DateBean>() {
|
||||
@Override
|
||||
public void onItemSelected(DateBean item) {
|
||||
|
||||
}
|
||||
});
|
||||
mBinding.pickerViewDay.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void setMonth(int year) {
|
||||
monthList = getMonth(year);
|
||||
mBinding.pickerViewMonth.setItems(monthList, new PickerView.OnItemSelectedListener<DateBean>() {
|
||||
@Override
|
||||
public void onItemSelected(DateBean item) {
|
||||
month = item.getDate();
|
||||
setDay(year, month);
|
||||
}
|
||||
});
|
||||
mBinding.pickerViewMonth.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void setYear() {
|
||||
yearList = getYear();
|
||||
mBinding.pickerViewYear.setItems(yearList, new PickerView.OnItemSelectedListener<DateBean>() {
|
||||
@Override
|
||||
public void onItemSelected(DateBean item) {
|
||||
year = item.getDate();
|
||||
setMonth(year);
|
||||
}
|
||||
});
|
||||
mBinding.pickerViewYear.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
private List<DateBean> getDay(int year, int month) {
|
||||
int day = TimeUtils.getDaysByYearMonth(year, month);
|
||||
if (year == TimeUtils.getYear() && month == TimeUtils.getMonth()) {
|
||||
day = TimeUtils.getDay();
|
||||
}
|
||||
List<DateBean> dayList = new ArrayList<>();
|
||||
for (int i = 1; i <= day; i++) {
|
||||
if (i <= 9) {
|
||||
dayList.add(new DateBean("0" + i, i));
|
||||
} else {
|
||||
dayList.add(new DateBean(String.valueOf(i), i));
|
||||
}
|
||||
}
|
||||
return dayList;
|
||||
}
|
||||
|
||||
private List<DateBean> getMonth(int year) {
|
||||
List<DateBean> mothList = new ArrayList<>();
|
||||
int month = 12;
|
||||
if (year == TimeUtils.getYear()) {
|
||||
month = TimeUtils.getMonth();
|
||||
}
|
||||
for (int i = 1; i <= month; i++) {
|
||||
if (i <= 9) {
|
||||
mothList.add(new DateBean("0" + i, i));
|
||||
} else {
|
||||
mothList.add(new DateBean(String.valueOf(i), i));
|
||||
}
|
||||
}
|
||||
return mothList;
|
||||
}
|
||||
|
||||
private List<DateBean> getYear() {
|
||||
int year = TimeUtils.getYear();
|
||||
List<DateBean> yearList = new ArrayList<>();
|
||||
for (int i = 1900; i <= year; i++) {
|
||||
yearList.add(new DateBean(String.valueOf(i), i));
|
||||
}
|
||||
return yearList;
|
||||
}
|
||||
|
||||
|
||||
public void onClick(View view) {
|
||||
|
||||
dismiss();
|
||||
if (view.getId() == R.id.tv_confirm) {
|
||||
if (mOnSelectDate != null) {
|
||||
DateBean year = mBinding.pickerViewYear.getSelectedItem(DateBean.class);
|
||||
DateBean month = mBinding.pickerViewMonth.getSelectedItem(DateBean.class);
|
||||
DateBean day = mBinding.pickerViewDay.getSelectedItem(DateBean.class);
|
||||
mOnSelectDate.selectDate(year.getText(), month.getText(), day.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setmOnSelectDate(OnSelectDate mOnSelectDate) {
|
||||
this.mOnSelectDate = mOnSelectDate;
|
||||
}
|
||||
|
||||
public interface OnSelectDate {
|
||||
void selectDate(String year, String month, String day);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.qxcm.moduleutil.widget.CommonAppConfig;
|
||||
import com.qxcm.moduleutil.widget.CommonAppContext;
|
||||
|
||||
|
||||
public class DeviceUtils {
|
||||
|
||||
public static String getDeviceId() {
|
||||
String s = StringUtil.contact(
|
||||
Settings.System.getString(CommonAppContext.getInstance().getContentResolver(), Settings.System.ANDROID_ID),
|
||||
Build.SERIAL,
|
||||
Build.FINGERPRINT,
|
||||
String.valueOf(Build.TIME),
|
||||
Build.USER,
|
||||
Build.HOST,
|
||||
Build.getRadioVersion(),
|
||||
Build.HARDWARE,
|
||||
CommonAppConfig.PACKAGE_NAME
|
||||
);
|
||||
return Md5Utils.getMD5(s);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
|
||||
import static java.security.AccessController.getContext;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.blankj.utilcode.util.ActivityUtils;
|
||||
import com.qxcm.moduleutil.widget.dialog.CommonDialog;
|
||||
import com.zhpan.bannerview.indicator.DrawableIndicator;
|
||||
import com.zhpan.indicator.base.IIndicator;
|
||||
|
||||
public class DialogUtils {
|
||||
public static void showNoBalance() {
|
||||
Activity activity = ActivityUtils.getTopActivity();
|
||||
if (!(activity instanceof FragmentActivity)) {
|
||||
return;
|
||||
}
|
||||
CommonDialog commonDialog = new CommonDialog(activity);
|
||||
commonDialog.setContent("您的余额已不足,请及时充值");
|
||||
commonDialog.setLeftText("再想想");
|
||||
commonDialog.setRightText("去充值");
|
||||
commonDialog.setmOnClickListener(new CommonDialog.OnClickListener() {
|
||||
@Override
|
||||
public void onLeftClick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightClick() {
|
||||
// DialogFragment navigation = (DialogFragment) ARouter.getInstance().build(ARouteConstants.RECHARGE_DIALOG).navigation();
|
||||
// navigation.show(((FragmentActivity) activity).getSupportFragmentManager(), "RechargeDialogFragment");
|
||||
}
|
||||
});
|
||||
commonDialog.show();
|
||||
}
|
||||
|
||||
public static void showDialogFragment(Object object) {
|
||||
showDialogFragment(object, null);
|
||||
}
|
||||
|
||||
public static void showDialogFragment(Object object, FragmentManager fragmentManager) {
|
||||
if (object instanceof DialogFragment) {
|
||||
Activity topActivity = ActivityUtils.getTopActivity();
|
||||
if (fragmentManager == null && topActivity instanceof FragmentActivity) {
|
||||
fragmentManager = ((FragmentActivity) topActivity).getSupportFragmentManager();
|
||||
}
|
||||
if (fragmentManager != null && !fragmentManager.isStateSaved()) {
|
||||
((DialogFragment) object).show(fragmentManager, object.getClass().getSimpleName());
|
||||
} else {
|
||||
ActivityUtils.finishActivity(topActivity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
|
||||
|
||||
public class FastBlurUtil {
|
||||
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
|
||||
Bitmap bitmap;
|
||||
if (canReuseInBitmap) {
|
||||
bitmap = sentBitmap;
|
||||
} else {
|
||||
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
|
||||
}
|
||||
|
||||
if (radius < 1) {
|
||||
return (null);
|
||||
}
|
||||
|
||||
int w = bitmap.getWidth();
|
||||
int h = bitmap.getHeight();
|
||||
|
||||
int[] pix = new int[w * h];
|
||||
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
|
||||
|
||||
int wm = w - 1;
|
||||
int hm = h - 1;
|
||||
int wh = w * h;
|
||||
int div = radius + radius + 1;
|
||||
|
||||
int r[] = new int[wh];
|
||||
int g[] = new int[wh];
|
||||
int b[] = new int[wh];
|
||||
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
|
||||
int vmin[] = new int[Math.max(w, h)];
|
||||
|
||||
int divsum = (div + 1) >> 1;
|
||||
divsum *= divsum;
|
||||
int dv[] = new int[256 * divsum];
|
||||
for (i = 0; i < 256 * divsum; i++) {
|
||||
dv[i] = (i / divsum);
|
||||
}
|
||||
|
||||
yw = yi = 0;
|
||||
|
||||
int[][] stack = new int[div][3];
|
||||
int stackpointer;
|
||||
int stackstart;
|
||||
int[] sir;
|
||||
int rbs;
|
||||
int r1 = radius + 1;
|
||||
int routsum, goutsum, boutsum;
|
||||
int rinsum, ginsum, binsum;
|
||||
|
||||
for (y = 0; y < h; y++) {
|
||||
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
|
||||
for (i = -radius; i <= radius; i++) {
|
||||
p = pix[yi + Math.min(wm, Math.max(i, 0))];
|
||||
sir = stack[i + radius];
|
||||
sir[0] = (p & 0xff0000) >> 16;
|
||||
sir[1] = (p & 0x00ff00) >> 8;
|
||||
sir[2] = (p & 0x0000ff);
|
||||
rbs = r1 - Math.abs(i);
|
||||
rsum += sir[0] * rbs;
|
||||
gsum += sir[1] * rbs;
|
||||
bsum += sir[2] * rbs;
|
||||
if (i > 0) {
|
||||
rinsum += sir[0];
|
||||
ginsum += sir[1];
|
||||
binsum += sir[2];
|
||||
} else {
|
||||
routsum += sir[0];
|
||||
goutsum += sir[1];
|
||||
boutsum += sir[2];
|
||||
}
|
||||
}
|
||||
stackpointer = radius;
|
||||
|
||||
for (x = 0; x < w; x++) {
|
||||
|
||||
r[yi] = dv[rsum];
|
||||
g[yi] = dv[gsum];
|
||||
b[yi] = dv[bsum];
|
||||
|
||||
rsum -= routsum;
|
||||
gsum -= goutsum;
|
||||
bsum -= boutsum;
|
||||
|
||||
stackstart = stackpointer - radius + div;
|
||||
sir = stack[stackstart % div];
|
||||
|
||||
routsum -= sir[0];
|
||||
goutsum -= sir[1];
|
||||
boutsum -= sir[2];
|
||||
|
||||
if (y == 0) {
|
||||
vmin[x] = Math.min(x + radius + 1, wm);
|
||||
}
|
||||
p = pix[yw + vmin[x]];
|
||||
|
||||
sir[0] = (p & 0xff0000) >> 16;
|
||||
sir[1] = (p & 0x00ff00) >> 8;
|
||||
sir[2] = (p & 0x0000ff);
|
||||
|
||||
rinsum += sir[0];
|
||||
ginsum += sir[1];
|
||||
binsum += sir[2];
|
||||
|
||||
rsum += rinsum;
|
||||
gsum += ginsum;
|
||||
bsum += binsum;
|
||||
|
||||
stackpointer = (stackpointer + 1) % div;
|
||||
sir = stack[(stackpointer) % div];
|
||||
|
||||
routsum += sir[0];
|
||||
goutsum += sir[1];
|
||||
boutsum += sir[2];
|
||||
|
||||
rinsum -= sir[0];
|
||||
ginsum -= sir[1];
|
||||
binsum -= sir[2];
|
||||
|
||||
yi++;
|
||||
}
|
||||
yw += w;
|
||||
}
|
||||
for (x = 0; x < w; x++) {
|
||||
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
|
||||
yp = -radius * w;
|
||||
for (i = -radius; i <= radius; i++) {
|
||||
yi = Math.max(0, yp) + x;
|
||||
|
||||
sir = stack[i + radius];
|
||||
|
||||
sir[0] = r[yi];
|
||||
sir[1] = g[yi];
|
||||
sir[2] = b[yi];
|
||||
|
||||
rbs = r1 - Math.abs(i);
|
||||
|
||||
rsum += r[yi] * rbs;
|
||||
gsum += g[yi] * rbs;
|
||||
bsum += b[yi] * rbs;
|
||||
|
||||
if (i > 0) {
|
||||
rinsum += sir[0];
|
||||
ginsum += sir[1];
|
||||
binsum += sir[2];
|
||||
} else {
|
||||
routsum += sir[0];
|
||||
goutsum += sir[1];
|
||||
boutsum += sir[2];
|
||||
}
|
||||
|
||||
if (i < hm) {
|
||||
yp += w;
|
||||
}
|
||||
}
|
||||
yi = x;
|
||||
stackpointer = radius;
|
||||
for (y = 0; y < h; y++) {
|
||||
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
|
||||
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
|
||||
|
||||
rsum -= routsum;
|
||||
gsum -= goutsum;
|
||||
bsum -= boutsum;
|
||||
|
||||
stackstart = stackpointer - radius + div;
|
||||
sir = stack[stackstart % div];
|
||||
|
||||
routsum -= sir[0];
|
||||
goutsum -= sir[1];
|
||||
boutsum -= sir[2];
|
||||
|
||||
if (x == 0) {
|
||||
vmin[y] = Math.min(y + r1, hm) * w;
|
||||
}
|
||||
p = x + vmin[y];
|
||||
|
||||
sir[0] = r[p];
|
||||
sir[1] = g[p];
|
||||
sir[2] = b[p];
|
||||
|
||||
rinsum += sir[0];
|
||||
ginsum += sir[1];
|
||||
binsum += sir[2];
|
||||
|
||||
rsum += rinsum;
|
||||
gsum += ginsum;
|
||||
bsum += binsum;
|
||||
|
||||
stackpointer = (stackpointer + 1) % div;
|
||||
sir = stack[stackpointer];
|
||||
|
||||
routsum += sir[0];
|
||||
goutsum += sir[1];
|
||||
boutsum += sir[2];
|
||||
|
||||
rinsum -= sir[0];
|
||||
ginsum -= sir[1];
|
||||
binsum -= sir[2];
|
||||
|
||||
yi += w;
|
||||
}
|
||||
}
|
||||
|
||||
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
|
||||
|
||||
return (bitmap);
|
||||
}
|
||||
|
||||
|
||||
public static Drawable getForegroundDrawable(Bitmap musicPicRes) {
|
||||
/*得到屏幕的宽高比,以便按比例切割图片一部分*/
|
||||
final float widthHeightSize = (float) (ScreenUtils.getScreenWidth()
|
||||
* 1.0 / ScreenUtils.getScreenHeight() * 1.0);
|
||||
|
||||
Bitmap bitmap = musicPicRes;
|
||||
int cropBitmapWidth = (int) (widthHeightSize * bitmap.getHeight());
|
||||
int cropBitmapWidthX = (int) ((bitmap.getWidth() - cropBitmapWidth) / 2.0);
|
||||
|
||||
/*切割部分图片*/
|
||||
Bitmap cropBitmap = Bitmap.createBitmap(bitmap, cropBitmapWidthX, 0, cropBitmapWidth,
|
||||
bitmap.getHeight());
|
||||
/*缩小图片*/
|
||||
Bitmap scaleBitmap = Bitmap.createScaledBitmap(cropBitmap, bitmap.getWidth() / 50, bitmap
|
||||
.getHeight() / 50, false);
|
||||
/*模糊化*/
|
||||
final Bitmap blurBitmap = FastBlurUtil.doBlur(scaleBitmap, 8, true);
|
||||
|
||||
final Drawable foregroundDrawable = new BitmapDrawable(blurBitmap);
|
||||
/*加入灰色遮罩层,避免图片过亮影响其他控件*/
|
||||
foregroundDrawable.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
|
||||
return foregroundDrawable;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
/**
|
||||
* 悬浮窗辅助类
|
||||
*/
|
||||
public class FloatWindowHelper {
|
||||
|
||||
private static ActionListener sActionListener;
|
||||
|
||||
public static void setActionListener(ActionListener actionListener) {
|
||||
sActionListener = actionListener;
|
||||
}
|
||||
|
||||
public static boolean checkVoice(boolean enterLive) {
|
||||
if (sActionListener != null) {
|
||||
return sActionListener.checkVoice(enterLive);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void setFloatWindowVisible(boolean visible) {
|
||||
if (sActionListener != null) {
|
||||
sActionListener.setFloatWindowVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ActionListener {
|
||||
/**
|
||||
* 是否可以播放声音
|
||||
*/
|
||||
boolean checkVoice(boolean enterLive);
|
||||
|
||||
/**
|
||||
* 设置隐藏和显示
|
||||
*/
|
||||
void setFloatWindowVisible(boolean visible);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.BitmapImageViewTarget;
|
||||
import com.bumptech.glide.request.target.ImageViewTarget;
|
||||
import com.luck.picture.lib.engine.ImageEngine;
|
||||
import com.luck.picture.lib.listener.OnImageCompleteCallback;
|
||||
import com.luck.picture.lib.tools.MediaUtils;
|
||||
import com.luck.picture.lib.widget.longimage.ImageSource;
|
||||
import com.luck.picture.lib.widget.longimage.ImageViewState;
|
||||
import com.luck.picture.lib.widget.longimage.SubsamplingScaleImageView;
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
/**
|
||||
* @author:luck
|
||||
* @date:2019-11-13 17:02
|
||||
* @describe:Glide加载引擎
|
||||
*/
|
||||
public class GlideEngine implements ImageEngine {
|
||||
|
||||
/**
|
||||
* 加载图片
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
@Override
|
||||
public void loadImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载网络图片适配长图方案
|
||||
* # 注意:此方法只有加载网络图片才会回调
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
* @param longImageView
|
||||
* @param callback 网络图片加载回调监听 {link after version 2.5.1 Please use the #OnImageCompleteCallback#}
|
||||
*/
|
||||
@Override
|
||||
public void loadImage(@NonNull Context context, @NonNull String url,
|
||||
@NonNull ImageView imageView,
|
||||
SubsamplingScaleImageView longImageView, OnImageCompleteCallback callback) {
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.into(new ImageViewTarget<Bitmap>(imageView) {
|
||||
@Override
|
||||
public void onLoadStarted(@Nullable Drawable placeholder) {
|
||||
super.onLoadStarted(placeholder);
|
||||
if (callback != null) {
|
||||
callback.onShowLoading();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
||||
super.onLoadFailed(errorDrawable);
|
||||
if (callback != null) {
|
||||
callback.onHideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setResource(@Nullable Bitmap resource) {
|
||||
if (callback != null) {
|
||||
callback.onHideLoading();
|
||||
}
|
||||
if (resource != null) {
|
||||
boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(),
|
||||
resource.getHeight());
|
||||
longImageView.setVisibility(eqLongImage ? View.VISIBLE : View.GONE);
|
||||
imageView.setVisibility(eqLongImage ? View.GONE : View.VISIBLE);
|
||||
if (eqLongImage) {
|
||||
// 加载长图
|
||||
longImageView.setQuickScaleEnabled(true);
|
||||
longImageView.setZoomEnabled(true);
|
||||
longImageView.setDoubleTapZoomDuration(100);
|
||||
longImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
|
||||
longImageView.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER);
|
||||
longImageView.setImage(ImageSource.bitmap(resource),
|
||||
new ImageViewState(0, new PointF(0, 0), 0));
|
||||
} else {
|
||||
// 普通图片
|
||||
imageView.setImageBitmap(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载网络图片适配长图方案
|
||||
* # 注意:此方法只有加载网络图片才会回调
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
* @param longImageView
|
||||
* @ 已废弃
|
||||
*/
|
||||
@Override
|
||||
public void loadImage(@NonNull Context context, @NonNull String url,
|
||||
@NonNull ImageView imageView,
|
||||
SubsamplingScaleImageView longImageView) {
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.into(new ImageViewTarget<Bitmap>(imageView) {
|
||||
@Override
|
||||
protected void setResource(@Nullable Bitmap resource) {
|
||||
if (resource != null) {
|
||||
boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(),
|
||||
resource.getHeight());
|
||||
longImageView.setVisibility(eqLongImage ? View.VISIBLE : View.GONE);
|
||||
imageView.setVisibility(eqLongImage ? View.GONE : View.VISIBLE);
|
||||
if (eqLongImage) {
|
||||
// 加载长图
|
||||
longImageView.setQuickScaleEnabled(true);
|
||||
longImageView.setZoomEnabled(true);
|
||||
longImageView.setDoubleTapZoomDuration(100);
|
||||
longImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
|
||||
longImageView.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER);
|
||||
longImageView.setImage(ImageSource.bitmap(resource),
|
||||
new ImageViewState(0, new PointF(0, 0), 0));
|
||||
} else {
|
||||
// 普通图片
|
||||
imageView.setImageBitmap(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载相册目录
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadFolderImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.override(180, 180)
|
||||
.centerCrop()
|
||||
.sizeMultiplier(0.5f)
|
||||
.apply(new RequestOptions().placeholder(com.luck.picture.lib.R.drawable.picture_image_placeholder))
|
||||
.into(new BitmapImageViewTarget(imageView) {
|
||||
@Override
|
||||
protected void setResource(Bitmap resource) {
|
||||
RoundedBitmapDrawable circularBitmapDrawable =
|
||||
RoundedBitmapDrawableFactory.
|
||||
create(context.getResources(), resource);
|
||||
circularBitmapDrawable.setCornerRadius(8);
|
||||
imageView.setImageDrawable(circularBitmapDrawable);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载gif
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadAsGifImage(@NonNull Context context, @NonNull String url,
|
||||
@NonNull ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.asGif()
|
||||
.load(url)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载图片列表图片
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadGridImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.override(200, 200)
|
||||
.centerCrop()
|
||||
.apply(new RequestOptions().placeholder(com.luck.picture.lib.R.drawable.picture_image_placeholder))
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
|
||||
private GlideEngine() {
|
||||
}
|
||||
|
||||
private static GlideEngine instance;
|
||||
|
||||
public static GlideEngine createGlideEngine() {
|
||||
if (null == instance) {
|
||||
synchronized (GlideEngine.class) {
|
||||
if (null == instance) {
|
||||
instance = new GlideEngine();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
|
||||
/**
|
||||
* Copyright (c) 1
|
||||
*
|
||||
*/
|
||||
|
||||
public class ImageLoader {
|
||||
|
||||
|
||||
public static void loadHead(Context context, ImageView view, String url) {
|
||||
RequestOptions options = RequestOptions.circleCropTransform();
|
||||
Glide.with(context).load(url).apply(options).error(com.qxcm.moduleutil.R.mipmap.default_avatar).placeholder(R.mipmap.default_avatar).diskCacheStrategy(DiskCacheStrategy.ALL).into(view);
|
||||
}
|
||||
|
||||
public static void loadHead(ImageView view, String url) {
|
||||
RequestOptions options = RequestOptions.circleCropTransform();
|
||||
Glide.with(view).load(url).apply(options).error(R.mipmap.default_avatar).placeholder(R.mipmap.default_avatar).diskCacheStrategy(DiskCacheStrategy.ALL).into(view);
|
||||
}
|
||||
|
||||
public static void loadImage(ImageView view, String url) {
|
||||
Glide.with(view).load(url).error(R.mipmap.default_image).placeholder(R.mipmap.default_image).diskCacheStrategy(DiskCacheStrategy.ALL).into(view);
|
||||
}
|
||||
|
||||
public static void loadImage(Context context, ImageView view, String url) {
|
||||
Glide.with(context).load(url).error(R.mipmap.default_image).placeholder(R.mipmap.default_image).diskCacheStrategy(DiskCacheStrategy.ALL).into(view);
|
||||
}
|
||||
|
||||
public static void loadIcon(Context context, ImageView view, String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
view.setVisibility(View.GONE);
|
||||
} else {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
}
|
||||
Glide.with(context).load(url).diskCacheStrategy(DiskCacheStrategy.ALL).into(view);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.blankj.utilcode.util.ConvertUtils;
|
||||
import com.blankj.utilcode.util.EncodeUtils;
|
||||
import com.blankj.utilcode.util.Utils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.load.resource.gif.GifDrawable;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.opensource.svgaplayer.SVGADrawable;
|
||||
import com.opensource.svgaplayer.SVGAImageView;
|
||||
import com.opensource.svgaplayer.SVGAParser;
|
||||
import com.opensource.svgaplayer.SVGAVideoEntity;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.utils.logger.Logger;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* <p> 图片加载工具类</p>
|
||||
*
|
||||
* @name ImageUtils
|
||||
*/
|
||||
public class ImageUtils {
|
||||
|
||||
public static final int ANIM = -1;
|
||||
|
||||
/**
|
||||
* 默认加载
|
||||
*/
|
||||
public static void loadImageView(String path, ImageView mImageView) {
|
||||
Glide.with(mImageView).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认加载
|
||||
*/
|
||||
public static void loadIcon(String path, ImageView mImageView) {
|
||||
mImageView.setVisibility(TextUtils.isEmpty(path) ? GONE : View.VISIBLE);
|
||||
Glide.with(mImageView).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载爵位动图
|
||||
*/
|
||||
public static void loadVipWebp(String path, ImageView mImageView) {
|
||||
loadSample(path, mImageView, ConvertUtils.dp2px(200), ConvertUtils.dp2px(200));
|
||||
}
|
||||
|
||||
/**
|
||||
* 采样
|
||||
*
|
||||
* @param path
|
||||
* @param mImageView
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
public static void loadSample(String path, ImageView mImageView, int width, int height) {
|
||||
RequestOptions options = new RequestOptions().override(width, height).diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
Glide.with(mImageView).load(path).apply(options).into(mImageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认加载
|
||||
*/
|
||||
public static void loadDecorationAvatar(String path, SVGAImageView mImageView) {
|
||||
if (path.endsWith(".svga")) {
|
||||
try {
|
||||
SVGAParser.Companion.shareParser().decodeFromURL(new URL(path), new SVGAParser.ParseCompletion() {
|
||||
@Override
|
||||
public void onComplete(@NotNull SVGAVideoEntity svgaVideoEntity) {
|
||||
if (mImageView != null) {
|
||||
SVGADrawable svgaDrawable = new SVGADrawable(svgaVideoEntity);
|
||||
mImageView.setImageDrawable(svgaDrawable);
|
||||
mImageView.startAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
Logger.e("loadDecorationAvatar error");
|
||||
}
|
||||
});
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (mImageView.isAnimating()) {
|
||||
mImageView.stopAnimation();
|
||||
}
|
||||
Glide.with(mImageView).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadDecorationAvatar2(int resourceId, SVGAImageView mImageView) {
|
||||
// 从资源文件夹加载SVGA文件
|
||||
if (resourceId != 0) {
|
||||
SVGAParser parser = SVGAParser.Companion.shareParser();
|
||||
parser.decodeFromInputStream(mImageView.getContext().getResources().openRawResource(resourceId), "",new SVGAParser.ParseCompletion() {
|
||||
@Override
|
||||
public void onComplete(@NotNull SVGAVideoEntity svgaVideoEntity) {
|
||||
if (mImageView != null) {
|
||||
SVGADrawable svgaDrawable = new SVGADrawable(svgaVideoEntity);
|
||||
mImageView.setImageDrawable(svgaDrawable);
|
||||
mImageView.startAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
Logger.e("loadDecorationAvatar2 error");
|
||||
}
|
||||
},true);
|
||||
|
||||
|
||||
} else {
|
||||
Logger.e("Resource ID is 0 or invalid");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void loadHeadCC(String path, ImageView mImageView) {
|
||||
Glide.with(mImageView).load(path).error(R.mipmap.default_avatar).placeholder(R.mipmap.default_avatar).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
|
||||
|
||||
}
|
||||
|
||||
public static void loadCompressImg(String path, ImageView mImageView, int width, int height) {
|
||||
Glide.with(mImageView)
|
||||
.load(path)
|
||||
.centerCrop()
|
||||
.override(width, height).diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.into(mImageView);
|
||||
}
|
||||
|
||||
public static void loadCenterCrop(String path, ImageView mImageView) {
|
||||
Glide.with(mImageView).load(path).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
|
||||
}
|
||||
|
||||
public static void loadRes(int path, ImageView mImageView) {
|
||||
Glide.with(mImageView).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
|
||||
}
|
||||
|
||||
public static void loadImageBlurBg(String url, ImageView imageView) {
|
||||
RequestOptions options = new RequestOptions().centerCrop().placeholder(R.mipmap.room_bg).error(R.mipmap.room_bg).diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
Glide.with(imageView).asBitmap().apply(options).load(url).into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
try {
|
||||
Drawable foregroundDrawable = FastBlurUtil.getForegroundDrawable(resource);
|
||||
imageView.setImageDrawable(foregroundDrawable);
|
||||
} catch (Exception e) {
|
||||
imageView.setImageResource(R.mipmap.room_bg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void loadCoverBlurBg(Context context, String url, LinearLayout linearLayout) {
|
||||
RequestOptions options = new RequestOptions().centerCrop().placeholder(R.mipmap.default_avatar).error(R.mipmap.default_avatar).diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
Glide.with(context).asBitmap().apply(options).load(url).into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
try {
|
||||
setUpCoverBg(linearLayout, resource);
|
||||
} catch (Exception e) {
|
||||
linearLayout.setBackgroundResource(R.mipmap.index_bg_hot);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setUpCoverBg(LinearLayout linearLayout, Bitmap resource) {
|
||||
|
||||
// Palette.from(resource).generate(new Palette.PaletteAsyncListener() {
|
||||
// @Override
|
||||
// public void onGenerated(Palette palette) {
|
||||
// //记得判空
|
||||
// if (palette == null) return;
|
||||
// //palette取色不一定取得到某些特定的颜色,这里通过取多种颜色来避免取不到颜色的情况
|
||||
// if (palette.getDarkVibrantColor(Color.TRANSPARENT) != Color.TRANSPARENT) {
|
||||
// createLinearGradientBitmap(linearLayout, resource, palette.getDarkVibrantColor(Color.TRANSPARENT), palette.getVibrantColor(Color.TRANSPARENT));
|
||||
// } else if (palette.getDarkMutedColor(Color.TRANSPARENT) != Color.TRANSPARENT) {
|
||||
// createLinearGradientBitmap(linearLayout, resource, palette.getDarkMutedColor(Color.TRANSPARENT), palette.getMutedColor(Color.TRANSPARENT));
|
||||
// } else {
|
||||
// createLinearGradientBitmap(linearLayout, resource, palette.getLightMutedColor(Color.TRANSPARENT), palette.getLightVibrantColor(Color.TRANSPARENT));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
//创建线性渐变背景色
|
||||
private static void createLinearGradientBitmap(LinearLayout ivBg, Bitmap bgBitmap, int darkColor, int color) {
|
||||
int bgColors[] = new int[2];
|
||||
bgColors[0] = darkColor;
|
||||
bgColors[1] = color;
|
||||
|
||||
if (bgBitmap == null) {
|
||||
bgBitmap = Bitmap.createBitmap(ivBg.getWidth(), ivBg.getHeight(), Bitmap.Config.ARGB_4444);
|
||||
}
|
||||
Canvas mCanvas = new Canvas();
|
||||
Paint mPaint = new Paint();
|
||||
mCanvas.setBitmap(bgBitmap);
|
||||
mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
|
||||
LinearGradient gradient = new LinearGradient(0, 0, 0, bgBitmap.getHeight(), bgColors[0], bgColors[1], Shader.TileMode.CLAMP);
|
||||
mPaint.setShader(gradient);
|
||||
RectF rectF = new RectF(0, 0, bgBitmap.getWidth(), bgBitmap.getHeight());
|
||||
mCanvas.drawRoundRect(rectF, 16, 16, mPaint);
|
||||
// mCanvas.drawRect(rectF, mPaint);
|
||||
ivBg.setBackground(new BitmapDrawable(bgBitmap));
|
||||
}
|
||||
|
||||
public static void loadRoomBg(String url, ImageView imageView) {
|
||||
RequestOptions options = new RequestOptions().centerCrop().placeholder(R.mipmap.room_bg).error(R.mipmap.room_bg).diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
Glide.with(imageView).load(url).apply(options).into(imageView);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置加载中以及加载失败图片
|
||||
*/
|
||||
public static void loadImageWithLoading(String path, ImageView mImageView, int lodingImage, int errorRes) {
|
||||
Glide.with(mImageView).load(path).placeholder(lodingImage).
|
||||
error(errorRes).diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载为bitmap
|
||||
*
|
||||
* @param path 图片地址
|
||||
* @param listener 回调
|
||||
*/
|
||||
public static void loadBitmap(String path, final onLoadBitmap listener) {
|
||||
Glide.with(Utils.getApp()).asBitmap().load(path).into(new SimpleTarget<Bitmap>() {
|
||||
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
listener.onReady(resource);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static void loadGift(ImageView view, int res) {
|
||||
if (res == ANIM) {
|
||||
try {
|
||||
AnimationDrawable background = (AnimationDrawable) view.getBackground();
|
||||
if (background != null) {
|
||||
background.start();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
Glide.with(view.getContext()).asGif().load(res).into(view);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadIconByHeight(String path, ImageView mImageView) {
|
||||
mImageView.setVisibility(TextUtils.isEmpty(path) ? GONE : View.VISIBLE);
|
||||
Glide.with(mImageView).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
mImageView.setImageDrawable(resource);
|
||||
ViewGroup.LayoutParams layoutParams = mImageView.getLayoutParams();
|
||||
layoutParams.width = (int) (layoutParams.height * 1f / resource.getIntrinsicHeight() * resource.getIntrinsicWidth());
|
||||
|
||||
mImageView.setLayoutParams(layoutParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void loadIconByHeight1(String path, ImageView mImageView,int height) {
|
||||
mImageView.setVisibility(TextUtils.isEmpty(path) ? GONE : View.VISIBLE);
|
||||
Glide.with(mImageView).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
mImageView.setImageDrawable(resource);
|
||||
ViewGroup.LayoutParams layoutParams = mImageView.getLayoutParams();
|
||||
layoutParams.width = (int) (layoutParams.height * 1f / resource.getIntrinsicHeight() * resource.getIntrinsicWidth());
|
||||
|
||||
layoutParams.height = height;
|
||||
mImageView.setLayoutParams(layoutParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载bitmap回调
|
||||
*/
|
||||
public interface onLoadBitmap {
|
||||
void onReady(Bitmap resource);
|
||||
}
|
||||
|
||||
public static void loadOneTimeGif(Context context, Object model, final ImageView imageView) {
|
||||
Glide.with(context).asGif().load(model).listener(new RequestListener<GifDrawable>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
try {
|
||||
Field gifStateField = GifDrawable.class.getDeclaredField("state");
|
||||
gifStateField.setAccessible(true);
|
||||
Class gifStateClass = Class.forName("com.bumptech.glide.load.resource.gif.GifDrawable$GifState");
|
||||
Field gifFrameLoaderField = gifStateClass.getDeclaredField("frameLoader");
|
||||
gifFrameLoaderField.setAccessible(true);
|
||||
Class gifFrameLoaderClass = Class.forName("com.bumptech.glide.load.resource.gif.GifFrameLoader");
|
||||
Field gifDecoderField = gifFrameLoaderClass.getDeclaredField("gifDecoder");
|
||||
gifDecoderField.setAccessible(true);
|
||||
Class gifDecoderClass = Class.forName("com.bumptech.glide.gifdecoder.GifDecoder");
|
||||
Object gifDecoder = gifDecoderField.get(gifFrameLoaderField.get(gifStateField.get(resource)));
|
||||
Method getDelayMethod = gifDecoderClass.getDeclaredMethod("getDelay", int.class);
|
||||
getDelayMethod.setAccessible(true);
|
||||
//设置只播放一次
|
||||
resource.setLoopCount(1);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}).into(imageView);
|
||||
}
|
||||
|
||||
// public static String getImagePath() {
|
||||
// String path = Constants.IMAGE_PATH;
|
||||
// File file = new File(path);
|
||||
// if (file.mkdirs()) {
|
||||
// return path;
|
||||
// } else {
|
||||
// return path;
|
||||
// }
|
||||
// }
|
||||
|
||||
public static String getUrl(String url) {
|
||||
// url = EncodeUtils.htmlDecode(url).toString();
|
||||
// if (!TextUtils.isEmpty(url) && !url.contains("http"))
|
||||
// url = BuildConfig.BASE_URL + url;
|
||||
return url;
|
||||
}
|
||||
|
||||
public static void preload(String url) {
|
||||
// Glide.with(BaseApplication.getInstance()).download(url).preload();
|
||||
}
|
||||
|
||||
public static void preloadImgConstants() {
|
||||
// try {
|
||||
// ImgConstants constants = new ImgConstants();
|
||||
// Field[] fields = ImgConstants.class.getDeclaredFields();
|
||||
// for (Field field : fields) {
|
||||
// preload(field.get(constants).toString());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class KeyWordUtil {
|
||||
|
||||
/**
|
||||
* 关键字高亮变色
|
||||
*
|
||||
* @param color 变化的色值
|
||||
* @param text 文字
|
||||
* @param keyword 文字中的关键字
|
||||
* @return 结果SpannableString
|
||||
*/
|
||||
public static SpannableString matcherSearchTitle(int color, String text, String keyword) {
|
||||
SpannableString s = new SpannableString(text);
|
||||
keyword=escapeExprSpecialWord(keyword);
|
||||
text=escapeExprSpecialWord(text);
|
||||
if (text.contains(keyword)&&!TextUtils.isEmpty(keyword)){
|
||||
try {
|
||||
Pattern p = Pattern.compile(keyword);
|
||||
Matcher m = p.matcher(s);
|
||||
while (m.find()) {
|
||||
int start = m.start();
|
||||
int end = m.end();
|
||||
s.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}catch (Exception e){
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转义正则特殊字符 ($()*+.[]?\^{},|)
|
||||
*
|
||||
* @param keyword
|
||||
* @return keyword
|
||||
*/
|
||||
public static String escapeExprSpecialWord(String keyword) {
|
||||
if (!TextUtils.isEmpty(keyword)) {
|
||||
String[] fbsArr = { "\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|" };
|
||||
for (String key : fbsArr) {
|
||||
if (keyword.contains(key)) {
|
||||
keyword = keyword.replace(key, "\\" + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return keyword;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
|
||||
|
||||
import com.qxcm.moduleutil.widget.CommonAppContext;
|
||||
import com.qxcm.moduleutil.widget.Constants;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2019/6/5.
|
||||
*/
|
||||
|
||||
public class LanguageUtil {
|
||||
|
||||
private static LanguageUtil instance;
|
||||
private String mLanguage;
|
||||
|
||||
public LanguageUtil() {
|
||||
mLanguage = SpUtil.getInstance().getStringValue(SpUtil.LANGUAGE);
|
||||
// if (TextUtils.isEmpty(mLanguage)) {
|
||||
getSystemLanguage();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
public static LanguageUtil getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (LanguageUtil.class) {
|
||||
if (instance == null) {
|
||||
instance = new LanguageUtil();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断系统语言是否是中文
|
||||
*/
|
||||
private void getSystemLanguage() {
|
||||
String lang = Constants.LANG_ZH;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
LocaleListCompat listCompat = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration());
|
||||
if (listCompat.size() > 0) {
|
||||
Locale locale = listCompat.get(0);
|
||||
if (locale != null) {
|
||||
String localeName = locale.toString();
|
||||
if (localeName.startsWith("en")) {
|
||||
lang = Constants.LANG_EN;
|
||||
} else {
|
||||
lang = Constants.LANG_ZH;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Locale locale = Locale.getDefault();
|
||||
if (locale != null) {
|
||||
String localeName = locale.toString();
|
||||
if (localeName.startsWith("en")) {
|
||||
lang = Constants.LANG_EN;
|
||||
} else {
|
||||
lang = Constants.LANG_ZH;
|
||||
}
|
||||
}
|
||||
}
|
||||
setLanguage(lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置语言
|
||||
*/
|
||||
private static void setConfiguration() {
|
||||
Locale targetLocale = getLanguageLocale();
|
||||
Resources resources = CommonAppContext.getInstance().getResources();
|
||||
Configuration configuration = resources.getConfiguration();
|
||||
configuration.setLocale(targetLocale);
|
||||
DisplayMetrics dm = resources.getDisplayMetrics();
|
||||
resources.updateConfiguration(configuration, dm);//语言更换生效的代码!
|
||||
}
|
||||
|
||||
|
||||
public static Locale getLanguageLocale() {
|
||||
String lang = LanguageUtil.getInstance().getLanguage();
|
||||
if (!TextUtils.isEmpty(lang)) {
|
||||
if (Constants.LANG_ZH.equals(lang)) {
|
||||
return Locale.SIMPLIFIED_CHINESE;
|
||||
} else if (Constants.LANG_EN.equals(lang)) {
|
||||
return Locale.US;
|
||||
}
|
||||
}
|
||||
return Locale.SIMPLIFIED_CHINESE;
|
||||
}
|
||||
|
||||
|
||||
public void updateLanguage(String language) {
|
||||
setLanguage(language);
|
||||
setConfiguration();
|
||||
}
|
||||
|
||||
|
||||
public static Context attachBaseContext(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
return createConfigurationResources(context);
|
||||
} else {
|
||||
setConfiguration();
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
private static Context createConfigurationResources(Context context) {
|
||||
Resources resources = context.getResources();
|
||||
Configuration configuration = resources.getConfiguration();
|
||||
Locale locale = getLanguageLocale();
|
||||
configuration.setLocale(locale);
|
||||
return context.createConfigurationContext(configuration);
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
if (TextUtils.isEmpty(mLanguage)) {
|
||||
mLanguage = SpUtil.getInstance().getStringValue(SpUtil.LANGUAGE);
|
||||
if (TextUtils.isEmpty(mLanguage)) {
|
||||
getSystemLanguage();
|
||||
}
|
||||
}
|
||||
return mLanguage;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
mLanguage = language;
|
||||
SpUtil.getInstance().setStringValue(SpUtil.LANGUAGE, language);
|
||||
}
|
||||
|
||||
public static boolean isZh() {
|
||||
return Constants.LANG_ZH.equals(LanguageUtil.getInstance().getLanguage());
|
||||
}
|
||||
|
||||
public static boolean isEn() {
|
||||
return Constants.LANG_EN.equals(LanguageUtil.getInstance().getLanguage());
|
||||
}
|
||||
}
|
||||
196
moduleUtil/src/main/java/com/qxcm/moduleutil/utils/Md5Utils.java
Normal file
196
moduleUtil/src/main/java/com/qxcm/moduleutil/utils/Md5Utils.java
Normal file
@@ -0,0 +1,196 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class Md5Utils {
|
||||
private final static String[] strDigits = {"0", "1", "2", "3", "4", "5",
|
||||
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
|
||||
|
||||
protected static char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
protected static MessageDigest messagedigest = null;
|
||||
|
||||
/**
|
||||
* MessageDigest初始化
|
||||
*
|
||||
* @author 高焕杰
|
||||
*/
|
||||
static {
|
||||
try {
|
||||
messagedigest = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
System.err.println("MD5FileUtil messagedigest初始化失败");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Md5Utils() {
|
||||
}
|
||||
|
||||
private static String byteToArrayString(byte bByte) {
|
||||
int iRet = bByte;
|
||||
if (iRet < 0) {
|
||||
iRet += 256;
|
||||
}
|
||||
int iD1 = iRet / 16;
|
||||
int iD2 = iRet % 16;
|
||||
return strDigits[iD1] + strDigits[iD2];
|
||||
}
|
||||
|
||||
private static String byteToString(byte[] bByte) {
|
||||
StringBuffer sBuffer = new StringBuffer();
|
||||
for (int i = 0; i < bByte.length; i++) {
|
||||
sBuffer.append(byteToArrayString(bByte[i]));
|
||||
}
|
||||
return sBuffer.toString();
|
||||
}
|
||||
|
||||
//MD5加密
|
||||
public static String get(String strObj) {
|
||||
String resultString = null;
|
||||
try {
|
||||
resultString = strObj;
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
resultString = byteToString(md.digest(strObj.getBytes()));
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
|
||||
public static String getFileMD5(File file) {
|
||||
if (!file.isFile()) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest digest = null;
|
||||
FileInputStream in = null;
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
in = new FileInputStream(file);
|
||||
while ((len = in.read(buffer, 0, 1024)) != -1) {
|
||||
digest.update(buffer, 0, len);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return byteToString(digest.digest());
|
||||
}
|
||||
|
||||
public static String getStringMD5(String input) {
|
||||
try {
|
||||
// 拿到一个MD5转换器(如果想要SHA1参数换成”SHA1”)
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
||||
// 输入的字符串转换成字节数组
|
||||
|
||||
byte[] inputByteArray = input.getBytes();
|
||||
// inputByteArray是输入字符串转换得到的字节数组
|
||||
messageDigest.update(inputByteArray);
|
||||
// 转换并返回结果,也是字节数组,包含16个元素
|
||||
byte[] resultByteArray = messageDigest.digest();
|
||||
// 字符数组转换成字符串返回
|
||||
return byteArrayToHex(resultByteArray);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String byteArrayToHex(byte[] byteArray) {
|
||||
// 首先初始化一个字符数组,用来存放每个16进制字符
|
||||
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
char[] resultCharArray = new char[byteArray.length * 2];
|
||||
// 遍历字节数组,通过位运算(位运算效率高),转换成字符放到字符数组中去
|
||||
int index = 0;
|
||||
for (byte b : byteArray) {
|
||||
resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
|
||||
resultCharArray[index++] = hexDigits[b & 0xf];
|
||||
}
|
||||
// 字符数组组合成字符串返回
|
||||
return new String(resultCharArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对文件进行MD5加密
|
||||
*
|
||||
* @author 高焕杰
|
||||
*/
|
||||
public static String getFileMD5String(File file) throws IOException {
|
||||
FileInputStream in = new FileInputStream(file);
|
||||
FileChannel ch = in.getChannel();
|
||||
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
|
||||
messagedigest.update(byteBuffer);
|
||||
return bufferToHex(messagedigest.digest());
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字符串进行MD5加密
|
||||
*
|
||||
* @author 高焕杰
|
||||
*/
|
||||
public static String getMD5String(String s) {
|
||||
return getMD5String(s.getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* 对byte类型的数组进行MD5加密
|
||||
*
|
||||
* @author 高焕杰
|
||||
*/
|
||||
public static String getMD5String(byte[] bytes) {
|
||||
messagedigest.update(bytes);
|
||||
return bufferToHex(messagedigest.digest());
|
||||
}
|
||||
|
||||
private static String bufferToHex(byte[] bytes) {
|
||||
return bufferToHex(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
private static String bufferToHex(byte[] bytes, int m, int n) {
|
||||
StringBuffer stringbuffer = new StringBuffer(2 * n);
|
||||
int k = m + n;
|
||||
for (int l = m; l < k; l++) {
|
||||
char c0 = hexDigits[(bytes[l] & 0xf0) >> 4];
|
||||
char c1 = hexDigits[bytes[l] & 0xf];
|
||||
stringbuffer.append(c0);
|
||||
stringbuffer.append(c1);
|
||||
}
|
||||
return stringbuffer.toString();
|
||||
}
|
||||
|
||||
private static char sHexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
public static String getMD5(String source) {
|
||||
try {
|
||||
byte[] bytes = source.getBytes();
|
||||
// 获得MD5摘要算法的 MessageDigest 对象
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
// 使用指定的字节更新摘要
|
||||
md.update(bytes);
|
||||
// 获得密文
|
||||
byte[] mdBytes = md.digest();
|
||||
// 把密文转换成十六进制的字符串形式
|
||||
int length = mdBytes.length;
|
||||
char[] chars = new char[length * 2];
|
||||
int k = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
byte byte0 = mdBytes[i];
|
||||
chars[k++] = sHexDigits[byte0 >>> 4 & 0xf];
|
||||
chars[k++] = sHexDigits[byte0 & 0xf];
|
||||
}
|
||||
return new String(chars);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.utils.logger.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* 描述 设置中的用户头像
|
||||
*/
|
||||
public class MeHeadView extends ConstraintLayout {
|
||||
private ImageView mRiv;
|
||||
private ImageView mIvFrame;
|
||||
private ImageView mIvSex;
|
||||
private ImageView mIvOnline;
|
||||
|
||||
public MeHeadView(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public MeHeadView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public MeHeadView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
initView(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private void initView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
LayoutInflater.from(context).inflate(R.layout.me_view_decoration_head, this, true);
|
||||
mRiv = findViewById(R.id.riv);
|
||||
mIvFrame = findViewById(R.id.iv_frame);
|
||||
mIvSex = findViewById(R.id.iv_sex);
|
||||
mIvOnline = findViewById(R.id.iv_online);
|
||||
}
|
||||
|
||||
public void setData(String headPicture, String framePicture, String sex) {
|
||||
Logger.e(headPicture, framePicture, sex);
|
||||
if (!TextUtils.isEmpty(headPicture)) {
|
||||
ImageUtils.loadHeadCC(headPicture, mRiv);
|
||||
}
|
||||
// if (TextUtils.isEmpty(framePicture)) {
|
||||
// mIvSex.setVisibility(VISIBLE);
|
||||
// if (!TextUtils.isEmpty(sex)) {
|
||||
// if (UserBean.MALE.equals(sex)) {
|
||||
// mIvSex.setBackgroundResource(R.mipmap.common_ic_headportriat_boy);
|
||||
// } else {
|
||||
// mIvSex.setBackgroundResource(R.mipmap.common_ic_headportriat_girl);
|
||||
// }
|
||||
// } else {
|
||||
// mIvSex.setBackgroundResource(R.drawable.common_bg_head_white);
|
||||
// }
|
||||
// } else {
|
||||
// mIvSex.setVisibility(GONE);
|
||||
// }
|
||||
ImageUtils.loadImageView(framePicture, mIvFrame);
|
||||
}
|
||||
|
||||
public void setOnline(boolean isOnline) {
|
||||
mIvOnline.setVisibility(VISIBLE);
|
||||
mIvOnline.setImageResource(isOnline ? R.mipmap.me_online_icon : R.mipmap.me_icon_unchecked);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.media.MediaPlayer;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class MediaPlayerUtiles {
|
||||
private MediaPlayer mediaPlayer;
|
||||
|
||||
private static MediaPlayerUtiles instance = new MediaPlayerUtiles();
|
||||
|
||||
public static MediaPlayerUtiles getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private MediaPlayerUtiles() {
|
||||
if (null == mediaPlayer) {
|
||||
mediaPlayer = new MediaPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
private OnMediaPlayerListener mOnMediaPlayerListener;
|
||||
|
||||
/**
|
||||
* 播放音频
|
||||
*/
|
||||
public void playAudio(String url, OnMediaPlayerListener onMediaPlayerListener) {
|
||||
playAudio(url, -1, onMediaPlayerListener);
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
return mediaPlayer != null && mediaPlayer.isPlaying();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 停止播放音频
|
||||
*/
|
||||
public void stopAudio() {
|
||||
try {
|
||||
if (null != mediaPlayer) {
|
||||
if (mediaPlayer.isPlaying()) {
|
||||
mediaPlayer.pause();
|
||||
mediaPlayer.reset();
|
||||
mediaPlayer.stop();
|
||||
}
|
||||
}
|
||||
if (mOnMediaPlayerListener != null) {
|
||||
mOnMediaPlayerListener.onCompletion(position);
|
||||
}
|
||||
this.mOnMediaPlayerListener = null;
|
||||
} catch (Exception e) {
|
||||
Log.e("stopAudio", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public long getCurrentPosition() {
|
||||
if (mediaPlayer != null) {
|
||||
return mediaPlayer.getCurrentPosition();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void playAudio(String url, int position, OnMediaPlayerListener onMediaPlayerListener) {
|
||||
this.position = position;
|
||||
try {
|
||||
stopAudio();//如果正在播放就停止
|
||||
if (this.mOnMediaPlayerListener != null) {
|
||||
this.mOnMediaPlayerListener.onCompletion(position);
|
||||
}
|
||||
this.mOnMediaPlayerListener = onMediaPlayerListener;
|
||||
mediaPlayer.reset();
|
||||
mediaPlayer.setDataSource(url);
|
||||
mediaPlayer.setLooping(false);
|
||||
mediaPlayer.prepareAsync();
|
||||
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mediaPlayer) {
|
||||
mediaPlayer.start();
|
||||
if (mOnMediaPlayerListener != null) {
|
||||
mOnMediaPlayerListener.onStartPlay(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
if (mOnMediaPlayerListener != null) {
|
||||
mOnMediaPlayerListener.onCompletion(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
||||
@Override
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("播放音频失败", "");
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnMediaPlayerListener {
|
||||
void onStartPlay(int position);
|
||||
|
||||
void onCompletion(int position);
|
||||
}
|
||||
|
||||
private int position = -1;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.qxcm.moduleutil.utils
|
||||
|
||||
import android.graphics.Color
|
||||
import com.luck.picture.lib.style.PictureParameterStyle
|
||||
import com.qxcm.moduleutil.R
|
||||
|
||||
/**
|
||||
*项目名称 isolated-island
|
||||
*包名:com.qpyy.libcommon.widget
|
||||
*创建人 黄强
|
||||
*创建时间 2021/4/1 14:36
|
||||
*描述 describe
|
||||
*/
|
||||
public class MyPictureParameterStyle {
|
||||
companion object {
|
||||
fun selectPicture(): PictureParameterStyle {
|
||||
val uiStyle = PictureParameterStyle()
|
||||
// 开启新选择风格
|
||||
uiStyle.isNewSelectStyle = true
|
||||
// 是否改变状态栏字体颜色(黑白切换)
|
||||
uiStyle.isChangeStatusBarFontColor = true
|
||||
// 是否开启右下角已完成(0/9)风格
|
||||
uiStyle.isOpenCompletedNumStyle = false
|
||||
// 是否开启类似QQ相册带数字选择风格
|
||||
uiStyle.isOpenCheckNumStyle = true
|
||||
// 状态栏背景色
|
||||
uiStyle.pictureStatusBarColor = Color.parseColor("#FFFFFF")
|
||||
// 相册列表标题栏背景色
|
||||
uiStyle.pictureTitleBarBackgroundColor = Color.parseColor("#FFFFFF")
|
||||
// 相册父容器背景色
|
||||
uiStyle.pictureContainerBackgroundColor = Color.parseColor("#FFFFFF")
|
||||
// 相册列表标题栏右侧上拉箭头
|
||||
uiStyle.pictureTitleUpResId = R.mipmap.common_picture_icon_wechat_up
|
||||
// 相册列表标题栏右侧下拉箭头
|
||||
uiStyle.pictureTitleDownResId = R.mipmap.common_picture_icon_wechat_down
|
||||
// 相册文件夹列表选中圆点
|
||||
uiStyle.pictureFolderCheckedDotStyle = R.drawable.common_picture_wechat_num_oval_select
|
||||
// 相册返回箭头
|
||||
uiStyle.pictureLeftBackIcon = com.luck.picture.lib.R.drawable.picture_icon_back_arrow
|
||||
// 标题栏字体颜色
|
||||
uiStyle.pictureTitleTextColor = Color.parseColor("#FF000000")
|
||||
// 相册右侧按钮字体默认颜色
|
||||
uiStyle.pictureRightDefaultTextColor = Color.parseColor("#FFFFFF")
|
||||
// 相册右侧按可点击字体颜色,只针对isWeChatStyle 为true时有效果
|
||||
uiStyle.pictureRightSelectedTextColor = Color.parseColor("#FFFFFF")
|
||||
//相册标题字体大小
|
||||
uiStyle.pictureTitleTextSize = 18
|
||||
// 相册右侧按钮背景样式,只针对isWeChatStyle 为true时有效果
|
||||
uiStyle.pictureUnCompleteBackgroundStyle = R.drawable.common_picture_send_button_default_bg
|
||||
// 相册右侧按钮可点击背景样式,只针对isWeChatStyle 为true时有效果
|
||||
uiStyle.pictureCompleteBackgroundStyle = R.drawable.common_picture_send_button_bg
|
||||
// 选择相册目录背景样式
|
||||
uiStyle.pictureAlbumStyle = com.luck.picture.lib.R.drawable.picture_item_select_bg
|
||||
// 相册列表勾选图片样式
|
||||
uiStyle.pictureCheckedStyle = R.drawable.common_picture_wechat_num_selector
|
||||
// 相册标题背景样式 ,只针对isWeChatStyle 为true时有效果
|
||||
uiStyle.pictureWeChatTitleBackgroundStyle = R.drawable.common_picture_album_bg
|
||||
// 微信样式 预览右下角样式 ,只针对isWeChatStyle 为true时有效果
|
||||
uiStyle.pictureWeChatChooseStyle = com.luck.picture.lib.R.drawable.picture_wechat_select_cb
|
||||
// 相册返回箭头 ,只针对isWeChatStyle 为true时有效果
|
||||
uiStyle.pictureWeChatLeftBackStyle = com.luck.picture.lib.R.drawable.picture_icon_back_arrow
|
||||
// 相册列表底部背景色
|
||||
uiStyle.pictureBottomBgColor = Color.parseColor("#FFFFFF")
|
||||
// 已选数量圆点背景样式
|
||||
uiStyle.pictureCheckNumBgStyle = R.drawable.common_picture_wechat_num_oval_select
|
||||
// 相册列表底下预览文字色值(预览按钮可点击时的色值)
|
||||
uiStyle.picturePreviewTextColor = Color.parseColor("#9b9b9b")
|
||||
// 相册列表底下不可预览文字色值(预览按钮不可点击时的色值)
|
||||
uiStyle.pictureUnPreviewTextColor = Color.parseColor("#9b9b9b")
|
||||
// 相册列表已完成色值(已完成 可点击色值)
|
||||
uiStyle.pictureCompleteTextColor = Color.parseColor("#FFFFFF")
|
||||
// 相册列表未完成色值(请选择 不可点击色值)
|
||||
uiStyle.pictureUnCompleteTextColor = Color.parseColor("#53575e")
|
||||
//相册列表已完成按钮文本
|
||||
uiStyle.pictureCompleteText = "完成"
|
||||
//相册列表未完成按钮文本
|
||||
uiStyle.pictureUnCompleteText = "完成"
|
||||
// 预览界面底部背景色
|
||||
uiStyle.picturePreviewBottomBgColor = Color.parseColor("#FFFFFF")
|
||||
// 外部预览界面删除按钮样式
|
||||
uiStyle.pictureExternalPreviewDeleteStyle = com.luck.picture.lib.R.drawable.picture_icon_delete
|
||||
// 原图按钮勾选样式 需设置.isOriginalImageControl(true); 才有效
|
||||
uiStyle.pictureOriginalControlStyle =com.luck.picture.lib.R.drawable.picture_original_wechat_checkbox
|
||||
// 原图文字颜色 需设置.isOriginalImageControl(true); 才有效
|
||||
uiStyle.pictureOriginalFontColor = Color.parseColor("#FF000000")
|
||||
// 外部预览界面是否显示删除按钮
|
||||
// 外部预览界面是否显示删除按钮
|
||||
uiStyle.pictureExternalPreviewGonePreviewDelete = true
|
||||
// 设置NavBar Color SDK Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP有效
|
||||
uiStyle.pictureNavBarColor = Color.parseColor("#FFFFFF")
|
||||
return uiStyle
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.blankj.utilcode.util.SPUtils;
|
||||
|
||||
/**
|
||||
* sp工具类
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public class PreferencesUtils {
|
||||
public static String PREFERENCE_NAME = "YuTang";
|
||||
|
||||
private PreferencesUtils() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* put string preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new values for the preference
|
||||
* @return True if the new values were successfully written to persistent storage.
|
||||
*/
|
||||
public static boolean putString(Context context, String key, String value) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putString(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get string preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference values if it exists, or null. Throws ClassCastException if there is a preference with this
|
||||
* name that is not a string
|
||||
* @see #getString(Context, String, String)
|
||||
*/
|
||||
public static String getString(Context context, String key) {
|
||||
return getString(context, key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* get string preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference values if it exists, or defValue. Throws ClassCastException if there is a preference with
|
||||
* this name that is not a string
|
||||
*/
|
||||
public static String getString(Context context, String key, String defaultValue) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getString(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* put int preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new values for the preference
|
||||
* @return True if the new values were successfully written to persistent storage.
|
||||
*/
|
||||
public static boolean putInt(Context context, String key, int value) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putInt(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get int preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference values if it exists, or -1. Throws ClassCastException if there is a preference with this
|
||||
* name that is not a int
|
||||
* @see #getInt(Context, String, int)
|
||||
*/
|
||||
public static int getInt(Context context, String key) {
|
||||
return getInt(context, key, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get int preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference values if it exists, or defValue. Throws ClassCastException if there is a preference with
|
||||
* this name that is not a int
|
||||
*/
|
||||
public static int getInt(Context context, String key, int defaultValue) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* put long preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new values for the preference
|
||||
* @return True if the new values were successfully written to persistent storage.
|
||||
*/
|
||||
public static boolean putLong(Context context, String key, long value) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putLong(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get long preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference values if it exists, or -1. Throws ClassCastException if there is a preference with this
|
||||
* name that is not a long
|
||||
* @see #getLong(Context, String, long)
|
||||
*/
|
||||
public static long getLong(Context context, String key) {
|
||||
return getLong(context, key, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get long preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference values if it exists, or defValue. Throws ClassCastException if there is a preference with
|
||||
* this name that is not a long
|
||||
*/
|
||||
public static long getLong(Context context, String key, long defaultValue) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getLong(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* put float preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new values for the preference
|
||||
* @return True if the new values were successfully written to persistent storage.
|
||||
*/
|
||||
public static boolean putFloat(Context context, String key, float value) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putFloat(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get float preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference values if it exists, or -1. Throws ClassCastException if there is a preference with this
|
||||
* name that is not a float
|
||||
* @see #getFloat(Context, String, float)
|
||||
*/
|
||||
public static float getFloat(Context context, String key) {
|
||||
return getFloat(context, key, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get float preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference values if it exists, or defValue. Throws ClassCastException if there is a preference with
|
||||
* this name that is not a float
|
||||
*/
|
||||
public static float getFloat(Context context, String key, float defaultValue) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getFloat(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* put boolean preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to modify
|
||||
* @param value The new values for the preference
|
||||
* @return True if the new values were successfully written to persistent storage.
|
||||
*/
|
||||
public static boolean putBoolean(Context context, String key, boolean value) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean(key, value);
|
||||
return editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* get boolean preferences, default is false
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @return The preference values if it exists, or false. Throws ClassCastException if there is a preference with this
|
||||
* name that is not a boolean
|
||||
* @see #getBoolean(Context, String, boolean)
|
||||
*/
|
||||
public static boolean getBoolean(Context context, String key) {
|
||||
return getBoolean(context, key, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* get boolean preferences
|
||||
*
|
||||
* @param context context
|
||||
* @param key The name of the preference to retrieve
|
||||
* @param defaultValue Value to return if this preference does not exist
|
||||
* @return The preference values if it exists, or defValue. Throws ClassCastException if there is a preference with
|
||||
* this name that is not a boolean
|
||||
*/
|
||||
public static boolean getBoolean(Context context, String key, boolean defaultValue) {
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
return settings.getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
public static boolean clear(Context context) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).clear(true);
|
||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.clear();
|
||||
return editor.commit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
/**
|
||||
* 描述 describe
|
||||
*/
|
||||
public class SPConstants {
|
||||
public final static String IntentKey_ImageList = "IntentKey_ImageList";
|
||||
public final static String IntentKey_CurrentPosition = "IntentKey_CurrentPosition";
|
||||
public static final String PREFERENCE_NAME = "Vespa";
|
||||
public static final String PREFERENCE_SEARCH_HISTORY = "searchHistory";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String SEARCH_HISTORY = "SearchHistory";
|
||||
public static final String USER_ID = "UserId";
|
||||
public static final String USER_INFO = "userInfo";
|
||||
public static final String EMQTT_CLIENT_ID = "emqttClientId";
|
||||
public static final String FIRST_ENTER_ROOM = "firstEnterRoom";
|
||||
public static final String PLAY_MODE = "PLAY_MODE"; //播放模式 0 顺序循序播放 1随机播放 2单曲循环
|
||||
public static final String VOLUME = "VOLUME"; //音量
|
||||
public static final String CURRENT_MUSIC = "CURRENT_MUSIC"; //当前播放音乐
|
||||
public static final String OPEN_EFFECT = "OPEN_EFFECT"; //开启特效
|
||||
public static final String OPEN_AU_BACK = "OPEN_AU_BACK"; //开启耳返
|
||||
public static final String ORDER_NEWS_COUNT = "orderNewsCount";
|
||||
public static final String ORDER_LAST_MSG = "lastOrderMsg";
|
||||
public static final String GIFT_LIST = "giftList";//礼物列表
|
||||
public static final String COMMON_EMOJI_LIST = "commonEmojiList";//普通房间表情列表
|
||||
public static final String SPECIAL_EMOJI_LIST = "specialEmojiList";//房间专属表情列表
|
||||
|
||||
public static final String CABIN="cabin";//小黑屋
|
||||
}
|
||||
467
moduleUtil/src/main/java/com/qxcm/moduleutil/utils/SpUtil.java
Normal file
467
moduleUtil/src/main/java/com/qxcm/moduleutil/utils/SpUtil.java
Normal file
@@ -0,0 +1,467 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.blankj.utilcode.util.SPUtils;
|
||||
import com.qxcm.moduleutil.widget.CommonAppContext;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/9/17.
|
||||
* SharedPreferences 封装
|
||||
*/
|
||||
|
||||
public class SpUtil {
|
||||
|
||||
private static SpUtil sInstance;
|
||||
private SharedPreferences mSharedPreferences;
|
||||
|
||||
public static final String UID = "uid";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String USER_INFO = "userInfo";
|
||||
public static final String CONFIG = "config";
|
||||
public static final String SYSTEM_MSG_COUNT = "systemMsgCount";
|
||||
public static final String LOCATION_LNG = "locationLng";
|
||||
public static final String LOCATION_LAT = "locationLat";
|
||||
public static final String LOCATION_PROVINCE = "locationProvince";
|
||||
public static final String LOCATION_CITY = "locationCity";
|
||||
public static final String LOCATION_DISTRICT = "locationDistrict";
|
||||
public static final String MH_BEAUTY_ENABLE = "mhBeautyEnable";
|
||||
public static final String BRIGHTNESS = "brightness";//亮度
|
||||
public static final String IM_MSG_RING = "imMsgRing";//私信音效
|
||||
public static final String DEVICE_ID = "deviceId";
|
||||
public static final String TEENAGER = "teenager";
|
||||
public static final String TEENAGER_SHOW = "teenagerShow";
|
||||
public static final String TX_IM_USER_SIGN = "txImUserSign";//腾讯IM用户签名,登录腾讯IM用
|
||||
public static final String TPNS_NOTIFY_EXT = "tpnsNotifyExt";//tpns通知携带参数
|
||||
public static final String BASE_FUNCTION_MODE = "baseFunctionMode";//基本功能模式
|
||||
public static final String LANGUAGE = "language";
|
||||
|
||||
private SpUtil() {
|
||||
mSharedPreferences = CommonAppContext.getInstance().getSharedPreferences("SharedPreferences", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static SpUtil getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (SpUtil.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new SpUtil();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public int getIntValue(String key, int defaultValue) {
|
||||
return mSharedPreferences.getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
public void setIntValue(String key, int value) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putInt(key, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存一个字符串
|
||||
*/
|
||||
public void setStringValue(String key, String value) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putString(key, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个字符串
|
||||
*/
|
||||
public String getStringValue(String key) {
|
||||
return mSharedPreferences.getString(key, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存多个字符串
|
||||
*/
|
||||
public void setMultiStringValue(Map<String, String> pairs) {
|
||||
if (pairs == null || pairs.size() == 0) {
|
||||
return;
|
||||
}
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
for (Map.Entry<String, String> entry : pairs.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) {
|
||||
editor.putString(key, value);
|
||||
}
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个字符串
|
||||
*/
|
||||
public String[] getMultiStringValue(String... keys) {
|
||||
if (keys == null || keys.length == 0) {
|
||||
return null;
|
||||
}
|
||||
int length = keys.length;
|
||||
String[] result = new String[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
String temp = "";
|
||||
if (!TextUtils.isEmpty(keys[i])) {
|
||||
temp = mSharedPreferences.getString(keys[i], "");
|
||||
}
|
||||
result[i] = temp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存一个布尔值
|
||||
*/
|
||||
public void setBooleanValue(String key, boolean value) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(key, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个布尔值
|
||||
*/
|
||||
public boolean getBooleanValue(String key) {
|
||||
return mSharedPreferences.getBoolean(key, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个布尔值
|
||||
*/
|
||||
public boolean getBooleanValue(String key, boolean defaultValue) {
|
||||
return mSharedPreferences.getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存多个布尔值
|
||||
*/
|
||||
public void setMultiBooleanValue(Map<String, Boolean> pairs) {
|
||||
if (pairs == null || pairs.size() == 0) {
|
||||
return;
|
||||
}
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
for (Map.Entry<String, Boolean> entry : pairs.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Boolean value = entry.getValue();
|
||||
if (!TextUtils.isEmpty(key)) {
|
||||
editor.putBoolean(key, value);
|
||||
}
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个布尔值
|
||||
*/
|
||||
public boolean[] getMultiBooleanValue(String[] keys) {
|
||||
if (keys == null || keys.length == 0) {
|
||||
return null;
|
||||
}
|
||||
int length = keys.length;
|
||||
boolean[] result = new boolean[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
boolean temp = false;
|
||||
if (!TextUtils.isEmpty(keys[i])) {
|
||||
temp = mSharedPreferences.getBoolean(keys[i], false);
|
||||
}
|
||||
result[i] = temp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void removeValue(String... keys) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
for (String key : keys) {
|
||||
editor.remove(key);
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 亮度
|
||||
*/
|
||||
public void setBrightness(float brightness) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putFloat(BRIGHTNESS, brightness);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* 亮度
|
||||
*/
|
||||
public float getBrightness() {
|
||||
return mSharedPreferences.getFloat(BRIGHTNESS, -1.0f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 私信音效
|
||||
*/
|
||||
public void setImMsgRingOpen(boolean imMsgRingOpen) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(IM_MSG_RING, imMsgRingOpen);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* 私信音效
|
||||
*/
|
||||
public boolean isImMsgRingOpen() {
|
||||
return mSharedPreferences.getBoolean(IM_MSG_RING, true);
|
||||
}
|
||||
|
||||
|
||||
public static String getToken() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.TOKEN);
|
||||
}
|
||||
|
||||
public static String getUserId() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.USER_ID);
|
||||
}
|
||||
|
||||
public static void saveUserId(String userId) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.USER_ID, userId, true);
|
||||
}
|
||||
|
||||
public static String getMyRoomId() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("MyRoomId");
|
||||
}
|
||||
|
||||
public static void saveMyRoomId(String roomId) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("MyRoomId", roomId, true);
|
||||
}
|
||||
|
||||
|
||||
public static void saveSearchHistory(String searchHistory) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_SEARCH_HISTORY).put(SPConstants.SEARCH_HISTORY, searchHistory);
|
||||
}
|
||||
|
||||
public static String getSearchHistory() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_SEARCH_HISTORY).getString(SPConstants.SEARCH_HISTORY);
|
||||
}
|
||||
|
||||
public static void putToken(String token) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.TOKEN, token, true);
|
||||
}
|
||||
|
||||
// public static void saveCabin(CabinEvent cabinEvent) {
|
||||
// String s = JSON.toJSONString(cabinEvent);
|
||||
// SPUtils.getInstance(SPConstants.CABIN).put("cabin", s, true);
|
||||
// }
|
||||
//
|
||||
// public static CabinEvent getCabin() {
|
||||
// String s = SPUtils.getInstance(SPConstants.CABIN).getString("cabin");
|
||||
// if (TextUtils.isEmpty(s)) {
|
||||
// return null;
|
||||
// }
|
||||
// CabinEvent cabinEvent = JSON.parseObject(s, CabinEvent.class);
|
||||
// return cabinEvent;
|
||||
// }
|
||||
//
|
||||
// public static void saveUserInfo(UserBean userBean) {
|
||||
// String s = JSON.toJSONString(userBean);
|
||||
// SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.USER_INFO, s, true);
|
||||
// }
|
||||
//
|
||||
// public static UserBean getUserInfo() {
|
||||
// String s = SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.USER_INFO);
|
||||
// if (TextUtils.isEmpty(s)) {
|
||||
// return new UserBean();
|
||||
// }
|
||||
// UserBean userBean = JSON.parseObject(s, UserBean.class);
|
||||
// if (userBean == null) {
|
||||
// return new UserBean();
|
||||
// }
|
||||
// return userBean;
|
||||
// }
|
||||
|
||||
public static void saveTzbl(String roomId, float bl) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(getUserId() + "-" + roomId + "_Tzbl", bl, true);
|
||||
}
|
||||
|
||||
public static float getTzbl(String roomId) {
|
||||
float bl = SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getFloat(getUserId() + "-" + roomId + "_Tzbl");
|
||||
if (bl < 0.0f) {
|
||||
if (roomId.equals(getMyRoomId())) {
|
||||
return 0.8f;
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
} else {
|
||||
return bl;
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveEmqttId(String clientId) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.EMQTT_CLIENT_ID, clientId);
|
||||
}
|
||||
|
||||
public static String getEmqttId() {
|
||||
String s = SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.EMQTT_CLIENT_ID);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//获取SharedPreferences音乐轮播方式
|
||||
public static int getPlayPattern() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.PLAY_MODE, 1);
|
||||
}
|
||||
|
||||
//通过SharedPreferences设置音乐轮播方式
|
||||
public static void setPlayPattern(int i) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.PLAY_MODE, i);
|
||||
}
|
||||
|
||||
//获取SharedPreferences音乐播放音量
|
||||
public static int getChannelVolume() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.VOLUME, 20);
|
||||
}
|
||||
|
||||
//设置SharedPreferences音乐播放音量
|
||||
public static void setChannelVolume(int i) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.VOLUME, i);
|
||||
}
|
||||
|
||||
//获取播放的音乐
|
||||
public static int getPlayCurrentMusic() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.CURRENT_MUSIC, 0);
|
||||
}
|
||||
|
||||
//设置播放的音乐
|
||||
public static void setPlayCurrentMusic(int i) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.CURRENT_MUSIC, i);
|
||||
}
|
||||
|
||||
//设置开启特效
|
||||
public static void setOpenEffect(int i) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.OPEN_EFFECT, i);
|
||||
}
|
||||
|
||||
//获取开启特效
|
||||
public static int getOpenEffect() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.OPEN_EFFECT, 1);
|
||||
}
|
||||
|
||||
//设置耳返
|
||||
public static void setAuricularBack(int i) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.OPEN_AU_BACK, i);
|
||||
}
|
||||
|
||||
//获取耳返
|
||||
public static int getAuricularBack() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.OPEN_AU_BACK, 0);
|
||||
}
|
||||
|
||||
//获取新的消息数量
|
||||
public static int getOrderNewCounts() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.ORDER_NEWS_COUNT, 0);
|
||||
}
|
||||
|
||||
//设置新的消息数量
|
||||
public static void setOrderNewCounts(int i) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.ORDER_NEWS_COUNT, i);
|
||||
}
|
||||
|
||||
//获取装载的消息
|
||||
public static String getLastOrderMsg() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.ORDER_LAST_MSG, " ");
|
||||
}
|
||||
|
||||
//设置装载的消息
|
||||
public static void setLastOrderMsg(String s) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.ORDER_LAST_MSG, s);
|
||||
}
|
||||
|
||||
//新的token
|
||||
public static void putNewToken(String token) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("newToken", token, true);
|
||||
}
|
||||
|
||||
//新的token
|
||||
public static String getNewToken() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("newToken", "");
|
||||
}
|
||||
|
||||
public static void setAgreeSkillProtocol() {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("agreeSkillProtocol", true, true);
|
||||
}
|
||||
|
||||
public static boolean getAgreeSkillProtocol() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getBoolean("agreeSkillProtocol", false);
|
||||
}
|
||||
|
||||
public static void setInReview(boolean inReview) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("inReview", inReview, true);
|
||||
}
|
||||
|
||||
public static boolean inReview() {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getBoolean("inReview", false);
|
||||
}
|
||||
|
||||
public static void setHomeBanner(String banner){
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("homeBanner", banner, true);
|
||||
}
|
||||
public static String getHomeBanner(){
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("homeBanner", "");
|
||||
}
|
||||
|
||||
public static void setTopRoom(String topRoom){
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("topRoom", topRoom, true);
|
||||
}
|
||||
public static String getTopRoom(){
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("topRoom", "");
|
||||
}
|
||||
|
||||
|
||||
public static void setRoomTypeModel(String roomTypeModel){
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("roomTypeModel", roomTypeModel, true);
|
||||
}
|
||||
public static String getRoomTypeModel(){
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("roomTypeModel", "");
|
||||
}
|
||||
|
||||
public static void setHomeBean(String homeBean){
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("homeBean", homeBean, true);
|
||||
}
|
||||
public static String getHomeBean(){
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("homeBean", "");
|
||||
}
|
||||
|
||||
public static void setRoomModel(String roomModel){
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("roomModel", roomModel, true);
|
||||
}
|
||||
public static String getRoomModel(){
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("roomModel", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否同意协议
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAgreePolicy() {
|
||||
return !SPUtils.getInstance("Constant").getBoolean("launchRequestPermission", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同意协议
|
||||
*/
|
||||
public static void completeAgreePolicy() {
|
||||
SPUtils.getInstance("Constant").put("launchRequestPermission",
|
||||
false, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
|
||||
|
||||
import com.qxcm.moduleutil.widget.CommonAppConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/9/28.
|
||||
*/
|
||||
|
||||
public class StringUtil {
|
||||
private static final DecimalFormat sDecimalFormat;
|
||||
private static final DecimalFormat sDecimalFormat2;
|
||||
// private static Pattern sPattern;
|
||||
private static final Pattern sIntPattern;
|
||||
private static final Random sRandom;
|
||||
private static final StringBuilder sStringBuilder;
|
||||
|
||||
|
||||
static {
|
||||
sDecimalFormat = new DecimalFormat("#.#");
|
||||
sDecimalFormat.setRoundingMode(RoundingMode.HALF_UP);
|
||||
sDecimalFormat2 = new DecimalFormat("#.##");
|
||||
sDecimalFormat2.setRoundingMode(RoundingMode.DOWN);
|
||||
//sPattern = Pattern.compile("[\u4e00-\u9fa5]");
|
||||
sIntPattern = Pattern.compile("^[-\\+]?[\\d]*$");
|
||||
sRandom = new Random();
|
||||
sStringBuilder = new StringBuilder();
|
||||
}
|
||||
|
||||
public static String format(double value) {
|
||||
return sDecimalFormat.format(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把数字转化成多少万
|
||||
*/
|
||||
public static String toWan(long num) {
|
||||
if (num < 10000) {
|
||||
return String.valueOf(num);
|
||||
}
|
||||
return sDecimalFormat.format(num / 10000d) + "W";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 把数字转化成多少万
|
||||
*/
|
||||
public static String toWan2(long num) {
|
||||
if (num < 10000) {
|
||||
return String.valueOf(num);
|
||||
}
|
||||
return sDecimalFormat.format(num / 10000d);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把数字转化成多少万
|
||||
*/
|
||||
public static String toWan3(long num) {
|
||||
if (num < 10000) {
|
||||
return String.valueOf(num);
|
||||
}
|
||||
return sDecimalFormat2.format(num / 10000d) + "w";
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 判断字符串中是否包含中文
|
||||
// */
|
||||
// public static boolean isContainChinese(String str) {
|
||||
// Matcher m = sPattern.matcher(str);
|
||||
// if (m.find()) {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 判断一个字符串是否是数字
|
||||
*/
|
||||
public static boolean isInt(String str) {
|
||||
return sIntPattern.matcher(str).matches();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 把一个long类型的总毫秒数转成时长
|
||||
*/
|
||||
public static String getDurationText(long mms) {
|
||||
int hours = (int) (mms / (1000 * 60 * 60));
|
||||
int minutes = (int) ((mms % (1000 * 60 * 60)) / (1000 * 60));
|
||||
int seconds = (int) ((mms % (1000 * 60)) / 1000);
|
||||
sStringBuilder.delete(0, sStringBuilder.length());
|
||||
if (hours > 0) {
|
||||
if (hours < 10) {
|
||||
sStringBuilder.append("0");
|
||||
}
|
||||
sStringBuilder.append(String.valueOf(hours));
|
||||
sStringBuilder.append(":");
|
||||
}
|
||||
if (minutes > 0) {
|
||||
if (minutes < 10) {
|
||||
sStringBuilder.append("0");
|
||||
}
|
||||
sStringBuilder.append(String.valueOf(minutes));
|
||||
sStringBuilder.append(":");
|
||||
} else {
|
||||
sStringBuilder.append("00:");
|
||||
}
|
||||
if (seconds > 0) {
|
||||
if (seconds < 10) {
|
||||
sStringBuilder.append("0");
|
||||
}
|
||||
sStringBuilder.append(String.valueOf(seconds));
|
||||
} else {
|
||||
sStringBuilder.append("00");
|
||||
}
|
||||
return sStringBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 把秒数转成时长
|
||||
*/
|
||||
public static String getDurationText2(int secondCount,StringBuilder sb) {
|
||||
int hours = secondCount / 3600;
|
||||
int minutes = 0;
|
||||
int last = secondCount % 3600;
|
||||
if (last > 0) {
|
||||
minutes = last / 60;
|
||||
}
|
||||
int seconds = secondCount % 60;
|
||||
sb.delete(0, sb.length());
|
||||
if (hours > 0) {
|
||||
if (hours < 10) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(String.valueOf(hours));
|
||||
sb.append(":");
|
||||
}
|
||||
if (minutes > 0) {
|
||||
if (minutes < 10) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(String.valueOf(minutes));
|
||||
sb.append(":");
|
||||
} else {
|
||||
sb.append("00:");
|
||||
}
|
||||
if (seconds > 0) {
|
||||
if (seconds < 10) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(String.valueOf(seconds));
|
||||
} else {
|
||||
sb.append("00");
|
||||
}
|
||||
|
||||
|
||||
// String s = sb.toString();
|
||||
// L.e("getDurationText---hours---->" + hours + "---minutes-->" + minutes + "---seconds-->" + seconds + "--s-->" + s);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置视频输出路径
|
||||
*/
|
||||
public static String generateVideoOutputPath() {
|
||||
String outputDir = CommonAppConfig.VIDEO_PATH;
|
||||
File outputFolder = new File(outputDir);
|
||||
if (!outputFolder.exists()) {
|
||||
outputFolder.mkdirs();
|
||||
}
|
||||
String videoName = DateFormatUtil.getVideoCurTimeString() + sRandom.nextInt(9999);
|
||||
return contact(outputDir, "/android_", CommonAppConfig.getInstance().getUid(), "_", videoName, ".mp4");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取随机文件名
|
||||
*/
|
||||
public static String generateFileName() {
|
||||
return contact("android_",
|
||||
CommonAppConfig.getInstance().getUid(),
|
||||
"_",
|
||||
DateFormatUtil.getVideoCurTimeString(),
|
||||
String.valueOf(sRandom.nextInt(9999)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 多个字符串拼接
|
||||
*/
|
||||
public static String contact(String... args) {
|
||||
sStringBuilder.delete(0, sStringBuilder.length());
|
||||
for (String s : args) {
|
||||
sStringBuilder.append(s);
|
||||
}
|
||||
return sStringBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
/*比较字符串*/
|
||||
public static boolean compareString(String var1, String var2) {
|
||||
if (var1 == null && var2 == null) {
|
||||
return true;
|
||||
} else if (var1 != null && var2 != null) {
|
||||
return var1.equals(var2);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getRandomInt(int bound){
|
||||
return sRandom.nextInt(bound);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class TimeUtils {
|
||||
|
||||
/**
|
||||
* 获取年
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getYear() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
return cd.get(Calendar.YEAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getMonth() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
return cd.get(Calendar.MONTH) + 1;
|
||||
}
|
||||
|
||||
public static String getMonths() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
int month = cd.get(Calendar.MONTH) + 1;
|
||||
if (month <= 9) {
|
||||
return "0" + month;
|
||||
} else {
|
||||
return String.valueOf(month);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getDay() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
return cd.get(Calendar.DATE);
|
||||
}
|
||||
|
||||
public static String getDays() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
int day = cd.get(Calendar.DATE);
|
||||
if (day <= 9) {
|
||||
return "0" + day;
|
||||
} else {
|
||||
return String.valueOf(day);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getHour() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
return cd.get(Calendar.HOUR);
|
||||
}
|
||||
|
||||
public static String getFormatterHour() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
int hour = cd.get(Calendar.HOUR_OF_DAY);
|
||||
if (hour < 10) {
|
||||
return "0" + hour;
|
||||
}
|
||||
return String.valueOf(hour);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getNewHour() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
return cd.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getMinute() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
return cd.get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getFormatterMinute() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
int minute = cd.get(Calendar.MINUTE);
|
||||
if (minute < 10) {
|
||||
return "0" + minute;
|
||||
}
|
||||
return String.valueOf(minute);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getSeconds() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
return cd.get(Calendar.SECOND);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getFormatterSeconds() {
|
||||
Calendar cd = Calendar.getInstance();
|
||||
int seconds = cd.get(Calendar.SECOND);
|
||||
if (seconds < 10) {
|
||||
return "0" + seconds;
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据某年份、某月份获取对应的月份天数
|
||||
*
|
||||
* @param year 年份
|
||||
* @param month 月份
|
||||
* @return 月份的天数
|
||||
*/
|
||||
public static int getDaysByYearMonth(int year, int month) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.YEAR, year);
|
||||
calendar.set(Calendar.MONTH, month - 1);
|
||||
calendar.set(Calendar.DATE, 1);
|
||||
calendar.roll(Calendar.DATE, -1);
|
||||
int days = calendar.get(Calendar.DATE);
|
||||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期字符串例如 2015-3-10 Num:需要减少的天数例如 7
|
||||
*
|
||||
* @param day 日期字符串例如 2015-3-10
|
||||
* @param Num 需要减少的天数例如 7
|
||||
* @return
|
||||
*/
|
||||
public static String getDateStr(String day, int Num) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date nowDate = null;
|
||||
try {
|
||||
nowDate = df.parse(day);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//如果需要向后计算日期 -改为+
|
||||
Date newDate2 = new Date(nowDate.getTime() - (long) Num * 24 * 60 * 60 * 1000);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String dateOk = simpleDateFormat.format(newDate2);
|
||||
return dateOk;
|
||||
}
|
||||
|
||||
/*获取系统时间 格式为:"yyyy/MM/dd "*/
|
||||
public static String getCurrentDate() {
|
||||
Date d = new Date();
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
return sf.format(d);
|
||||
}
|
||||
|
||||
/*时间戳转换成字符窜*/
|
||||
public static String getDateToString(long time) {
|
||||
Date d = new Date(time);
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
return sf.format(d);
|
||||
}
|
||||
|
||||
/*将字符串转为时间戳*/
|
||||
public static long getStringToDate(String time) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
Date date = new Date();
|
||||
try {
|
||||
date = sdf.parse(time);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return date.getTime();
|
||||
}
|
||||
//获取当前日期
|
||||
public static String getCurrentDate2() {
|
||||
Date d = new Date();
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return sf.format(d);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.qxcm.moduleutil.utils;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.LocaleList;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
|
||||
import com.qxcm.moduleutil.widget.CommonAppContext;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/10/10.
|
||||
* 获取string.xml中的字
|
||||
*/
|
||||
|
||||
public class WordUtil {
|
||||
|
||||
private static Resources sResources;
|
||||
|
||||
static {
|
||||
sResources = CommonAppContext.getInstance().getResources();
|
||||
}
|
||||
|
||||
public static String getString(int res) {
|
||||
if (res == 0) {
|
||||
return "";
|
||||
}
|
||||
Locale appLocale = LanguageUtil.getLanguageLocale();
|
||||
Configuration configuration = sResources.getConfiguration();
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
||||
LocaleList localeList = configuration.getLocales();
|
||||
if (localeList.isEmpty() || !localeList.get(0).equals(appLocale)) {
|
||||
configuration.setLocale(appLocale);
|
||||
DisplayMetrics dm = sResources.getDisplayMetrics();
|
||||
sResources.updateConfiguration(configuration, dm);
|
||||
}
|
||||
} else {
|
||||
Locale locale = configuration.locale;
|
||||
if (locale == null || !locale.equals(appLocale)) {
|
||||
configuration.setLocale(appLocale);
|
||||
DisplayMetrics dm = sResources.getDisplayMetrics();
|
||||
sResources.updateConfiguration(configuration, dm);
|
||||
}
|
||||
}
|
||||
return sResources.getString(res);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.qxcm.moduleutil.utils.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*@author
|
||||
*@data
|
||||
*@description: 模拟获取网络配置信息
|
||||
*/
|
||||
public class ConfigLoader {
|
||||
public interface LoadCallback {
|
||||
void onFailure(Exception e);
|
||||
|
||||
void onSuccess(Object config);
|
||||
}
|
||||
|
||||
public static void loadRemoteConfig(EnvironmentEnum env, LoadCallback callback) {
|
||||
// 模拟异步加载远程配置
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(500); // 模拟网络延迟
|
||||
|
||||
// 模拟不同环境返回不同的配置
|
||||
Map<String, String> remoteData = new HashMap<>();
|
||||
if (env == EnvironmentEnum.PRODUCTION) {
|
||||
remoteData.put("feature_new_ui", "true");
|
||||
remoteData.put("app_version", "3.0.0");
|
||||
} else {
|
||||
remoteData.put("feature_new_ui", "false");
|
||||
remoteData.put("app_version", "2.1.0");
|
||||
}
|
||||
|
||||
callback.onSuccess(new RemoteConfig(remoteData));
|
||||
} catch (Exception e) {
|
||||
callback.onFailure(e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.qxcm.moduleutil.utils.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfigManager {
|
||||
// 当前环境配置
|
||||
private EnvironmentEnum currentEnvironment = EnvironmentEnum.TEST;
|
||||
|
||||
// 远程配置缓存
|
||||
private Map<String, String> remoteConfigs = new HashMap<>();
|
||||
|
||||
// 单例模式
|
||||
private static final ConfigManager instance = new ConfigManager();
|
||||
|
||||
private ConfigManager() {}
|
||||
|
||||
public static ConfigManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
// 切换环境
|
||||
public void switchEnvironment(EnvironmentEnum environment) {
|
||||
this.currentEnvironment = environment;
|
||||
}
|
||||
|
||||
// 获取当前环境
|
||||
public EnvironmentEnum getCurrentEnvironment() {
|
||||
return currentEnvironment;
|
||||
}
|
||||
|
||||
// 获取当前服务器地址
|
||||
public String getCurrentServerUrl() {
|
||||
return currentEnvironment.getServerUrl();
|
||||
}
|
||||
|
||||
// 获取当前第三方 Key
|
||||
public String getCurrentThirdPartyKey() {
|
||||
return currentEnvironment.getALI_AUTH_KEY();
|
||||
}
|
||||
|
||||
// 模拟获取远程配置(可替换为网络请求)
|
||||
public void fetchRemoteConfigsFromApi() {
|
||||
remoteConfigs.put("feature_flag", "enabled");
|
||||
remoteConfigs.put("app_version", "2.0.0");
|
||||
}
|
||||
|
||||
// 获取远程配置值
|
||||
public String getRemoteConfigValue(String key) {
|
||||
return remoteConfigs.get(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.qxcm.moduleutil.utils.config;
|
||||
/**
|
||||
*@author
|
||||
*@data
|
||||
*@description: 统一配置提供者
|
||||
*/
|
||||
public class ConfigProvider {
|
||||
|
||||
private static final RemoteConfigManager configManager = new RemoteConfigManager();
|
||||
|
||||
public static void loadConfigForEnvironment(EnvironmentEnum env, ConfigLoader.LoadCallback callback) {
|
||||
// ConfigLoader.loadRemoteConfig(env, config -> {
|
||||
//// configManager.saveConfig(env, config);
|
||||
// callback.onSuccess(null);
|
||||
// });
|
||||
}
|
||||
|
||||
public static String getConfigValue(EnvironmentEnum env, String key) {
|
||||
RemoteConfig config = configManager.getConfig(env);
|
||||
if (config != null && config.containsKey(key)) {
|
||||
return config.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RemoteConfig getAllConfigs(EnvironmentEnum env) {
|
||||
return configManager.getConfig(env);
|
||||
}
|
||||
private static EnvironmentEnum currentEnv = EnvironmentEnum.TEST;
|
||||
|
||||
public static void setCurrentEnvironment(EnvironmentEnum env) {
|
||||
currentEnv = env;
|
||||
}
|
||||
|
||||
public static String getAliAuthKey() {
|
||||
return currentEnv.getALI_AUTH_KEY();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.qxcm.moduleutil.utils.config;
|
||||
|
||||
public enum EnvironmentEnum {
|
||||
PRODUCTION("https://api.production.com", "6rdWuz058oq5OahdbFiGEybUcdahd12J83L34Uc7MrPIrxtFG+rXiwDvRcqNvjwbClbbmvMrmxKVkIysFByBsl0Qe9kqd2w8T/nhK5G6eXXlk2V9AjYCieIU+jRnjZBB+Cfechr6rCGJ2aeBARIsXcRPW7wm9WFK9euh5T+v6Pyte68yNaNdcYCll3+U4/uCEog7HygCnMIbAU+kqoPdmn2H+51YOHW+VsnsHd4w1+I3f8Tt0xLIXGM4GWnQueZ5GR46GTWiSYMy8dCIh9SPIMRyC91GosVcfGPMJSdcXqc="),
|
||||
TEST("https://api.test.com", "6rdWuz058oq5OahdbFiGEybUcdahd12J83L34Uc7MrPIrxtFG+rXiwDvRcqNvjwbClbbmvMrmxKVkIysFByBsl0Qe9kqd2w8T/nhK5G6eXXlk2V9AjYCieIU+jRnjZBB+Cfechr6rCGJ2aeBARIsXcRPW7wm9WFK9euh5T+v6Pyte68yNaNdcYCll3+U4/uCEog7HygCnMIbAU+kqoPdmn2H+51YOHW+VsnsHd4w1+I3f8Tt0xLIXGM4GWnQueZ5GR46GTWiSYMy8dCIh9SPIMRyC91GosVcfGPMJSdcXqc=");
|
||||
|
||||
private final String serverUrl;
|
||||
private final String ALI_AUTH_KEY;//阿里云授权key
|
||||
|
||||
EnvironmentEnum(String serverUrl, String ALI_AUTH_KEY) {
|
||||
this.serverUrl = serverUrl;
|
||||
this.ALI_AUTH_KEY = ALI_AUTH_KEY;
|
||||
}
|
||||
|
||||
public String getServerUrl() {
|
||||
return serverUrl;
|
||||
}
|
||||
|
||||
public String getALI_AUTH_KEY() {
|
||||
return ALI_AUTH_KEY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.qxcm.moduleutil.utils.config;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
/**
|
||||
*@author
|
||||
*@data
|
||||
*@description: 将配置信息保存在本地
|
||||
*/
|
||||
public class EnvironmentPrefs {
|
||||
private static final String PREFS_NAME = "EnvironmentPrefs";
|
||||
private static final String KEY_ENV = "selected_environment";
|
||||
|
||||
private final SharedPreferences sharedPreferences;
|
||||
|
||||
public EnvironmentPrefs(Context context) {
|
||||
sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
// 保存当前选择的环境
|
||||
public void setSelectedEnvironment(EnvironmentEnum environment) {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString(KEY_ENV, environment.name());
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
// 获取当前选择的环境,默认为 PRODUCTION
|
||||
public EnvironmentEnum getSelectedEnvironment() {
|
||||
String envName = sharedPreferences.getString(KEY_ENV, EnvironmentEnum.PRODUCTION.name());
|
||||
try {
|
||||
return EnvironmentEnum.valueOf(envName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return EnvironmentEnum.PRODUCTION; // 出错时默认返回生产环境
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.qxcm.moduleutil.utils.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class RemoteConfig {
|
||||
private Map<String, String> configs;
|
||||
|
||||
public RemoteConfig(Map<String, String> configs) {
|
||||
this.configs = configs;
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
return configs.get(key);
|
||||
}
|
||||
|
||||
public boolean containsKey(String key) {
|
||||
return configs.containsKey(key);
|
||||
}
|
||||
|
||||
public Map<String, String> getAll() {
|
||||
return configs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.qxcm.moduleutil.utils.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RemoteConfigManager {
|
||||
private Map<EnvironmentEnum, RemoteConfig> configCache = new HashMap<>();
|
||||
|
||||
|
||||
public RemoteConfig getConfig(EnvironmentEnum env) {
|
||||
return configCache.get(env);
|
||||
}
|
||||
|
||||
public boolean hasConfig(EnvironmentEnum env) {
|
||||
return configCache.containsKey(env);
|
||||
}
|
||||
|
||||
public void saveConfig(EnvironmentEnum env, Object config) {
|
||||
configCache.put(env, (RemoteConfig) config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.qxcm.moduleutil.utils.logger;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
/**
|
||||
* SCore
|
||||
* Created by ShangChuanliang
|
||||
* on 2017/9/29.
|
||||
*/
|
||||
public class Logger {
|
||||
public interface OnLoggerListener {
|
||||
void onLogI(String buildType, String tag, String msg);
|
||||
void onLogD(String buildType, String tag, String msg);
|
||||
void onLogE(String buildType, String tag, String msg);
|
||||
void onLogV(String buildType, String tag, String msg);
|
||||
void onLogW(String buildType, String tag, String msg);
|
||||
}
|
||||
|
||||
private Logger() {}
|
||||
private static SoftReference<OnLoggerListener> sOnLoggerListener;
|
||||
|
||||
private static final String Tag = "SLog";
|
||||
|
||||
private static String BuildType;
|
||||
private static boolean IsRelease;
|
||||
private static boolean IsBeta;
|
||||
private static boolean Loggable;
|
||||
|
||||
public static void init(String buildType) {
|
||||
BuildType = buildType;
|
||||
IsRelease = "release".equalsIgnoreCase(BuildType);
|
||||
IsBeta = "beta".equalsIgnoreCase(BuildType);
|
||||
Loggable = !IsRelease;
|
||||
}
|
||||
|
||||
public static void setOnLoggerListener(OnLoggerListener listener) {
|
||||
sOnLoggerListener = new SoftReference<>(listener);
|
||||
}
|
||||
|
||||
public static String getBuildType() {
|
||||
return BuildType;
|
||||
}
|
||||
|
||||
public static boolean isRelease() {
|
||||
return IsRelease;
|
||||
}
|
||||
|
||||
public static boolean isBeta() {
|
||||
return IsBeta;
|
||||
}
|
||||
|
||||
public static boolean isLoggable() {
|
||||
return Loggable;
|
||||
}
|
||||
|
||||
public static void i(String msg, Object... args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object arg : args) if (arg != null) sb.append(";").append(arg);
|
||||
callOnLoggerListener(1, BuildType, Tag, msg + sb.toString());
|
||||
if (isLoggable()) Log.i(Tag, msg + sb.toString());
|
||||
}
|
||||
|
||||
public static void d(String msg, Object... args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object arg : args) if (arg != null) sb.append(";").append(arg);
|
||||
callOnLoggerListener(2, BuildType, Tag, msg + sb.toString());
|
||||
if (isLoggable()) Log.d(Tag, msg + sb.toString());
|
||||
}
|
||||
|
||||
public static void e(String msg, Object... args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object arg : args) if (arg != null) sb.append(";").append(arg);
|
||||
callOnLoggerListener(3, BuildType, Tag, msg + sb.toString());
|
||||
if (isLoggable()) Log.e(Tag, msg + sb.toString());
|
||||
}
|
||||
|
||||
public static void v(String msg, Object... args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object arg : args) if (arg != null) sb.append(";").append(arg);
|
||||
callOnLoggerListener(4, BuildType, Tag, msg + sb.toString());
|
||||
if (isLoggable()) Log.v(Tag, msg + sb.toString());
|
||||
}
|
||||
|
||||
public static void w(String msg, Object... args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object arg : args) if (arg != null) sb.append(";").append(arg);
|
||||
callOnLoggerListener(5, BuildType, Tag, msg + sb.toString());
|
||||
if (isLoggable()) Log.w(Tag, msg + sb.toString());
|
||||
}
|
||||
|
||||
private static void callOnLoggerListener(int type, String buildType, String tag, String msg) {
|
||||
if (sOnLoggerListener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
OnLoggerListener listener = sOnLoggerListener.get();
|
||||
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 1: listener.onLogI(buildType, tag, msg); break;
|
||||
case 2: listener.onLogD(buildType, tag, msg); break;
|
||||
case 3: listener.onLogE(buildType, tag, msg); break;
|
||||
case 4: listener.onLogV(buildType, tag, msg); break;
|
||||
case 5: listener.onLogW(buildType, tag, msg); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.utils.ImageUtils;
|
||||
|
||||
|
||||
/**
|
||||
* ProjectName: isolated-island
|
||||
* Package: com.qpyy.libcommon.widget
|
||||
* Description: 靓号View(有靓号一定有id特效(靓字+id),有id特效不一是靓号(只显示id))
|
||||
* Author: 姚闻达
|
||||
* CreateDate: 2021/3/16
|
||||
* UpdateUser: 更新者
|
||||
* UpdateDate: 2021/3/16 9:59
|
||||
* UpdateRemark: 更新说明
|
||||
* Version: 1.0
|
||||
*/
|
||||
public class BeautifulNameView extends LinearLayout {
|
||||
private ImageView ivIcon;
|
||||
private ScanTextView stvBeautiful;
|
||||
private int textColor;
|
||||
private int lightColor;
|
||||
private float textSize;
|
||||
private int speed;
|
||||
|
||||
public BeautifulNameView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public BeautifulNameView(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public BeautifulNameView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
private void init(@Nullable AttributeSet attrs) {
|
||||
LayoutInflater.from(getContext()).inflate(R.layout.view_beautiful_name, this, true);
|
||||
ivIcon = findViewById(R.id.iv_liang);
|
||||
stvBeautiful = findViewById(R.id.stv_beautiful_value);
|
||||
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.BeautifulNameView);
|
||||
textColor = typedArray.getInt(R.styleable.BeautifulNameView_textColorc, Color.WHITE);
|
||||
lightColor = typedArray.getInt(R.styleable.BeautifulNameView_lightColor, Color.WHITE);
|
||||
textSize = typedArray.getDimension(R.styleable.BeautifulNameView_textSizec, 12);
|
||||
speed = typedArray.getInt(R.styleable.BeautifulNameView_speed, 50);
|
||||
typedArray.recycle();
|
||||
stvBeautiful.setTextColor(textColor);
|
||||
stvBeautiful.setLightColor(lightColor);
|
||||
stvBeautiful.setTextSize(textSize);
|
||||
stvBeautiful.setSpeed(speed);
|
||||
ImageUtils.loadRes(R.mipmap.me_icon_liang, ivIcon);
|
||||
}
|
||||
|
||||
public void setImg(String url) {
|
||||
if (!TextUtils.isEmpty(url)) {
|
||||
ImageUtils.loadIcon(url, ivIcon);
|
||||
}
|
||||
}
|
||||
|
||||
public void setImg(int resId) {
|
||||
ImageUtils.loadRes(resId, ivIcon);
|
||||
}
|
||||
|
||||
public void setImgVisible(boolean visible) {
|
||||
ivIcon.setVisibility(visible ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
public void setTextColor(String color) {
|
||||
if (TextUtils.isEmpty(color) || !color.startsWith("#")) {
|
||||
return;
|
||||
}
|
||||
stvBeautiful.setTextColor(Color.parseColor(color));
|
||||
}
|
||||
|
||||
public void setTextColor(int color) {
|
||||
stvBeautiful.setTextColor(color);
|
||||
}
|
||||
|
||||
public void setTextSize(float textSize) {
|
||||
stvBeautiful.setTextSize(textSize);
|
||||
}
|
||||
|
||||
public void setText(String value) {
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
stvBeautiful.setText(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 只有服务端返回颜色(id_color字段)才播动效
|
||||
* @param play
|
||||
*/
|
||||
public void setPlay(boolean play) {
|
||||
stvBeautiful.setScan(play);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
/**
|
||||
* 圆形头像
|
||||
*/
|
||||
public class CircularImage extends MaskedImage {
|
||||
|
||||
public CircularImage(Context paramContext) {
|
||||
super(paramContext);
|
||||
}
|
||||
|
||||
public CircularImage(Context paramContext, AttributeSet paramAttributeSet) {
|
||||
super(paramContext, paramAttributeSet);
|
||||
}
|
||||
|
||||
public CircularImage(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
|
||||
super(paramContext, paramAttributeSet, paramInt);
|
||||
}
|
||||
|
||||
public Bitmap createMask() {
|
||||
int i = getWidth();
|
||||
int j = getHeight();
|
||||
Bitmap.Config localConfig = Bitmap.Config.ARGB_8888;
|
||||
Bitmap localBitmap = Bitmap.createBitmap(i, j, localConfig);
|
||||
Canvas localCanvas = new Canvas(localBitmap);
|
||||
Paint localPaint = new Paint(1);
|
||||
float f1 = getWidth();
|
||||
float f2 = getHeight();
|
||||
RectF localRectF = new RectF(0.0F, 0.0F, f1, f2);
|
||||
localCanvas.drawOval(localRectF, localPaint);
|
||||
return localBitmap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatEditText;
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
|
||||
/**
|
||||
* 带删除按钮的editText
|
||||
* Created by air on 2017/1/12.
|
||||
* updated by air on 2017/3/20
|
||||
*/
|
||||
public class ClearEditText extends AppCompatEditText implements View.OnFocusChangeListener, TextWatcher {
|
||||
|
||||
//EditText右侧的删除按钮
|
||||
private Drawable mClearDrawable;
|
||||
|
||||
private boolean hasFocus;
|
||||
|
||||
private onFocusListener onFocusListener;
|
||||
|
||||
public ClearEditText(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public ClearEditText(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, android.R.attr.editTextStyle);
|
||||
}
|
||||
|
||||
public ClearEditText(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
//获取EditText的DrawableRight,假如没有设置我们就使用默认的图片
|
||||
mClearDrawable = getCompoundDrawables()[2];
|
||||
if (mClearDrawable == null) {
|
||||
mClearDrawable = getResources().getDrawable(R.mipmap.common_et_clear_icon);
|
||||
}
|
||||
mClearDrawable.setBounds(0, 0, mClearDrawable.getIntrinsicWidth(),
|
||||
mClearDrawable.getIntrinsicHeight());
|
||||
// 默认设置隐藏图标
|
||||
setClearIconVisible(false);
|
||||
// 设置焦点改变的监听
|
||||
setOnFocusChangeListener(this);
|
||||
// 设置输入框里面内容发生改变的监听
|
||||
addTextChangedListener(this);
|
||||
}
|
||||
|
||||
/* *
|
||||
* @说明:isInnerWidth, isInnerHeight为ture,触摸点在删除图标之内,则视为点击了删除图标
|
||||
* event.getX() 获取相对应自身左上角的X坐标
|
||||
* event.getY() 获取相对应自身左上角的Y坐标
|
||||
* getWidth() 获取控件的宽度
|
||||
* getHeight() 获取控件的高度
|
||||
* getTotalPaddingRight() 获取删除图标左边缘到控件右边缘的距离
|
||||
* getPaddingRight() 获取删除图标右边缘到控件右边缘的距离
|
||||
* isInnerWidth:
|
||||
* getWidth() - getTotalPaddingRight() 计算删除图标左边缘到控件左边缘的距离
|
||||
* getWidth() - getPaddingRight() 计算删除图标右边缘到控件左边缘的距离
|
||||
* isInnerHeight:
|
||||
* distance 删除图标顶部边缘到控件顶部边缘的距离
|
||||
* distance + height 删除图标底部边缘到控件顶部边缘的距离
|
||||
*/
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (getCompoundDrawables()[2] != null) {
|
||||
int x = (int) event.getX();
|
||||
int y = (int) event.getY();
|
||||
Rect rect = getCompoundDrawables()[2].getBounds();
|
||||
int height = rect.height();
|
||||
int distance = (getHeight() - height) / 2;
|
||||
boolean isInnerWidth = x > (getWidth() - getTotalPaddingRight()) && x < (getWidth() - getPaddingRight());
|
||||
boolean isInnerHeight = y > distance && y < (distance + height);
|
||||
if (isInnerWidth && isInnerHeight) {
|
||||
this.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public void setClearIconVisible(boolean visible) {
|
||||
Drawable right = visible ? mClearDrawable : null;
|
||||
setCompoundDrawables(getCompoundDrawables()[0],
|
||||
getCompoundDrawables()[1], right, getCompoundDrawables()[3]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 当ClearEditText焦点发生变化的时候,
|
||||
* 输入长度为零,隐藏删除图标,否则,显示删除图标
|
||||
*/
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
this.hasFocus = hasFocus;
|
||||
if (hasFocus) {
|
||||
setClearIconVisible(getText().length() > 0);
|
||||
if (onFocusListener != null) {
|
||||
onFocusListener.onFocus();
|
||||
}
|
||||
} else {
|
||||
setClearIconVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int count, int after) {
|
||||
if (hasFocus) {
|
||||
setClearIconVisible(s.length() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
public interface onFocusListener {
|
||||
void onFocus();
|
||||
}
|
||||
|
||||
|
||||
public void setOnFocusListener(ClearEditText.onFocusListener onFocusListener) {
|
||||
this.onFocusListener = onFocusListener;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
/**
|
||||
*@author
|
||||
*@data
|
||||
*@description: listview自定义间隔
|
||||
*/
|
||||
public class CommItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
|
||||
private static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
|
||||
|
||||
private int mSpace = 1; //间隔
|
||||
private Rect mRect = new Rect(0,0,0,0);
|
||||
private Paint mPaint = new Paint();
|
||||
|
||||
private int mOrientation;
|
||||
|
||||
private CommItemDecoration(Context context, int orientation, @ColorInt int color, int space) {
|
||||
mOrientation = orientation;
|
||||
if(space>0){
|
||||
mSpace = space;
|
||||
}
|
||||
mPaint.setColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDraw(c, parent, state);
|
||||
if (mOrientation == VERTICAL_LIST) {
|
||||
drawVertical(c, parent);
|
||||
} else {
|
||||
drawHorizontal(c, parent);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawVertical(Canvas c, RecyclerView parent) {
|
||||
final int left = parent.getPaddingLeft();
|
||||
final int right = parent.getWidth() - parent.getPaddingRight();
|
||||
|
||||
final int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
|
||||
.getLayoutParams();
|
||||
final int top = child.getBottom() + params.bottomMargin;
|
||||
final int bottom = top + mSpace;
|
||||
mRect.set(left,top,right,bottom);
|
||||
c.drawRect(mRect,mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHorizontal(Canvas c, RecyclerView parent) {
|
||||
final int top = parent.getPaddingTop();
|
||||
final int bottom = parent.getHeight() - parent.getPaddingBottom();
|
||||
|
||||
final int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
|
||||
.getLayoutParams();
|
||||
final int left = child.getRight() + params.rightMargin;
|
||||
final int right = left + mSpace;
|
||||
mRect.set(left, top, right, bottom);
|
||||
c.drawRect(mRect,mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
if (mOrientation == VERTICAL_LIST) {
|
||||
outRect.set(0, 0, 0,mSpace);
|
||||
} else {
|
||||
outRect.set(0, 0, mSpace, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static CommItemDecoration createVertical(Context context, @ColorInt int color, int height){
|
||||
return new CommItemDecoration(context,VERTICAL_LIST,color,height);
|
||||
}
|
||||
|
||||
public static CommItemDecoration createHorizontal(Context context, @ColorInt int color, int width){
|
||||
return new CommItemDecoration(context,HORIZONTAL_LIST,color,width);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,743 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.qxcm.moduleutil.bean.ConfigBean;
|
||||
import com.qxcm.moduleutil.interfaces.CommonCallback;
|
||||
import com.qxcm.moduleutil.utils.DeviceUtils;
|
||||
import com.qxcm.moduleutil.utils.LanguageUtil;
|
||||
import com.qxcm.moduleutil.utils.SpUtil;
|
||||
import com.qxcm.moduleutil.utils.StringUtil;
|
||||
import com.qxcm.moduleutil.utils.WordUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/8/4 .
|
||||
*/
|
||||
|
||||
public class CommonAppConfig {
|
||||
public static final String PACKAGE_NAME = "com.qxcm.liveShort";
|
||||
//Http请求头 Header
|
||||
public static final Map<String, String> HEADER = new HashMap<>();
|
||||
//域名
|
||||
public static final String HOST = getHost();
|
||||
|
||||
public static final String EXTERNAL_PATH = getExternalPath();
|
||||
public static final String DOWNLOAD_PATH = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();
|
||||
public static final String VIDEO_PATH = EXTERNAL_PATH + "/video/";
|
||||
public static final String VIDEO_RECORD_PATH = VIDEO_PATH + "/record/";
|
||||
public static final String VIDEO_RECORD_PARTS_PATH = VIDEO_RECORD_PATH + "/parts/";
|
||||
//下载视频保存路径
|
||||
public static final String VIDEO_DOWNLOAD_PATH = DOWNLOAD_PATH + "/video/";
|
||||
//下载音乐保存路径
|
||||
public static final String MUSIC_PATH = EXTERNAL_PATH + "/music/";
|
||||
|
||||
public static final String IMAGE_PATH = EXTERNAL_PATH + "/image/";
|
||||
//下载图片保存路径
|
||||
public static final String IMAGE_DOWNLOAD_PATH = DOWNLOAD_PATH + "/image/";
|
||||
//log保存路径
|
||||
public static final String LOG_PATH = EXTERNAL_PATH + "/log/";
|
||||
|
||||
public static final String GIF_PATH = EXTERNAL_PATH + "/gif/";
|
||||
public static final String WATER_MARK_PATH = EXTERNAL_PATH + "/water/";
|
||||
public static final String IM_SOUND = EXTERNAL_PATH + "/im_sound/";
|
||||
public static final String IM_IMAGE = EXTERNAL_PATH + "/im_image/";
|
||||
//腾讯IM appId
|
||||
public static final int TX_IM_APP_ID = getMetaDataInt("TxIMAppId");
|
||||
//QQ登录是否与PC端互通
|
||||
public static final boolean QQ_LOGIN_WITH_PC = false;
|
||||
//是否使用游戏
|
||||
public static final boolean GAME_ENABLE = true;
|
||||
//是否上下滑动切换直播间
|
||||
public static final boolean LIVE_ROOM_SCROLL = true;
|
||||
|
||||
private static String getExternalPath() {
|
||||
String outPath = null;
|
||||
try {
|
||||
File externalFilesDir = CommonAppContext.getInstance().getExternalFilesDir("yunbao");
|
||||
if (externalFilesDir != null) {
|
||||
if (!externalFilesDir.exists()) {
|
||||
externalFilesDir.mkdirs();
|
||||
}
|
||||
outPath = externalFilesDir.getAbsolutePath();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
outPath = null;
|
||||
}
|
||||
if (TextUtils.isEmpty(outPath)) {
|
||||
outPath = CommonAppContext.getInstance().getFilesDir().getAbsolutePath();
|
||||
}
|
||||
return outPath;
|
||||
}
|
||||
|
||||
private static CommonAppConfig sInstance;
|
||||
|
||||
private CommonAppConfig() {
|
||||
|
||||
}
|
||||
|
||||
public static CommonAppConfig getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (CommonAppConfig.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new CommonAppConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private String mUid;
|
||||
private String mToken;
|
||||
private ConfigBean mConfig;
|
||||
private double mLng;
|
||||
private double mLat;
|
||||
private String mProvince;//省
|
||||
private String mCity;//市
|
||||
private String mDistrict;//区
|
||||
// private UserBean mUserBean;
|
||||
// private UserBean mEmptyUserBean;//未登录游客
|
||||
private String mVersion;
|
||||
private boolean mLaunched;//App是否启动了
|
||||
// private SparseArray<LevelBean> mLevelMap;
|
||||
// private SparseArray<LevelBean> mAnchorLevelMap;
|
||||
private String mGiftListJson;
|
||||
private String mGiftDaoListJson;
|
||||
private String mTxMapAppKey;//腾讯定位,地图的AppKey
|
||||
private String mTxMapAppSecret;//腾讯地图的AppSecret
|
||||
private boolean mFrontGround;
|
||||
private int mAppIconRes;
|
||||
private String mAppName;
|
||||
private Boolean mMhBeautyEnable;//是否使用美狐 true使用美狐 false 使用基础美颜
|
||||
private String mDeviceId;
|
||||
private Boolean mTeenagerType;//是否是青少年模式
|
||||
private int mTopActivityType;//最上面的Activity的类型 1直播间 2消息
|
||||
private boolean mShowLiveFloatWindow;//退出直播后是否显示直播悬浮窗
|
||||
|
||||
public String getUid() {
|
||||
if (TextUtils.isEmpty(mUid)) {
|
||||
String[] uidAndToken = SpUtil.getInstance()
|
||||
.getMultiStringValue(new String[]{SpUtil.UID, SpUtil.TOKEN});
|
||||
if (uidAndToken != null) {
|
||||
if (!TextUtils.isEmpty(uidAndToken[0]) && !TextUtils.isEmpty(uidAndToken[1])) {
|
||||
mUid = uidAndToken[0];
|
||||
mToken = uidAndToken[1];
|
||||
} else {
|
||||
mUid = Constants.NOT_LOGIN_UID;
|
||||
mToken = Constants.NOT_LOGIN_TOKEN;
|
||||
}
|
||||
} else {
|
||||
mUid = Constants.NOT_LOGIN_UID;
|
||||
mToken = Constants.NOT_LOGIN_TOKEN;
|
||||
}
|
||||
}
|
||||
return mUid;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return mToken;
|
||||
}
|
||||
|
||||
public boolean isLogin() {
|
||||
return !Constants.NOT_LOGIN_UID.equals(getUid());
|
||||
}
|
||||
|
||||
public String getCoinName() {
|
||||
ConfigBean configBean = getConfig();
|
||||
if (configBean != null) {
|
||||
return configBean.getCoinName();
|
||||
}
|
||||
return Constants.DIAMONDS;
|
||||
}
|
||||
|
||||
public String getVotesName() {
|
||||
ConfigBean configBean = getConfig();
|
||||
if (configBean != null) {
|
||||
return configBean.getVotesName();
|
||||
}
|
||||
return Constants.VOTES;
|
||||
}
|
||||
|
||||
|
||||
public String getScoreName() {
|
||||
ConfigBean configBean = getConfig();
|
||||
if (configBean != null) {
|
||||
return configBean.getScoreName();
|
||||
}
|
||||
return Constants.SCORE;
|
||||
}
|
||||
|
||||
public ConfigBean getConfig() {
|
||||
if (mConfig == null) {
|
||||
String configString = SpUtil.getInstance().getStringValue(SpUtil.CONFIG);
|
||||
if (!TextUtils.isEmpty(configString)) {
|
||||
mConfig = JSON.parseObject(configString, ConfigBean.class);
|
||||
}
|
||||
}
|
||||
return mConfig;
|
||||
}
|
||||
|
||||
public void getConfig(CommonCallback<ConfigBean> callback) {
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
ConfigBean configBean = getConfig();
|
||||
if (configBean != null) {
|
||||
callback.callback(configBean);
|
||||
} else {
|
||||
// CommonHttpUtil.getConfig(callback);
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfig(ConfigBean config) {
|
||||
mConfig = config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
public double getLng() {
|
||||
if (mLng == 0) {
|
||||
String lng = SpUtil.getInstance().getStringValue(SpUtil.LOCATION_LNG);
|
||||
if (!TextUtils.isEmpty(lng)) {
|
||||
try {
|
||||
mLng = Double.parseDouble(lng);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mLng;
|
||||
}
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
public double getLat() {
|
||||
if (mLat == 0) {
|
||||
String lat = SpUtil.getInstance().getStringValue(SpUtil.LOCATION_LAT);
|
||||
if (!TextUtils.isEmpty(lat)) {
|
||||
try {
|
||||
mLat = Double.parseDouble(lat);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mLat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
public String getProvince() {
|
||||
if (TextUtils.isEmpty(mProvince)) {
|
||||
mProvince = SpUtil.getInstance().getStringValue(SpUtil.LOCATION_PROVINCE);
|
||||
}
|
||||
return mProvince == null ? "" : mProvince;
|
||||
}
|
||||
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
public String getCity() {
|
||||
if (TextUtils.isEmpty(mCity)) {
|
||||
mCity = SpUtil.getInstance().getStringValue(SpUtil.LOCATION_CITY);
|
||||
}
|
||||
return mCity == null ? "" : mCity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 区
|
||||
*/
|
||||
public String getDistrict() {
|
||||
if (TextUtils.isEmpty(mDistrict)) {
|
||||
mDistrict = SpUtil.getInstance().getStringValue(SpUtil.LOCATION_DISTRICT);
|
||||
}
|
||||
return mDistrict == null ? "" : mDistrict;
|
||||
}
|
||||
|
||||
// public void setUserBean(UserBean bean) {
|
||||
// mUserBean = bean;
|
||||
// }
|
||||
|
||||
// public UserBean getUserBean() {
|
||||
// if (mUserBean == null) {
|
||||
// String userBeanJson = SpUtil.getInstance().getStringValue(SpUtil.USER_INFO);
|
||||
// if (!TextUtils.isEmpty(userBeanJson)) {
|
||||
//// mUserBean = JSON.parseObject(userBeanJson, UserBean.class);
|
||||
// }
|
||||
// }
|
||||
// if (mUserBean == null) {
|
||||
//// mUserBean = getEmptyUserBean();
|
||||
// }
|
||||
// return mUserBean;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 设置美狐是否可用
|
||||
*/
|
||||
public void setMhBeautyEnable(boolean mhBeautyEnable) {
|
||||
mMhBeautyEnable = mhBeautyEnable;
|
||||
SpUtil.getInstance().setBooleanValue(SpUtil.MH_BEAUTY_ENABLE, mhBeautyEnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 美狐是否可用
|
||||
*/
|
||||
public boolean isMhBeautyEnable() {
|
||||
if (mMhBeautyEnable == null) {
|
||||
mMhBeautyEnable = SpUtil.getInstance().getBooleanValue(SpUtil.MH_BEAUTY_ENABLE);
|
||||
}
|
||||
return mMhBeautyEnable;
|
||||
}
|
||||
|
||||
|
||||
public void setTeenagerType(boolean teenagerType) {
|
||||
mTeenagerType = teenagerType;
|
||||
SpUtil.getInstance().setBooleanValue(SpUtil.TEENAGER, teenagerType);
|
||||
}
|
||||
|
||||
public boolean isTeenagerType() {
|
||||
if (mTeenagerType == null) {
|
||||
mTeenagerType = SpUtil.getInstance().getBooleanValue(SpUtil.TEENAGER);
|
||||
}
|
||||
return mTeenagerType;
|
||||
}
|
||||
|
||||
public void setShowLiveFloatWindow(boolean showLiveFloatWindow) {
|
||||
mShowLiveFloatWindow = showLiveFloatWindow;
|
||||
}
|
||||
|
||||
public boolean isShowLiveFloatWindow() {
|
||||
return mShowLiveFloatWindow;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置登录信息
|
||||
*/
|
||||
public void setLoginInfo(String uid, String token, boolean save) {
|
||||
LogUtils.e("登录成功", "uid------>" + uid);
|
||||
LogUtils.e("登录成功", "token------>" + token);
|
||||
mUid = uid;
|
||||
mToken = token;
|
||||
if (save) {
|
||||
SpUtil.getInstance().setBooleanValue(SpUtil.TEENAGER_SHOW, false);
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(SpUtil.UID, uid);
|
||||
map.put(SpUtil.TOKEN, token);
|
||||
SpUtil.getInstance().setMultiStringValue(map);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除登录信息
|
||||
*/
|
||||
public void clearLoginInfo() {
|
||||
mUid = null;
|
||||
mToken = null;
|
||||
SpUtil.getInstance().removeValue(
|
||||
SpUtil.UID, SpUtil.TOKEN, SpUtil.USER_INFO, SpUtil.TX_IM_USER_SIGN,
|
||||
Constants.CASH_ACCOUNT_ID, Constants.CASH_ACCOUNT, Constants.CASH_ACCOUNT_TYPE,
|
||||
SpUtil.TEENAGER, SpUtil.TEENAGER_SHOW
|
||||
);
|
||||
// CommonAppConfig.getInstance().setUserBean(getEmptyUserBean());
|
||||
mShowLiveFloatWindow = false;
|
||||
// EventBus.getDefault().post(new CloseFloatWindowEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 未登录,游客
|
||||
*/
|
||||
// private UserBean getEmptyUserBean() {
|
||||
// if (mEmptyUserBean == null) {
|
||||
// UserBean bean = new UserBean();
|
||||
// bean.setId(Constants.NOT_LOGIN_UID);
|
||||
// bean.setUserNiceName("游客");
|
||||
// bean.setLevel(1);
|
||||
// bean.setLevelAnchor(1);
|
||||
// String defaultAvatar = CommonAppConfig.HOST + "/default.jpg";
|
||||
// bean.setAvatar(defaultAvatar);
|
||||
// bean.setAvatarThumb(defaultAvatar);
|
||||
// bean.setSignature(Constants.EMPTY_STRING);
|
||||
// bean.setCoin(Constants.EMPTY_STRING);
|
||||
// bean.setVotes(Constants.EMPTY_STRING);
|
||||
// bean.setConsumption(Constants.EMPTY_STRING);
|
||||
// bean.setVotestotal(Constants.EMPTY_STRING);
|
||||
// bean.setProvince(Constants.EMPTY_STRING);
|
||||
// bean.setCity(Constants.EMPTY_STRING);
|
||||
// bean.setLocation(Constants.EMPTY_STRING);
|
||||
// bean.setBirthday(Constants.EMPTY_STRING);
|
||||
// bean.setVip(new UserBean.Vip());
|
||||
// bean.setLiang(new UserBean.Liang());
|
||||
// bean.setCar(new UserBean.Car());
|
||||
// mEmptyUserBean = bean;
|
||||
// }
|
||||
// return mEmptyUserBean;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 设置位置信息
|
||||
*
|
||||
* @param lng 经度
|
||||
* @param lat 纬度
|
||||
*/
|
||||
public void setLngLat(double lng, double lat) {
|
||||
mLng = lng;
|
||||
mLat = lat;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(SpUtil.LOCATION_LNG, String.valueOf(lng));
|
||||
map.put(SpUtil.LOCATION_LAT, String.valueOf(lat));
|
||||
SpUtil.getInstance().setMultiStringValue(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置位置信息
|
||||
*
|
||||
* @param lng 经度
|
||||
* @param lat 纬度
|
||||
* @param province 省
|
||||
* @param city 市
|
||||
*/
|
||||
public void setLocationInfo(double lng, double lat, String province, String city, String district) {
|
||||
mLng = lng;
|
||||
mLat = lat;
|
||||
mProvince = province;
|
||||
mCity = city;
|
||||
mDistrict = district;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(SpUtil.LOCATION_LNG, String.valueOf(lng));
|
||||
map.put(SpUtil.LOCATION_LAT, String.valueOf(lat));
|
||||
map.put(SpUtil.LOCATION_PROVINCE, province);
|
||||
map.put(SpUtil.LOCATION_CITY, city);
|
||||
map.put(SpUtil.LOCATION_DISTRICT, district);
|
||||
SpUtil.getInstance().setMultiStringValue(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除定位信息
|
||||
*/
|
||||
public void clearLocationInfo() {
|
||||
mLng = 0;
|
||||
mLat = 0;
|
||||
mProvince = null;
|
||||
mCity = null;
|
||||
mDistrict = null;
|
||||
SpUtil.getInstance().removeValue(
|
||||
SpUtil.LOCATION_LNG,
|
||||
SpUtil.LOCATION_LAT,
|
||||
SpUtil.LOCATION_PROVINCE,
|
||||
SpUtil.LOCATION_CITY,
|
||||
SpUtil.LOCATION_DISTRICT);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取版本号
|
||||
*/
|
||||
public String getVersion() {
|
||||
if (TextUtils.isEmpty(mVersion)) {
|
||||
try {
|
||||
PackageManager manager = CommonAppContext.getInstance().getPackageManager();
|
||||
PackageInfo info = manager.getPackageInfo(PACKAGE_NAME, 0);
|
||||
mVersion = info.versionName;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
public static boolean isYunBaoApp() {
|
||||
if (!TextUtils.isEmpty(PACKAGE_NAME)) {
|
||||
return PACKAGE_NAME.contains("com.yunbao.phoneliv");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取App名称
|
||||
*/
|
||||
public String getAppName() {
|
||||
if (TextUtils.isEmpty(mAppName)) {
|
||||
int res = CommonAppContext.getInstance().getResources().getIdentifier("app_name", "string", "com.qxcm.liveShort");
|
||||
mAppName = WordUtil.getString(res);
|
||||
}
|
||||
return mAppName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取App图标的资源id
|
||||
*/
|
||||
public int getAppIconRes() {
|
||||
if (mAppIconRes == 0) {
|
||||
mAppIconRes = CommonAppContext.getInstance().getResources().getIdentifier("icon_app", "mipmap", "com.qxcm.liveShort");
|
||||
}
|
||||
return mAppIconRes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取MetaData中的腾讯定位,地图的AppKey
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTxMapAppKey() {
|
||||
if (mTxMapAppKey == null) {
|
||||
mTxMapAppKey = getMetaDataString("TencentMapSDK");
|
||||
}
|
||||
return mTxMapAppKey;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取MetaData中的腾讯定位,地图的AppSecret
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTxMapAppSecret() {
|
||||
if (mTxMapAppSecret == null) {
|
||||
mTxMapAppSecret = getMetaDataString("TencentMapAppSecret");
|
||||
}
|
||||
return mTxMapAppSecret;
|
||||
}
|
||||
|
||||
|
||||
public static String getMetaDataString(String key) {
|
||||
String res = null;
|
||||
try {
|
||||
ApplicationInfo appInfo = CommonAppContext.getInstance().getPackageManager().getApplicationInfo(PACKAGE_NAME, PackageManager.GET_META_DATA);
|
||||
res = appInfo.metaData.getString(key);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static boolean getMetaDataBoolean(String key) {
|
||||
boolean res = false;
|
||||
try {
|
||||
ApplicationInfo appInfo = CommonAppContext.getInstance().getPackageManager().getApplicationInfo(PACKAGE_NAME, PackageManager.GET_META_DATA);
|
||||
res = appInfo.metaData.getBoolean(key);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static int getMetaDataInt(String key) {
|
||||
int res = 0;
|
||||
try {
|
||||
ApplicationInfo appInfo = CommonAppContext.getInstance().getPackageManager().getApplicationInfo(PACKAGE_NAME, PackageManager.GET_META_DATA);
|
||||
res = appInfo.metaData.getInt(key, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static String getHost() {
|
||||
String host = getMetaDataString("SERVER_HOST");
|
||||
HEADER.put("referer", host);
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存用户等级信息
|
||||
*/
|
||||
// public void setLevel(String levelJson) {
|
||||
// if (TextUtils.isEmpty(levelJson)) {
|
||||
// return;
|
||||
// }
|
||||
// List<LevelBean> list = JSON.parseArray(levelJson, LevelBean.class);
|
||||
// if (list == null || list.size() == 0) {
|
||||
// return;
|
||||
// }
|
||||
// if (mLevelMap == null) {
|
||||
// mLevelMap = new SparseArray<>();
|
||||
// }
|
||||
// mLevelMap.clear();
|
||||
// for (LevelBean bean : list) {
|
||||
// mLevelMap.put(bean.getLevel(), bean);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 保存主播等级信息
|
||||
*/
|
||||
// public void setAnchorLevel(String anchorLevelJson) {
|
||||
// if (TextUtils.isEmpty(anchorLevelJson)) {
|
||||
// return;
|
||||
// }
|
||||
// List<LevelBean> list = JSON.parseArray(anchorLevelJson, LevelBean.class);
|
||||
// if (list == null || list.size() == 0) {
|
||||
// return;
|
||||
// }
|
||||
// if (mAnchorLevelMap == null) {
|
||||
// mAnchorLevelMap = new SparseArray<>();
|
||||
// }
|
||||
// mAnchorLevelMap.clear();
|
||||
// for (LevelBean bean : list) {
|
||||
// mAnchorLevelMap.put(bean.getLevel(), bean);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取用户等级
|
||||
*/
|
||||
// public LevelBean getLevel(int level) {
|
||||
// if (mLevelMap == null) {
|
||||
// String configString = SpUtil.getInstance().getStringValue(SpUtil.CONFIG);
|
||||
// if (!TextUtils.isEmpty(configString)) {
|
||||
// JSONObject obj = JSON.parseObject(configString);
|
||||
// setLevel(obj.getString("level"));
|
||||
// }
|
||||
// }
|
||||
// if (mLevelMap == null || mLevelMap.size() == 0) {
|
||||
// return null;
|
||||
// }
|
||||
// return mLevelMap.get(level);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取主播等级
|
||||
*/
|
||||
// public LevelBean getAnchorLevel(int level) {
|
||||
// if (mAnchorLevelMap == null) {
|
||||
// String configString = SpUtil.getInstance().getStringValue(SpUtil.CONFIG);
|
||||
// if (!TextUtils.isEmpty(configString)) {
|
||||
// JSONObject obj = JSON.parseObject(configString);
|
||||
// setAnchorLevel(obj.getString("levelanchor"));
|
||||
// }
|
||||
// }
|
||||
// if (mAnchorLevelMap == null || mAnchorLevelMap.size() == 0) {
|
||||
// return null;
|
||||
// }
|
||||
// return mAnchorLevelMap.get(level);
|
||||
// }
|
||||
|
||||
public String getGiftListJson() {
|
||||
return mGiftListJson;
|
||||
}
|
||||
|
||||
public void setGiftListJson(String getGiftListJson) {
|
||||
mGiftListJson = getGiftListJson;
|
||||
}
|
||||
|
||||
|
||||
public String getGiftDaoListJson() {
|
||||
return mGiftDaoListJson;
|
||||
}
|
||||
|
||||
public void setGiftDaoListJson(String getGiftDaoListJson) {
|
||||
mGiftDaoListJson = getGiftDaoListJson;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断某APP是否安装
|
||||
*/
|
||||
public static boolean isAppExist(String packageName) {
|
||||
if (!TextUtils.isEmpty(packageName)) {
|
||||
PackageManager manager = CommonAppContext.getInstance().getPackageManager();
|
||||
List<PackageInfo> list = manager.getInstalledPackages(0);
|
||||
for (PackageInfo info : list) {
|
||||
if (packageName.equalsIgnoreCase(info.packageName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isLaunched() {
|
||||
return mLaunched;
|
||||
}
|
||||
|
||||
public void setLaunched(boolean launched) {
|
||||
mLaunched = launched;
|
||||
}
|
||||
|
||||
//app是否在前台
|
||||
public boolean isFrontGround() {
|
||||
return mFrontGround;
|
||||
}
|
||||
|
||||
//app是否在前台
|
||||
public void setFrontGround(boolean frontGround) {
|
||||
mFrontGround = frontGround;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
if (TextUtils.isEmpty(mDeviceId)) {
|
||||
String deviceId = SpUtil.getInstance().getStringValue(SpUtil.DEVICE_ID);
|
||||
if (TextUtils.isEmpty(deviceId)) {
|
||||
deviceId = DeviceUtils.getDeviceId();
|
||||
SpUtil.getInstance().setStringValue(SpUtil.DEVICE_ID, deviceId);
|
||||
}
|
||||
mDeviceId = deviceId;
|
||||
}
|
||||
LogUtils.e("getDeviceId---mDeviceId-----> " + mDeviceId);
|
||||
return mDeviceId;
|
||||
}
|
||||
|
||||
public int getTopActivityType() {
|
||||
return mTopActivityType;
|
||||
}
|
||||
|
||||
public void setTopActivityType(int topActivityType) {
|
||||
mTopActivityType = topActivityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是基本功能模式
|
||||
*/
|
||||
public boolean isBaseFunctionMode() {
|
||||
return SpUtil.getInstance().getBooleanValue(SpUtil.BASE_FUNCTION_MODE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置基本功能模式
|
||||
*/
|
||||
public void setBaseFunctionMode(boolean baseFunctionMode) {
|
||||
SpUtil.getInstance().setBooleanValue(SpUtil.BASE_FUNCTION_MODE, baseFunctionMode);
|
||||
}
|
||||
|
||||
public static String getHtmlUrl(String url) {
|
||||
if (!TextUtils.isEmpty(url) && url.startsWith(CommonAppConfig.HOST)) {
|
||||
if (!url.contains("?")) {
|
||||
url = StringUtil.contact(url, "?");
|
||||
}
|
||||
url = StringUtil.contact(url,
|
||||
"&uid=", CommonAppConfig.getInstance().getUid(),
|
||||
"&token=", CommonAppConfig.getInstance().getToken(),
|
||||
"&", Constants.LANGUAGE, "=", LanguageUtil.getInstance().getLanguage()
|
||||
);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public boolean isPrivateMsgSwitchOpen() {
|
||||
ConfigBean configBean = getConfig();
|
||||
if (configBean != null) {
|
||||
return configBean.getPriMsgSwitch() == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Base64;
|
||||
|
||||
import androidx.multidex.MultiDex;
|
||||
import androidx.multidex.MultiDexApplication;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.qxcm.moduleutil.event.AppLifecycleEvent;
|
||||
import com.qxcm.moduleutil.interfaces.AppLifecycleUtil;
|
||||
import com.qxcm.moduleutil.utils.FloatWindowHelper;
|
||||
import com.qxcm.moduleutil.utils.SpUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/8/3.
|
||||
*/
|
||||
|
||||
public class CommonAppContext extends MultiDexApplication {
|
||||
|
||||
private static CommonAppContext sInstance;
|
||||
private static Handler sMainThreadHandler;
|
||||
private int mCount;
|
||||
private boolean mFront;//是否前台
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
sInstance = this;
|
||||
sMainThreadHandler=new Handler();
|
||||
registerActivityLifecycleCallbacks();
|
||||
}
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
MultiDex.install(this);
|
||||
super.attachBaseContext(base);
|
||||
}
|
||||
|
||||
public static CommonAppContext getInstance() {
|
||||
if (sInstance == null) {
|
||||
try {
|
||||
Class clazz = Class.forName("android.app.ActivityThread");
|
||||
Method method = clazz.getMethod("currentApplication", new Class[]{});
|
||||
Object obj = method.invoke(null, new Object[]{});
|
||||
if (obj != null && obj instanceof CommonAppContext) {
|
||||
sInstance = (CommonAppContext) obj;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void postDelayed(Runnable runnable, long delayMillis) {
|
||||
if (sMainThreadHandler != null) {
|
||||
sMainThreadHandler.postDelayed(runnable, delayMillis);
|
||||
}
|
||||
}
|
||||
|
||||
public static void post(Runnable runnable) {
|
||||
if (sMainThreadHandler != null) {
|
||||
sMainThreadHandler.post(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return SpUtil.getToken();
|
||||
}
|
||||
private void registerActivityLifecycleCallbacks() {
|
||||
registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
mCount++;
|
||||
if (!mFront) {
|
||||
mFront = true;
|
||||
LogUtils.e("AppContext------->处于前台");
|
||||
EventBus.getDefault().post(new AppLifecycleEvent(true));
|
||||
CommonAppConfig.getInstance().setFrontGround(true);
|
||||
FloatWindowHelper.setFloatWindowVisible(true);
|
||||
AppLifecycleUtil.onAppFrontGround();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
mCount--;
|
||||
if (mCount == 0) {
|
||||
mFront = false;
|
||||
LogUtils.e("AppContext------->处于后台");
|
||||
EventBus.getDefault().post(new AppLifecycleEvent(false));
|
||||
CommonAppConfig.getInstance().setFrontGround(false);
|
||||
FloatWindowHelper.setFloatWindowVisible(false);
|
||||
AppLifecycleUtil.onAppBackGround();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取App签名md5值
|
||||
*/
|
||||
public String getAppSignature() {
|
||||
try {
|
||||
PackageInfo info =
|
||||
this.getPackageManager().getPackageInfo(this.getPackageName(),
|
||||
PackageManager.GET_SIGNATURES);
|
||||
if (info != null) {
|
||||
Signature[] signs = info.signatures;
|
||||
byte[] bytes = signs[0].toByteArray();
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(bytes);
|
||||
bytes = md.digest();
|
||||
StringBuilder stringBuilder = new StringBuilder(2 * bytes.length);
|
||||
for (int i = 0; ; i++) {
|
||||
if (i >= bytes.length) {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
String str = Integer.toString(0xFF & bytes[i], 16);
|
||||
if (str.length() == 1) {
|
||||
str = "0" + str;
|
||||
}
|
||||
stringBuilder.append(str);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取facebook散列秘钥
|
||||
*/
|
||||
public String getFacebookHashKey() {
|
||||
try {
|
||||
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
|
||||
for (Signature signature : info.signatures) {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA");
|
||||
md.update(signature.toByteArray());
|
||||
return Base64.encodeToString(md.digest(), Base64.DEFAULT);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return "get error";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isFront() {
|
||||
return mFront;
|
||||
}
|
||||
|
||||
public void startInitSdk(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/6/7.
|
||||
*/
|
||||
|
||||
public class Constants {
|
||||
public static final String URL = "url";
|
||||
public static final String PAYLOAD = "payload";
|
||||
public static final String SEX = "sex";
|
||||
public static final String NICK_NAME = "nickname";
|
||||
public static final String AVATAR = "avatar";
|
||||
public static final String SIGN = "sign";
|
||||
public static final String TO_UID = "toUid";
|
||||
public static final String FROM_LIVE_ROOM = "fromLiveRoom";
|
||||
public static final String FROM_LOGIN = "fromLogin";
|
||||
public static final String TO_NAME = "toName";
|
||||
public static final String STREAM = "stream";
|
||||
public static final String LIMIT = "limit";
|
||||
public static final String UID = "uid";
|
||||
public static final String TIP = "tip";
|
||||
public static final String EXIT = "exit";
|
||||
public static final String FIRST_LOGIN = "firstLogin";
|
||||
public static final String USER_BEAN = "userBean";
|
||||
public static final String CLASS_ID = "classID";
|
||||
public static final String CLASS_NAME = "className";
|
||||
public static final String CHECKED_ID = "checkedId";
|
||||
public static final String CHECKED_COIN = "checkedCoin";
|
||||
public static final String LIVE_DANMU_PRICE = "danmuPrice";
|
||||
public static final String COIN_NAME = "coinName";
|
||||
public static final String AT_NAME = "atName";
|
||||
public static final String LIVE_BEAN = "liveBean";
|
||||
public static final String LIVE_TYPE = "liveType";
|
||||
public static final String LIVE_KEY = "liveKey";
|
||||
public static final String LIVE_POSITION = "livePosition";
|
||||
public static final String LIVE_TYPE_VAL = "liveTypeVal";
|
||||
public static final String LIVE_UID = "liveUid";
|
||||
public static final String LIVE_PLAY_URL = "livePlayUrl";
|
||||
public static final String SHARE_UID = "shareUid";
|
||||
public static final String LIVE_STREAM = "liveStream";
|
||||
public static final String OPEN_PACK = "openPack";
|
||||
public static final String LIVE_HOME = "liveHome";
|
||||
public static final String LIVE_FOLLOW = "liveFollow";
|
||||
public static final String LIVE_NEAR = "liveNear";
|
||||
public static final String LIVE_CLASS_PREFIX = "liveClass_";
|
||||
public static final String LIVE_CLASS_RECOMMEND = "liveRecommend";
|
||||
public static final String LIVE_ADMIN_ROOM = "liveAdminRoom";
|
||||
public static final String HAS_GAME = "hasGame";
|
||||
public static final String OPEN_FLASH = "openFlash";
|
||||
public static final String LINK_MIC = "linkMic";
|
||||
public static final String SHARE_QR_CODE_FILE = "shareQrCodeFile.png";
|
||||
public static final String ANCHOR = "anchor";
|
||||
public static final String FOLLOW = "follow";
|
||||
public static final String DIAMONDS = "钻石";
|
||||
public static final String VOTES = "映票";
|
||||
public static final String SCORE = "积分";
|
||||
public static final String PAY_TYPE_ALI = "ali";
|
||||
public static final String PAY_TYPE_WX = "wx";
|
||||
public static final String PAY_TYPE_PAYPAL = "paypal";
|
||||
public static final String PAY_TYPE_BALANCE = "balance";
|
||||
public static final String PAY_BUY_COIN_ALI = "Charge.getAliOrder";
|
||||
public static final String PAY_BUY_COIN_WX = "Charge.getWxOrder";
|
||||
public static final String PAY_BUY_COIN_PAYPAL = "Charge.getBraintreePaypalOrder";
|
||||
|
||||
public static final String PACKAGE_NAME_ALI = "com.eg.android.AlipayGphone";//支付宝的包名
|
||||
public static final String PACKAGE_NAME_WX = "com.tencent.mm";//微信的包名
|
||||
public static final String PACKAGE_NAME_QQ = "com.tencent.mobileqq";//QQ的包名
|
||||
public static final String PACKAGE_NAME_GAODE_MAP = "com.autonavi.minimap";//高德地图包名
|
||||
public static final String PACKAGE_NAME_BAIDU_MAP = "com.baidu.BaiduMap";//百度地图包名
|
||||
public static final String PACKAGE_NAME_TX_MAP = "com.tencent.map";//腾讯地图包名
|
||||
public static final String LAT = "lat";
|
||||
public static final String LNG = "lng";
|
||||
public static final String ADDRESS = "address";
|
||||
public static final String SELECT_IMAGE_PATH = "selectedImagePath";
|
||||
public static final String COPY_PREFIX = "copy://";
|
||||
public static final String TEL_PREFIX = "tel://";
|
||||
public static final String AUTH_PREFIX = "auth://";
|
||||
public static final int GUARD_TYPE_NONE = 0;
|
||||
public static final int GUARD_TYPE_MONTH = 1;
|
||||
public static final int GUARD_TYPE_YEAR = 2;
|
||||
|
||||
public static final String DOWNLOAD_MUSIC = "downloadMusic";
|
||||
public static final String LINK = "link";
|
||||
public static final String REPORT = "report";
|
||||
public static final String SAVE = "save";
|
||||
public static final String DELETE = "delete";
|
||||
public static final String GOODS = "goods";
|
||||
public static final String MAX_COUNT = "maxCount";
|
||||
public static final String USE_CAMERA = "useCamera";
|
||||
public static final String USE_PREVIEW = "usePreview";
|
||||
|
||||
|
||||
public static final int SETTING_MODIFY_PWD = 15;
|
||||
public static final int SETTING_UPDATE_ID = 16;
|
||||
public static final int SETTING_CLEAR_CACHE = 18;
|
||||
public static final int SEX_MALE = 1;
|
||||
public static final int SEX_FEMALE = 2;
|
||||
public static final int FOLLOW_FROM_FOLLOW = 1002;
|
||||
public static final int FOLLOW_FROM_FANS = 1003;
|
||||
public static final int FOLLOW_FROM_SEARCH = 1004;
|
||||
public static final String IM_FROM_HOME = "imFromHome";
|
||||
//直播房间类型
|
||||
public static final int LIVE_TYPE_NORMAL = 0;//普通房间
|
||||
public static final int LIVE_TYPE_PWD = 1;//密码房间
|
||||
public static final int LIVE_TYPE_PAY = 2;//收费房间
|
||||
public static final int LIVE_TYPE_TIME = 3;//计时房间
|
||||
//主播直播间功能
|
||||
public static final int LIVE_FUNC_BEAUTY = 2001;//美颜
|
||||
public static final int LIVE_FUNC_CAMERA = 2002;//切换摄像头
|
||||
public static final int LIVE_FUNC_FLASH = 2003;//闪光灯
|
||||
public static final int LIVE_FUNC_MUSIC = 2004;//伴奏
|
||||
public static final int LIVE_FUNC_SHARE = 2005;//分享
|
||||
public static final int LIVE_FUNC_GAME = 2006;//游戏
|
||||
public static final int LIVE_FUNC_RED_PACK = 2007;//红包
|
||||
public static final int LIVE_FUNC_LINK_MIC = 2008;//连麦
|
||||
public static final int LIVE_FUNC_MIRROR = 2009;//镜像
|
||||
public static final int LIVE_FUNC_TASK = 2010;//每日任务
|
||||
public static final int LIVE_FUNC_LUCK = 2011;//幸运奖池
|
||||
public static final int LIVE_FUNC_PAN = 2012;//转盘
|
||||
public static final int LIVE_FUNC_MSG = 2013;//私信
|
||||
public static final int LIVE_FUNC_FACE = 2014;//表情
|
||||
public static final int LIVE_FUNC_LINK_MIC_AUD = 2015;//用户连麦
|
||||
public static final int LIVE_FUNC_REPORT = 2016;//举报
|
||||
//socket
|
||||
public static final String SOCKET_CONN = "conn";
|
||||
public static final String SOCKET_BROADCAST = "broadcastingListen";
|
||||
public static final String SOCKET_SEND = "broadcast";
|
||||
public static final String SOCKET_STOP_PLAY = "stopplay";//超管关闭直播间
|
||||
public static final String SOCKET_STOP_LIVE = "stopLive";//超管关闭直播间
|
||||
public static final String SOCKET_SEND_MSG = "SendMsg";//发送文字消息,点亮,用户进房间
|
||||
public static final String SOCKET_LIGHT = "light";//飘心
|
||||
public static final String SOCKET_SEND_GIFT = "SendGift";//送礼物
|
||||
public static final String SOCKET_SEND_BARRAGE = "SendBarrage";//发弹幕
|
||||
public static final String SOCKET_LEAVE_ROOM = "disconnect";//用户离开房间
|
||||
public static final String SOCKET_LIVE_END = "StartEndLive";//主播关闭直播
|
||||
public static final String SOCKET_SYSTEM = "SystemNot";//系统消息
|
||||
public static final String SOCKET_KICK = "KickUser";//踢人
|
||||
public static final String SOCKET_SHUT_UP = "ShutUpUser";//禁言
|
||||
public static final String SOCKET_SET_ADMIN = "setAdmin";//设置或取消管理员
|
||||
public static final String SOCKET_CHANGE_LIVE = "changeLive";//切换计时收费类型
|
||||
public static final String SOCKET_UPDATE_VOTES = "updateVotes";//门票或计时收费时候更新主播的映票数
|
||||
public static final String SOCKET_FAKE_FANS = "requestFans";//僵尸粉
|
||||
public static final String SOCKET_LINK_MIC = "ConnectVideo";//连麦
|
||||
public static final String SOCKET_LINK_MIC_ANCHOR = "LiveConnect";//主播连麦
|
||||
public static final String SOCKET_LINK_MIC_PK = "LivePK";//主播PK
|
||||
public static final String SOCKET_BUY_GUARD = "BuyGuard";//购买守护
|
||||
public static final String SOCKET_RED_PACK = "SendRed";//红包
|
||||
public static final String SOCKET_LUCK_WIN = "luckWin";//幸运礼物中奖
|
||||
public static final String SOCKET_PRIZE_POOL_WIN = "jackpotWin";//奖池中奖
|
||||
public static final String SOCKET_PRIZE_POOL_UP = "jackpotUp";//奖池升级
|
||||
public static final String SOCKET_GIFT_GLOBAL = "Sendplatgift";//全站礼物
|
||||
public static final String SOCKET_LIVE_GOODS_SHOW = "goodsLiveShow";//直播间展示商品
|
||||
public static final String SOCKET_LIVE_GOODS_SALE_NUM = "liveGoodsSaleNums";//直播间商品销量
|
||||
public static final String SOCKET_LIVE_GOODS_FLOAT = "shopGoodsLiveFloat";//直播间商品飘屏
|
||||
public static final String SOCKET_VOICE_ROOM = "voiceRoom";//语音聊天室
|
||||
public static final String SOCKET_LIVE_WARNING = "warning";//直播间警告
|
||||
public static final String SOCKET_XQTB_WIN = "xqtbWin";//星球探宝中奖后发送
|
||||
public static final String SOCKET_LUCKPAN_WIN = "xydzpWin";//幸运大转盘中奖后发送
|
||||
|
||||
//游戏socket
|
||||
public static final String SOCKET_GAME_ZJH = "startGame";//炸金花
|
||||
public static final String SOCKET_GAME_HD = "startLodumaniGame";//海盗船长
|
||||
public static final String SOCKET_GAME_NZ = "startCattleGame";//开心牛仔
|
||||
public static final String SOCKET_GAME_ZP = "startRotationGame";//幸运转盘
|
||||
public static final String SOCKET_GAME_EBB = "startShellGame";//二八贝
|
||||
|
||||
public static final int SOCKET_WHAT_CONN = 0;
|
||||
public static final int SOCKET_WHAT_DISCONN = 2;
|
||||
public static final int SOCKET_WHAT_BROADCAST = 1;
|
||||
//socket 用户类型
|
||||
public static final int SOCKET_USER_TYPE_NORMAL = 30;//普通用户
|
||||
public static final int SOCKET_USER_TYPE_ADMIN = 40;//房间管理员
|
||||
public static final int SOCKET_USER_TYPE_ANCHOR = 50;//主播
|
||||
public static final int SOCKET_USER_TYPE_SUPER = 60;//超管
|
||||
|
||||
//提现账号类型,1表示支付宝,2表示微信,3表示银行卡
|
||||
public static final int CASH_ACCOUNT_ALI = 1;
|
||||
public static final int CASH_ACCOUNT_WX = 2;
|
||||
public static final int CASH_ACCOUNT_BANK = 3;
|
||||
public static final String CASH_ACCOUNT_ID = "cashAccountID";
|
||||
public static final String CASH_ACCOUNT = "cashAccount";
|
||||
public static final String CASH_ACCOUNT_NAME = "cashAccountName";
|
||||
public static final String CASH_ACCOUNT_TYPE = "cashAccountType";
|
||||
|
||||
|
||||
public static final int RED_PACK_TYPE_AVERAGE = 0;//平均红包
|
||||
public static final int RED_PACK_TYPE_SHOU_QI = 1;//拼手气红包
|
||||
public static final int RED_PACK_SEND_TIME_NORMAL = 0;//立即发放
|
||||
public static final int RED_PACK_SEND_TIME_DELAY = 1;//延时发放
|
||||
|
||||
public static final int PUSH_TYPE_LIVE = 1;//直播
|
||||
public static final int PUSH_TYPE_MESSAGE = 2;//消息
|
||||
public static final String PUSH_TYPE = "pushType";
|
||||
public static final String PUSH_DATA = "pushData";
|
||||
|
||||
public static final String VIDEO_HOME = "videoHome";
|
||||
public static final String VIDEO_USER = "videoUser_";
|
||||
public static final String VIDEO_LIKE = "videoLike_";
|
||||
public static final String VIDEO_KEY = "videoKey";
|
||||
public static final String VIDEO_POSITION = "videoPosition";
|
||||
public static final String VIDEO_SINGLE = "videoSingle";
|
||||
public static final String VIDEO_PAGE = "videoPage";
|
||||
public static final String VIDEO_BEAN = "videoBean";
|
||||
public static final String VIDEO_ID = "videoId";
|
||||
public static final String VIDEO_COMMENT_BEAN = "videoCommnetBean";
|
||||
public static final String VIDEO_FACE_OPEN = "videoOpenFace";
|
||||
public static final String VIDEO_FACE_HEIGHT = "videoFaceHeight";
|
||||
public static final String VIDEO_DURATION = "videoDuration";
|
||||
public static final String VIDEO_PATH = "videoPath";
|
||||
public static final String VIDEO_PATH_WATER = "videoPathWater";
|
||||
public static final String VIDEO_FROM_RECORD = "videoFromRecord";
|
||||
public static final String VIDEO_MUSIC_ID = "videoMusicId";
|
||||
public static final String VIDEO_HAS_BGM = "videoHasBgm";
|
||||
public static final String VIDEO_MUSIC_NAME_PREFIX = "videoMusicName_";
|
||||
public static final String VIDEO_SAVE_TYPE = "videoSaveType";
|
||||
public static final int VIDEO_SAVE_SAVE_AND_PUB = 1;//保存并发布
|
||||
public static final int VIDEO_SAVE_SAVE = 2;//仅保存
|
||||
public static final int VIDEO_SAVE_PUB = 3;//仅发布
|
||||
|
||||
public static final String MOB_QQ = "qq";
|
||||
public static final String MOB_QZONE = "qzone";
|
||||
public static final String MOB_WX = "wx";
|
||||
public static final String MOB_WX_PYQ = "wchat";
|
||||
public static final String MOB_FACEBOOK = "facebook";
|
||||
public static final String MOB_TWITTER = "twitter";
|
||||
public static final String MOB_PHONE = "phone";
|
||||
|
||||
public static final String LIVE_SDK = "liveSdk";
|
||||
public static final String LIVE_CONFIG = "liveConfig";
|
||||
public static final int LIVE_SDK_TX = 1;//腾讯推流
|
||||
|
||||
|
||||
public static final int LINK_MIC_TYPE_NORMAL = 0;//观众与主播连麦
|
||||
public static final int LINK_MIC_TYPE_ANCHOR = 1;//主播与主播连麦
|
||||
|
||||
public static final String HAVE_STORE = "haveStore";
|
||||
public static final String IS_CHAT_ROOM = "isChatRoom";
|
||||
public static final String CHAT_ROOM_TYPE = "voiceChatRoomType";
|
||||
public static final String SCREEN_RECORD = "screenRecord";
|
||||
|
||||
public static final String MONEY_SIGN = "¥";
|
||||
|
||||
public static final String CHOOSE_IMG = "chooseImage";
|
||||
public static final String CHOOSE_LOCATION = "chooseLocation";
|
||||
public static final String ACTIVE_BEAN = "activeBean";
|
||||
//动态类型
|
||||
public static final int ACTIVE_TYPE_TEXT = 0;//0:纯文字;
|
||||
public static final int ACTIVE_TYPE_IMAGE = 1;//1:文字+图片;
|
||||
public static final int ACTIVE_TYPE_VIDEO = 2;//2:文字+视频;
|
||||
public static final int ACTIVE_TYPE_VOICE = 3;//3:文字+音频
|
||||
public static final int ACTIVE_TYPE_GOODS = 4;//4:文字+商品
|
||||
|
||||
|
||||
public static final int GIFT_TYPE_NORMAL = 0;//正常礼物
|
||||
public static final int GIFT_TYPE_DAO = 1;//道具
|
||||
public static final int GIFT_TYPE_PACK = 2;//背包
|
||||
|
||||
|
||||
public static final String MALL_APPLY_FAILED = "mallApplyFailed";
|
||||
public static final String MALL_APPLY_MANAGE_CLASS = "mallApplyManageClass";
|
||||
public static final String MALL_APPLY_BOND = "mallApplyBond";
|
||||
public static final String MALL_GOODS_CLASS = "mallGoodsClass";
|
||||
public static final String MALL_GOODS_ID = "mallGoodsId";
|
||||
public static final String MALL_GOODS_NAME = "mallGoodsName";
|
||||
public static final String MALL_GOODS_FROM_SHOP = "mallGoodsFromShop";
|
||||
public static final String MALL_CERT_IMG = "mallCertImg";
|
||||
public static final String MALL_CERT_TEXT = "mallCertText";
|
||||
|
||||
public static final String MALL_REFUND_NAME = "mallRefundName";
|
||||
public static final String MALL_REFUND_PHONE = "mallRefundPhone";
|
||||
public static final String MALL_REFUND_PROVINCE = "mallRefundProvince";
|
||||
public static final String MALL_REFUND_CITY = "mallRefundCity";
|
||||
public static final String MALL_REFUND_ZONE = "mallRefundZone";
|
||||
public static final String MALL_REFUND_ADDRESS = "mallRefundAddress";
|
||||
|
||||
public static final String MALL_BUYER_ADDRESS = "mallBuyerAddress";
|
||||
public static final String MALL_GOODS_SPEC = "mallGoodsSpec";
|
||||
public static final String MALL_GOODS_COUNT = "mallGoodsCount";
|
||||
public static final String MALL_POSTAGE = "mallPostage";
|
||||
public static final String MALL_SHOP_NAME = "mallShopName";
|
||||
|
||||
public static final int GOODS_TYPE_OUT = 1;//站外商品
|
||||
public static final int GOODS_TYPE_INNER = 2;//站内商品
|
||||
|
||||
public static final String MALL_ORDER_ID = "mallOrderId";
|
||||
public static final String MALL_ORDER_MONEY = "mallOrderMoney";
|
||||
public static final String MALL_ORDER_INDEX = "mallOrderIndex";
|
||||
public static final String MALL_PAY_GOODS_ORDER = "Buyer.goodsOrderPay";
|
||||
public static final String MALL_PAY_CONTENT_ALI = "Paidprogram.getAliOrder";
|
||||
public static final String MALL_PAY_CONTENT_WX = "Paidprogram.getWxOrder";
|
||||
public static final String MALL_PAY_CONTENT_PAYPAL = "Paidprogram.getBraintreePaypalOrder";
|
||||
|
||||
// 订单状态 -1已关闭,0待付款,1待发货,2待收货,3待评价,4已评价,5退款
|
||||
public static final int MALL_ORDER_STATUS_CLOSE = -1;
|
||||
public static final int MALL_ORDER_STATUS_WAIT_PAY = 0;
|
||||
public static final int MALL_ORDER_STATUS_WAIT_SEND = 1;
|
||||
public static final int MALL_ORDER_STATUS_WAIT_RECEIVE = 2;
|
||||
public static final int MALL_ORDER_STATUS_WAIT_COMMENT = 3;
|
||||
public static final int MALL_ORDER_STATUS_COMMENT = 4;
|
||||
public static final int MALL_ORDER_STATUS_REFUND = 5;
|
||||
|
||||
public static final String MALL_CASH_BALANCE = "mallCashBalance";
|
||||
public static final String MALL_CASH_TOTAL = "mallCashTotal";
|
||||
public static final String MALL_GOODS_ORDER = "goodsorder_admin";
|
||||
public static final String MALL_PLAT_UID = "1";
|
||||
|
||||
|
||||
public static final int VOICE_CTRL_EMPTY = 0;//无人且麦位可用
|
||||
public static final int VOICE_CTRL_BAN = 2;//无人且麦位不可用,被禁了
|
||||
public static final int VOICE_CTRL_CLOSE = -1;//有人且被关麦,无法说话
|
||||
public static final int VOICE_CTRL_OPEN = 1;//有人且正常说话
|
||||
public static final String VOICE_FACE = "voiceRoomFace";
|
||||
|
||||
public static final String NOT_LOGIN_UID = "-9999";//未登录的uid
|
||||
public static final String NOT_LOGIN_TOKEN = "-9999";//未登录的token
|
||||
|
||||
public static final int ZERO = 0;
|
||||
public static final String EMPTY_STRING = "";
|
||||
public static final String[] EMPTY_STRING_ARR = new String[]{};
|
||||
|
||||
public static final String IM_MSG_CONCAT = "dsp_fans";
|
||||
public static final String IM_MSG_LIKE = "dsp_like";
|
||||
public static final String IM_MSG_AT = "dsp_at";
|
||||
public static final String IM_MSG_COMMENT = "dsp_comment";
|
||||
public static final String IM_CUSTOM_METHOD_GOODS = "GoodsMsg";
|
||||
public static final String IM_CUSTOM_METHOD_ORDER = "order";
|
||||
|
||||
public static final int FLOAT_TYPE_DEFAULT = 0;
|
||||
public static final int FLOAT_TYPE_GOODS = 1;
|
||||
|
||||
public static final String LANGUAGE = "language";
|
||||
public static final String LANG_EN = "en";//英文
|
||||
public static final String LANG_ZH = "zh-cn";//中文
|
||||
public static final String SOCKET_CT_ZH = "ct";
|
||||
public static final String SOCKET_CT_EN = "ct_en";
|
||||
public static final int CHAT_ROOM_TYPE_VOICE = 0;
|
||||
public static final int CHAT_ROOM_TYPE_VIDEO = 1;
|
||||
|
||||
public static final String MUTE_REMOTE_AUDIO = "muteRemoteAudio";
|
||||
|
||||
public static final String FILE_PATH = "/YuTang";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.blankj.utilcode.util.BarUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.databinding.ViewCustomTopBarBinding;
|
||||
|
||||
public class CustomTopBar extends ConstraintLayout {
|
||||
private OnCallBackRightIcon onCallBackRightIcon;
|
||||
private OnCallBackRightIcon2 onCallBackRightIcon2;
|
||||
private ViewCustomTopBarBinding mBinding;
|
||||
|
||||
public CustomTopBar(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public CustomTopBar(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public CustomTopBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.view_custom_top_bar, this, true);
|
||||
mBinding.ivBack.setOnClickListener(v -> {
|
||||
if (getContext() instanceof Activity) {
|
||||
((Activity) getContext()).finish();
|
||||
}
|
||||
});
|
||||
mBinding.ivIntent.setOnClickListener(v -> onCallBackRightIcon.onIntent());
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomTopBar);
|
||||
String title = typedArray.getString(R.styleable.CustomTopBar_TopBarTitle);
|
||||
typedArray.recycle();
|
||||
setTitle(title);
|
||||
setPadding(0, BarUtils.getStatusBarHeight(), 0, 0);
|
||||
mBinding.tvRight.setOnClickListener(v -> onCallBackRightIcon2.onIntent());
|
||||
}
|
||||
|
||||
public ImageView getIvBack() {
|
||||
return mBinding.ivBack;
|
||||
}
|
||||
|
||||
public TextView getTvRight() {
|
||||
return mBinding.tvRight;
|
||||
}
|
||||
|
||||
public TextView getTvTitle() {
|
||||
return mBinding.tvTitle;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
mBinding.tvTitle.setText(title);
|
||||
}
|
||||
|
||||
public void setRightText(String txt) {
|
||||
mBinding.tvRight.setText(txt);
|
||||
}
|
||||
|
||||
public void setRightColor(int color) {
|
||||
mBinding.tvRight.setTextColor(color);
|
||||
}
|
||||
|
||||
public void setRightSize(int size) {
|
||||
mBinding.tvRight.setTextSize(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置右图片
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
public void setRightIcon(int res) {
|
||||
mBinding.ivIntent.setImageResource(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片右边距
|
||||
*
|
||||
* @param i
|
||||
*/
|
||||
public void setImgPaddingRight(int i) {
|
||||
mBinding.ivIntent.setPadding(0, 0, i, 0);
|
||||
}
|
||||
|
||||
public void setRightTxtVisible(boolean b) {
|
||||
mBinding.tvRight.setVisibility(b ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
public void setRightImgVIsible(boolean b) {
|
||||
mBinding.ivIntent.setVisibility(b ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
mBinding.tvTitle.setTextColor(color);
|
||||
mBinding.ivBack.setColorFilter(color);
|
||||
}
|
||||
|
||||
public void addIntentListener(OnCallBackRightIcon onCallBackRightIcon) {
|
||||
this.onCallBackRightIcon = onCallBackRightIcon;
|
||||
}
|
||||
|
||||
public interface OnCallBackRightIcon {
|
||||
void onIntent();
|
||||
}
|
||||
|
||||
public void addIntentListener2(OnCallBackRightIcon2 onCallBackRightIcon) {
|
||||
this.onCallBackRightIcon2 = onCallBackRightIcon;
|
||||
}
|
||||
|
||||
public interface OnCallBackRightIcon2 {
|
||||
void onIntent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewOutlineProvider;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DimenRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
|
||||
public class GifAvatarOvalView extends AppCompatImageView {
|
||||
public GifAvatarOvalView(@NonNull Context context) {
|
||||
super(context);
|
||||
init(null);
|
||||
}
|
||||
|
||||
public GifAvatarOvalView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
public GifAvatarOvalView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
protected int mWidth;
|
||||
protected int mHeight;
|
||||
protected float mRadius;
|
||||
|
||||
public static final float DEFAULT_BORDER_WIDTH = 0f;
|
||||
public static final int DEFAULT_BORDER_COLOR = Color.WHITE;
|
||||
protected float mBorderWidth = DEFAULT_BORDER_WIDTH;
|
||||
protected ColorStateList mBorderColor = ColorStateList.valueOf(DEFAULT_BORDER_COLOR);
|
||||
protected RectF mBorderRect = new RectF();
|
||||
protected Paint mBorderPaint;
|
||||
|
||||
private void init(@Nullable AttributeSet attrs) {
|
||||
if (attrs != null) {
|
||||
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.GifAvatarOvalView);
|
||||
mBorderWidth = a.getDimensionPixelSize(R.styleable.GifAvatarOvalView_gav_border_width, -1);
|
||||
if (mBorderWidth < 0) {
|
||||
mBorderWidth = DEFAULT_BORDER_WIDTH;
|
||||
}
|
||||
mBorderColor = a.getColorStateList(R.styleable.GifAvatarOvalView_gav_border_color);
|
||||
if (mBorderColor == null) {
|
||||
mBorderColor = ColorStateList.valueOf(DEFAULT_BORDER_COLOR);
|
||||
}
|
||||
a.recycle();
|
||||
}
|
||||
mBorderPaint = new Paint();
|
||||
mBorderPaint.setStyle(Paint.Style.STROKE);
|
||||
mBorderPaint.setAntiAlias(true);
|
||||
mBorderPaint.setColor(mBorderColor.getDefaultColor());
|
||||
mBorderPaint.setStrokeWidth(mBorderWidth);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
mWidth = mHeight = Math.min(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
|
||||
mRadius = mWidth / 2.0f;
|
||||
mBorderRect.set(0, 0, mWidth, mHeight);
|
||||
setMeasuredDimension(mWidth, mHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
setClipToOutline(true);
|
||||
setOutlineProvider(new ViewOutlineProvider() {
|
||||
@Override
|
||||
public void getOutline(View view, Outline outline) {
|
||||
Rect selfRect = new Rect(0, 0, mWidth, mHeight);
|
||||
outline.setRoundRect(selfRect, mRadius);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (mBorderWidth > 0) {
|
||||
canvas.drawOval(mBorderRect, mBorderPaint);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBorderWidth(@DimenRes int resId) {
|
||||
setBorderWidth(getResources().getDimension(resId));
|
||||
}
|
||||
|
||||
public void setBorderWidth(float width) {
|
||||
if (mBorderWidth == width) { return; }
|
||||
mBorderWidth = width;
|
||||
mBorderPaint.setStrokeWidth(mBorderWidth);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setBorderColor(@ColorInt int color) {
|
||||
setBorderColor(ColorStateList.valueOf(color));
|
||||
}
|
||||
|
||||
public void setBorderColor(ColorStateList colors) {
|
||||
if (mBorderColor.equals(colors)) { return; }
|
||||
mBorderColor = (colors != null) ? colors : ColorStateList.valueOf(DEFAULT_BORDER_COLOR);
|
||||
mBorderPaint.setColor(mBorderColor.getDefaultColor());
|
||||
if (mBorderWidth > 0) {
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class InfintLinearLayoutManager extends LinearLayoutManager {
|
||||
public InfintLinearLayoutManager(RecyclerView recyclerView) {
|
||||
super(recyclerView.getContext(), HORIZONTAL, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollHorizontally() {
|
||||
return true; // 允许水平滑动
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
return super.scrollVerticallyBy(dy, recycler, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
// 获取最后一个和第一个可见 item 的位置
|
||||
int first = findFirstVisibleItemPosition();
|
||||
int last = findLastVisibleItemPosition();
|
||||
|
||||
if (first == 0 && dx > 0) {
|
||||
// 滑动到了最左边,现在往右滑,把最后一个 item 移动到前面复用
|
||||
View lastView = getChildAt(last);
|
||||
if (lastView != null) {
|
||||
layoutScrapView(lastView, last, -1);
|
||||
offsetChildrenHorizontal(-getDecoratedMeasuredWidth(lastView));
|
||||
return dx;
|
||||
}
|
||||
} else if (last == getItemCount() - 1 && dx < 0) {
|
||||
// 滑动到了最右边,现在往左滑,把第一个 item 移动到最后面复用
|
||||
View firstView = getChildAt(first);
|
||||
if (firstView != null) {
|
||||
layoutScrapView(firstView, first, +1);
|
||||
offsetChildrenHorizontal(+getDecoratedMeasuredWidth(firstView));
|
||||
return dx;
|
||||
}
|
||||
}
|
||||
|
||||
return super.scrollHorizontallyBy(dx, recycler, state);
|
||||
}
|
||||
|
||||
private void layoutScrapView(View view, int position, int direction) {
|
||||
removeView(view);
|
||||
|
||||
// 复用的 item 设置为新的位置
|
||||
int newPosition = direction > 0 ? getItemCount() - 1 : 0;
|
||||
addView(view, direction > 0 ? getChildCount() : 0);
|
||||
|
||||
// 更新 adapter 的 position
|
||||
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) view.getLayoutParams();
|
||||
layoutDecoratedWithMargins(view,
|
||||
0,
|
||||
0,
|
||||
getDecoratedMeasuredWidth(view),
|
||||
getDecoratedMeasuredHeight(view));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Xfermode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
/**
|
||||
* 圆形头像
|
||||
*/
|
||||
@SuppressLint("AppCompatCustomView")
|
||||
public abstract class MaskedImage extends ImageView {
|
||||
|
||||
private static final Xfermode MASK_XFERMODE;
|
||||
private Bitmap mask;
|
||||
private Paint paint;
|
||||
|
||||
static {
|
||||
PorterDuff.Mode localMode = PorterDuff.Mode.DST_IN;
|
||||
MASK_XFERMODE = new PorterDuffXfermode(localMode);
|
||||
}
|
||||
|
||||
public MaskedImage(Context paramContext) {
|
||||
super(paramContext);
|
||||
}
|
||||
|
||||
public MaskedImage(Context paramContext, AttributeSet paramAttributeSet) {
|
||||
super(paramContext, paramAttributeSet);
|
||||
}
|
||||
|
||||
public MaskedImage(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
|
||||
super(paramContext, paramAttributeSet, paramInt);
|
||||
}
|
||||
|
||||
public abstract Bitmap createMask();
|
||||
|
||||
protected void onDraw(Canvas paramCanvas) {
|
||||
Drawable localDrawable = getDrawable();
|
||||
if (localDrawable == null)
|
||||
return;
|
||||
try {
|
||||
if (this.paint == null) {
|
||||
Paint localPaint1 = new Paint();
|
||||
this.paint = localPaint1;
|
||||
this.paint.setFilterBitmap(false);
|
||||
Paint localPaint2 = this.paint;
|
||||
Xfermode localXfermode1 = MASK_XFERMODE;
|
||||
@SuppressWarnings("unused")
|
||||
Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1);
|
||||
}
|
||||
float f1 = getWidth();
|
||||
float f2 = getHeight();
|
||||
int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, Canvas.ALL_SAVE_FLAG);
|
||||
int j = getWidth();
|
||||
int k = getHeight();
|
||||
localDrawable.setBounds(0, 0, j, k);
|
||||
localDrawable.draw(paramCanvas);
|
||||
if ((this.mask == null) || (this.mask.isRecycled())) {
|
||||
Bitmap localBitmap1 = createMask();
|
||||
this.mask = localBitmap1;
|
||||
}
|
||||
Bitmap localBitmap2 = this.mask;
|
||||
Paint localPaint3 = this.paint;
|
||||
paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3);
|
||||
paramCanvas.restoreToCount(i);
|
||||
return;
|
||||
} catch (Exception localException) {
|
||||
StringBuilder localStringBuilder = new StringBuilder()
|
||||
.append("Attempting to draw with recycled bitmap. View ID = ");
|
||||
System.out.println("localStringBuilder==" + localStringBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.GridView;
|
||||
|
||||
public class MyGridView extends GridView {
|
||||
public MyGridView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public MyGridView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int heightSpec;
|
||||
|
||||
if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
|
||||
// The great Android "hackatlon", the love, the magic.
|
||||
// The two leftmost bits in the height measure spec have
|
||||
// a special meaning, hence we can't use them to describe height.
|
||||
heightSpec = MeasureSpec.makeMeasureSpec(
|
||||
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
|
||||
}
|
||||
else {
|
||||
// Any other height should be respected as is.
|
||||
heightSpec = heightMeasureSpec;
|
||||
}
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightSpec);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Shader;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* ProjectName: CustomViewApp
|
||||
* Package: com.yde.libview
|
||||
* Description: 扫光TextView
|
||||
* Author: 姚闻达
|
||||
* CreateDate: 2021/3/11
|
||||
* UpdateUser: 更新者
|
||||
* UpdateDate: 2021/3/11 10:58
|
||||
* UpdateRemark: 更新说明
|
||||
* Version: 1.0
|
||||
*/
|
||||
public class ScanTextView extends TextView {
|
||||
|
||||
//渲染器
|
||||
private LinearGradient mLinearGradient;
|
||||
//渲染范围
|
||||
private Matrix mGradientMatrix;
|
||||
//渲染的起始位置
|
||||
private int mViewWidth = 0;
|
||||
//渲染的终止距离
|
||||
private int mTranslate = 0;
|
||||
//是否启动动画
|
||||
private boolean mAnimating = true;
|
||||
//多少毫秒刷新一次
|
||||
private int speed = 50;
|
||||
private int lightColor;
|
||||
private Paint mPaint;
|
||||
|
||||
public ScanTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mPaint = getPaint();
|
||||
mGradientMatrix = new Matrix();
|
||||
}
|
||||
|
||||
@SuppressLint("DrawAllocation")
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
mViewWidth = getMeasuredWidth();
|
||||
// mLinearGradient = new LinearGradient(0, 0, mViewWidth, 0, new int[] { Color.GRAY, Color.WHITE, Color.GRAY }, null, Shader.TileMode.CLAMP);
|
||||
if (mAnimating) {
|
||||
mLinearGradient = new LinearGradient(0, 0, mViewWidth, 0, new int[]{getCurrentTextColor(), lightColor, getCurrentTextColor()}, null, Shader.TileMode.CLAMP);
|
||||
} else {
|
||||
mLinearGradient = new LinearGradient(0, 0, mViewWidth, 0, new int[]{getCurrentTextColor(), getCurrentTextColor(), getCurrentTextColor()}, null, Shader.TileMode.CLAMP);
|
||||
}
|
||||
mPaint.setShader(mLinearGradient);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (mAnimating && mGradientMatrix != null) {
|
||||
mTranslate += mViewWidth / 10;//每次移动屏幕的1/10宽
|
||||
if (mTranslate > 2 * mViewWidth) {
|
||||
mTranslate = -mViewWidth;
|
||||
}
|
||||
mGradientMatrix.setTranslate(mTranslate, 0);
|
||||
mLinearGradient.setLocalMatrix(mGradientMatrix);//在指定矩阵上渲染
|
||||
postInvalidateDelayed(speed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
}
|
||||
|
||||
public void setSpeed(int speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public void setLightColor(int lightColor) {
|
||||
this.lightColor = lightColor;
|
||||
}
|
||||
|
||||
public void setScan(boolean canScan) {
|
||||
this.mAnimating = canScan;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2017/5/17.
|
||||
*/
|
||||
|
||||
public class ScrollViewPager extends ViewPager {
|
||||
private boolean scroll = true;
|
||||
|
||||
public ScrollViewPager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ScrollViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public void setScroll(boolean scroll) {
|
||||
this.scroll = scroll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
super.scrollTo(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent arg0) {
|
||||
/*return false;//super.onTouchEvent(arg0);*/
|
||||
if (scroll)
|
||||
return false;
|
||||
else
|
||||
return super.onTouchEvent(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent arg0) {
|
||||
if (scroll)
|
||||
return false;
|
||||
else
|
||||
return super.onInterceptTouchEvent(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item, boolean smoothScroll) {
|
||||
super.setCurrentItem(item, smoothScroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item) {
|
||||
super.setCurrentItem(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.qxcm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.TypedValue;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static <T> T checkNotNull(T object, String message) {
|
||||
if (object == null) {
|
||||
throw new NullPointerException(message);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
public static int pixelOfScaled(Context c, int sp) {
|
||||
Resources r = c.getResources();
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, r.getDisplayMetrics());
|
||||
}
|
||||
|
||||
public static int pixelOfDp(Context c, int dp) {
|
||||
Resources r = c.getResources();
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
|
||||
}
|
||||
|
||||
|
||||
private static final Object sLock = new Object();
|
||||
private static TypedValue sTempValue;
|
||||
/**
|
||||
* Returns a drawable object associated with a particular resource ID.
|
||||
* <p>
|
||||
* Starting in {@link Build.VERSION_CODES#LOLLIPOP}, the
|
||||
* returned drawable will be styled for the specified Context's theme.
|
||||
*
|
||||
* @param id The desired resource identifier, as generated by the aapt tool.
|
||||
* This integer encodes the package, type, and resource entry.
|
||||
* The value 0 is an invalid identifier.
|
||||
* @return Drawable An object that can be used to draw this resource.
|
||||
*/
|
||||
public static Drawable getDrawable(Context context, int id) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return context.getDrawable(id);
|
||||
} else if (Build.VERSION.SDK_INT >= 16) {
|
||||
//noinspection deprecation
|
||||
return context.getResources().getDrawable(id);
|
||||
} else {
|
||||
// Prior to JELLY_BEAN, Resources.getDrawable() would not correctly
|
||||
// retrieve the final configuration density when the resource ID
|
||||
// is a reference another Drawable resource. As a workaround, try
|
||||
// to resolve the drawable reference manually.
|
||||
final int resolvedId;
|
||||
synchronized (sLock) {
|
||||
if (sTempValue == null) {
|
||||
sTempValue = new TypedValue();
|
||||
}
|
||||
context.getResources().getValue(id, sTempValue, true);
|
||||
resolvedId = sTempValue.resourceId;
|
||||
}
|
||||
//noinspection deprecation
|
||||
return context.getResources().getDrawable(resolvedId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.qxcm.moduleutil.widget.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
|
||||
public abstract class BaseDialog<VDM extends ViewDataBinding> extends Dialog {
|
||||
|
||||
protected VDM mBinding;
|
||||
|
||||
public BaseDialog(@NonNull Context context) {
|
||||
this(context, R.style.BaseDialogStyle);
|
||||
}
|
||||
|
||||
public BaseDialog(@NonNull Context context, int themeResId) {
|
||||
super(context, themeResId);
|
||||
mBinding = DataBindingUtil.bind(LayoutInflater.from(context).inflate(getLayoutId(), null, false));
|
||||
if (mBinding != null) {
|
||||
setContentView(mBinding.getRoot());
|
||||
}
|
||||
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
if (mBinding!=null){
|
||||
mBinding.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract int getLayoutId();
|
||||
|
||||
public abstract void initView();
|
||||
|
||||
public abstract void initData();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.qxcm.moduleutil.widget.dialog;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
public class CommonDialog extends BaseDialog {
|
||||
|
||||
TextView tvContent;
|
||||
TextView textViewLeft;
|
||||
TextView textViewRight;
|
||||
|
||||
private OnClickListener mOnClickListener;
|
||||
|
||||
|
||||
public CommonDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_common;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
getWindow().setLayout((int) (ScreenUtils.getScreenWidth() * 0.86), ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
tvContent = mBinding.getRoot().findViewById(R.id.tv_content);
|
||||
textViewLeft = mBinding.getRoot().findViewById(R.id.tv_left);
|
||||
textViewRight = mBinding.getRoot().findViewById(R.id.tv_right);
|
||||
textViewLeft.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
mOnClickListener.onLeftClick();
|
||||
}
|
||||
});
|
||||
textViewRight.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
mOnClickListener.onRightClick();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setContent(String content) {
|
||||
tvContent.setText(content);
|
||||
}
|
||||
|
||||
public void setLeftText(String leftText) {
|
||||
textViewLeft.setText(leftText);
|
||||
}
|
||||
|
||||
public void setRightText(String rightText) {
|
||||
textViewRight.setText(rightText);
|
||||
}
|
||||
|
||||
public void setmOnClickListener(OnClickListener onClickListener) {
|
||||
this.mOnClickListener = onClickListener;
|
||||
}
|
||||
|
||||
|
||||
public interface OnClickListener {
|
||||
void onLeftClick();
|
||||
|
||||
void onRightClick();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.qxcm.moduleutil.widget.img;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 看大图
|
||||
*/
|
||||
public class FullScreenUtil {
|
||||
|
||||
public static void showFullScreenDialog(Context context, final int pos, final List<String> imgList) {
|
||||
final Dialog dialog = new Dialog(context, R.style.big_pic_dialog);
|
||||
//设置是否允许Dialog可以被点击取消,也会阻止Back键
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
Window window = dialog.getWindow();
|
||||
window.setGravity(Gravity.CENTER);
|
||||
//获取Dialog窗体的根容器
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
ViewGroup root = (ViewGroup) dialog.getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
//设置窗口大小为屏幕大小item_img_pv
|
||||
WindowManager wm = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
||||
Point screenSize = new Point();
|
||||
wm.getDefaultDisplay().getSize(screenSize);
|
||||
root.setLayoutParams(new LinearLayout.LayoutParams(screenSize.x, screenSize.y));
|
||||
// 获取自定义布局,并设置给Dialog
|
||||
View view = inflater.inflate(R.layout.pop_photo_vp, root, false);
|
||||
final ViewPager img_vp = view.findViewById(R.id.img_vp);
|
||||
final TextView img_num_iv = view.findViewById(R.id.img_num_iv);
|
||||
final ImageView img_down_iv = view.findViewById(R.id.img_down_iv);
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
ImgVPAdapter vpAdapter = new ImgVPAdapter(context, imgList);
|
||||
img_vp.setAdapter(vpAdapter);
|
||||
img_vp.setCurrentItem(pos);
|
||||
img_num_iv.setText((pos + 1) + "/" + imgList.size());
|
||||
img_down_iv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//保存
|
||||
/* if (imgList.get(pos) != null) {
|
||||
ImageSaveUtils.saveImg(XQDetailActivity.this, imgList.get(pos));
|
||||
}*/
|
||||
|
||||
}
|
||||
});
|
||||
img_vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(final int position) {
|
||||
img_num_iv.setText((position + 1) + "/" + imgList.size());
|
||||
img_down_iv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
/* if(imgList.get(position)!=null){
|
||||
ImageSaveUtils.saveImg(XQDetailActivity.this, imgList.get(position));
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
});
|
||||
vpAdapter.setAllClickListener(new ImgVPAdapter.AllClickListener() {
|
||||
@Override
|
||||
public void allclick(int pos) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.qxcm.moduleutil.widget.img;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.qxcm.moduleutil.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ImgVPAdapter extends PagerAdapter {
|
||||
private Context context;
|
||||
private List<String> paths;
|
||||
|
||||
public ImgVPAdapter(Context context, List<String> paths) {
|
||||
this.context = context;
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return paths.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, final int position) {
|
||||
ImageView iv_img = (ImageView) LayoutInflater.from(context).inflate(R.layout.item_img_pv, null);
|
||||
// iv_img.setScaleType(ImageView.ScaleType.CENTER);
|
||||
Glide.with(context).load( paths.get(position)).error(R.mipmap.default_image).into(iv_img);
|
||||
iv_img.setScaleType(ImageView.ScaleType.CENTER);
|
||||
iv_img.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (allClickListener != null) {
|
||||
allClickListener.allclick(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
container.addView(iv_img);
|
||||
return iv_img;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
container.removeView((View) object);
|
||||
}
|
||||
|
||||
public interface AllClickListener {
|
||||
void allclick(int pos);
|
||||
}
|
||||
|
||||
public AllClickListener allClickListener;
|
||||
|
||||
public void setAllClickListener(AllClickListener allClickListener) {
|
||||
this.allClickListener = allClickListener;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,730 @@
|
||||
package com.qxcm.moduleutil.widget.picker;
|
||||
|
||||
|
||||
import static lombok.Lombok.checkNotNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Camera;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.text.Layout;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.OverScroller;
|
||||
|
||||
import com.qxcm.moduleutil.R;
|
||||
import com.qxcm.moduleutil.utils.logger.Logger;
|
||||
import com.qxcm.moduleutil.widget.Utils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PickerView extends View {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
static final int DEFAULT_TEXT_SIZE_IN_SP = 14;
|
||||
static final int DEFAULT_ITEM_HEIGHT_IN_DP = 24;
|
||||
static final int DEFAULT_MAX_OFFSET_ITEM_COUNT = 3;
|
||||
private int preferredMaxOffsetItemCount = DEFAULT_MAX_OFFSET_ITEM_COUNT;
|
||||
private int selectedItemPosition;
|
||||
|
||||
private static final int DURATION_SHORT = 250;
|
||||
private static final int DURATION_LONG = 1000;
|
||||
|
||||
private Adapter<? extends PickerItem> adapter;
|
||||
|
||||
private Paint textPaint;
|
||||
private Rect textBounds = new Rect();
|
||||
|
||||
private GestureDetector gestureDetector;
|
||||
private OverScroller scroller;
|
||||
private boolean scrolling;
|
||||
private boolean pendingJustify;
|
||||
private boolean isScrollSuspendedByDownEvent;
|
||||
private float actionDownY;
|
||||
private float previousTouchedY;
|
||||
private int previousScrollerY;
|
||||
private int yOffset;
|
||||
private int minY;
|
||||
private int maxY;
|
||||
private int maxOverScrollY;
|
||||
private int touchSlop;
|
||||
|
||||
private int itemHeight;
|
||||
private int textSize;
|
||||
private int textColor = Color.BLACK;
|
||||
private int selectTextColor = Color.BLACK;
|
||||
private Typeface typeface;
|
||||
private boolean isCyclic;
|
||||
private boolean autoFitSize;
|
||||
private boolean curved;
|
||||
private Drawable selectedItemDrawable;
|
||||
private int selectedMaskPadding;
|
||||
private int[] DEFAULT_GRADIENT_COLORS = new int[]{0xcfffffff, 0x9fffffff, 0x5fffffff};
|
||||
private int[] gradientColors = DEFAULT_GRADIENT_COLORS;
|
||||
private GradientDrawable topMask;
|
||||
private GradientDrawable bottomMask;
|
||||
private Layout.Alignment textAlign = Layout.Alignment.ALIGN_CENTER;
|
||||
|
||||
private float radius;
|
||||
private Camera camera;
|
||||
private Matrix matrix;
|
||||
|
||||
public interface PickerItem {
|
||||
String getText();
|
||||
}
|
||||
|
||||
public PickerView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public PickerView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public PickerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
int startScrollerY = yOffset - itemHeight * selectedItemPosition;
|
||||
|
||||
if (startScrollerY <= minY || startScrollerY >= maxY) {
|
||||
justify(DURATION_LONG);
|
||||
return true;
|
||||
}
|
||||
|
||||
scroller.fling(
|
||||
0, startScrollerY,
|
||||
0, (int) velocityY,
|
||||
0, 0,
|
||||
minY,
|
||||
maxY,
|
||||
0, maxOverScrollY);
|
||||
|
||||
if (DEBUG) {
|
||||
Logger.d("fling: " + startScrollerY + ", velocityY: " + velocityY);
|
||||
}
|
||||
|
||||
previousScrollerY = scroller.getCurrY();
|
||||
pendingJustify = true;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
scroller = new OverScroller(getContext());
|
||||
touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
||||
|
||||
if (isInEditMode()) {
|
||||
adapter = new Adapter<PickerItem>() {
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return getMaxCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PickerItem getItem(final int index) {
|
||||
return new PickerItem() {
|
||||
@Override
|
||||
public String getText() {
|
||||
return "Item " + index;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
} else {
|
||||
selectedMaskPadding = dp2px(18);
|
||||
selectedItemDrawable = Utils.getDrawable(getContext(), R.drawable.top_defaults_view_pickerview_selected_item);
|
||||
}
|
||||
|
||||
topMask = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, gradientColors);
|
||||
bottomMask = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, gradientColors);
|
||||
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.PickerView);
|
||||
preferredMaxOffsetItemCount = typedArray.getInt(R.styleable.PickerView_preferredMaxOffsetItemCount, DEFAULT_MAX_OFFSET_ITEM_COUNT);
|
||||
if (preferredMaxOffsetItemCount <= 0)
|
||||
preferredMaxOffsetItemCount = DEFAULT_MAX_OFFSET_ITEM_COUNT;
|
||||
|
||||
int defaultItemHeight = Utils.pixelOfDp(getContext(), DEFAULT_ITEM_HEIGHT_IN_DP);
|
||||
itemHeight = typedArray.getDimensionPixelSize(R.styleable.PickerView_itemHeight, defaultItemHeight);
|
||||
if (itemHeight <= 0) itemHeight = defaultItemHeight;
|
||||
|
||||
int defaultTextSize = Utils.pixelOfScaled(getContext(), DEFAULT_TEXT_SIZE_IN_SP);
|
||||
textSize = typedArray.getDimensionPixelSize(R.styleable.PickerView_textSizec, defaultTextSize);
|
||||
textColor = typedArray.getColor(R.styleable.PickerView_textColorc, Color.BLACK);
|
||||
selectTextColor = typedArray.getColor(R.styleable.PickerView_selectTextColor, Color.BLACK);
|
||||
|
||||
isCyclic = typedArray.getBoolean(R.styleable.PickerView_isCyclic, false);
|
||||
autoFitSize = typedArray.getBoolean(R.styleable.PickerView_autoFitSize, true);
|
||||
curved = typedArray.getBoolean(R.styleable.PickerView_curved, false);
|
||||
typedArray.recycle();
|
||||
|
||||
initPaints();
|
||||
|
||||
camera = new Camera();
|
||||
matrix = new Matrix();
|
||||
}
|
||||
|
||||
protected int dp2px(float dp) {
|
||||
final float scale = getResources().getDisplayMetrics().density;
|
||||
return (int) (dp * scale + 0.5f);
|
||||
}
|
||||
|
||||
private void initPaints() {
|
||||
textPaint = new Paint();
|
||||
textPaint.setAntiAlias(true);
|
||||
}
|
||||
|
||||
public Adapter getAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
public <T extends PickerItem> void setAdapter(final Adapter<T> adapter) {
|
||||
checkNotNull(adapter, "adapter == null");
|
||||
if (adapter.getItemCount() > Integer.MAX_VALUE / itemHeight) {
|
||||
throw new RuntimeException("getItemCount() is too large, max count can be PickerView.getMaxCount()");
|
||||
}
|
||||
adapter.setPickerView(this);
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
public interface OnItemSelectedListener<T extends PickerItem> {
|
||||
void onItemSelected(T item);
|
||||
}
|
||||
|
||||
public <T extends PickerItem> void setItems(final List<T> items, final OnItemSelectedListener<T> listener) {
|
||||
final Adapter<T> simpleAdapter = new Adapter<T>() {
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getItem(int index) {
|
||||
return items.get(index);
|
||||
}
|
||||
};
|
||||
setAdapter(simpleAdapter);
|
||||
|
||||
setOnSelectedItemChangedListener(new OnSelectedItemChangedListener() {
|
||||
@Override
|
||||
public void onSelectedItemChanged(PickerView pickerView, int previousPosition, int selectedItemPosition) {
|
||||
if (listener != null) {
|
||||
listener.onItemSelected(simpleAdapter.getItem(selectedItemPosition));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected int getMaxCount() {
|
||||
return Integer.MAX_VALUE / itemHeight;
|
||||
}
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
if (adapter != null) {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSelectedItem() {
|
||||
float centerPosition = centerPosition();
|
||||
int newSelectedItemPosition = (int) Math.floor(centerPosition);
|
||||
notifySelectedItemChangedIfNeeded(newSelectedItemPosition, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public abstract static class Adapter<T extends PickerItem> {
|
||||
private WeakReference<PickerView> pickerViewRef;
|
||||
|
||||
private void setPickerView(PickerView pickerView) {
|
||||
this.pickerViewRef = new WeakReference<>(pickerView);
|
||||
}
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
if (pickerViewRef != null) {
|
||||
PickerView pickerView = pickerViewRef.get();
|
||||
if (pickerView != null) {
|
||||
pickerView.updateSelectedItem();
|
||||
pickerView.computeScrollParams();
|
||||
if (!pickerView.scroller.isFinished()) {
|
||||
pickerView.scroller.forceFinished(true);
|
||||
}
|
||||
pickerView.justify(0);
|
||||
pickerView.invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract int getItemCount();
|
||||
|
||||
public abstract T getItem(int index);
|
||||
|
||||
public T getLastItem() {
|
||||
return getItem(getItemCount() - 1);
|
||||
}
|
||||
|
||||
public String getText(int index) {
|
||||
if (getItem(index) == null) return "null";
|
||||
return getItem(index).getText();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPreferredMaxOffsetItemCount(int preferredMaxOffsetItemCount) {
|
||||
this.preferredMaxOffsetItemCount = preferredMaxOffsetItemCount;
|
||||
}
|
||||
|
||||
public void setItemHeight(int itemHeight) {
|
||||
if (this.itemHeight != itemHeight) {
|
||||
this.itemHeight = itemHeight;
|
||||
invalidate();
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextSize(int textSize) {
|
||||
if (this.textSize != textSize) {
|
||||
this.textSize = textSize;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextColor(int textColor) {
|
||||
if (this.textColor != textColor) {
|
||||
this.textColor = textColor;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTypeface(Typeface typeface) {
|
||||
if (this.typeface != typeface) {
|
||||
this.typeface = typeface;
|
||||
textPaint.setTypeface(typeface);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCyclic(boolean cyclic) {
|
||||
if (this.isCyclic != cyclic) {
|
||||
isCyclic = cyclic;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAutoFitSize(boolean autoFitSize) {
|
||||
if (this.autoFitSize != autoFitSize) {
|
||||
this.autoFitSize = autoFitSize;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurved(boolean curved) {
|
||||
if (this.curved != curved) {
|
||||
this.curved = curved;
|
||||
invalidate();
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSelectedItemPosition() {
|
||||
return clampItemPosition(selectedItemPosition);
|
||||
}
|
||||
|
||||
public void setSelectedItemPosition(int selectedItemPosition) {
|
||||
checkNotNull(adapter, "adapter must be set first");
|
||||
|
||||
notifySelectedItemChangedIfNeeded(selectedItemPosition);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public <T extends PickerItem> T getSelectedItem(Class<T> cls) {
|
||||
checkNotNull(adapter, "adapter must be set first");
|
||||
|
||||
PickerItem item = adapter.getItem(getSelectedItemPosition());
|
||||
if (!cls.isInstance(item)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cls.cast(item);
|
||||
}
|
||||
|
||||
public interface OnSelectedItemChangedListener {
|
||||
void onSelectedItemChanged(PickerView pickerView, int previousPosition, int selectedItemPosition);
|
||||
}
|
||||
|
||||
private OnSelectedItemChangedListener onSelectedItemChangedListener;
|
||||
|
||||
public void setOnSelectedItemChangedListener(OnSelectedItemChangedListener onSelectedItemChangedListener) {
|
||||
this.onSelectedItemChangedListener = onSelectedItemChangedListener;
|
||||
}
|
||||
|
||||
private void notifySelectedItemChangedIfNeeded(int newSelectedItemPosition) {
|
||||
notifySelectedItemChangedIfNeeded(newSelectedItemPosition, false);
|
||||
}
|
||||
|
||||
private void notifySelectedItemChangedIfNeeded(int newSelectedItemPosition, boolean forceNotify) {
|
||||
int oldSelectedItemPosition = selectedItemPosition;
|
||||
int clampedNewSelectedItemPosition = clampItemPosition(newSelectedItemPosition);
|
||||
|
||||
boolean changed = forceNotify;
|
||||
if (isCyclic) {
|
||||
if (selectedItemPosition != newSelectedItemPosition) {
|
||||
selectedItemPosition = newSelectedItemPosition;
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
if (selectedItemPosition != clampedNewSelectedItemPosition) {
|
||||
selectedItemPosition = clampedNewSelectedItemPosition;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed && onSelectedItemChangedListener != null) {
|
||||
onSelectedItemChangedListener.onSelectedItemChanged(this, oldSelectedItemPosition, clampedNewSelectedItemPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
checkNotNull(adapter, "adapter == null");
|
||||
|
||||
int height = resolveSizeAndState(calculateIntrinsicHeight(), heightMeasureSpec, 0);
|
||||
computeScrollParams();
|
||||
setMeasuredDimension(widthMeasureSpec, height);
|
||||
}
|
||||
|
||||
private int calculateIntrinsicHeight() {
|
||||
if (curved) {
|
||||
radius = itemHeight / (float) Math.sin(Math.PI / (3 + 2 * preferredMaxOffsetItemCount));
|
||||
return (int) Math.ceil(2 * radius);
|
||||
} else {
|
||||
return (1 + 2 * preferredMaxOffsetItemCount) * itemHeight;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
checkNotNull(adapter, "adapter == null");
|
||||
if (adapter.getItemCount() == 0 || itemHeight == 0) return;
|
||||
|
||||
if (!isInEditMode()) {
|
||||
selectedItemDrawable.setBounds(selectedMaskPadding, (getMeasuredHeight() - itemHeight) / 2, getMeasuredWidth() - selectedMaskPadding, (getMeasuredHeight() + itemHeight) / 2);
|
||||
selectedItemDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
drawItems(canvas);
|
||||
drawMasks(canvas);
|
||||
}
|
||||
|
||||
private void drawItems(Canvas canvas) {
|
||||
// 绘制选中项
|
||||
float drawYOffset = yOffset + (getMeasuredHeight() - itemHeight) / 2;
|
||||
int itemPosition = selectedItemPosition;
|
||||
String text = adapter.getText(clampItemPosition(itemPosition));
|
||||
drawText(canvas, text, drawYOffset, 0);
|
||||
drawYOffset -= itemHeight;
|
||||
|
||||
// 绘制选中项上方的item
|
||||
itemPosition = selectedItemPosition - 1;
|
||||
while (drawYOffset + (itemHeight * (curved ? 2 : 1)) > 0) {
|
||||
if (isPositionInvalid(itemPosition) && !isCyclic) {
|
||||
break;
|
||||
}
|
||||
|
||||
text = adapter.getText(clampItemPosition(itemPosition));
|
||||
drawText(canvas, text, drawYOffset, -1);
|
||||
drawYOffset -= itemHeight;
|
||||
itemPosition--;
|
||||
}
|
||||
|
||||
// 绘制选中项下方的item
|
||||
drawYOffset = yOffset + (getMeasuredHeight() + itemHeight) / 2;
|
||||
itemPosition = selectedItemPosition + 1;
|
||||
while (drawYOffset - (itemHeight * (curved ? 1 : 0)) < getMeasuredHeight()) {
|
||||
if (isPositionInvalid(itemPosition) && !isCyclic) {
|
||||
break;
|
||||
}
|
||||
|
||||
text = adapter.getText(clampItemPosition(itemPosition));
|
||||
drawText(canvas, text, drawYOffset, 1);
|
||||
drawYOffset += itemHeight;
|
||||
itemPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawMasks(Canvas canvas) {
|
||||
topMask.setBounds(0, 0, getMeasuredWidth(), (getMeasuredHeight() - itemHeight) / 2);
|
||||
topMask.draw(canvas);
|
||||
|
||||
bottomMask.setBounds(0, (getMeasuredHeight() + itemHeight) / 2, getMeasuredWidth(), getMeasuredHeight());
|
||||
bottomMask.draw(canvas);
|
||||
}
|
||||
|
||||
private void drawText(Canvas canvas, String text, float offset, int postion) {
|
||||
textPaint.setTextSize(textSize);
|
||||
if (postion == 0) {
|
||||
textPaint.setColor(selectTextColor);
|
||||
} else {
|
||||
textPaint.setColor(textColor);
|
||||
}
|
||||
textPaint.getTextBounds(text, 0, text.length(), textBounds);
|
||||
|
||||
if (autoFitSize) {
|
||||
while (getMeasuredWidth() < textBounds.width() && textPaint.getTextSize() > 16) {
|
||||
textPaint.setTextSize(textPaint.getTextSize() - 1);
|
||||
textPaint.getTextBounds(text, 0, text.length(), textBounds);
|
||||
}
|
||||
}
|
||||
|
||||
float textBottom = offset + (itemHeight + (textBounds.height())) / 2;
|
||||
|
||||
if (curved) {
|
||||
// 根据当前item的offset换算得到对应的倾斜角度,rotateRatio用于减小倾斜角度,否则倾斜角度过大会导致视觉效果不佳
|
||||
float rotateRatio = 2f / preferredMaxOffsetItemCount;
|
||||
double radian = Math.atan((radius - (offset + itemHeight / 2)) / radius) * rotateRatio;
|
||||
float degree = (float) (radian * 180 / Math.PI);
|
||||
camera.save();
|
||||
camera.rotateX(degree);
|
||||
camera.translate(0, 0, -Math.abs((radius / (2 + preferredMaxOffsetItemCount)) * (float) Math.sin(radian)));
|
||||
camera.getMatrix(matrix);
|
||||
matrix.preTranslate(-getMeasuredWidth() / 2, -getMeasuredHeight() / 2);
|
||||
matrix.postTranslate(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
|
||||
canvas.save();
|
||||
canvas.concat(matrix);
|
||||
}
|
||||
if (textAlign == Layout.Alignment.ALIGN_CENTER) {
|
||||
textPaint.setTextAlign(Paint.Align.CENTER);
|
||||
canvas.drawText(text, getMeasuredWidth() / 2, textBottom, textPaint);
|
||||
} else if (textAlign == Layout.Alignment.ALIGN_OPPOSITE) {
|
||||
textPaint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText(text, getMeasuredWidth(), textBottom, textPaint);
|
||||
} else {
|
||||
textPaint.setTextAlign(Paint.Align.LEFT);
|
||||
canvas.drawText(text, 0, textBottom, textPaint);
|
||||
}
|
||||
if (curved) {
|
||||
canvas.restore();
|
||||
camera.restore();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performClick() {
|
||||
return super.performClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (gestureDetector.onTouchEvent(event)) {
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
float y = event.getY();
|
||||
int dy;
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
pendingJustify = false;
|
||||
actionDownY = y;
|
||||
previousTouchedY = y;
|
||||
scrolling = false;
|
||||
if (!scroller.isFinished()) {
|
||||
scroller.forceFinished(true);
|
||||
isScrollSuspendedByDownEvent = true;
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (!scrolling && Math.abs(y - actionDownY) <= touchSlop) {
|
||||
break;
|
||||
}
|
||||
if (!scrolling) {
|
||||
scrolling = true;
|
||||
previousTouchedY = y;
|
||||
break;
|
||||
}
|
||||
pendingJustify = false;
|
||||
dy = (int) (y - previousTouchedY);
|
||||
handleOffset(dy);
|
||||
previousTouchedY = y;
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (!isScrollSuspendedByDownEvent && !scrolling && Math.abs(y - actionDownY) <= touchSlop) {
|
||||
// 单击事件
|
||||
performClick();
|
||||
previousScrollerY = yOffset - itemHeight * selectedItemPosition;
|
||||
// 最近的整数倍数的单元格高度
|
||||
int centerItemTopY = (getMeasuredHeight() - itemHeight) / 2;
|
||||
int centerItemBottomY = (getMeasuredHeight() + itemHeight) / 2;
|
||||
if (y >= centerItemTopY && y <= centerItemBottomY) break;
|
||||
|
||||
int scrollOffset;
|
||||
if (y < centerItemTopY) {
|
||||
scrollOffset = ((int) y - centerItemBottomY) / itemHeight * itemHeight;
|
||||
if (selectedItemPosition + scrollOffset / itemHeight < 0) break;
|
||||
} else {
|
||||
scrollOffset = ((int) y - centerItemTopY) / itemHeight * itemHeight;
|
||||
if (selectedItemPosition + scrollOffset / itemHeight > adapter.getItemCount() - 1)
|
||||
break;
|
||||
}
|
||||
scroller.startScroll(
|
||||
0, previousScrollerY,
|
||||
0, -scrollOffset,
|
||||
DURATION_SHORT);
|
||||
if (DEBUG) {
|
||||
Logger.d("scrollOffset = %d", scrollOffset);
|
||||
}
|
||||
break;
|
||||
}
|
||||
scrolling = false;
|
||||
isScrollSuspendedByDownEvent = false;
|
||||
|
||||
// align items
|
||||
dy = (int) (y - previousTouchedY);
|
||||
handleOffset(dy);
|
||||
justify(DURATION_SHORT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeScroll() {
|
||||
if (scroller.computeScrollOffset()) {
|
||||
int scrollerY = scroller.getCurrY();
|
||||
if (DEBUG) {
|
||||
Logger.d("scrollerY = %d, previousScrollerY = %d", scrollerY, previousScrollerY);
|
||||
}
|
||||
int dy = scrollerY - previousScrollerY;
|
||||
handleOffset(dy);
|
||||
previousScrollerY = scrollerY;
|
||||
invalidate();
|
||||
} else {
|
||||
if (pendingJustify) {
|
||||
justify(DURATION_SHORT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void computeScrollParams() {
|
||||
if (isCyclic) {
|
||||
minY = Integer.MIN_VALUE;
|
||||
maxY = Integer.MAX_VALUE;
|
||||
} else {
|
||||
minY = -(adapter.getItemCount() - 1) * itemHeight;
|
||||
maxY = 0;
|
||||
}
|
||||
maxOverScrollY = 2 * itemHeight;
|
||||
}
|
||||
|
||||
private boolean isPositionInvalid(int itemPosition) {
|
||||
return itemPosition < 0 || itemPosition >= adapter.getItemCount();
|
||||
}
|
||||
|
||||
private int clampItemPosition(int itemPosition) {
|
||||
if (adapter.getItemCount() == 0) return 0;
|
||||
|
||||
if (isCyclic) {
|
||||
if (itemPosition < 0) {
|
||||
itemPosition = itemPosition % adapter.getItemCount();
|
||||
if (itemPosition != 0) itemPosition += adapter.getItemCount();
|
||||
} else if (itemPosition >= adapter.getItemCount())
|
||||
itemPosition %= adapter.getItemCount();
|
||||
}
|
||||
|
||||
if (itemPosition < 0) itemPosition = 0;
|
||||
else if (itemPosition >= adapter.getItemCount()) itemPosition = adapter.getItemCount() - 1;
|
||||
return itemPosition;
|
||||
}
|
||||
|
||||
// 中心线切割的单元位置
|
||||
private float centerPosition() {
|
||||
return selectedItemPosition + 0.5f - yOffset / itemHeight;
|
||||
}
|
||||
|
||||
// 对齐item
|
||||
private void justify(int duration) {
|
||||
if (yOffset != 0) {
|
||||
int scrollOffset = -yOffset;
|
||||
if (selectedItemPosition != 0 && selectedItemPosition != adapter.getItemCount() - 1) {
|
||||
if (yOffset > 0) {
|
||||
if (yOffset > itemHeight / 3) {
|
||||
scrollOffset = itemHeight - yOffset;
|
||||
}
|
||||
} else {
|
||||
if (Math.abs(yOffset) > itemHeight / 3) {
|
||||
scrollOffset = -(itemHeight + yOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果item数量为1,总是回到0偏移
|
||||
if (adapter.getItemCount() > 1) {
|
||||
if (selectedItemPosition == 0 && yOffset < 0) {
|
||||
if (Math.abs(yOffset) > itemHeight / 3) {
|
||||
scrollOffset = -(itemHeight + yOffset);
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedItemPosition == adapter.getItemCount() - 1 && yOffset > 0) {
|
||||
if (yOffset > itemHeight / 3) {
|
||||
scrollOffset = itemHeight - yOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousScrollerY = yOffset - itemHeight * selectedItemPosition;
|
||||
scroller.startScroll(
|
||||
0, previousScrollerY,
|
||||
0, scrollOffset,
|
||||
duration);
|
||||
if (DEBUG) {
|
||||
Logger.d("justify: duration = %d, yOffset = %d, scrollOffset = %d", duration, yOffset, scrollOffset);
|
||||
}
|
||||
|
||||
invalidate();
|
||||
}
|
||||
pendingJustify = false;
|
||||
}
|
||||
|
||||
private void handleOffset(int dy) {
|
||||
if (DEBUG) {
|
||||
Logger.d("yOffset = %d, dy = %d", yOffset, dy);
|
||||
}
|
||||
yOffset += dy;
|
||||
|
||||
if (Math.abs(yOffset) >= itemHeight) {
|
||||
// 滚动到边界时
|
||||
if (selectedItemPosition == 0 && dy >= 0 || selectedItemPosition == adapter.getItemCount() - 1 && dy <= 0) {
|
||||
if (Math.abs(yOffset) > maxOverScrollY) {
|
||||
yOffset = yOffset > 0 ? maxOverScrollY : -maxOverScrollY;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int preSelection = selectedItemPosition;
|
||||
notifySelectedItemChangedIfNeeded(selectedItemPosition - (yOffset / itemHeight));
|
||||
yOffset -= (preSelection - selectedItemPosition) * itemHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user