Commit c14e01ff authored by mengcuiguang's avatar mengcuiguang

项目优化

parent cc7fb9fa
......@@ -10,44 +10,23 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import com.google.android.material.snackbar.Snackbar;
import android.util.DisplayMetrics;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.mints.wisdomclean.R;
import com.mints.library.loading.VaryViewHelperController;
import com.mints.library.net.netstatus.NetChangeObserver;
import com.mints.library.net.netstatus.NetStateReceiver;
import com.mints.library.net.netstatus.NetUtils;
import com.google.android.material.snackbar.Snackbar;
import com.mints.library.utils.CommonUtils;
import com.mints.wisdomclean.R;
import com.readystatesoftware.systembartint.SystemBarTintManager;
/**
* 描述:BaseAppCompatActivity
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
* 时间:2023/1/10 17:51
*/
public abstract class BaseAppCompatActivity extends TransitionActivity {
/**
* Log tag
*/
protected static String TAG_LOG = null;
/**
* Screen information
*/
protected int mScreenWidth = 0;
protected int mScreenHeight = 0;
protected float mScreenDensity = 0.0f;
public Bundle savedInstanceState;
/**
......@@ -55,16 +34,6 @@ public abstract class BaseAppCompatActivity extends TransitionActivity {
*/
protected Context mContext = null;
/**
* network status
*/
protected NetChangeObserver mNetChangeObserver = null;
/**
* loading view controller
*/
private VaryViewHelperController mVaryViewHelperController = null;
/**
* overridePendingTransition mode
*/
......@@ -109,13 +78,6 @@ public abstract class BaseAppCompatActivity extends TransitionActivity {
setTranslucentStatus(isApplyStatusBarTranslucency());
mContext = this;
TAG_LOG = this.getClass().getSimpleName();
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
mScreenDensity = displayMetrics.density;
mScreenHeight = displayMetrics.heightPixels;
mScreenWidth = displayMetrics.widthPixels;
// 布局
if (getContentViewLayoutID() != 0) {
......@@ -124,22 +86,6 @@ public abstract class BaseAppCompatActivity extends TransitionActivity {
throw new IllegalArgumentException("You must return a right contentView layout resource Id");
}
mNetChangeObserver = new NetChangeObserver() {
@Override
public void onNetConnected(NetUtils.NetType type) {
super.onNetConnected(type);
onNetworkConnected(type);
}
@Override
public void onNetDisConnect() {
super.onNetDisConnect();
onNetworkDisConnected();
}
};
NetStateReceiver.registerObserver(mNetChangeObserver);
initViewsAndEvents();
}
......@@ -155,9 +101,6 @@ public abstract class BaseAppCompatActivity extends TransitionActivity {
@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
if (null != getLoadingTargetView()) {
mVaryViewHelperController = new VaryViewHelperController(getLoadingTargetView());
}
}
@Override
......@@ -174,7 +117,6 @@ public abstract class BaseAppCompatActivity extends TransitionActivity {
@Override
protected void onDestroy() {
super.onDestroy();
NetStateReceiver.removeRegisterObserver(mNetChangeObserver);
}
/**
......@@ -191,26 +133,11 @@ public abstract class BaseAppCompatActivity extends TransitionActivity {
*/
protected abstract int getContentViewLayoutID();
/**
* get loading target view
*/
protected abstract View getLoadingTargetView();
/**
* init all views and add events
*/
protected abstract void initViewsAndEvents();
/**
* network connected
*/
protected abstract void onNetworkConnected(NetUtils.NetType type);
/**
* network disconnected
*/
protected abstract void onNetworkDisConnected();
/**
* is applyStatusBarTranslucency
*
......@@ -356,95 +283,6 @@ public abstract class BaseAppCompatActivity extends TransitionActivity {
builder.show();
}
/**
* toggle show loading
*
* @param toggle
*/
protected void toggleShowLoading(boolean toggle, String msg) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showLoading(msg);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show empty
*
* @param toggle
*/
protected void toggleShowEmpty(boolean toggle, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showEmpty(msg, R.mipmap.icon_empty, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show empty
*
* @param toggle
* @param resId
* @param msg
* @param onClickListener
*/
protected void toggleShowEmpty(boolean toggle, int resId, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (resId == 0)
resId = R.mipmap.icon_empty;
if (toggle) {
mVaryViewHelperController.showEmpty(msg, resId, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show error
*
* @param toggle
*/
protected void toggleShowError(boolean toggle, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showError(msg, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show network error
*
* @param toggle
*/
protected void toggleNetworkError(boolean toggle, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showNetworkError(onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* use SytemBarTintManager
*
......
......@@ -4,51 +4,29 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.google.android.material.snackbar.Snackbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import com.mints.wisdomclean.R;
import com.mints.wisdomclean.common.AppConfig;
import com.mints.library.loading.VaryViewHelperController;
import com.google.android.material.snackbar.Snackbar;
import com.mints.library.utils.CommonUtils;
import java.lang.reflect.Field;
/**
* 描述:BaseAppFragment
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
* 时间:2023/1/10 17:51
*/
public abstract class BaseAppFragment extends TransitionFragment {
/**
* Log tag
*/
protected static String TAG_LOG = null;
/**
* Screen information
*/
protected int mScreenWidth = 0;
protected int mScreenHeight = 0;
protected float mScreenDensity = 0.0f;
/**
* context
*/
protected Context mContext = null;
private VaryViewHelperController mVaryViewHelperController = null;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
......@@ -59,7 +37,6 @@ public abstract class BaseAppFragment extends TransitionFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TAG_LOG = this.getClass().getSimpleName();
}
@Override
......@@ -80,18 +57,6 @@ public abstract class BaseAppFragment extends TransitionFragment {
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (null != getLoadingTargetView()) {
mVaryViewHelperController = new VaryViewHelperController(getLoadingTargetView());
}
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
mScreenDensity = displayMetrics.density;
mScreenHeight = displayMetrics.heightPixels;
mScreenWidth = displayMetrics.widthPixels;
initViewsAndEvents();
}
......@@ -208,95 +173,6 @@ public abstract class BaseAppFragment extends TransitionFragment {
}
}
/**
* toggle show loading
*
* @param toggle
*/
protected void toggleShowLoading(boolean toggle, String msg) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showLoading(msg);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show empty
*
* @param toggle
*/
protected void toggleShowEmpty(boolean toggle, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showEmpty(msg, R.mipmap.icon_empty, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show empty
*
* @param toggle
* @param resId
* @param msg
* @param onClickListener
*/
protected void toggleShowEmpty(boolean toggle, int resId, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (resId == 0)
resId = R.mipmap.icon_empty;
if (toggle) {
mVaryViewHelperController.showEmpty(msg, resId, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show error
*
* @param toggle
*/
protected void toggleShowError(boolean toggle, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showError(msg, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show network error
*
* @param toggle
*/
protected void toggleNetworkError(boolean toggle, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showNetworkError(onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
@Override
protected boolean toggleIsBack2Left() { return false; }
}
package com.mints.library.base;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.mints.library.loading.VaryViewHelperController;
import com.mints.library.utils.CommonUtils;
import com.mints.wisdomclean.R;
import java.lang.reflect.Field;
/**
* 描述:BaseLazyViewFragment
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public abstract class BaseLazyViewFragment extends Fragment {
/**
* Log tag
*/
protected static String TAG_LOG = null;
/**
* Screen information
*/
protected int mScreenWidth = 0;
protected int mScreenHeight = 0;
protected float mScreenDensity = 0.0f;
/**
* context
*/
protected Context mContext = null;
private View rootView;
private VaryViewHelperController mVaryViewHelperController = null;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mContext = activity;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TAG_LOG = this.getClass().getSimpleName();
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (getContentViewLayoutID() != 0) {
//这里将VIEW也缓存
if (rootView==null){
rootView=inflater.inflate(getContentViewLayoutID(), null);
onlyInitViewsAndData();
}
ViewGroup parent = (ViewGroup) rootView.getParent();
if (parent != null) {
parent.removeView(rootView);
}
return rootView;
} else {
return super.onCreateView(inflater, container, savedInstanceState);
}
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (null != getLoadingTargetView()) {
mVaryViewHelperController = new VaryViewHelperController(getLoadingTargetView());
}
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
mScreenDensity = displayMetrics.density;
mScreenHeight = displayMetrics.heightPixels;
mScreenWidth = displayMetrics.widthPixels;
initViewsAndEvents();
}
@Override
public void onDestroyView() {
super.onDestroyView();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onDetach() {
super.onDetach();
// // for bug ---> java.lang.IllegalStateException: Activity has been destroyed
// try {
// Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
// childFragmentManager.setAccessible(true);
// childFragmentManager.set(this, null);
//
// } catch (NoSuchFieldException e) {
// throw new RuntimeException(e);
// } catch (IllegalAccessException e) {
// throw new RuntimeException(e);
// }
}
/**
* get loading target view
*/
protected abstract View getLoadingTargetView();
/**
* init all views and add events
*/
protected abstract void initViewsAndEvents();
/**
* init all views and data
*/
protected abstract void onlyInitViewsAndData();
/**
* bind layout resource file
*
* @return id of layout resource
*/
protected abstract int getContentViewLayoutID();
/**
* get the support fragment manager
*
* @return
*/
protected FragmentManager getSupportFragmentManager() {
return getActivity().getSupportFragmentManager();
}
/**
* startActivity
*
* @param clazz
*/
protected void readyGo(Class<?> clazz) {
Intent intent = new Intent(getActivity(), clazz);
startActivity(intent);
}
/**
* startActivity with bundle
*
* @param clazz
* @param bundle
*/
protected void readyGo(Class<?> clazz, Bundle bundle) {
Intent intent = new Intent(getActivity(), clazz);
if (null != bundle) {
intent.putExtras(bundle);
}
startActivity(intent);
}
/**
* startActivityForResult
*
* @param clazz
* @param requestCode
*/
protected void readyGoForResult(Class<?> clazz, int requestCode) {
Intent intent = new Intent(getActivity(), clazz);
startActivityForResult(intent, requestCode);
}
/**
* startActivityForResult with bundle
*
* @param clazz
* @param requestCode
* @param bundle
*/
protected void readyGoForResult(Class<?> clazz, int requestCode, Bundle bundle) {
Intent intent = new Intent(getActivity(), clazz);
if (null != bundle) {
intent.putExtras(bundle);
}
startActivityForResult(intent, requestCode);
}
/**
* show toast
*
* @param msg
*/
protected void showToast(String msg) {
if (null != msg && !CommonUtils.isEmpty(msg)) {
// Snackbar.make(((Activity) mContext).getWindow().getDecorView(), msg, Snackbar.LENGTH_SHORT).show();
Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
}
}
/**
* toggle show loading
*
* @param toggle
*/
protected void toggleShowLoading(boolean toggle, String msg) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showLoading(msg);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show empty
*
* @param toggle
*/
protected void toggleShowEmpty(boolean toggle, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showEmpty(msg, R.mipmap.icon_empty, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show empty
*
* @param toggle
* @param resId
* @param msg
* @param onClickListener
*/
protected void toggleShowEmpty(boolean toggle, int resId, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (resId == 0)
resId = R.mipmap.icon_empty;
if (toggle) {
mVaryViewHelperController.showEmpty(msg, resId, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show error
*
* @param toggle
*/
protected void toggleShowError(boolean toggle, String msg, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showError(msg, onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
/**
* toggle show network error
*
* @param toggle
*/
protected void toggleNetworkError(boolean toggle, View.OnClickListener onClickListener) {
if (null == mVaryViewHelperController) {
throw new IllegalArgumentException("You must return a right target view for loading");
}
if (toggle) {
mVaryViewHelperController.showNetworkError(onClickListener);
} else {
mVaryViewHelperController.restore();
}
}
}
package com.mints.library.base;
import android.os.Bundle;
import android.view.View;
import com.mints.library.swipeback.SwipeBackActivityBase;
import com.mints.library.swipeback.SwipeBackActivityHelper;
import com.mints.library.swipeback.SwipeBackLayout;
import com.mints.library.swipeback.Utils;
/**
* 描述:BaseSwipeBackCompatActivity
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public abstract class BaseSwipeBackCompatActivity extends BaseAppCompatActivity implements SwipeBackActivityBase {
private SwipeBackActivityHelper mHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHelper = new SwipeBackActivityHelper(this);
mHelper.onActivityCreate();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mHelper.onPostCreate();
}
@Override
public View findViewById(int id) {
View v = super.findViewById(id);
if (v == null && mHelper != null)
return mHelper.findViewById(id);
return v;
}
@Override
public SwipeBackLayout getSwipeBackLayout() {
return mHelper.getSwipeBackLayout();
}
@Override
public void setSwipeBackEnable(boolean enable) {
getSwipeBackLayout().setEnableGesture(enable);
}
@Override
public void scrollToFinishActivity() {
Utils.convertActivityToTranslucent(this);
getSwipeBackLayout().scrollToFinishActivity();
}
}
package com.mints.library.base;
import android.os.Bundle;
import android.view.View;
import com.mints.library.swipeback.SwipeBackActivityBase;
import com.mints.library.swipeback.SwipeBackActivityHelper;
import com.mints.library.swipeback.SwipeBackLayout;
import com.mints.library.swipeback.Utils;
/**
* 描述:BaseSwipeBackFragmentActivity
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public abstract class BaseSwipeBackFragmentActivity extends BaseFragmentActivity implements SwipeBackActivityBase {
private SwipeBackActivityHelper mHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHelper = new SwipeBackActivityHelper(this);
mHelper.onActivityCreate();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mHelper.onPostCreate();
}
@Override
public View findViewById(int id) {
View v = super.findViewById(id);
if (v == null && mHelper != null)
return mHelper.findViewById(id);
return v;
}
@Override
public SwipeBackLayout getSwipeBackLayout() {
return mHelper.getSwipeBackLayout();
}
@Override
public void setSwipeBackEnable(boolean enable) {
getSwipeBackLayout().setEnableGesture(enable);
}
@Override
public void scrollToFinishActivity() {
Utils.convertActivityToTranslucent(this);
getSwipeBackLayout().scrollToFinishActivity();
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.base;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.mints.wisdomclean.R;
import com.mints.library.net.netstatus.NetUtils;
import com.mints.library.utils.CommonUtils;
import com.mints.library.widgets.BrowserLayout;
/**
* 描述:BaseWebActivity
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class BaseWebActivity extends BaseSwipeBackCompatActivity {
public static final String BUNDLE_KEY_URL = "BUNDLE_KEY_URL";
public static final String BUNDLE_KEY_TITLE = "BUNDLE_KEY_TITLE";
public static final String BUNDLE_KEY_SHOW_BOTTOM_BAR = "BUNDLE_KEY_SHOW_BOTTOM_BAR";
private String mWebUrl = null;
private String mWebTitle = null;
private boolean isShowBottomBar = true;
private ImageView leftBtn;
private TextView title;
private BrowserLayout mBrowserLayout = null;
@Override
protected void getBundleExtras(Bundle extras) {
mWebTitle = extras.getString(BUNDLE_KEY_TITLE);
mWebUrl = extras.getString(BUNDLE_KEY_URL);
isShowBottomBar = extras.getBoolean(BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
}
@Override
protected int getContentViewLayoutID() {
return R.layout.activity_common_web;
}
@Override
protected View getLoadingTargetView() {
return null;
}
@Override
protected void initViewsAndEvents() {
setSystemBarTintDrawable(ContextCompat.getDrawable(this, R.drawable.sr_primary_r));
title = (TextView) findViewById(R.id.title);
leftBtn = (ImageView) findViewById( R.id.left_btn);
mBrowserLayout = (BrowserLayout) findViewById(R.id.common_web_browser_layout);
// leftBtn.setBackgroundResource(R.mipmap.icon_back);
leftBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
title.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
if (!CommonUtils.isEmpty(mWebTitle)) {
title.setText(mWebTitle);
} else {
mBrowserLayout.setWebTitle(title);
}
if (!CommonUtils.isEmpty(mWebUrl)) {
mBrowserLayout.loadUrl(mWebUrl);
} else {
showToast(getString(R.string.url_falil));
}
if (!isShowBottomBar) {
mBrowserLayout.hideBrowserController();
} else {
mBrowserLayout.showBrowserController();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mBrowserLayout != null) {
mBrowserLayout.destroyDrawingCache();
mBrowserLayout.clearWebView();
}
}
@Override
protected void onNetworkConnected(NetUtils.NetType type) {
}
@Override
protected void onNetworkDisConnected() {
}
@Override
protected boolean isApplyStatusBarTranslucency() {
return true;
}
@Override
protected boolean toggleOverridePendingTransition() {
return false;
}
@Override
protected TransitionMode getOverridePendingTransitionMode() {
return null;
}
@Override
protected boolean toggleIsBack2Left() {
return false;
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.loading;
import android.content.Context;
import android.view.View;
public interface IVaryViewHelper {
public abstract View getCurrentLayout();
public abstract void restoreView();
public abstract void showLayout(View view);
public abstract View inflate(int layoutId);
public abstract Context getContext();
public abstract View getView();
}
\ No newline at end of file
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.loading;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class VaryViewHelper implements IVaryViewHelper {
private View view;
private ViewGroup parentView;
private int viewIndex;
private ViewGroup.LayoutParams params;
private View currentView;
public VaryViewHelper(View view) {
super();
this.view = view;
}
private void init() {
params = view.getLayoutParams();
if (view.getParent() != null) {
parentView = (ViewGroup) view.getParent();
} else {
parentView = (ViewGroup) view.getRootView().findViewById(android.R.id.content);
}
int count = parentView.getChildCount();
for (int index = 0; index < count; index++) {
if (view == parentView.getChildAt(index)) {
viewIndex = index;
break;
}
}
currentView = view;
}
@Override
public View getCurrentLayout() {
return currentView;
}
@Override
public void restoreView() {
showLayout(view);
}
@Override
public void showLayout(View view) {
if (parentView == null) {
init();
}
this.currentView = view;
// 如果已经是那个view,那就不需要再进行替换操作了
if (parentView.getChildAt(viewIndex) != view) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeView(view);
}
parentView.removeViewAt(viewIndex);
parentView.addView(view, viewIndex, params);
}
}
@Override
public View inflate(int layoutId) {
return LayoutInflater.from(view.getContext()).inflate(layoutId, null);
}
@Override
public Context getContext() {
return view.getContext();
}
@Override
public View getView() {
return view;
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.loading;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.mints.library.utils.CommonUtils;
import com.mints.wisdomclean.R;
public class VaryViewHelperController {
private IVaryViewHelper helper;
public VaryViewHelperController(View view) {
this(new VaryViewHelper(view));
}
public VaryViewHelperController(IVaryViewHelper helper) {
super();
this.helper = helper;
}
public void showNetworkError(View.OnClickListener onClickListener) {
View layout = helper.inflate(R.layout.message);
TextView textView = (TextView) layout.findViewById(R.id.message_info);
textView.setText(helper.getContext().getResources().getString(R.string.netfail));
ImageView imageView = (ImageView) layout.findViewById(R.id.message_icon);
imageView.setImageResource(R.mipmap.icon_empty);
if (null != onClickListener) {
layout.setOnClickListener(onClickListener);
}
helper.showLayout(layout);
}
public void showError(String errorMsg, View.OnClickListener onClickListener) {
View layout = helper.inflate(R.layout.message);
TextView textView = (TextView) layout.findViewById(R.id.message_info);
if (!CommonUtils.isEmpty(errorMsg)) {
textView.setText(errorMsg);
} else {
textView.setText(helper.getContext().getResources().getString(R.string.common_error_msg));
}
ImageView imageView = (ImageView) layout.findViewById(R.id.message_icon);
imageView.setImageResource(R.mipmap.ic_error);
if (null != onClickListener) {
layout.setOnClickListener(onClickListener);
}
helper.showLayout(layout);
}
public void showEmpty(String emptyMsg, int resId, View.OnClickListener onClickListener) {
View layout = helper.inflate(R.layout.message);
TextView textView = (TextView) layout.findViewById(R.id.message_info);
if (!CommonUtils.isEmpty(emptyMsg)) {
textView.setText(emptyMsg);
} else {
textView.setText(helper.getContext().getResources().getString(R.string.common_empty_msg));
}
ImageView imageView = (ImageView) layout.findViewById(R.id.message_icon);
imageView.setImageResource(resId);
if (null != onClickListener) {
layout.setOnClickListener(onClickListener);
}
helper.showLayout(layout);
}
public void showLoading(String msg) {
View layout = helper.inflate(R.layout.loading);
if (!CommonUtils.isEmpty(msg)) {
TextView textView = (TextView) layout.findViewById(R.id.loading_msg);
textView.setText(msg);
}
helper.showLayout(layout);
}
public void restore() {
helper.restoreView();
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.loading;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
public class VaryViewHelperX implements IVaryViewHelper {
private IVaryViewHelper helper;
private View view;
public VaryViewHelperX(View view) {
super();
this.view = view;
ViewGroup group = (ViewGroup) view.getParent();
LayoutParams layoutParams = view.getLayoutParams();
FrameLayout frameLayout = new FrameLayout(view.getContext());
group.removeView(view);
group.addView(frameLayout, layoutParams);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
View floatView = new View(view.getContext());
frameLayout.addView(view, params);
frameLayout.addView(floatView, params);
helper = new VaryViewHelper(floatView);
}
@Override
public View getCurrentLayout() {
return helper.getCurrentLayout();
}
@Override
public void restoreView() {
helper.restoreView();
}
@Override
public void showLayout(View view) {
helper.showLayout(view);
}
@Override
public View inflate(int layoutId) {
return helper.inflate(layoutId);
}
@Override
public Context getContext() {
return helper.getContext();
}
@Override
public View getView() {
return view;
}
}
package com.mints.library.net;
import retrofit2.adapter.rxjava.HttpException;
/**
* 描述:NetCommon
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class NetCommon {
/**
* 网络请求错误码
*
* @param error
* @return
*/
public static int httpErrorCode(Throwable error) {
int httpErrorCode = 0;
if (error instanceof HttpException) {
httpErrorCode = ((HttpException) error).code();
}
return httpErrorCode;
}
}
package com.mints.library.net;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.Buffer;
import okio.BufferedSource;
import okio.ForwardingSource;
import okio.Okio;
import okio.Source;
/**
* 描述:下载进度
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class OkHttpProgress {
public void run() throws Exception {
Request request = new Request.Builder()
.url("https://publicobject.com/helloworld.txt")
.build();
final ProgressListener progressListener = new ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
System.out.println(bytesRead);
System.out.println(contentLength);
System.out.println(done);
System.out.format("%d%% done\n", (100 * bytesRead) / contentLength);
}
};
// OkHttpClient client = new OkHttpClient.Builder()
// .addNetworkInterceptor(new Interceptor() {
// @Override public Response intercept(Chain chain) throws IOException {
// Response originalResponse = chain.proceed(chain.request());
// return originalResponse.newBuilder()
// .body(new ProgressResponseBody(originalResponse.body(), progressListener))
// .build();
// }
// })
// .build();
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
}
public static void main(String... arg) throws Exception {
// try{
new OkHttpProgress().run();
// }catch (Exception e){}
}
private static class ProgressResponseBody extends ResponseBody {
private final ResponseBody responseBody;
private final ProgressListener progressListener;
private BufferedSource bufferedSource;
public ProgressResponseBody(ResponseBody responseBody, ProgressListener progressListener) {
this.responseBody = responseBody;
this.progressListener = progressListener;
}
@Override
public MediaType contentType() {
return responseBody.contentType();
}
@Override
public long contentLength() {
return responseBody.contentLength();
}
@Override
public BufferedSource source() {
if (bufferedSource == null) {
bufferedSource = Okio.buffer(source(responseBody.source()));
}
return bufferedSource;
}
private Source source(Source source) {
return new ForwardingSource(source) {
long totalBytesRead = 0L;
@Override
public long read(Buffer sink, long byteCount) throws IOException {
long bytesRead = super.read(sink, byteCount);
// read() returns the number of bytes read, or -1 if this source is exhausted.
totalBytesRead += bytesRead != -1 ? bytesRead : 0;
progressListener.update(totalBytesRead, responseBody.contentLength(), bytesRead == -1);
return bytesRead;
}
};
}
}
interface ProgressListener {
void update(long bytesRead, long contentLength, boolean done);
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.net.netstatus;
/**
* 描述:NetChangeObserver
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class NetChangeObserver {
/**
* when network connected callback
*/
public void onNetConnected(NetUtils.NetType type) {
}
/**
* when network disconnected callback
*/
public void onNetDisConnect() {
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.net.netstatus;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import com.mints.library.utils.TLog;
import java.util.ArrayList;
/**
* 描述:NetStateReceiver
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class NetStateReceiver extends BroadcastReceiver {
public final static String CUSTOM_ANDROID_NET_CHANGE_ACTION = "cn.com.huafg.net.conn.CONNECTIVITY_CHANGE";
private final static String ANDROID_NET_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
private final static String TAG = NetStateReceiver.class.getSimpleName();
private static boolean isNetAvailable = false;
private static NetUtils.NetType mNetType;
private static ArrayList<NetChangeObserver> mNetChangeObservers = new ArrayList<NetChangeObserver>();
private static BroadcastReceiver mBroadcastReceiver;
private static BroadcastReceiver getReceiver() {
if (null == mBroadcastReceiver) {
synchronized (NetStateReceiver.class) {
if (null == mBroadcastReceiver) {
mBroadcastReceiver = new NetStateReceiver();
}
}
}
return mBroadcastReceiver;
}
@Override
public void onReceive(Context context, Intent intent) {
mBroadcastReceiver = NetStateReceiver.this;
if (intent.getAction().equalsIgnoreCase(ANDROID_NET_CHANGE_ACTION) || intent.getAction().equalsIgnoreCase(CUSTOM_ANDROID_NET_CHANGE_ACTION)) {
if (!NetUtils.isNetworkAvailable(context)) {
TLog.i(TAG, "<--- network disconnected --->");
isNetAvailable = false;
} else {
TLog.i(TAG, "<--- network connected --->");
isNetAvailable = true;
mNetType = NetUtils.getAPNType(context);
}
notifyObserver();
}
}
public static void registerNetworkStateReceiver(Context mContext) {
IntentFilter filter = new IntentFilter();
filter.addAction(CUSTOM_ANDROID_NET_CHANGE_ACTION);
filter.addAction(ANDROID_NET_CHANGE_ACTION);
mContext.getApplicationContext().registerReceiver(getReceiver(), filter);
}
public static void checkNetworkState(Context mContext) {
Intent intent = new Intent();
intent.setAction(CUSTOM_ANDROID_NET_CHANGE_ACTION);
mContext.sendBroadcast(intent);
}
public static void unRegisterNetworkStateReceiver(Context mContext) {
if (mBroadcastReceiver != null) {
try {
mContext.getApplicationContext().unregisterReceiver(mBroadcastReceiver);
} catch (Exception e) {
TLog.d(TAG, e.getMessage());
}
}
}
public static boolean isNetworkAvailable() {
return isNetAvailable;
}
public static NetUtils.NetType getAPNType() {
return mNetType;
}
private void notifyObserver() {
if (!mNetChangeObservers.isEmpty()) {
int size = mNetChangeObservers.size();
for (int i = 0; i < size; i++) {
NetChangeObserver observer = mNetChangeObservers.get(i);
if (observer != null) {
if (isNetworkAvailable()) {
observer.onNetConnected(mNetType);
} else {
observer.onNetDisConnect();
}
}
}
}
}
public static void registerObserver(NetChangeObserver observer) {
if (mNetChangeObservers == null) {
mNetChangeObservers = new ArrayList<NetChangeObserver>();
}
mNetChangeObservers.add(observer);
}
public static void removeRegisterObserver(NetChangeObserver observer) {
if (mNetChangeObservers != null) {
if (mNetChangeObservers.contains(observer)) {
mNetChangeObservers.remove(observer);
}
}
}
}
\ No newline at end of file
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.net.netstatus;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import java.util.Locale;
/**
* 描述:NetUtils
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class NetUtils {
public enum NetType {
WIFI, CMNET, CMWAP, NONE
}
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] info = mgr.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
public static boolean isWifiConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
// if (mWiFiNetworkInfo != null) {
// return mWiFiNetworkInfo.isAvailable();
// }
if (mWiFiNetworkInfo.isConnected()) {
return true;
}
}
return false;
}
public static boolean isMobileConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (mMobileNetworkInfo != null) {
return mMobileNetworkInfo.isAvailable();
}
}
return false;
}
public static int getConnectedType(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
return mNetworkInfo.getType();
}
}
return -1;
}
public static NetType getAPNType(Context context) {
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null) {
return NetType.NONE;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_MOBILE) {
Locale netDefault = Locale.getDefault();
String extraInfo = networkInfo.getExtraInfo();
if (netDefault != null && !TextUtils.isEmpty(extraInfo) && TextUtils.equals(extraInfo.toLowerCase(netDefault), "cmnet")) {
return NetType.CMNET;
} else {
return NetType.CMWAP;
}
} else if (nType == ConnectivityManager.TYPE_WIFI) {
return NetType.WIFI;
}
return NetType.NONE;
}
public static String getNetworkState(Context context) {
String strNetworkType = "UNKNOWN";
final NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (activeNetworkInfo != null && activeNetworkInfo.getType() == 1) {
strNetworkType = "WIFI";
} else if (activeNetworkInfo != null && activeNetworkInfo.getType() == 0) {
String subtypeName = activeNetworkInfo.getSubtypeName();
switch (((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN: //api<8 : replace by 11
strNetworkType = "2G";
break;
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B: //api<9 : replace by 14
case TelephonyManager.NETWORK_TYPE_EHRPD: //api<11 : replace by 12
case TelephonyManager.NETWORK_TYPE_HSPAP: //api<13 : replace by 15
strNetworkType = "3G";
break;
case TelephonyManager.NETWORK_TYPE_LTE:
strNetworkType = "4G";
break;
default:
if (subtypeName.equalsIgnoreCase("TD-SCDMA") || subtypeName.equalsIgnoreCase("WCDMA") || subtypeName.equalsIgnoreCase("CDMA2000")) {
strNetworkType = "3G";
break;
}
strNetworkType = subtypeName;
break;
}
}
return strNetworkType;
}
/**
* 根据传入的URL获取一级域名
*
* @param url
* @return
*/
public static String getDomain(String url) {
String domain = "";
if (!TextUtils.isEmpty(url) && url.startsWith("http")) {
try {
String host = Uri.parse(url).getHost();
if (!TextUtils.isEmpty(host) && host.contains(".")) {
domain = host.substring(host.indexOf("."), host.length());
}
} catch (Exception ex) {
}
}
return domain;
}
}
package com.mints.library.recyclerview;
import android.view.View;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
/**
* Created by cundong on 2015/10/9.
* <p/>
* 继承自RecyclerView.OnScrollListener,可以监听到是否滑动到页面最低部
*/
public class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener implements OnListLoadNextPageListener {
/**
* 当前RecyclerView类型
*/
protected LayoutManagerType layoutManagerType;
/**
* 最后一个的位置
*/
private int[] lastPositions;
/**
* 最后一个可见的item的位置
*/
private int lastVisibleItemPosition;
/**
* 当前滑动的状态
*/
private int currentScrollState = 0;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManagerType == null) {
if (layoutManager instanceof GridLayoutManager) {
layoutManagerType = LayoutManagerType.GridLayout;
} else if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LayoutManagerType.LinearLayout;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
layoutManagerType = LayoutManagerType.StaggeredGridLayout;
} else {
throw new RuntimeException(
"Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
}
switch (layoutManagerType) {
case LinearLayout:
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case GridLayout:
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case StaggeredGridLayout:
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
if (lastPositions == null) {
lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
}
staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
lastVisibleItemPosition = findMax(lastPositions);
break;
}
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
currentScrollState = newState;
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
int visibleItemCount = layoutManager.getChildCount();
int totalItemCount = layoutManager.getItemCount();
if ((visibleItemCount > 0 && currentScrollState == RecyclerView.SCROLL_STATE_IDLE && (lastVisibleItemPosition) >= totalItemCount - 1)) {
onLoadNextPage(recyclerView);
}
}
/**
* 取数组中最大值
*
* @param lastPositions
* @return
*/
private int findMax(int[] lastPositions) {
int max = lastPositions[0];
for (int value : lastPositions) {
if (value > max) {
max = value;
}
}
return max;
}
@Override
public void onLoadNextPage(final View view) {
}
public static enum LayoutManagerType {
LinearLayout,
StaggeredGridLayout,
GridLayout
}
}
package com.mints.library.recyclerview;
import android.view.View;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
/**
* Created by cundong on 2015/10/9.
* <p/>
* 拓展的StaggeredGridLayoutManager,tks @Jack Tony
*/
public class ExStaggeredGridLayoutManager extends StaggeredGridLayoutManager {
private final String TAG = getClass().getSimpleName();
GridLayoutManager.SpanSizeLookup mSpanSizeLookup;
public ExStaggeredGridLayoutManager(int spanCount, int orientation) {
super(spanCount, orientation);
}
/**
* Returns the current used by the GridLayoutManager.
*
* @return The current used by the GridLayoutManager.
*/
public GridLayoutManager.SpanSizeLookup getSpanSizeLookup() {
return mSpanSizeLookup;
}
/**
* 设置某个位置的item的跨列程度,这里和GridLayoutManager有点不一样,
* 如果你设置某个位置的item的span>1了,那么这个item会占据所有列
*
* @param spanSizeLookup instance to be used to query number of spans
* occupied by each item
*/
public void setSpanSizeLookup(GridLayoutManager.SpanSizeLookup spanSizeLookup) {
mSpanSizeLookup = spanSizeLookup;
}
@Override
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
//Log.d(TAG, "item count = " + getItemCount());
for (int i = 0; i < getItemCount(); i++) {
if (mSpanSizeLookup.getSpanSize(i) > 1) {
//Log.d(TAG, "lookup > 1 = " + i);
try {
//fix 动态添加时报IndexOutOfBoundsException
View view = recycler.getViewForPosition(i);
if (view != null) {
/**
*占用所有的列
* @see https://plus.google.com/+EtienneLawlor/posts/c5T7fu9ujqi
*/
StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
lp.setFullSpan(true);
}
// recycler.recycleView(view);
} catch (Exception e) {
e.printStackTrace();
}
}
}
super.onMeasure(recycler, state, widthSpec, heightSpec);
}
}
\ No newline at end of file
package com.mints.library.recyclerview;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import java.util.ArrayList;
/**
* Created by cundong on 2015/10/9.
* <p/>
* RecyclerView.Adapter with Header and Footer
*/
public class HeaderAndFooterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER_VIEW = Integer.MIN_VALUE;
private static final int TYPE_FOOTER_VIEW = Integer.MIN_VALUE + 1;
/**
* RecyclerView使用的,真正的Adapter
*/
private RecyclerView.Adapter<RecyclerView.ViewHolder> mInnerAdapter;
private ArrayList<View> mHeaderViews = new ArrayList<>();
private ArrayList<View> mFooterViews = new ArrayList<>();
private RecyclerView mRecyclerView;
private RecyclerView.LayoutManager mLayoutManager;
private RecyclerView.AdapterDataObserver mDataObserver = new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
notifyDataSetChanged();
}
@Override
public void onItemRangeChanged(int positionStart, int itemCount) {
super.onItemRangeChanged(positionStart, itemCount);
notifyItemRangeChanged(positionStart + getHeaderViewsCount(), itemCount);
}
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
super.onItemRangeInserted(positionStart, itemCount);
notifyItemRangeInserted(positionStart + getHeaderViewsCount(), itemCount);
}
@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
super.onItemRangeRemoved(positionStart, itemCount);
notifyItemRangeRemoved(positionStart + getHeaderViewsCount(), itemCount);
}
@Override
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
super.onItemRangeMoved(fromPosition, toPosition, itemCount);
int headerViewsCountCount = getHeaderViewsCount();
notifyItemRangeChanged(fromPosition + headerViewsCountCount, toPosition + headerViewsCountCount + itemCount);
}
};
public HeaderAndFooterRecyclerViewAdapter() {
}
public HeaderAndFooterRecyclerViewAdapter(RecyclerView.Adapter innerAdapter) {
setAdapter(innerAdapter);
}
/**
* 设置adapter
* @param adapter
*/
public void setAdapter(RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
if (adapter != null) {
if (!(adapter instanceof RecyclerView.Adapter))
throw new RuntimeException("your adapter must be a RecyclerView.Adapter");
}
if (mInnerAdapter != null) {
notifyItemRangeRemoved(getHeaderViewsCount(), mInnerAdapter.getItemCount());
mInnerAdapter.unregisterAdapterDataObserver(mDataObserver);
}
this.mInnerAdapter = adapter;
mInnerAdapter.registerAdapterDataObserver(mDataObserver);
notifyItemRangeInserted(getHeaderViewsCount(), mInnerAdapter.getItemCount());
}
public RecyclerView.Adapter getInnerAdapter() {
return mInnerAdapter;
}
public void addHeaderView(View header) {
if (header == null) {
throw new RuntimeException("header is null");
}
mHeaderViews.add(header);
this.notifyDataSetChanged();
}
public void addFooterView(View footer) {
if (footer == null) {
throw new RuntimeException("footer is null");
}
mFooterViews.add(footer);
this.notifyDataSetChanged();
}
/**
* 返回第一个FoView
* @return
*/
public View getFooterView() {
return getFooterViewsCount()>0 ? mFooterViews.get(0) : null;
}
/**
* 返回第一个HeaderView
* @return
*/
public View getHeaderView() {
return getHeaderViewsCount()>0 ? mHeaderViews.get(0) : null;
}
public void removeHeaderView(View view) {
mHeaderViews.remove(view);
this.notifyDataSetChanged();
}
public void removeFooterView(View view) {
mFooterViews.remove(view);
this.notifyDataSetChanged();
}
public int getHeaderViewsCount() {
return mHeaderViews.size();
}
public int getFooterViewsCount() {
return mFooterViews.size();
}
public boolean isHeader(int position) {
return getHeaderViewsCount() > 0 && position == 0;
}
public boolean isFooter(int position) {
int lastPosition = getItemCount() - 1;
return getFooterViewsCount() > 0 && position == lastPosition;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
int headerViewsCountCount = getHeaderViewsCount();
if (viewType < TYPE_HEADER_VIEW + headerViewsCountCount) {
return new ViewHolder(mHeaderViews.get(viewType - TYPE_HEADER_VIEW));
} else if (viewType >= TYPE_FOOTER_VIEW && viewType < Integer.MAX_VALUE / 2) {
return new ViewHolder(mFooterViews.get(viewType - TYPE_FOOTER_VIEW));
} else {
return mInnerAdapter.onCreateViewHolder(parent, viewType - Integer.MAX_VALUE / 2);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
int headerViewsCountCount = getHeaderViewsCount();
if (position >= headerViewsCountCount && position < headerViewsCountCount + mInnerAdapter.getItemCount()) {
mInnerAdapter.onBindViewHolder(holder, position - headerViewsCountCount);
} else {
ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
if(layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) layoutParams).setFullSpan(true);
} else if (layoutParams == null && mLayoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager.LayoutParams lp = new StaggeredGridLayoutManager.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
lp.setFullSpan(true);
holder.itemView.setLayoutParams(lp);
}
}
}
@Override
public int getItemCount() {
return getHeaderViewsCount() + getFooterViewsCount() + mInnerAdapter.getItemCount();
}
@Override
public int getItemViewType(int position) {
int innerCount = mInnerAdapter.getItemCount();
int headerViewsCountCount = getHeaderViewsCount();
if (position < headerViewsCountCount) {
return TYPE_HEADER_VIEW + position;
} else if (headerViewsCountCount <= position && position < headerViewsCountCount + innerCount) {
int innerItemViewType = mInnerAdapter.getItemViewType(position - headerViewsCountCount);
if(innerItemViewType >= Integer.MAX_VALUE / 2) {
throw new IllegalArgumentException("your adapter's return value of getViewTypeCount() must < Integer.MAX_VALUE / 2");
}
return innerItemViewType + Integer.MAX_VALUE / 2;
} else {
return TYPE_FOOTER_VIEW + position - headerViewsCountCount - innerCount;
}
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
}
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
mRecyclerView = recyclerView;
mInnerAdapter.onAttachedToRecyclerView(recyclerView);
if (mLayoutManager == null) {
mLayoutManager = recyclerView.getLayoutManager();
}
}
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
super.onViewAttachedToWindow(holder);
if (mLayoutManager == null && mRecyclerView != null) {
mLayoutManager = mRecyclerView.getLayoutManager();
}
}
}
\ No newline at end of file
package com.mints.library.recyclerview;
import androidx.recyclerview.widget.GridLayoutManager;
/**
* Created by cundong on 2015/10/23.
* <p/>
* RecyclerView为GridLayoutManager时,设置了HeaderView,就会用到这个SpanSizeLookup
*/
public class HeaderSpanSizeLookup extends GridLayoutManager.SpanSizeLookup {
private HeaderAndFooterRecyclerViewAdapter mAdapter;
private int mSpanSize = 1;
public HeaderSpanSizeLookup(HeaderAndFooterRecyclerViewAdapter adapter, int spanSize) {
this.mAdapter = adapter;
this.mSpanSize = spanSize;
}
@Override
public int getSpanSize(int position) {
if (mAdapter == null) {
throw new RuntimeException("you must setAdapter for RecyclerView first.");
}
boolean isHeaderOrFooter = mAdapter.isHeader(position) || mAdapter.isFooter(position);
return isHeaderOrFooter ? mSpanSize : 1;
}
}
\ No newline at end of file
package com.mints.library.recyclerview;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class MyDividerItemDecoration extends RecyclerView.ItemDecoration {
private int orientation = LinearLayoutManager.VERTICAL;
private Drawable divider;
private final int[] attrs = new int[]{android.R.attr.listDivider};
public MyDividerItemDecoration(Context context, int orientation) {
TypedArray typedArray = context.obtainStyledAttributes(attrs);
divider = typedArray.getDrawable(0);
typedArray.recycle();
setOrientation(orientation);
}
public void setOrientation(int orientation) {
if (orientation != LinearLayoutManager.VERTICAL
&& orientation != LinearLayoutManager.HORIZONTAL) {
throw new IllegalArgumentException("unsupport type");
}
this.orientation = orientation;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (orientation == LinearLayoutManager.VERTICAL) {
outRect.set(0, 0, 0, divider.getIntrinsicHeight());
} else {
outRect.set(0, 0, divider.getIntrinsicWidth(), 0);
}
}
//RecyclerView回调绘制方法
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (orientation == LinearLayoutManager.VERTICAL) {
drawVertical(c, parent);
} else {
drawHorizontal(c, parent);
}
super.onDraw(c, parent, state);
}
private void drawHorizontal(Canvas c, RecyclerView parent) {
int top = parent.getPaddingTop();
int bottom = parent.getHeight() - parent.getPaddingBottom();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int left = child.getRight() + params.rightMargin + Math.round(ViewCompat.getTranslationX(child));
int right = left + divider.getIntrinsicHeight();
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
}
private void drawVertical(Canvas c, RecyclerView parent) {
int left = parent.getPaddingLeft();
int right = parent.getWidth() - parent.getPaddingRight();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
int bottom = top + divider.getIntrinsicHeight();
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
}
}
package com.mints.library.recyclerview;
import android.view.View;
/**
* Created by cundong on 2015/10/9.
* RecyclerView/ListView/GridView 滑动加载下一页时的回调接口
*/
public interface OnListLoadNextPageListener {
/**
* 开始加载下一页
*
* @param view 当前RecyclerView/ListView/GridView
*/
void onLoadNextPage(View view);
}
\ No newline at end of file
package com.mints.library.recyclerview;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
/**
* Created by cundong on 2015/10/22.
* <p/>
* RecyclerView设置Header/Footer所用到的工具类
*/
public class RecyclerViewUtils {
/**
* 设置HeaderView
*
* @param recyclerView
* @param view
*/
public static void setHeaderView(RecyclerView recyclerView, View view) {
RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
if (outerAdapter == null || !(outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter)) {
return;
}
HeaderAndFooterRecyclerViewAdapter headerAndFooterAdapter = (HeaderAndFooterRecyclerViewAdapter) outerAdapter;
if (headerAndFooterAdapter.getHeaderViewsCount() == 0) {
headerAndFooterAdapter.addHeaderView(view);
}
}
/**
* 设置FooterView
*
* @param recyclerView
* @param view
*/
public static void setFooterView(RecyclerView recyclerView, View view) {
RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
if (outerAdapter == null || !(outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter)) {
return;
}
HeaderAndFooterRecyclerViewAdapter headerAndFooterAdapter = (HeaderAndFooterRecyclerViewAdapter) outerAdapter;
if (headerAndFooterAdapter.getFooterViewsCount() == 0) {
headerAndFooterAdapter.addFooterView(view);
}
}
/**
* 移除FooterView
*
* @param recyclerView
*/
public static void removeFooterView(RecyclerView recyclerView) {
RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
if (outerAdapter != null && outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter) {
int footerViewCounter = ((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getFooterViewsCount();
if (footerViewCounter > 0) {
View footerView = ((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getFooterView();
((HeaderAndFooterRecyclerViewAdapter) outerAdapter).removeFooterView(footerView);
}
}
}
/**
* 移除HeaderView
*
* @param recyclerView
*/
public static void removeHeaderView(RecyclerView recyclerView) {
RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
if (outerAdapter != null && outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter) {
int headerViewCounter = ((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getHeaderViewsCount();
if (headerViewCounter > 0) {
View headerView = ((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getHeaderView();
((HeaderAndFooterRecyclerViewAdapter) outerAdapter).removeFooterView(headerView);
}
}
}
/**
* 请使用本方法替代RecyclerView.ViewHolder的getLayoutPosition()方法
*
* @param recyclerView
* @param holder
* @return
*/
public static int getLayoutPosition(RecyclerView recyclerView, RecyclerView.ViewHolder holder) {
RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
if (outerAdapter != null && outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter) {
int headerViewCounter = ((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getHeaderViewsCount();
if (headerViewCounter > 0) {
return holder.getLayoutPosition() - headerViewCounter;
}
}
return holder.getLayoutPosition();
}
/**
* 请使用本方法替代RecyclerView.ViewHolder的getAdapterPosition()方法
*
* @param recyclerView
* @param holder
* @return
*/
public static int getAdapterPosition(RecyclerView recyclerView, RecyclerView.ViewHolder holder) {
RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
if (outerAdapter != null && outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter) {
int headerViewCounter = ((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getHeaderViewsCount();
if (headerViewCounter > 0) {
return holder.getAdapterPosition() - headerViewCounter;
}
}
return holder.getAdapterPosition();
}
}
\ No newline at end of file
package me.hgj.jetpackmvvm.demo.app.weight.recyclerview
import android.annotation.SuppressLint
import android.graphics.Canvas
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class SpaceItemDecoration(private val leftRight: Int, private val topBottom: Int,private val firstNeedTop:Boolean = true) : RecyclerView.ItemDecoration() {
//leftRight为横向间的距离 topBottom为纵向间距离
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
super.onDraw(c, parent, state)
}
@SuppressLint("WrongConstant")
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
val layoutManager = parent.layoutManager as LinearLayoutManager?
//竖直方向的
if (layoutManager!!.orientation == LinearLayoutManager.VERTICAL) {
//最后一项需要 bottom
if (parent.getChildAdapterPosition(view) == layoutManager.itemCount - 1) {
outRect.bottom = topBottom
}
if(!firstNeedTop&&parent.getChildAdapterPosition(view)==0){
outRect.top = 0
}else{
outRect.top = topBottom
}
outRect.left = leftRight
outRect.right = leftRight
} else {
//最后一项需要right
if (parent.getChildAdapterPosition(view) != layoutManager.itemCount - 1) {
outRect.right = leftRight
}
outRect.top = topBottom
outRect.left = 0
outRect.bottom = topBottom
}
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.swipeback;
/**
* @author Yrom
*/
public interface SwipeBackActivityBase {
/**
* @return the SwipeBackLayout associated with this activity.
*/
public abstract SwipeBackLayout getSwipeBackLayout();
public abstract void setSwipeBackEnable(boolean enable);
/**
* Scroll out contentView and finish the activity
*/
public abstract void scrollToFinishActivity();
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.swipeback;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import com.mints.wisdomclean.R;
/**
* @author Yrom
*/
public class SwipeBackActivityHelper {
private Activity mActivity;
private SwipeBackLayout mSwipeBackLayout;
public SwipeBackActivityHelper(Activity activity) {
mActivity = activity;
}
@SuppressWarnings("deprecation")
public void onActivityCreate() {
mActivity.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
mActivity.getWindow().getDecorView().setBackgroundDrawable(null);
mSwipeBackLayout = (SwipeBackLayout) LayoutInflater.from(mActivity).inflate(
R.layout.swipeback_layout, null);
mSwipeBackLayout.addSwipeListener(new SwipeBackLayout.SwipeListener() {
@Override
public void onScrollStateChange(int state, float scrollPercent) {
}
@Override
public void onEdgeTouch(int edgeFlag) {
Utils.convertActivityToTranslucent(mActivity);
}
@Override
public void onScrollOverThreshold() {
}
});
}
public void onPostCreate() {
mSwipeBackLayout.attachToActivity(mActivity);
}
public View findViewById(int id) {
if (mSwipeBackLayout != null) {
return mSwipeBackLayout.findViewById(id);
}
return null;
}
public SwipeBackLayout getSwipeBackLayout() {
return mSwipeBackLayout;
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.swipeback;
import android.app.Activity;
import android.app.ActivityOptions;
import android.os.Build;
import java.lang.reflect.Method;
/**
*
*/
public class Utils {
private Utils() {
}
/**
* Convert a translucent themed Activity
* {@link android.R.attr#windowIsTranslucent} to a fullscreen opaque
* Activity.
* <p>
* Call this whenever the background of a translucent Activity has changed
* to become opaque. Doing so will allow the {@link android.view.Surface} of
* the Activity behind to be released.
* <p>
* This call has no effect on non-translucent activities or on activities
* with the {@link android.R.attr#windowIsFloating} attribute.
*/
public static void convertActivityFromTranslucent(Activity activity) {
try {
Method method = Activity.class.getDeclaredMethod("convertFromTranslucent");
method.setAccessible(true);
method.invoke(activity);
} catch (Throwable t) {
}
}
/**
* Convert a translucent themed Activity
* {@link android.R.attr#windowIsTranslucent} back from opaque to
* translucent following a call to
* {@link #convertActivityFromTranslucent(Activity)} .
* <p>
* Calling this allows the Activity behind this one to be seen again. Once
* all such Activities have been redrawn
* <p>
* This call has no effect on non-translucent activities or on activities
* with the {@link android.R.attr#windowIsFloating} attribute.
*/
// public static void convertActivityToTranslucent(Activity activity) {
// try {
// Class<?>[] classes = Activity.class.getDeclaredClasses();
// Class<?> translucentConversionListenerClazz = null;
// for (Class clazz : classes) {
// if (clazz.getSimpleName().contains("TranslucentConversionListener")) {
// translucentConversionListenerClazz = clazz;
// }
// }
// Method method = Activity.class.getDeclaredMethod("convertToTranslucent",
// translucentConversionListenerClazz);
// method.setAccessible(true);
// method.invoke(activity, new Object[] {
// null
// });
// } catch (Throwable t) {
// }
// }
public static void convertActivityToTranslucent(Activity activity) {
try {
Class[] t = Activity.class.getDeclaredClasses();
Class translucentConversionListenerClazz = null;
Class[] method = t;
int len$ = t.length;
for(int i$ = 0; i$ < len$; ++i$) {
Class clazz = method[i$];
if(clazz.getSimpleName().contains("TranslucentConversionListener")) {
translucentConversionListenerClazz = clazz;
break;
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Method var8 = Activity.class.getDeclaredMethod("convertToTranslucent", translucentConversionListenerClazz, ActivityOptions.class);
var8.setAccessible(true);
var8.invoke(activity, new Object[]{null, null});
} else {
Method var8 = Activity.class.getDeclaredMethod("convertToTranslucent", translucentConversionListenerClazz);
var8.setAccessible(true);
var8.invoke(activity, new Object[]{null});
}
} catch (Throwable e) {
}
}
}
package com.mints.library.utils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class AITextUtil {
public static final String TAG = AITextUtil.class.getSimpleName();
public AITextUtil() {
}
public static boolean isEmpty(Collection collection) {
return null == collection || collection.isEmpty();
}
public static boolean isEmpty(Map map) {
return null == map || map.isEmpty();
}
public static boolean isEmpty(Object[] objs) {
return null == objs || objs.length <= 0;
}
public static boolean isEmpty(int[] objs) {
return null == objs || objs.length <= 0;
}
public static boolean isEmpty(CharSequence charSequence) {
return null == charSequence || charSequence.length() <= 0;
}
public static boolean isBlank(CharSequence charSequence) {
return null == charSequence || charSequence.toString().trim().length() <= 0;
}
public static boolean isLeast(Object[] objs, int count) {
return null != objs && objs.length >= count;
}
public static boolean isLeast(int[] objs, int count) {
return null != objs && objs.length >= count;
}
public static boolean isEquals(Object a, Object b) {
return a == null?b == null:a.equals(b);
}
public static String trim(CharSequence charSequence) {
return null == charSequence?null:charSequence.toString().trim();
}
public static String pickFirstNotNull(CharSequence... options) {
if(isEmpty((Object[])options)) {
return null;
} else {
String result = null;
CharSequence[] var2 = options;
int var3 = options.length;
for(int var4 = 0; var4 < var3; ++var4) {
CharSequence cs = var2[var4];
if(null != cs) {
result = cs.toString();
break;
}
}
return result;
}
}
// @SafeVarargs
// public static <T> T pickFirstNotNull(Class<T> clazz, T... options) {
// if(isEmpty(options)) {
// return null;
// } else {
// Object result = null;
// Object[] var3 = options;
// int var4 = options.length;
//
// for(int var5 = 0; var5 < var4; ++var5) {
// Object obj = var3[var5];
// if(null != obj) {
// result = obj;
// break;
// }
// }
//
// return result;
// }
// }
// public static SpannableString replaceImageSpan(CharSequence charSequence, String regPattern, Drawable drawable) {
// SpannableString ss = charSequence instanceof SpannableString?(SpannableString)charSequence:new SpannableString(charSequence);
//
// try {
// ImageSpan ex = new ImageSpan(drawable);
// Pattern pattern = Pattern.compile(regPattern);
// Matcher matcher = pattern.matcher(ss);
//
// while(matcher.find()) {
// String key = matcher.group();
// ss.setSpan(ex, matcher.start(), matcher.start() + key.length(), 17);
// }
// } catch (Exception var8) {
// Logger.e(TAG, var8);
// }
//
// return ss;
// }
public static String compress(String str) throws IOException {
if(str != null && str.length() != 0) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(str.getBytes());
gzip.close();
return out.toString("ISO-8859-1");
} else {
return str;
}
}
public static String uncompress(String str) throws IOException {
if(str != null && str.length() != 0) {
ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes("UTF-8"));
return uncompress((InputStream)in);
} else {
return str;
}
}
public static String uncompress(InputStream inputStream) throws IOException {
if(inputStream == null) {
return null;
} else {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPInputStream gunzip = new GZIPInputStream(inputStream);
byte[] buffer = new byte[256];
int n;
while((n = gunzip.read(buffer)) >= 0) {
out.write(buffer, 0, n);
}
return out.toString();
}
}
public static String inputStream2String(InputStream in) throws IOException {
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
int n;
while((n = in.read(b)) != -1) {
out.append(new String(b, 0, n));
}
return out.toString();
}
// public static String inputStream2StringFromGZIP(InputStream is) {
// StringBuilder resultSb = new StringBuilder();
// BufferedInputStream bis = null;
// InputStreamReader reader = null;
//
// try {
// bis = new BufferedInputStream((InputStream)is);
// bis.mark(2);
// byte[] e = new byte[2];
// int result = bis.read(e);
// bis.reset();
// int headerData = getShort(e);
// if(result != -1 && headerData == 8075) {
// is = new GZIPInputStream(bis);
// } else {
// is = bis;
// }
//
// reader = new InputStreamReader((InputStream)is, "utf-8");
// char[] data = new char[100];
//
// int readSize;
// while((readSize = reader.read(data)) > 0) {
// resultSb.append(data, 0, readSize);
// }
// } catch (Exception var12) {
// Logger.e(TAG, var12);
// } finally {
// ABIOUtil.closeIO(new Closeable[]{(Closeable)is, bis, reader});
// }
//
// return resultSb.toString();
// }
private static int getShort(byte[] data) {
return data[0] << 8 | data[1] & 255;
}
}
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.library.utils;
import android.content.Context;
import android.content.res.Configuration;
import android.util.DisplayMetrics;
import android.util.TypedValue;
/**
* 描述:DensityUtils
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class DensityUtils {
private static final float DOT_FIVE = 0.5f;
/**
* dip to px
*
* @param context
* @param dip
* @return
*/
public static int dip2px(Context context, float dip) {
float density = getDensity(context);
return (int) (dip * density + DensityUtils.DOT_FIVE);
}
/**
* px to dip
*
* @param context
* @param px
* @return
*/
public static int px2dip(Context context, float px) {
float density = getDensity(context);
return (int) (px / density + DOT_FIVE);
}
/**
* pt to px
*
* @param context context
* @param value 需要转换的pt值,若context.resources.displayMetrics经过resetDensity()的修改则得到修正的相对长度,否则得到原生的磅
* @return px值
*/
public static float pt2px(Context context, float value) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, value, context.getResources().getDisplayMetrics());
}
/**
* 将sp值转换为px值,保证文字大小不变
*
* @param context
* @param spValue (DisplayMetrics类中属性scaledDensity)
* @return
*/
public static int sp2px(Context context, float spValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}
private static DisplayMetrics sDisplayMetrics;
/**
* get screen width
*
* @param context
* @return
*/
public static int getDisplayWidth(Context context) {
initDisplayMetrics(context);
return sDisplayMetrics.widthPixels;
}
/**
* get screen height
*
* @param context
* @return
*/
public static int getDisplayHeight(Context context) {
initDisplayMetrics(context);
return sDisplayMetrics.heightPixels;
}
/**
* get screen density
*
* @param context
* @return
*/
public static float getDensity(Context context) {
initDisplayMetrics(context);
return sDisplayMetrics.density;
}
/**
* get screen density dpi
*
* @param context
* @return
*/
public static int getDensityDpi(Context context) {
initDisplayMetrics(context);
return sDisplayMetrics.densityDpi;
}
/**
* init display metrics
*
* @param context
*/
private static synchronized void initDisplayMetrics(Context context) {
sDisplayMetrics = context.getResources().getDisplayMetrics();
}
/**
* is landscape
*
* @param context
* @return
*/
public static boolean isLandscape(Context context) {
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}
/**
* is portrait
*
* @param context
* @return
*/
public static boolean isPortrait(Context context) {
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}
}
\ No newline at end of file
package com.mints.library.utils;
import android.app.Application;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* 描述:获取手机参数信息
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class PhoneParameterUtils {
/**
* 获取MAC地址
*
* @return
*/
public static String getMacAddress(Application application) {
WifiManager manager = (WifiManager) application.getSystemService(Context.WIFI_SERVICE);
String MacAddress = "";
if (manager != null) {
MacAddress = manager.getConnectionInfo().getMacAddress();
}
return MacAddress;
}
/**
* 返回用户手机运营商名称 * @param telephonyManager * @return
*/
public static String getProvidersName(Application loanApplication) {
String ProvidersName = null;
try {
TelephonyManager telephonyManager = (TelephonyManager) loanApplication.getSystemService(Context.TELEPHONY_SERVICE);
String IMSI; // 返回唯一的用户ID;就是这张卡的编号神马的
IMSI = telephonyManager.getSubscriberId();
if (IMSI == null)
return "unkwon";
// IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。其中
if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
ProvidersName = "中国移动";
} else if (IMSI.startsWith("46001")) {
ProvidersName = "中国联通";
} else if (IMSI.startsWith("46003")) {
ProvidersName = "中国电信";
}
ProvidersName = URLEncoder.encode("" + ProvidersName, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
return ProvidersName;
}
}
......@@ -3,8 +3,7 @@ package com.mints.wisdomclean.common;
/**
* 描述:配置app设置开关
* 作者:孟崔广
* 时间:2020/06/22 17:51
* 邮箱:mengcuiguang@cashbang.cn
* 时间:2023/06/22 17:51
*/
public class AppConfig {
......@@ -17,50 +16,4 @@ public class AppConfig {
* app应用首页 0-主页 1-position 2-我
*/
public static int fragmentClickFlag = 0;
public static boolean isLoadMainFragment = false;
/**
* 主页功能文字展示
*/
/* 内存占用率 */
public static int fakeBoostCount = 0;
/* 已清理垃圾数量 */
public static int fakeCleanCount = 0;
/* 当前耗电应用数 */
public static int fakeSaveBatteryCount = 0;
/* 当前耗电应用数 */
public static int fakeSaveBatteryMinter = 0;
/* 当前降温数据 */
public static int fakeCoolTemp = 0;
/* 上次降温操作时间 */
public static long fakeCoolTime = 0L;
/* 上次加速操作时间 */
public static long fakeBoostTime = 0L;
/* 上次清理操作时间 */
public static long fakeCleanTime = 0L;
/* 上次省电操作时间 */
public static long fakeSaveBatteryTime = 0L;
/*是否可以 一键加速 */
public static boolean isCanBoost = true;
/*是否可以 一键清理 */
public static boolean isCanClean = true;
/*是否可以 超强省电 */
public static boolean isCanSaveBattery = true;
/*是否可以 瞬间降温 */
public static boolean isCanCool = true;
public static long splashTime = 0;
public static long fakeJunkCleanTime = 0L;
public static long fakeWechatCleanTime = 0L;
public static long fakeSafeCheckTime = 0L;
public static int mainCleanValue = 0;
public static boolean isMainCleanValue = false;
}
package com.mints.wisdomclean.common
import androidx.recyclerview.widget.RecyclerView
/**
* 作者 : hegaojian
* 时间 : 2020/2/20
* 描述 :项目中自定义类的拓展函数
*/
//绑定普通的Recyclerview
fun RecyclerView.init(
layoutManger: RecyclerView.LayoutManager,
bindAdapter: RecyclerView.Adapter<*>,
isScroll: Boolean = true
): RecyclerView {
layoutManager = layoutManger
setHasFixedSize(true)
adapter = bindAdapter
isNestedScrollingEnabled = isScroll
return this
}
package com.mints.wisdomclean.mvp.model
data class FileBean(
val image: Any,
val path: String,
var time: String,
val name: String,
val size: Long
)
\ No newline at end of file
package com.mints.wisdomclean.mvp.views
interface GuideView : BaseView {
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment