Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_vedio
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_vedio
Commits
c14e01ff
Commit
c14e01ff
authored
Jul 04, 2023
by
mengcuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目优化
parent
cc7fb9fa
Changes
55
Hide whitespace changes
Inline
Side-by-side
Showing
55 changed files
with
9 additions
and
7108 deletions
+9
-7108
BaseAppCompatActivity.java
...in/java/com/mints/library/base/BaseAppCompatActivity.java
+3
-165
BaseAppFragment.java
...src/main/java/com/mints/library/base/BaseAppFragment.java
+4
-128
BaseFragmentActivity.java
...ain/java/com/mints/library/base/BaseFragmentActivity.java
+0
-459
BaseLazyFragment.java
...rc/main/java/com/mints/library/base/BaseLazyFragment.java
+0
-380
BaseLazyViewFragment.java
...ain/java/com/mints/library/base/BaseLazyViewFragment.java
+0
-311
BaseSwipeBackCompatActivity.java
...a/com/mints/library/base/BaseSwipeBackCompatActivity.java
+0
-56
BaseSwipeBackFragmentActivity.java
...com/mints/library/base/BaseSwipeBackFragmentActivity.java
+0
-56
BaseWebActivity.java
...src/main/java/com/mints/library/base/BaseWebActivity.java
+0
-154
IVaryViewHelper.java
.../main/java/com/mints/library/loading/IVaryViewHelper.java
+0
-35
VaryViewHelper.java
...c/main/java/com/mints/library/loading/VaryViewHelper.java
+0
-94
VaryViewHelperController.java
...a/com/mints/library/loading/VaryViewHelperController.java
+0
-105
VaryViewHelperX.java
.../main/java/com/mints/library/loading/VaryViewHelperX.java
+0
-75
NetCommon.java
video/app/src/main/java/com/mints/library/net/NetCommon.java
+0
-27
OkHttpProgress.java
...p/src/main/java/com/mints/library/net/OkHttpProgress.java
+0
-124
NetChangeObserver.java
...va/com/mints/library/net/netstatus/NetChangeObserver.java
+0
-40
NetStateReceiver.java
...ava/com/mints/library/net/netstatus/NetStateReceiver.java
+0
-134
NetUtils.java
...c/main/java/com/mints/library/net/netstatus/NetUtils.java
+0
-183
EndlessRecyclerOnScrollListener.java
...library/recyclerview/EndlessRecyclerOnScrollListener.java
+0
-112
ExStaggeredGridLayoutManager.java
...ts/library/recyclerview/ExStaggeredGridLayoutManager.java
+0
-70
HeaderAndFooterRecyclerViewAdapter.java
...rary/recyclerview/HeaderAndFooterRecyclerViewAdapter.java
+0
-239
HeaderSpanSizeLookup.java
.../com/mints/library/recyclerview/HeaderSpanSizeLookup.java
+0
-30
MyDividerItemDecoration.java
...m/mints/library/recyclerview/MyDividerItemDecoration.java
+0
-82
OnListLoadNextPageListener.java
...ints/library/recyclerview/OnListLoadNextPageListener.java
+0
-17
RecyclerViewUtils.java
...ava/com/mints/library/recyclerview/RecyclerViewUtils.java
+0
-129
SpaceItemDecoration.kt
...ava/com/mints/library/recyclerview/SpaceItemDecoration.kt
+0
-52
SwipeBackActivityBase.java
...va/com/mints/library/swipeback/SwipeBackActivityBase.java
+0
-35
SwipeBackActivityHelper.java
.../com/mints/library/swipeback/SwipeBackActivityHelper.java
+0
-77
SwipeBackLayout.java
...ain/java/com/mints/library/swipeback/SwipeBackLayout.java
+0
-540
Utils.java
.../app/src/main/java/com/mints/library/swipeback/Utils.java
+0
-110
ViewDragHelper.java
...main/java/com/mints/library/swipeback/ViewDragHelper.java
+0
-1573
AITextUtil.java
...app/src/main/java/com/mints/library/utils/AITextUtil.java
+0
-212
DensityUtils.java
...p/src/main/java/com/mints/library/utils/DensityUtils.java
+0
-156
PhoneParameterUtils.java
...ain/java/com/mints/library/utils/PhoneParameterUtils.java
+0
-59
SmartBarUtils.java
.../src/main/java/com/mints/library/utils/SmartBarUtils.java
+0
-331
AppConfig.java
...src/main/java/com/mints/wisdomclean/common/AppConfig.java
+1
-48
Constant.kt
...pp/src/main/java/com/mints/wisdomclean/common/Constant.kt
+0
-36
CustomViewExt.kt
...c/main/java/com/mints/wisdomclean/common/CustomViewExt.kt
+0
-22
AppBean.java
...rc/main/java/com/mints/wisdomclean/mvp/model/AppBean.java
+0
-215
DataModel.java
.../main/java/com/mints/wisdomclean/mvp/model/DataModel.java
+0
-25
Duplicate.java
.../main/java/com/mints/wisdomclean/mvp/model/Duplicate.java
+0
-34
EventMessage.java
...in/java/com/mints/wisdomclean/mvp/model/EventMessage.java
+0
-27
FileBean.kt
...src/main/java/com/mints/wisdomclean/mvp/model/FileBean.kt
+0
-9
Folder.kt
...p/src/main/java/com/mints/wisdomclean/mvp/model/Folder.kt
+0
-25
GridBean.kt
...src/main/java/com/mints/wisdomclean/mvp/model/GridBean.kt
+0
-15
Image.kt
...pp/src/main/java/com/mints/wisdomclean/mvp/model/Image.kt
+0
-48
PkgInfo.java
...rc/main/java/com/mints/wisdomclean/mvp/model/PkgInfo.java
+0
-33
RiskBean.kt
...src/main/java/com/mints/wisdomclean/mvp/model/RiskBean.kt
+0
-13
TypeFile.java
...c/main/java/com/mints/wisdomclean/mvp/model/TypeFile.java
+0
-58
GuidePresenter.kt
...va/com/mints/wisdomclean/mvp/presenters/GuidePresenter.kt
+0
-92
GuideView.kt
...rc/main/java/com/mints/wisdomclean/mvp/views/GuideView.kt
+0
-5
GuideActivity.kt
.../java/com/mints/wisdomclean/ui/activitys/GuideActivity.kt
+1
-7
SplashActivity.kt
...java/com/mints/wisdomclean/ui/activitys/SplashActivity.kt
+0
-2
BaseActivity.java
...com/mints/wisdomclean/ui/activitys/base/BaseActivity.java
+0
-23
VPAdapter.kt
...c/main/java/com/mints/wisdomclean/ui/adapter/VPAdapter.kt
+0
-1
swipeback_layout.xml
video/app/src/main/res/layout/swipeback_layout.xml
+0
-20
No files found.
video/app/src/main/java/com/mints/library/base/BaseAppCompatActivity.java
View file @
c14e01ff
...
...
@@ -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
*
...
...
video/app/src/main/java/com/mints/library/base/BaseAppFragment.java
View file @
c14e01ff
...
...
@@ -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
;
}
}
video/app/src/main/java/com/mints/library/base/BaseFragmentActivity.java
deleted
100755 → 0
View file @
cc7fb9fa
package
com
.
mints
.
library
.
base
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.drawable.Drawable
;
import
android.os.Build
;
import
android.os.Bundle
;
import
com.google.android.material.snackbar.Snackbar
;
import
androidx.fragment.app.FragmentActivity
;
import
android.util.DisplayMetrics
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.WindowManager
;
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.mints.library.utils.CommonUtils
;
import
com.mints.wisdomclean.R
;
import
com.readystatesoftware.systembartint.SystemBarTintManager
;
/**
* 描述:BaseFragmentActivity
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public
abstract
class
BaseFragmentActivity
extends
FragmentActivity
{
/**
* 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
;
/**
* network status
*/
protected
NetChangeObserver
mNetChangeObserver
=
null
;
/**
* loading view controller
*/
private
VaryViewHelperController
mVaryViewHelperController
=
null
;
/**
* overridePendingTransition mode
*/
public
enum
TransitionMode
{
LEFT
,
RIGHT
,
TOP
,
BOTTOM
,
SCALE
,
FADE
}
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
if
(
toggleOverridePendingTransition
())
{
switch
(
getOverridePendingTransitionMode
())
{
case
LEFT:
overridePendingTransition
(
R
.
anim
.
left_in
,
R
.
anim
.
left_out
);
break
;
case
RIGHT:
overridePendingTransition
(
R
.
anim
.
right_in
,
R
.
anim
.
right_out
);
break
;
case
TOP:
overridePendingTransition
(
R
.
anim
.
top_in
,
R
.
anim
.
top_out
);
break
;
case
BOTTOM:
overridePendingTransition
(
R
.
anim
.
push_bottom_in
,
R
.
anim
.
push_bottom_out
);
break
;
case
SCALE:
overridePendingTransition
(
R
.
anim
.
scale_in
,
R
.
anim
.
scale_out
);
break
;
case
FADE:
overridePendingTransition
(
R
.
anim
.
fade_in
,
R
.
anim
.
fade_out
);
break
;
}
}
super
.
onCreate
(
savedInstanceState
);
// base setup
Bundle
extras
=
getIntent
().
getExtras
();
if
(
null
!=
extras
)
{
getBundleExtras
(
extras
);
}
// SmartBarUtils.hide(getWindow().getDecorView());
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
)
{
setContentView
(
getContentViewLayoutID
());
}
else
{
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
();
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
if
(
item
.
getItemId
()
==
android
.
R
.
id
.
home
)
{
finish
();
return
true
;
}
return
super
.
onOptionsItemSelected
(
item
);
}
@Override
public
void
setContentView
(
int
layoutResID
)
{
super
.
setContentView
(
layoutResID
);
if
(
null
!=
getLoadingTargetView
())
{
mVaryViewHelperController
=
new
VaryViewHelperController
(
getLoadingTargetView
());
}
}
@Override
public
void
finish
()
{
super
.
finish
();
if
(
toggleOverridePendingTransition
())
{
switch
(
getOverridePendingTransitionMode
())
{
case
LEFT:
overridePendingTransition
(
R
.
anim
.
left_in
,
R
.
anim
.
left_out
);
break
;
case
RIGHT:
overridePendingTransition
(
R
.
anim
.
right_in
,
R
.
anim
.
right_out
);
break
;
case
TOP:
overridePendingTransition
(
R
.
anim
.
top_in
,
R
.
anim
.
top_out
);
break
;
case
BOTTOM:
overridePendingTransition
(
R
.
anim
.
push_bottom_in
,
R
.
anim
.
push_bottom_out
);
break
;
case
SCALE:
overridePendingTransition
(
R
.
anim
.
scale_in
,
R
.
anim
.
scale_out
);
break
;
case
FADE:
overridePendingTransition
(
R
.
anim
.
fade_in
,
R
.
anim
.
fade_out
);
break
;
}
}
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
NetStateReceiver
.
removeRegisterObserver
(
mNetChangeObserver
);
}
/**
* get bundle data
*
* @param extras
*/
protected
abstract
void
getBundleExtras
(
Bundle
extras
);
/**
* bind layout resource file
*
* @return id of layout resource
*/
protected
abstract
int
getContentViewLayoutID
();
/**
* when event comming
*
* @param eventCenter
*/
// protected abstract void onEventComming(EventCenter eventCenter);
/**
* 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
*
* @return
*/
protected
abstract
boolean
isApplyStatusBarTranslucency
();
/**
* toggle overridePendingTransition
*
* @return
*/
protected
abstract
boolean
toggleOverridePendingTransition
();
/**
* get the overridePendingTransition mode
*/
protected
abstract
TransitionMode
getOverridePendingTransitionMode
();
/**
* startActivity
*
* @param clazz
*/
protected
void
readyGo
(
Class
<?>
clazz
)
{
Intent
intent
=
new
Intent
(
this
,
clazz
);
startActivity
(
intent
);
}
/**
* startActivity with bundle
*
* @param clazz
* @param bundle
*/
protected
void
readyGo
(
Class
<?>
clazz
,
Bundle
bundle
)
{
Intent
intent
=
new
Intent
(
this
,
clazz
);
if
(
null
!=
bundle
)
{
intent
.
putExtras
(
bundle
);
}
startActivity
(
intent
);
}
/**
* startActivity then finish
*
* @param clazz
*/
protected
void
readyGoThenKill
(
Class
<?>
clazz
)
{
Intent
intent
=
new
Intent
(
this
,
clazz
);
startActivity
(
intent
);
finish
();
}
/**
* startActivity with bundle then finish
*
* @param clazz
* @param bundle
*/
protected
void
readyGoThenKill
(
Class
<?>
clazz
,
Bundle
bundle
)
{
Intent
intent
=
new
Intent
(
this
,
clazz
);
if
(
null
!=
bundle
)
{
intent
.
putExtras
(
bundle
);
}
startActivity
(
intent
);
finish
();
}
/**
* startActivityForResult
*
* @param clazz
* @param requestCode
*/
protected
void
readyGoForResult
(
Class
<?>
clazz
,
int
requestCode
)
{
Intent
intent
=
new
Intent
(
this
,
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
(
this
,
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
(
getWindow
().
getDecorView
(),
msg
,
Snackbar
.
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
();
}
}
/**
* use SytemBarTintManager
*
* @param tintDrawable
*/
protected
void
setSystemBarTintDrawable
(
Drawable
tintDrawable
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
SystemBarTintManager
mTintManager
=
new
SystemBarTintManager
(
this
);
if
(
tintDrawable
!=
null
)
{
mTintManager
.
setStatusBarTintEnabled
(
true
);
mTintManager
.
setTintDrawable
(
tintDrawable
);
}
else
{
mTintManager
.
setStatusBarTintEnabled
(
false
);
mTintManager
.
setTintDrawable
(
null
);
}
}
}
/**
* set status bar translucency
*
* @param on
*/
protected
void
setTranslucentStatus
(
boolean
on
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
Window
win
=
getWindow
();
WindowManager
.
LayoutParams
winParams
=
win
.
getAttributes
();
final
int
bits
=
WindowManager
.
LayoutParams
.
FLAG_TRANSLUCENT_STATUS
;
if
(
on
)
{
winParams
.
flags
|=
bits
;
}
else
{
winParams
.
flags
&=
~
bits
;
}
win
.
setAttributes
(
winParams
);
}
}
}
\ No newline at end of file
video/app/src/main/java/com/mints/library/base/BaseLazyFragment.java
deleted
100755 → 0
View file @
cc7fb9fa
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
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
com.mints.wisdomclean.R
;
import
com.mints.library.loading.VaryViewHelperController
;
import
com.mints.library.utils.CommonUtils
;
import
java.lang.reflect.Field
;
/**
* 描述:BaseLazyFragment
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public
abstract
class
BaseLazyFragment
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
boolean
isFirstResume
=
true
;
private
boolean
isFirstVisible
=
true
;
private
boolean
isFirstInvisible
=
true
;
private
boolean
isPrepared
;
private
VaryViewHelperController
mVaryViewHelperController
=
null
;
@Override
public
void
onAttach
(
Activity
activity
)
{
super
.
onAttach
(
activity
);
mContext
=
activity
;
// RudenessScreenHelper.resetDensity(getActivity(), AppConfig.design_width);
}
@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
)
{
return
inflater
.
inflate
(
getContentViewLayoutID
(),
null
);
}
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
);
// RudenessScreenHelper.resetDensity(getActivity(), AppConfig.design_width);
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);
// }
}
@Override
public
void
onActivityCreated
(
Bundle
savedInstanceState
)
{
super
.
onActivityCreated
(
savedInstanceState
);
initPrepare
();
}
@Override
public
void
onResume
()
{
super
.
onResume
();
if
(
isFirstResume
)
{
isFirstResume
=
false
;
return
;
}
if
(
getUserVisibleHint
())
{
onUserVisible
();
}
}
@Override
public
void
onPause
()
{
super
.
onPause
();
if
(
getUserVisibleHint
())
{
onUserInvisible
();
}
}
@Override
public
void
setUserVisibleHint
(
boolean
isVisibleToUser
)
{
super
.
setUserVisibleHint
(
isVisibleToUser
);
if
(
isVisibleToUser
)
{
if
(
isFirstVisible
)
{
isFirstVisible
=
false
;
initPrepare
();
}
else
{
onUserVisible
();
}
}
else
{
if
(
isFirstInvisible
)
{
isFirstInvisible
=
false
;
onFirstUserInvisible
();
}
else
{
onUserInvisible
();
}
}
}
private
synchronized
void
initPrepare
()
{
if
(
isPrepared
)
{
onFirstUserVisible
();
}
else
{
isPrepared
=
true
;
}
}
/**
* when fragment is visible for the first time, here we can do some initialized work or refresh data only once
*/
protected
abstract
void
onFirstUserVisible
();
/**
* this method like the fragment's lifecycle method onResume()
*/
protected
abstract
void
onUserVisible
();
/**
* when fragment is invisible for the first time
*/
private
void
onFirstUserInvisible
()
{
// here we do not recommend do something
}
/**
* this method like the fragment's lifecycle method onPause()
*/
protected
abstract
void
onUserInvisible
();
/**
* get loading target view
*/
protected
abstract
View
getLoadingTargetView
();
/**
* init all views and add events
*/
protected
abstract
void
initViewsAndEvents
();
/**
* 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
();
}
}
/**
* 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
;
}
}
video/app/src/main/java/com/mints/library/base/BaseLazyViewFragment.java
deleted
100755 → 0
View file @
cc7fb9fa
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
();
}
}
}
video/app/src/main/java/com/mints/library/base/BaseSwipeBackCompatActivity.java
deleted
100755 → 0
View file @
cc7fb9fa
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
();
}
}
video/app/src/main/java/com/mints/library/base/BaseSwipeBackFragmentActivity.java
deleted
100755 → 0
View file @
cc7fb9fa
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
();
}
}
video/app/src/main/java/com/mints/library/base/BaseWebActivity.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
;
}
}
video/app/src/main/java/com/mints/library/loading/IVaryViewHelper.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
video/app/src/main/java/com/mints/library/loading/VaryViewHelper.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
;
}
}
video/app/src/main/java/com/mints/library/loading/VaryViewHelperController.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
();
}
}
video/app/src/main/java/com/mints/library/loading/VaryViewHelperX.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
;
}
}
video/app/src/main/java/com/mints/library/net/NetCommon.java
deleted
100755 → 0
View file @
cc7fb9fa
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
;
}
}
video/app/src/main/java/com/mints/library/net/OkHttpProgress.java
deleted
100755 → 0
View file @
cc7fb9fa
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
);
}
}
video/app/src/main/java/com/mints/library/net/netstatus/NetChangeObserver.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
()
{
}
}
video/app/src/main/java/com/mints/library/net/netstatus/NetStateReceiver.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
video/app/src/main/java/com/mints/library/net/netstatus/NetUtils.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
;
}
}
video/app/src/main/java/com/mints/library/recyclerview/EndlessRecyclerOnScrollListener.java
deleted
100755 → 0
View file @
cc7fb9fa
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
}
}
video/app/src/main/java/com/mints/library/recyclerview/ExStaggeredGridLayoutManager.java
deleted
100755 → 0
View file @
cc7fb9fa
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
video/app/src/main/java/com/mints/library/recyclerview/HeaderAndFooterRecyclerViewAdapter.java
deleted
100755 → 0
View file @
cc7fb9fa
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
video/app/src/main/java/com/mints/library/recyclerview/HeaderSpanSizeLookup.java
deleted
100755 → 0
View file @
cc7fb9fa
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
video/app/src/main/java/com/mints/library/recyclerview/MyDividerItemDecoration.java
deleted
100644 → 0
View file @
cc7fb9fa
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
);
}
}
}
video/app/src/main/java/com/mints/library/recyclerview/OnListLoadNextPageListener.java
deleted
100755 → 0
View file @
cc7fb9fa
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
video/app/src/main/java/com/mints/library/recyclerview/RecyclerViewUtils.java
deleted
100755 → 0
View file @
cc7fb9fa
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
video/app/src/main/java/com/mints/library/recyclerview/SpaceItemDecoration.kt
deleted
100755 → 0
View file @
cc7fb9fa
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
}
}
}
video/app/src/main/java/com/mints/library/swipeback/SwipeBackActivityBase.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
();
}
video/app/src/main/java/com/mints/library/swipeback/SwipeBackActivityHelper.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
;
}
}
video/app/src/main/java/com/mints/library/swipeback/SwipeBackLayout.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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.content.Context
;
import
android.content.res.TypedArray
;
import
android.graphics.Canvas
;
import
android.graphics.Rect
;
import
androidx.core.view.ViewCompat
;
import
android.util.AttributeSet
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.Window
;
import
android.widget.FrameLayout
;
import
com.mints.wisdomclean.R
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
SwipeBackLayout
extends
FrameLayout
{
/**
* Minimum velocity that will be detected as a fling
*/
private
static
final
int
MIN_FLING_VELOCITY
=
400
;
// dips per second
private
static
final
int
DEFAULT_SCRIM_COLOR
=
0x99000000
;
private
static
final
int
FULL_ALPHA
=
255
;
/**
* Edge flag indicating that the left edge should be affected.
*/
public
static
final
int
EDGE_LEFT
=
ViewDragHelper
.
EDGE_LEFT
;
/**
* Edge flag indicating that the right edge should be affected.
*/
public
static
final
int
EDGE_RIGHT
=
ViewDragHelper
.
EDGE_RIGHT
;
/**
* Edge flag indicating that the bottom edge should be affected.
*/
public
static
final
int
EDGE_BOTTOM
=
ViewDragHelper
.
EDGE_BOTTOM
;
/**
* Edge flag set indicating all edges should be affected.
*/
public
static
final
int
EDGE_ALL
=
EDGE_LEFT
|
EDGE_RIGHT
|
EDGE_BOTTOM
;
/**
* A view is not currently being dragged or animating as a result of a
* fling/snap.
*/
public
static
final
int
STATE_IDLE
=
ViewDragHelper
.
STATE_IDLE
;
/**
* A view is currently being dragged. The position is currently changing as
* a result of user input or simulated user input.
*/
public
static
final
int
STATE_DRAGGING
=
ViewDragHelper
.
STATE_DRAGGING
;
/**
* A view is currently settling into place as a result of a fling or
* predefined non-interactive motion.
*/
public
static
final
int
STATE_SETTLING
=
ViewDragHelper
.
STATE_SETTLING
;
/**
* Default threshold of scroll
*/
private
static
final
float
DEFAULT_SCROLL_THRESHOLD
=
0.3f
;
private
static
final
int
OVERSCROLL_DISTANCE
=
10
;
private
static
final
int
[]
EDGE_FLAGS
=
{
EDGE_LEFT
,
EDGE_RIGHT
,
EDGE_BOTTOM
,
EDGE_ALL
};
private
int
mEdgeFlag
;
/**
* Threshold of scroll, we will close the activity, when scrollPercent over
* this value;
*/
private
float
mScrollThreshold
=
DEFAULT_SCROLL_THRESHOLD
;
private
Activity
mActivity
;
private
boolean
mEnable
=
true
;
private
View
mContentView
;
private
ViewDragHelper
mDragHelper
;
private
float
mScrollPercent
;
private
int
mContentLeft
;
private
int
mContentTop
;
/**
* The set of listeners to be sent events through.
*/
private
List
<
SwipeListener
>
mListeners
;
private
float
mScrimOpacity
;
private
int
mScrimColor
=
DEFAULT_SCRIM_COLOR
;
private
boolean
mInLayout
;
private
Rect
mTmpRect
=
new
Rect
();
/**
* Edge being dragged
*/
private
int
mTrackingEdge
;
public
SwipeBackLayout
(
Context
context
)
{
this
(
context
,
null
);
}
public
SwipeBackLayout
(
Context
context
,
AttributeSet
attrs
)
{
this
(
context
,
attrs
,
R
.
attr
.
SwipeBackLayoutStyle
);
}
public
SwipeBackLayout
(
Context
context
,
AttributeSet
attrs
,
int
defStyle
)
{
super
(
context
,
attrs
);
mDragHelper
=
ViewDragHelper
.
create
(
this
,
new
ViewDragCallback
());
TypedArray
a
=
context
.
obtainStyledAttributes
(
attrs
,
R
.
styleable
.
SwipeBackLayout
,
defStyle
,
R
.
style
.
SwipeBackLayout
);
int
edgeSize
=
a
.
getDimensionPixelSize
(
R
.
styleable
.
SwipeBackLayout_edge_size
,
-
1
);
if
(
edgeSize
>
0
)
setEdgeSize
(
edgeSize
);
int
mode
=
EDGE_FLAGS
[
a
.
getInt
(
R
.
styleable
.
SwipeBackLayout_edge_flag
,
0
)];
setEdgeTrackingEnabled
(
mode
);
a
.
recycle
();
final
float
density
=
getResources
().
getDisplayMetrics
().
density
;
final
float
minVel
=
MIN_FLING_VELOCITY
*
density
;
mDragHelper
.
setMinVelocity
(
minVel
);
mDragHelper
.
setMaxVelocity
(
minVel
*
2
f
);
}
/**
* Sets the sensitivity of the NavigationLayout.
*
* @param context The application context.
* @param sensitivity value between 0 and 1, the final value for touchSlop =
* ViewConfiguration.getScaledTouchSlop * (1 / s);
*/
public
void
setSensitivity
(
Context
context
,
float
sensitivity
)
{
mDragHelper
.
setSensitivity
(
context
,
sensitivity
);
}
/**
* Set up contentView which will be moved by user gesture
*
* @param view
*/
private
void
setContentView
(
View
view
)
{
mContentView
=
view
;
}
public
void
setEnableGesture
(
boolean
enable
)
{
mEnable
=
enable
;
}
/**
* Enable edge tracking for the selected edges of the parent view. The
* callback's
* methods will only be invoked for edges for which edge tracking has been
* enabled.
*
* @param edgeFlags Combination of edge flags describing the edges to watch
* @see #EDGE_LEFT
* @see #EDGE_RIGHT
* @see #EDGE_BOTTOM
*/
public
void
setEdgeTrackingEnabled
(
int
edgeFlags
)
{
mEdgeFlag
=
edgeFlags
;
mDragHelper
.
setEdgeTrackingEnabled
(
mEdgeFlag
);
}
/**
* Set a color to use for the scrim that obscures primary content while a
* drawer is open.
*
* @param color Color to use in 0xAARRGGBB format.
*/
public
void
setScrimColor
(
int
color
)
{
mScrimColor
=
color
;
invalidate
();
}
/**
* Set the size of an edge. This is the range in pixels along the edges of
* this view that will actively detect edge touches or drags if edge
* tracking is enabled.
*
* @param size The size of an edge in pixels
*/
public
void
setEdgeSize
(
int
size
)
{
mDragHelper
.
setEdgeSize
(
size
);
}
/**
* Register a callback to be invoked when a swipe event is sent to this
* view.
*
* @param listener the swipe listener to attach to this view
* @deprecated use {@link #addSwipeListener} instead
*/
@Deprecated
public
void
setSwipeListener
(
SwipeListener
listener
)
{
addSwipeListener
(
listener
);
}
/**
* Add a callback to be invoked when a swipe event is sent to this view.
*
* @param listener the swipe listener to attach to this view
*/
public
void
addSwipeListener
(
SwipeListener
listener
)
{
if
(
mListeners
==
null
)
{
mListeners
=
new
ArrayList
<
SwipeListener
>();
}
mListeners
.
add
(
listener
);
}
/**
* Removes a listener from the set of listeners
*
* @param listener
*/
public
void
removeSwipeListener
(
SwipeListener
listener
)
{
if
(
mListeners
==
null
)
{
return
;
}
mListeners
.
remove
(
listener
);
}
public
static
interface
SwipeListener
{
/**
* Invoke when state change
*
* @param state flag to describe scroll state
* @param scrollPercent scroll percent of this view
* @see #STATE_IDLE
* @see #STATE_DRAGGING
* @see #STATE_SETTLING
*/
public
void
onScrollStateChange
(
int
state
,
float
scrollPercent
);
/**
* Invoke when edge touched
*
* @param edgeFlag edge flag describing the edge being touched
* @see #EDGE_LEFT
* @see #EDGE_RIGHT
* @see #EDGE_BOTTOM
*/
public
void
onEdgeTouch
(
int
edgeFlag
);
/**
* Invoke when scroll percent over the threshold for the first time
*/
public
void
onScrollOverThreshold
();
}
/**
* Set scroll threshold, we will close the activity, when scrollPercent over
* this value
*
* @param threshold
*/
public
void
setScrollThresHold
(
float
threshold
)
{
if
(
threshold
>=
1.0f
||
threshold
<=
0
)
{
throw
new
IllegalArgumentException
(
"Threshold value should be between 0 and 1.0"
);
}
mScrollThreshold
=
threshold
;
}
/**
* Scroll out contentView and finish the activity
*/
public
void
scrollToFinishActivity
()
{
final
int
childWidth
=
mContentView
.
getWidth
();
final
int
childHeight
=
mContentView
.
getHeight
();
int
left
=
0
,
top
=
0
;
if
((
mEdgeFlag
&
EDGE_LEFT
)
!=
0
)
{
left
=
childWidth
+
OVERSCROLL_DISTANCE
;
mTrackingEdge
=
EDGE_LEFT
;
}
else
if
((
mEdgeFlag
&
EDGE_RIGHT
)
!=
0
)
{
left
=
-
childWidth
-
OVERSCROLL_DISTANCE
;
mTrackingEdge
=
EDGE_RIGHT
;
}
else
if
((
mEdgeFlag
&
EDGE_BOTTOM
)
!=
0
)
{
top
=
-
childHeight
-
OVERSCROLL_DISTANCE
;
mTrackingEdge
=
EDGE_BOTTOM
;
}
mDragHelper
.
smoothSlideViewTo
(
mContentView
,
left
,
top
);
invalidate
();
}
@Override
public
boolean
onInterceptTouchEvent
(
MotionEvent
event
)
{
if
(!
mEnable
)
{
return
false
;
}
try
{
return
mDragHelper
.
shouldInterceptTouchEvent
(
event
);
}
catch
(
ArrayIndexOutOfBoundsException
e
)
{
// FIXME: handle exception
// issues #9
return
false
;
}
}
@Override
public
boolean
onTouchEvent
(
MotionEvent
event
)
{
if
(!
mEnable
)
{
return
false
;
}
mDragHelper
.
processTouchEvent
(
event
);
return
true
;
}
@Override
protected
void
onLayout
(
boolean
changed
,
int
left
,
int
top
,
int
right
,
int
bottom
)
{
mInLayout
=
true
;
if
(
mContentView
!=
null
)
mContentView
.
layout
(
mContentLeft
,
mContentTop
,
mContentLeft
+
mContentView
.
getMeasuredWidth
(),
mContentTop
+
mContentView
.
getMeasuredHeight
());
mInLayout
=
false
;
}
@Override
public
void
requestLayout
()
{
if
(!
mInLayout
)
{
super
.
requestLayout
();
}
}
@Override
protected
boolean
drawChild
(
Canvas
canvas
,
View
child
,
long
drawingTime
)
{
final
boolean
drawContent
=
child
==
mContentView
;
boolean
ret
=
super
.
drawChild
(
canvas
,
child
,
drawingTime
);
if
(
mScrimOpacity
>
0
&&
drawContent
&&
mDragHelper
.
getViewDragState
()
!=
ViewDragHelper
.
STATE_IDLE
)
{
drawScrim
(
canvas
,
child
);
}
return
ret
;
}
private
void
drawScrim
(
Canvas
canvas
,
View
child
)
{
final
int
baseAlpha
=
(
mScrimColor
&
0xff000000
)
>>>
24
;
final
int
alpha
=
(
int
)
(
baseAlpha
*
mScrimOpacity
);
final
int
color
=
alpha
<<
24
|
(
mScrimColor
&
0xffffff
);
if
((
mTrackingEdge
&
EDGE_LEFT
)
!=
0
)
{
canvas
.
clipRect
(
0
,
0
,
child
.
getLeft
(),
getHeight
());
}
else
if
((
mTrackingEdge
&
EDGE_RIGHT
)
!=
0
)
{
canvas
.
clipRect
(
child
.
getRight
(),
0
,
getRight
(),
getHeight
());
}
else
if
((
mTrackingEdge
&
EDGE_BOTTOM
)
!=
0
)
{
canvas
.
clipRect
(
child
.
getLeft
(),
child
.
getBottom
(),
getRight
(),
getHeight
());
}
canvas
.
drawColor
(
color
);
}
//这里注解掉为activity设置背景色
public
void
attachToActivity
(
Activity
activity
)
{
mActivity
=
activity
;
// TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
// android.R.attr.windowBackground
// });
// int background = a.getResourceId(0, 0);
// a.recycle();
ViewGroup
decor
=
(
ViewGroup
)
activity
.
getWindow
().
getDecorView
().
findViewById
(
Window
.
ID_ANDROID_CONTENT
);
ViewGroup
decorChild
=
(
ViewGroup
)
decor
.
getChildAt
(
0
);
// decorChild.setBackgroundResource(background);
decor
.
removeView
(
decorChild
);
addView
(
decorChild
);
setContentView
(
decorChild
);
decor
.
addView
(
this
);
}
@Override
public
void
computeScroll
()
{
mScrimOpacity
=
1
-
mScrollPercent
;
if
(
mDragHelper
.
continueSettling
(
true
))
{
ViewCompat
.
postInvalidateOnAnimation
(
this
);
}
}
private
class
ViewDragCallback
extends
ViewDragHelper
.
Callback
{
private
boolean
mIsScrollOverValid
;
@Override
public
boolean
tryCaptureView
(
View
view
,
int
i
)
{
boolean
ret
=
mDragHelper
.
isEdgeTouched
(
mEdgeFlag
,
i
);
if
(
ret
)
{
if
(
mDragHelper
.
isEdgeTouched
(
EDGE_LEFT
,
i
))
{
mTrackingEdge
=
EDGE_LEFT
;
}
else
if
(
mDragHelper
.
isEdgeTouched
(
EDGE_RIGHT
,
i
))
{
mTrackingEdge
=
EDGE_RIGHT
;
}
else
if
(
mDragHelper
.
isEdgeTouched
(
EDGE_BOTTOM
,
i
))
{
mTrackingEdge
=
EDGE_BOTTOM
;
}
if
(
mListeners
!=
null
&&
!
mListeners
.
isEmpty
())
{
for
(
SwipeListener
listener
:
mListeners
)
{
listener
.
onEdgeTouch
(
mTrackingEdge
);
}
}
mIsScrollOverValid
=
true
;
}
return
ret
;
}
@Override
public
int
getViewHorizontalDragRange
(
View
child
)
{
return
mEdgeFlag
&
(
EDGE_LEFT
|
EDGE_RIGHT
);
}
@Override
public
int
getViewVerticalDragRange
(
View
child
)
{
return
mEdgeFlag
&
EDGE_BOTTOM
;
}
@Override
public
void
onViewPositionChanged
(
View
changedView
,
int
left
,
int
top
,
int
dx
,
int
dy
)
{
super
.
onViewPositionChanged
(
changedView
,
left
,
top
,
dx
,
dy
);
if
((
mTrackingEdge
&
EDGE_LEFT
)
!=
0
)
{
mScrollPercent
=
Math
.
abs
((
float
)
left
/
(
mContentView
.
getWidth
()));
}
else
if
((
mTrackingEdge
&
EDGE_RIGHT
)
!=
0
)
{
mScrollPercent
=
Math
.
abs
((
float
)
left
/
(
mContentView
.
getWidth
()));
}
else
if
((
mTrackingEdge
&
EDGE_BOTTOM
)
!=
0
)
{
mScrollPercent
=
Math
.
abs
((
float
)
top
/
(
mContentView
.
getHeight
()));
}
mContentLeft
=
left
;
mContentTop
=
top
;
invalidate
();
if
(
mScrollPercent
<
mScrollThreshold
&&
!
mIsScrollOverValid
)
{
mIsScrollOverValid
=
true
;
}
if
(
mListeners
!=
null
&&
!
mListeners
.
isEmpty
()
&&
mDragHelper
.
getViewDragState
()
==
STATE_DRAGGING
&&
mScrollPercent
>=
mScrollThreshold
&&
mIsScrollOverValid
)
{
mIsScrollOverValid
=
false
;
for
(
SwipeListener
listener
:
mListeners
)
{
listener
.
onScrollOverThreshold
();
}
}
if
(
mScrollPercent
>=
1
)
{
if
(!
mActivity
.
isFinishing
())
mActivity
.
finish
();
}
}
@Override
public
void
onViewReleased
(
View
releasedChild
,
float
xvel
,
float
yvel
)
{
final
int
childWidth
=
releasedChild
.
getWidth
();
final
int
childHeight
=
releasedChild
.
getHeight
();
int
left
=
0
,
top
=
0
;
if
((
mTrackingEdge
&
EDGE_LEFT
)
!=
0
)
{
left
=
xvel
>
0
||
xvel
==
0
&&
mScrollPercent
>
mScrollThreshold
?
childWidth
+
OVERSCROLL_DISTANCE
:
0
;
}
else
if
((
mTrackingEdge
&
EDGE_RIGHT
)
!=
0
)
{
left
=
xvel
<
0
||
xvel
==
0
&&
mScrollPercent
>
mScrollThreshold
?
-(
childWidth
+
OVERSCROLL_DISTANCE
)
:
0
;
}
else
if
((
mTrackingEdge
&
EDGE_BOTTOM
)
!=
0
)
{
top
=
yvel
<
0
||
yvel
==
0
&&
mScrollPercent
>
mScrollThreshold
?
-(
childHeight
+
OVERSCROLL_DISTANCE
)
:
0
;
}
mDragHelper
.
settleCapturedViewAt
(
left
,
top
);
invalidate
();
}
@Override
public
int
clampViewPositionHorizontal
(
View
child
,
int
left
,
int
dx
)
{
int
ret
=
0
;
if
((
mTrackingEdge
&
EDGE_LEFT
)
!=
0
)
{
ret
=
Math
.
min
(
child
.
getWidth
(),
Math
.
max
(
left
,
0
));
}
else
if
((
mTrackingEdge
&
EDGE_RIGHT
)
!=
0
)
{
ret
=
Math
.
min
(
0
,
Math
.
max
(
left
,
-
child
.
getWidth
()));
}
return
ret
;
}
@Override
public
int
clampViewPositionVertical
(
View
child
,
int
top
,
int
dy
)
{
int
ret
=
0
;
if
((
mTrackingEdge
&
EDGE_BOTTOM
)
!=
0
)
{
ret
=
Math
.
min
(
0
,
Math
.
max
(
top
,
-
child
.
getHeight
()));
}
return
ret
;
}
@Override
public
void
onViewDragStateChanged
(
int
state
)
{
super
.
onViewDragStateChanged
(
state
);
if
(
mListeners
!=
null
&&
!
mListeners
.
isEmpty
())
{
for
(
SwipeListener
listener
:
mListeners
)
{
listener
.
onScrollStateChange
(
state
,
mScrollPercent
);
}
}
}
}
}
video/app/src/main/java/com/mints/library/swipeback/Utils.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
)
{
}
}
}
video/app/src/main/java/com/mints/library/swipeback/ViewDragHelper.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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.content.Context
;
import
androidx.core.view.MotionEventCompat
;
import
androidx.core.view.VelocityTrackerCompat
;
import
androidx.core.view.ViewCompat
;
import
androidx.core.widget.ScrollerCompat
;
import
android.view.MotionEvent
;
import
android.view.VelocityTracker
;
import
android.view.View
;
import
android.view.ViewConfiguration
;
import
android.view.ViewGroup
;
import
android.view.animation.Interpolator
;
import
java.util.Arrays
;
/**
* ViewDragHelper is a utility class for writing custom ViewGroups. It offers a
* number of useful operations and state tracking for allowing a user to drag
* and reposition views within their parent ViewGroup.
*/
public
class
ViewDragHelper
{
private
static
final
String
TAG
=
"ViewDragHelper"
;
/**
* A null/invalid pointer ID.
*/
public
static
final
int
INVALID_POINTER
=
-
1
;
/**
* A view is not currently being dragged or animating as a result of a
* fling/snap.
*/
public
static
final
int
STATE_IDLE
=
0
;
/**
* A view is currently being dragged. The position is currently changing as
* a result of user input or simulated user input.
*/
public
static
final
int
STATE_DRAGGING
=
1
;
/**
* A view is currently settling into place as a result of a fling or
* predefined non-interactive motion.
*/
public
static
final
int
STATE_SETTLING
=
2
;
/**
* Edge flag indicating that the left edge should be affected.
*/
public
static
final
int
EDGE_LEFT
=
1
<<
0
;
/**
* Edge flag indicating that the right edge should be affected.
*/
public
static
final
int
EDGE_RIGHT
=
1
<<
1
;
/**
* Edge flag indicating that the top edge should be affected.
*/
public
static
final
int
EDGE_TOP
=
1
<<
2
;
/**
* Edge flag indicating that the bottom edge should be affected.
*/
public
static
final
int
EDGE_BOTTOM
=
1
<<
3
;
/**
* Edge flag set indicating all edges should be affected.
*/
public
static
final
int
EDGE_ALL
=
EDGE_LEFT
|
EDGE_TOP
|
EDGE_RIGHT
|
EDGE_BOTTOM
;
/**
* Indicates that a check should occur along the horizontal axis
*/
public
static
final
int
DIRECTION_HORIZONTAL
=
1
<<
0
;
/**
* Indicates that a check should occur along the vertical axis
*/
public
static
final
int
DIRECTION_VERTICAL
=
1
<<
1
;
/**
* Indicates that a check should occur along all axes
*/
public
static
final
int
DIRECTION_ALL
=
DIRECTION_HORIZONTAL
|
DIRECTION_VERTICAL
;
public
static
final
int
EDGE_SIZE
=
20
;
// dp
private
static
final
int
BASE_SETTLE_DURATION
=
256
;
// ms
private
static
final
int
MAX_SETTLE_DURATION
=
600
;
// ms
// Current drag state; idle, dragging or settling
private
int
mDragState
;
// Distance to travel before a drag may begin
private
int
mTouchSlop
;
// Last known position/pointer tracking
private
int
mActivePointerId
=
INVALID_POINTER
;
private
float
[]
mInitialMotionX
;
private
float
[]
mInitialMotionY
;
private
float
[]
mLastMotionX
;
private
float
[]
mLastMotionY
;
private
int
[]
mInitialEdgeTouched
;
private
int
[]
mEdgeDragsInProgress
;
private
int
[]
mEdgeDragsLocked
;
private
int
mPointersDown
;
private
VelocityTracker
mVelocityTracker
;
private
float
mMaxVelocity
;
private
float
mMinVelocity
;
private
int
mEdgeSize
;
private
int
mTrackingEdges
;
private
ScrollerCompat
mScroller
;
private
final
Callback
mCallback
;
private
View
mCapturedView
;
private
boolean
mReleaseInProgress
;
private
final
ViewGroup
mParentView
;
/**
* A Callback is used as a communication channel with the ViewDragHelper
* back to the parent view using it. <code>on*</code>methods are invoked on
* siginficant events and several accessor methods are expected to provide
* the ViewDragHelper with more information about the state of the parent
* view upon request. The callback also makes decisions governing the range
* and draggability of child views.
*/
public
static
abstract
class
Callback
{
/**
* Called when the drag state changes. See the <code>STATE_*</code>
* constants for more information.
*
* @param state The new drag state
* @see #STATE_IDLE
* @see #STATE_DRAGGING
* @see #STATE_SETTLING
*/
public
void
onViewDragStateChanged
(
int
state
)
{
}
/**
* Called when the captured view's position changes as the result of a
* drag or settle.
*
* @param changedView View whose position changed
* @param left New X coordinate of the left edge of the view
* @param top New Y coordinate of the top edge of the view
* @param dx Change in X position from the last call
* @param dy Change in Y position from the last call
*/
public
void
onViewPositionChanged
(
View
changedView
,
int
left
,
int
top
,
int
dx
,
int
dy
)
{
}
/**
* Called when a child view is captured for dragging or settling. The ID
* of the pointer currently dragging the captured view is supplied. If
* activePointerId is identified as {@link #INVALID_POINTER} the capture
* is programmatic instead of pointer-initiated.
*
* @param capturedChild Child view that was captured
* @param activePointerId Pointer id tracking the child capture
*/
public
void
onViewCaptured
(
View
capturedChild
,
int
activePointerId
)
{
}
/**
* Called when the child view is no longer being actively dragged. The
* fling velocity is also supplied, if relevant. The velocity values may
* be clamped to system minimums or maximums.
* <p>
* Calling code may decide to fling or otherwise release the view to let
* it settle into place. It should do so using
* {@link #settleCapturedViewAt(int, int)} or
* {@link #flingCapturedView(int, int, int, int)}. If the Callback
* invokes one of these methods, the ViewDragHelper will enter
* {@link #STATE_SETTLING} and the view capture will not fully end until
* it comes to a complete stop. If neither of these methods is invoked
* before <code>onViewReleased</code> returns, the view will stop in
* place and the ViewDragHelper will return to {@link #STATE_IDLE}.
* </p>
*
* @param releasedChild The captured child view now being released
* @param xvel X velocity of the pointer as it left the screen in pixels
* per second.
* @param yvel Y velocity of the pointer as it left the screen in pixels
* per second.
*/
public
void
onViewReleased
(
View
releasedChild
,
float
xvel
,
float
yvel
)
{
}
/**
* Called when one of the subscribed edges in the parent view has been
* touched by the user while no child view is currently captured.
*
* @param edgeFlags A combination of edge flags describing the edge(s)
* currently touched
* @param pointerId ID of the pointer touching the described edge(s)
* @see #EDGE_LEFT
* @see #EDGE_TOP
* @see #EDGE_RIGHT
* @see #EDGE_BOTTOM
*/
public
void
onEdgeTouched
(
int
edgeFlags
,
int
pointerId
)
{
}
/**
* Called when the given edge may become locked. This can happen if an
* edge drag was preliminarily rejected before beginning, but after
* {@link #onEdgeTouched(int, int)} was called. This method should
* return true to lock this edge or false to leave it unlocked. The
* default behavior is to leave edges unlocked.
*
* @param edgeFlags A combination of edge flags describing the edge(s)
* locked
* @return true to lock the edge, false to leave it unlocked
*/
public
boolean
onEdgeLock
(
int
edgeFlags
)
{
return
false
;
}
/**
* Called when the user has started a deliberate drag away from one of
* the subscribed edges in the parent view while no child view is
* currently captured.
*
* @param edgeFlags A combination of edge flags describing the edge(s)
* dragged
* @param pointerId ID of the pointer touching the described edge(s)
* @see #EDGE_LEFT
* @see #EDGE_TOP
* @see #EDGE_RIGHT
* @see #EDGE_BOTTOM
*/
public
void
onEdgeDragStarted
(
int
edgeFlags
,
int
pointerId
)
{
}
/**
* Called to determine the Z-order of child views.
*
* @param index the ordered position to query for
* @return index of the view that should be ordered at position
* <code>index</code>
*/
public
int
getOrderedChildIndex
(
int
index
)
{
return
index
;
}
/**
* Return the magnitude of a draggable child view's horizontal range of
* motion in pixels. This method should return 0 for views that cannot
* move horizontally.
*
* @param child Child view to check
* @return range of horizontal motion in pixels
*/
public
int
getViewHorizontalDragRange
(
View
child
)
{
return
0
;
}
/**
* Return the magnitude of a draggable child view's vertical range of
* motion in pixels. This method should return 0 for views that cannot
* move vertically.
*
* @param child Child view to check
* @return range of vertical motion in pixels
*/
public
int
getViewVerticalDragRange
(
View
child
)
{
return
0
;
}
/**
* Called when the user's input indicates that they want to capture the
* given child view with the pointer indicated by pointerId. The
* callback should return true if the user is permitted to drag the
* given view with the indicated pointer.
* <p>
* ViewDragHelper may call this method multiple times for the same view
* even if the view is already captured; this indicates that a new
* pointer is trying to take control of the view.
* </p>
* <p>
* If this method returns true, a call to
* {@link #onViewCaptured(View, int)} will follow if the
* capture is successful.
* </p>
*
* @param child Child the user is attempting to capture
* @param pointerId ID of the pointer attempting the capture
* @return true if capture should be allowed, false otherwise
*/
public
abstract
boolean
tryCaptureView
(
View
child
,
int
pointerId
);
/**
* Restrict the motion of the dragged child view along the horizontal
* axis. The default implementation does not allow horizontal motion;
* the extending class must override this method and provide the desired
* clamping.
*
* @param child Child view being dragged
* @param left Attempted motion along the X axis
* @param dx Proposed change in position for left
* @return The new clamped position for left
*/
public
int
clampViewPositionHorizontal
(
View
child
,
int
left
,
int
dx
)
{
return
0
;
}
/**
* Restrict the motion of the dragged child view along the vertical
* axis. The default implementation does not allow vertical motion; the
* extending class must override this method and provide the desired
* clamping.
*
* @param child Child view being dragged
* @param top Attempted motion along the Y axis
* @param dy Proposed change in position for top
* @return The new clamped position for top
*/
public
int
clampViewPositionVertical
(
View
child
,
int
top
,
int
dy
)
{
return
0
;
}
}
/**
* Interpolator defining the animation curve for mScroller
*/
private
static
final
Interpolator
sInterpolator
=
new
Interpolator
()
{
public
float
getInterpolation
(
float
t
)
{
t
-=
1.0f
;
return
t
*
t
*
t
*
t
*
t
+
1.0f
;
}
};
private
final
Runnable
mSetIdleRunnable
=
new
Runnable
()
{
public
void
run
()
{
setDragState
(
STATE_IDLE
);
}
};
/**
* Factory method to create a new ViewDragHelper.
*
* @param forParent Parent view to monitor
* @param cb Callback to provide information and receive events
* @return a new ViewDragHelper instance
*/
public
static
ViewDragHelper
create
(
ViewGroup
forParent
,
Callback
cb
)
{
return
new
ViewDragHelper
(
forParent
.
getContext
(),
forParent
,
cb
);
}
/**
* Factory method to create a new ViewDragHelper.
*
* @param forParent Parent view to monitor
* @param sensitivity Multiplier for how sensitive the helper should be
* about detecting the start of a drag. Larger values are more
* sensitive. 1.0f is normal.
* @param cb Callback to provide information and receive events
* @return a new ViewDragHelper instance
*/
public
static
ViewDragHelper
create
(
ViewGroup
forParent
,
float
sensitivity
,
Callback
cb
)
{
final
ViewDragHelper
helper
=
create
(
forParent
,
cb
);
helper
.
mTouchSlop
=
(
int
)
(
helper
.
mTouchSlop
*
(
1
/
sensitivity
));
return
helper
;
}
/**
* Apps should use ViewDragHelper.create() to get a new instance. This will
* allow VDH to use internal compatibility implementations for different
* platform versions.
*
* @param context Context to initialize config-dependent params from
* @param forParent Parent view to monitor
*/
private
ViewDragHelper
(
Context
context
,
ViewGroup
forParent
,
Callback
cb
)
{
if
(
forParent
==
null
)
{
throw
new
IllegalArgumentException
(
"Parent view may not be null"
);
}
if
(
cb
==
null
)
{
throw
new
IllegalArgumentException
(
"Callback may not be null"
);
}
mParentView
=
forParent
;
mCallback
=
cb
;
final
ViewConfiguration
vc
=
ViewConfiguration
.
get
(
context
);
final
float
density
=
context
.
getResources
().
getDisplayMetrics
().
density
;
mEdgeSize
=
(
int
)
(
EDGE_SIZE
*
density
+
0.5f
);
mTouchSlop
=
vc
.
getScaledTouchSlop
();
mMaxVelocity
=
vc
.
getScaledMaximumFlingVelocity
();
mMinVelocity
=
vc
.
getScaledMinimumFlingVelocity
();
mScroller
=
ScrollerCompat
.
create
(
context
,
sInterpolator
);
}
/**
* Sets the sensitivity of the dragger.
*
* @param context The application context.
* @param sensitivity value between 0 and 1, the final value for touchSlop =
* ViewConfiguration.getScaledTouchSlop * (1 / s);
*/
public
void
setSensitivity
(
Context
context
,
float
sensitivity
)
{
float
s
=
Math
.
max
(
0
f
,
Math
.
min
(
1.0f
,
sensitivity
));
ViewConfiguration
viewConfiguration
=
ViewConfiguration
.
get
(
context
);
mTouchSlop
=
(
int
)
(
viewConfiguration
.
getScaledTouchSlop
()
*
(
1
/
s
));
}
/**
* Set the minimum velocity that will be detected as having a magnitude
* greater than zero in pixels per second. Callback methods accepting a
* velocity will be clamped appropriately.
*
* @param minVel minimum velocity to detect
*/
public
void
setMinVelocity
(
float
minVel
)
{
mMinVelocity
=
minVel
;
}
/**
* Set the max velocity that will be detected as having a magnitude
* greater than zero in pixels per second. Callback methods accepting a
* velocity will be clamped appropriately.
*
* @param maxVel max velocity to detect
*/
public
void
setMaxVelocity
(
float
maxVel
)
{
mMaxVelocity
=
maxVel
;
}
/**
* Return the currently configured minimum velocity. Any flings with a
* magnitude less than this value in pixels per second. Callback methods
* accepting a velocity will receive zero as a velocity value if the real
* detected velocity was below this threshold.
*
* @return the minimum velocity that will be detected
*/
public
float
getMinVelocity
()
{
return
mMinVelocity
;
}
/**
* Retrieve the current drag state of this helper. This will return one of
* {@link #STATE_IDLE}, {@link #STATE_DRAGGING} or {@link #STATE_SETTLING}.
*
* @return The current drag state
*/
public
int
getViewDragState
()
{
return
mDragState
;
}
/**
* Enable edge tracking for the selected edges of the parent view. The
* callback's
* methods will only be invoked for edges for which edge tracking has been
* enabled.
*
* @param edgeFlags Combination of edge flags describing the edges to watch
* @see #EDGE_LEFT
* @see #EDGE_TOP
* @see #EDGE_RIGHT
* @see #EDGE_BOTTOM
*/
public
void
setEdgeTrackingEnabled
(
int
edgeFlags
)
{
mTrackingEdges
=
edgeFlags
;
}
/**
* Return the size of an edge. This is the range in pixels along the edges
* of this view that will actively detect edge touches or drags if edge
* tracking is enabled.
*
* @return The size of an edge in pixels
* @see #setEdgeTrackingEnabled(int)
*/
public
int
getEdgeSize
()
{
return
mEdgeSize
;
}
/**
* Set the size of an edge. This is the range in pixels along the edges of
* this view that will actively detect edge touches or drags if edge
* tracking is enabled.
*
* @param size The size of an edge in pixels
*/
public
void
setEdgeSize
(
int
size
)
{
mEdgeSize
=
size
;
}
/**
* Capture a specific child view for dragging within the parent. The
* callback will be notified but
* will not be asked permission to capture this view.
*
* @param childView Child view to capture
* @param activePointerId ID of the pointer that is dragging the captured
* child view
*/
public
void
captureChildView
(
View
childView
,
int
activePointerId
)
{
if
(
childView
.
getParent
()
!=
mParentView
)
{
throw
new
IllegalArgumentException
(
"captureChildView: parameter must be a descendant "
+
"of the ViewDragHelper's tracked parent view ("
+
mParentView
+
")"
);
}
mCapturedView
=
childView
;
mActivePointerId
=
activePointerId
;
mCallback
.
onViewCaptured
(
childView
,
activePointerId
);
setDragState
(
STATE_DRAGGING
);
}
/**
* @return The currently captured view, or null if no view has been
* captured.
*/
public
View
getCapturedView
()
{
return
mCapturedView
;
}
/**
* @return The ID of the pointer currently dragging the captured view, or
* {@link #INVALID_POINTER}.
*/
public
int
getActivePointerId
()
{
return
mActivePointerId
;
}
/**
* @return The minimum distance in pixels that the user must travel to
* initiate a drag
*/
public
int
getTouchSlop
()
{
return
mTouchSlop
;
}
/**
* The result of a call to this method is equivalent to
* {@link #processTouchEvent(MotionEvent)} receiving an
* ACTION_CANCEL event.
*/
public
void
cancel
()
{
mActivePointerId
=
INVALID_POINTER
;
clearMotionHistory
();
if
(
mVelocityTracker
!=
null
)
{
mVelocityTracker
.
recycle
();
mVelocityTracker
=
null
;
}
}
/**
* {@link #cancel()}, but also abort all motion in progress and snap to the
* end of any animation.
*/
public
void
abort
()
{
cancel
();
if
(
mDragState
==
STATE_SETTLING
)
{
final
int
oldX
=
mScroller
.
getCurrX
();
final
int
oldY
=
mScroller
.
getCurrY
();
mScroller
.
abortAnimation
();
final
int
newX
=
mScroller
.
getCurrX
();
final
int
newY
=
mScroller
.
getCurrY
();
mCallback
.
onViewPositionChanged
(
mCapturedView
,
newX
,
newY
,
newX
-
oldX
,
newY
-
oldY
);
}
setDragState
(
STATE_IDLE
);
}
/**
* Animate the view <code>child</code> to the given (left, top) position. If
* this method returns true, the caller should invoke
* {@link #continueSettling(boolean)} on each subsequent frame to continue
* the motion until it returns false. If this method returns false there is
* no further work to do to complete the movement.
* <p>
* This operation does not count as a capture event, though
* {@link #getCapturedView()} will still report the sliding view while the
* slide is in progress.
* </p>
*
* @param child Child view to capture and animate
* @param finalLeft Final left position of child
* @param finalTop Final top position of child
* @return true if animation should continue through
* {@link #continueSettling(boolean)} calls
*/
public
boolean
smoothSlideViewTo
(
View
child
,
int
finalLeft
,
int
finalTop
)
{
mCapturedView
=
child
;
mActivePointerId
=
INVALID_POINTER
;
return
forceSettleCapturedViewAt
(
finalLeft
,
finalTop
,
0
,
0
);
}
/**
* Settle the captured view at the given (left, top) position. The
* appropriate velocity from prior motion will be taken into account. If
* this method returns true, the caller should invoke
* {@link #continueSettling(boolean)} on each subsequent frame to continue
* the motion until it returns false. If this method returns false there is
* no further work to do to complete the movement.
*
* @param finalLeft Settled left edge position for the captured view
* @param finalTop Settled top edge position for the captured view
* @return true if animation should continue through
* {@link #continueSettling(boolean)} calls
*/
public
boolean
settleCapturedViewAt
(
int
finalLeft
,
int
finalTop
)
{
if
(!
mReleaseInProgress
)
{
throw
new
IllegalStateException
(
"Cannot settleCapturedViewAt outside of a call to "
+
"Callback#onViewReleased"
);
}
return
forceSettleCapturedViewAt
(
finalLeft
,
finalTop
,
(
int
)
VelocityTrackerCompat
.
getXVelocity
(
mVelocityTracker
,
mActivePointerId
),
(
int
)
VelocityTrackerCompat
.
getYVelocity
(
mVelocityTracker
,
mActivePointerId
));
}
/**
* Settle the captured view at the given (left, top) position.
*
* @param finalLeft Target left position for the captured view
* @param finalTop Target top position for the captured view
* @param xvel Horizontal velocity
* @param yvel Vertical velocity
* @return true if animation should continue through
* {@link #continueSettling(boolean)} calls
*/
private
boolean
forceSettleCapturedViewAt
(
int
finalLeft
,
int
finalTop
,
int
xvel
,
int
yvel
)
{
final
int
startLeft
=
mCapturedView
.
getLeft
();
final
int
startTop
=
mCapturedView
.
getTop
();
final
int
dx
=
finalLeft
-
startLeft
;
final
int
dy
=
finalTop
-
startTop
;
if
(
dx
==
0
&&
dy
==
0
)
{
// Nothing to do. Send callbacks, be done.
mScroller
.
abortAnimation
();
setDragState
(
STATE_IDLE
);
return
false
;
}
final
int
duration
=
computeSettleDuration
(
mCapturedView
,
dx
,
dy
,
xvel
,
yvel
);
mScroller
.
startScroll
(
startLeft
,
startTop
,
dx
,
dy
,
duration
);
setDragState
(
STATE_SETTLING
);
return
true
;
}
private
int
computeSettleDuration
(
View
child
,
int
dx
,
int
dy
,
int
xvel
,
int
yvel
)
{
xvel
=
clampMag
(
xvel
,
(
int
)
mMinVelocity
,
(
int
)
mMaxVelocity
);
yvel
=
clampMag
(
yvel
,
(
int
)
mMinVelocity
,
(
int
)
mMaxVelocity
);
final
int
absDx
=
Math
.
abs
(
dx
);
final
int
absDy
=
Math
.
abs
(
dy
);
final
int
absXVel
=
Math
.
abs
(
xvel
);
final
int
absYVel
=
Math
.
abs
(
yvel
);
final
int
addedVel
=
absXVel
+
absYVel
;
final
int
addedDistance
=
absDx
+
absDy
;
final
float
xweight
=
xvel
!=
0
?
(
float
)
absXVel
/
addedVel
:
(
float
)
absDx
/
addedDistance
;
final
float
yweight
=
yvel
!=
0
?
(
float
)
absYVel
/
addedVel
:
(
float
)
absDy
/
addedDistance
;
int
xduration
=
computeAxisDuration
(
dx
,
xvel
,
mCallback
.
getViewHorizontalDragRange
(
child
));
int
yduration
=
computeAxisDuration
(
dy
,
yvel
,
mCallback
.
getViewVerticalDragRange
(
child
));
return
(
int
)
(
xduration
*
xweight
+
yduration
*
yweight
);
}
private
int
computeAxisDuration
(
int
delta
,
int
velocity
,
int
motionRange
)
{
if
(
delta
==
0
)
{
return
0
;
}
final
int
width
=
mParentView
.
getWidth
();
final
int
halfWidth
=
width
/
2
;
final
float
distanceRatio
=
Math
.
min
(
1
f
,
(
float
)
Math
.
abs
(
delta
)
/
width
);
final
float
distance
=
halfWidth
+
halfWidth
*
distanceInfluenceForSnapDuration
(
distanceRatio
);
int
duration
;
velocity
=
Math
.
abs
(
velocity
);
if
(
velocity
>
0
)
{
duration
=
4
*
Math
.
round
(
1000
*
Math
.
abs
(
distance
/
velocity
));
}
else
{
final
float
range
=
(
float
)
Math
.
abs
(
delta
)
/
motionRange
;
duration
=
(
int
)
((
range
+
1
)
*
BASE_SETTLE_DURATION
);
}
return
Math
.
min
(
duration
,
MAX_SETTLE_DURATION
);
}
/**
* Clamp the magnitude of value for absMin and absMax. If the value is below
* the minimum, it will be clamped to zero. If the value is above the
* maximum, it will be clamped to the maximum.
*
* @param value Value to clamp
* @param absMin Absolute value of the minimum significant value to return
* @param absMax Absolute value of the maximum value to return
* @return The clamped value with the same sign as <code>value</code>
*/
private
int
clampMag
(
int
value
,
int
absMin
,
int
absMax
)
{
final
int
absValue
=
Math
.
abs
(
value
);
if
(
absValue
<
absMin
)
return
0
;
if
(
absValue
>
absMax
)
return
value
>
0
?
absMax
:
-
absMax
;
return
value
;
}
/**
* Clamp the magnitude of value for absMin and absMax. If the value is below
* the minimum, it will be clamped to zero. If the value is above the
* maximum, it will be clamped to the maximum.
*
* @param value Value to clamp
* @param absMin Absolute value of the minimum significant value to return
* @param absMax Absolute value of the maximum value to return
* @return The clamped value with the same sign as <code>value</code>
*/
private
float
clampMag
(
float
value
,
float
absMin
,
float
absMax
)
{
final
float
absValue
=
Math
.
abs
(
value
);
if
(
absValue
<
absMin
)
return
0
;
if
(
absValue
>
absMax
)
return
value
>
0
?
absMax
:
-
absMax
;
return
value
;
}
private
float
distanceInfluenceForSnapDuration
(
float
f
)
{
f
-=
0.5f
;
// center the values about 0.
f
*=
0.3f
*
Math
.
PI
/
2.0f
;
return
(
float
)
Math
.
sin
(
f
);
}
/**
* Settle the captured view based on standard free-moving fling behavior.
* The caller should invoke {@link #continueSettling(boolean)} on each
* subsequent frame to continue the motion until it returns false.
*
* @param minLeft Minimum X position for the view's left edge
* @param minTop Minimum Y position for the view's top edge
* @param maxLeft Maximum X position for the view's left edge
* @param maxTop Maximum Y position for the view's top edge
*/
public
void
flingCapturedView
(
int
minLeft
,
int
minTop
,
int
maxLeft
,
int
maxTop
)
{
if
(!
mReleaseInProgress
)
{
throw
new
IllegalStateException
(
"Cannot flingCapturedView outside of a call to "
+
"Callback#onViewReleased"
);
}
mScroller
.
fling
(
mCapturedView
.
getLeft
(),
mCapturedView
.
getTop
(),
(
int
)
VelocityTrackerCompat
.
getXVelocity
(
mVelocityTracker
,
mActivePointerId
),
(
int
)
VelocityTrackerCompat
.
getYVelocity
(
mVelocityTracker
,
mActivePointerId
),
minLeft
,
maxLeft
,
minTop
,
maxTop
);
setDragState
(
STATE_SETTLING
);
}
/**
* Move the captured settling view by the appropriate amount for the current
* time. If <code>continueSettling</code> returns true, the caller should
* call it again on the next frame to continue.
*
* @param deferCallbacks true if state callbacks should be deferred via
* posted message. Set this to true if you are calling this
* method from {@link View#computeScroll()} or
* similar methods invoked as part of layout or drawing.
* @return true if settle is still in progress
*/
public
boolean
continueSettling
(
boolean
deferCallbacks
)
{
if
(
mDragState
==
STATE_SETTLING
)
{
boolean
keepGoing
=
mScroller
.
computeScrollOffset
();
final
int
x
=
mScroller
.
getCurrX
();
final
int
y
=
mScroller
.
getCurrY
();
final
int
dx
=
x
-
mCapturedView
.
getLeft
();
final
int
dy
=
y
-
mCapturedView
.
getTop
();
if
(
dx
!=
0
)
{
mCapturedView
.
offsetLeftAndRight
(
dx
);
}
if
(
dy
!=
0
)
{
mCapturedView
.
offsetTopAndBottom
(
dy
);
}
if
(
dx
!=
0
||
dy
!=
0
)
{
mCallback
.
onViewPositionChanged
(
mCapturedView
,
x
,
y
,
dx
,
dy
);
}
if
(
keepGoing
&&
x
==
mScroller
.
getFinalX
()
&&
y
==
mScroller
.
getFinalY
())
{
// Close enough. The interpolator/scroller might think we're
// still moving
// but the user sure doesn't.
mScroller
.
abortAnimation
();
keepGoing
=
mScroller
.
isFinished
();
}
if
(!
keepGoing
)
{
if
(
deferCallbacks
)
{
mParentView
.
post
(
mSetIdleRunnable
);
}
else
{
setDragState
(
STATE_IDLE
);
}
}
}
return
mDragState
==
STATE_SETTLING
;
}
/**
* Like all callback events this must happen on the UI thread, but release
* involves some extra semantics. During a release (mReleaseInProgress) is
* the only time it is valid to call {@link #settleCapturedViewAt(int, int)}
* or {@link #flingCapturedView(int, int, int, int)}.
*/
private
void
dispatchViewReleased
(
float
xvel
,
float
yvel
)
{
mReleaseInProgress
=
true
;
mCallback
.
onViewReleased
(
mCapturedView
,
xvel
,
yvel
);
mReleaseInProgress
=
false
;
if
(
mDragState
==
STATE_DRAGGING
)
{
// onViewReleased didn't call a method that would have changed this.
// Go idle.
setDragState
(
STATE_IDLE
);
}
}
private
void
clearMotionHistory
()
{
if
(
mInitialMotionX
==
null
)
{
return
;
}
Arrays
.
fill
(
mInitialMotionX
,
0
);
Arrays
.
fill
(
mInitialMotionY
,
0
);
Arrays
.
fill
(
mLastMotionX
,
0
);
Arrays
.
fill
(
mLastMotionY
,
0
);
Arrays
.
fill
(
mInitialEdgeTouched
,
0
);
Arrays
.
fill
(
mEdgeDragsInProgress
,
0
);
Arrays
.
fill
(
mEdgeDragsLocked
,
0
);
mPointersDown
=
0
;
}
private
void
clearMotionHistory
(
int
pointerId
)
{
if
(
mInitialMotionX
==
null
)
{
return
;
}
mInitialMotionX
[
pointerId
]
=
0
;
mInitialMotionY
[
pointerId
]
=
0
;
mLastMotionX
[
pointerId
]
=
0
;
mLastMotionY
[
pointerId
]
=
0
;
mInitialEdgeTouched
[
pointerId
]
=
0
;
mEdgeDragsInProgress
[
pointerId
]
=
0
;
mEdgeDragsLocked
[
pointerId
]
=
0
;
mPointersDown
&=
~(
1
<<
pointerId
);
}
private
void
ensureMotionHistorySizeForId
(
int
pointerId
)
{
if
(
mInitialMotionX
==
null
||
mInitialMotionX
.
length
<=
pointerId
)
{
float
[]
imx
=
new
float
[
pointerId
+
1
];
float
[]
imy
=
new
float
[
pointerId
+
1
];
float
[]
lmx
=
new
float
[
pointerId
+
1
];
float
[]
lmy
=
new
float
[
pointerId
+
1
];
int
[]
iit
=
new
int
[
pointerId
+
1
];
int
[]
edip
=
new
int
[
pointerId
+
1
];
int
[]
edl
=
new
int
[
pointerId
+
1
];
if
(
mInitialMotionX
!=
null
)
{
System
.
arraycopy
(
mInitialMotionX
,
0
,
imx
,
0
,
mInitialMotionX
.
length
);
System
.
arraycopy
(
mInitialMotionY
,
0
,
imy
,
0
,
mInitialMotionY
.
length
);
System
.
arraycopy
(
mLastMotionX
,
0
,
lmx
,
0
,
mLastMotionX
.
length
);
System
.
arraycopy
(
mLastMotionY
,
0
,
lmy
,
0
,
mLastMotionY
.
length
);
System
.
arraycopy
(
mInitialEdgeTouched
,
0
,
iit
,
0
,
mInitialEdgeTouched
.
length
);
System
.
arraycopy
(
mEdgeDragsInProgress
,
0
,
edip
,
0
,
mEdgeDragsInProgress
.
length
);
System
.
arraycopy
(
mEdgeDragsLocked
,
0
,
edl
,
0
,
mEdgeDragsLocked
.
length
);
}
mInitialMotionX
=
imx
;
mInitialMotionY
=
imy
;
mLastMotionX
=
lmx
;
mLastMotionY
=
lmy
;
mInitialEdgeTouched
=
iit
;
mEdgeDragsInProgress
=
edip
;
mEdgeDragsLocked
=
edl
;
}
}
private
void
saveInitialMotion
(
float
x
,
float
y
,
int
pointerId
)
{
ensureMotionHistorySizeForId
(
pointerId
);
mInitialMotionX
[
pointerId
]
=
mLastMotionX
[
pointerId
]
=
x
;
mInitialMotionY
[
pointerId
]
=
mLastMotionY
[
pointerId
]
=
y
;
mInitialEdgeTouched
[
pointerId
]
=
getEdgeTouched
((
int
)
x
,
(
int
)
y
);
mPointersDown
|=
1
<<
pointerId
;
}
private
void
saveLastMotion
(
MotionEvent
ev
)
{
final
int
pointerCount
=
MotionEventCompat
.
getPointerCount
(
ev
);
for
(
int
i
=
0
;
i
<
pointerCount
;
i
++)
{
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
i
);
final
float
x
=
MotionEventCompat
.
getX
(
ev
,
i
);
final
float
y
=
MotionEventCompat
.
getY
(
ev
,
i
);
mLastMotionX
[
pointerId
]
=
x
;
mLastMotionY
[
pointerId
]
=
y
;
}
}
/**
* Check if the given pointer ID represents a pointer that is currently down
* (to the best of the ViewDragHelper's knowledge).
* <p>
* The state used to report this information is populated by the methods
* {@link #shouldInterceptTouchEvent(MotionEvent)} or
* {@link #processTouchEvent(MotionEvent)}. If one of these
* methods has not been called for all relevant MotionEvents to track, the
* information reported by this method may be stale or incorrect.
* </p>
*
* @param pointerId pointer ID to check; corresponds to IDs provided by
* MotionEvent
* @return true if the pointer with the given ID is still down
*/
public
boolean
isPointerDown
(
int
pointerId
)
{
return
(
mPointersDown
&
1
<<
pointerId
)
!=
0
;
}
void
setDragState
(
int
state
)
{
if
(
mDragState
!=
state
)
{
mDragState
=
state
;
mCallback
.
onViewDragStateChanged
(
state
);
if
(
state
==
STATE_IDLE
)
{
mCapturedView
=
null
;
}
}
}
/**
* Attempt to capture the view with the given pointer ID. The callback will
* be involved. This will put us into the "dragging" state. If we've already
* captured this view with this pointer this method will immediately return
* true without consulting the callback.
*
* @param toCapture View to capture
* @param pointerId Pointer to capture with
* @return true if capture was successful
*/
boolean
tryCaptureViewForDrag
(
View
toCapture
,
int
pointerId
)
{
if
(
toCapture
==
mCapturedView
&&
mActivePointerId
==
pointerId
)
{
// Already done!
return
true
;
}
if
(
toCapture
!=
null
&&
mCallback
.
tryCaptureView
(
toCapture
,
pointerId
))
{
mActivePointerId
=
pointerId
;
captureChildView
(
toCapture
,
pointerId
);
return
true
;
}
return
false
;
}
/**
* Tests scrollability within child views of v given a delta of dx.
*
* @param v View to test for horizontal scrollability
* @param checkV Whether the view v passed should itself be checked for
* scrollability (true), or just its children (false).
* @param dx Delta scrolled in pixels along the X axis
* @param dy Delta scrolled in pixels along the Y axis
* @param x X coordinate of the active touch point
* @param y Y coordinate of the active touch point
* @return true if child views of v can be scrolled by delta of dx.
*/
protected
boolean
canScroll
(
View
v
,
boolean
checkV
,
int
dx
,
int
dy
,
int
x
,
int
y
)
{
if
(
v
instanceof
ViewGroup
)
{
final
ViewGroup
group
=
(
ViewGroup
)
v
;
final
int
scrollX
=
v
.
getScrollX
();
final
int
scrollY
=
v
.
getScrollY
();
final
int
count
=
group
.
getChildCount
();
// Count backwards - let topmost views consume scroll distance
// first.
for
(
int
i
=
count
-
1
;
i
>=
0
;
i
--)
{
// TODO: Add versioned support here for transformed views.
// This will not work for transformed views in Honeycomb+
final
View
child
=
group
.
getChildAt
(
i
);
if
(
x
+
scrollX
>=
child
.
getLeft
()
&&
x
+
scrollX
<
child
.
getRight
()
&&
y
+
scrollY
>=
child
.
getTop
()
&&
y
+
scrollY
<
child
.
getBottom
()
&&
canScroll
(
child
,
true
,
dx
,
dy
,
x
+
scrollX
-
child
.
getLeft
(),
y
+
scrollY
-
child
.
getTop
()))
{
return
true
;
}
}
}
return
checkV
&&
(
ViewCompat
.
canScrollHorizontally
(
v
,
-
dx
)
||
ViewCompat
.
canScrollVertically
(
v
,
-
dy
));
}
/**
* Check if this event as provided to the parent view's
* onInterceptTouchEvent should cause the parent to intercept the touch
* event stream.
*
* @param ev MotionEvent provided to onInterceptTouchEvent
* @return true if the parent view should return true from
* onInterceptTouchEvent
*/
public
boolean
shouldInterceptTouchEvent
(
MotionEvent
ev
)
{
final
int
action
=
MotionEventCompat
.
getActionMasked
(
ev
);
final
int
actionIndex
=
MotionEventCompat
.
getActionIndex
(
ev
);
if
(
action
==
MotionEvent
.
ACTION_DOWN
)
{
// Reset things for a new event stream, just in case we didn't get
// the whole previous stream.
cancel
();
}
if
(
mVelocityTracker
==
null
)
{
mVelocityTracker
=
VelocityTracker
.
obtain
();
}
mVelocityTracker
.
addMovement
(
ev
);
switch
(
action
)
{
case
MotionEvent
.
ACTION_DOWN
:
{
final
float
x
=
ev
.
getX
();
final
float
y
=
ev
.
getY
();
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
0
);
saveInitialMotion
(
x
,
y
,
pointerId
);
final
View
toCapture
=
findTopChildUnder
((
int
)
x
,
(
int
)
y
);
// Catch a settling view if possible.
if
(
toCapture
==
mCapturedView
&&
mDragState
==
STATE_SETTLING
)
{
tryCaptureViewForDrag
(
toCapture
,
pointerId
);
}
final
int
edgesTouched
=
mInitialEdgeTouched
[
pointerId
];
if
((
edgesTouched
&
mTrackingEdges
)
!=
0
)
{
mCallback
.
onEdgeTouched
(
edgesTouched
&
mTrackingEdges
,
pointerId
);
}
break
;
}
case
MotionEventCompat
.
ACTION_POINTER_DOWN
:
{
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
actionIndex
);
final
float
x
=
MotionEventCompat
.
getX
(
ev
,
actionIndex
);
final
float
y
=
MotionEventCompat
.
getY
(
ev
,
actionIndex
);
saveInitialMotion
(
x
,
y
,
pointerId
);
// A ViewDragHelper can only manipulate one view at a time.
if
(
mDragState
==
STATE_IDLE
)
{
final
int
edgesTouched
=
mInitialEdgeTouched
[
pointerId
];
if
((
edgesTouched
&
mTrackingEdges
)
!=
0
)
{
mCallback
.
onEdgeTouched
(
edgesTouched
&
mTrackingEdges
,
pointerId
);
}
}
else
if
(
mDragState
==
STATE_SETTLING
)
{
// Catch a settling view if possible.
final
View
toCapture
=
findTopChildUnder
((
int
)
x
,
(
int
)
y
);
if
(
toCapture
==
mCapturedView
)
{
tryCaptureViewForDrag
(
toCapture
,
pointerId
);
}
}
break
;
}
case
MotionEvent
.
ACTION_MOVE
:
{
// First to cross a touch slop over a draggable view wins. Also
// report edge drags.
final
int
pointerCount
=
MotionEventCompat
.
getPointerCount
(
ev
);
for
(
int
i
=
0
;
i
<
pointerCount
;
i
++)
{
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
i
);
final
float
x
=
MotionEventCompat
.
getX
(
ev
,
i
);
final
float
y
=
MotionEventCompat
.
getY
(
ev
,
i
);
final
float
dx
=
x
-
mInitialMotionX
[
pointerId
];
final
float
dy
=
y
-
mInitialMotionY
[
pointerId
];
reportNewEdgeDrags
(
dx
,
dy
,
pointerId
);
if
(
mDragState
==
STATE_DRAGGING
)
{
// Callback might have started an edge drag
break
;
}
final
View
toCapture
=
findTopChildUnder
((
int
)
x
,
(
int
)
y
);
if
(
toCapture
!=
null
&&
checkTouchSlop
(
toCapture
,
dx
,
dy
)
&&
tryCaptureViewForDrag
(
toCapture
,
pointerId
))
{
break
;
}
}
saveLastMotion
(
ev
);
break
;
}
case
MotionEventCompat
.
ACTION_POINTER_UP
:
{
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
actionIndex
);
clearMotionHistory
(
pointerId
);
break
;
}
case
MotionEvent
.
ACTION_UP
:
case
MotionEvent
.
ACTION_CANCEL
:
{
cancel
();
break
;
}
}
return
mDragState
==
STATE_DRAGGING
;
}
/**
* Process a touch event received by the parent view. This method will
* dispatch callback events as needed before returning. The parent view's
* onTouchEvent implementation should call this.
*
* @param ev The touch event received by the parent view
*/
public
void
processTouchEvent
(
MotionEvent
ev
)
{
final
int
action
=
MotionEventCompat
.
getActionMasked
(
ev
);
final
int
actionIndex
=
MotionEventCompat
.
getActionIndex
(
ev
);
if
(
action
==
MotionEvent
.
ACTION_DOWN
)
{
// Reset things for a new event stream, just in case we didn't get
// the whole previous stream.
cancel
();
}
if
(
mVelocityTracker
==
null
)
{
mVelocityTracker
=
VelocityTracker
.
obtain
();
}
mVelocityTracker
.
addMovement
(
ev
);
switch
(
action
)
{
case
MotionEvent
.
ACTION_DOWN
:
{
final
float
x
=
ev
.
getX
();
final
float
y
=
ev
.
getY
();
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
0
);
final
View
toCapture
=
findTopChildUnder
((
int
)
x
,
(
int
)
y
);
saveInitialMotion
(
x
,
y
,
pointerId
);
// Since the parent is already directly processing this touch
// event,
// there is no reason to delay for a slop before dragging.
// Start immediately if possible.
tryCaptureViewForDrag
(
toCapture
,
pointerId
);
final
int
edgesTouched
=
mInitialEdgeTouched
[
pointerId
];
if
((
edgesTouched
&
mTrackingEdges
)
!=
0
)
{
mCallback
.
onEdgeTouched
(
edgesTouched
&
mTrackingEdges
,
pointerId
);
}
break
;
}
case
MotionEventCompat
.
ACTION_POINTER_DOWN
:
{
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
actionIndex
);
final
float
x
=
MotionEventCompat
.
getX
(
ev
,
actionIndex
);
final
float
y
=
MotionEventCompat
.
getY
(
ev
,
actionIndex
);
saveInitialMotion
(
x
,
y
,
pointerId
);
// A ViewDragHelper can only manipulate one view at a time.
if
(
mDragState
==
STATE_IDLE
)
{
// If we're idle we can do anything! Treat it like a normal
// down event.
final
View
toCapture
=
findTopChildUnder
((
int
)
x
,
(
int
)
y
);
tryCaptureViewForDrag
(
toCapture
,
pointerId
);
final
int
edgesTouched
=
mInitialEdgeTouched
[
pointerId
];
if
((
edgesTouched
&
mTrackingEdges
)
!=
0
)
{
mCallback
.
onEdgeTouched
(
edgesTouched
&
mTrackingEdges
,
pointerId
);
}
}
else
if
(
isCapturedViewUnder
((
int
)
x
,
(
int
)
y
))
{
// We're still tracking a captured view. If the same view is
// under this
// point, we'll swap to controlling it with this pointer
// instead.
// (This will still work if we're "catching" a settling
// view.)
tryCaptureViewForDrag
(
mCapturedView
,
pointerId
);
}
break
;
}
case
MotionEvent
.
ACTION_MOVE
:
{
if
(
mDragState
==
STATE_DRAGGING
)
{
final
int
index
=
MotionEventCompat
.
findPointerIndex
(
ev
,
mActivePointerId
);
final
float
x
=
MotionEventCompat
.
getX
(
ev
,
index
);
final
float
y
=
MotionEventCompat
.
getY
(
ev
,
index
);
final
int
idx
=
(
int
)
(
x
-
mLastMotionX
[
mActivePointerId
]);
final
int
idy
=
(
int
)
(
y
-
mLastMotionY
[
mActivePointerId
]);
dragTo
(
mCapturedView
.
getLeft
()
+
idx
,
mCapturedView
.
getTop
()
+
idy
,
idx
,
idy
);
saveLastMotion
(
ev
);
}
else
{
// Check to see if any pointer is now over a draggable view.
final
int
pointerCount
=
MotionEventCompat
.
getPointerCount
(
ev
);
for
(
int
i
=
0
;
i
<
pointerCount
;
i
++)
{
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
i
);
final
float
x
=
MotionEventCompat
.
getX
(
ev
,
i
);
final
float
y
=
MotionEventCompat
.
getY
(
ev
,
i
);
final
float
dx
=
x
-
mInitialMotionX
[
pointerId
];
final
float
dy
=
y
-
mInitialMotionY
[
pointerId
];
reportNewEdgeDrags
(
dx
,
dy
,
pointerId
);
if
(
mDragState
==
STATE_DRAGGING
)
{
// Callback might have started an edge drag.
break
;
}
final
View
toCapture
=
findTopChildUnder
((
int
)
x
,
(
int
)
y
);
if
(
checkTouchSlop
(
toCapture
,
dx
,
dy
)
&&
tryCaptureViewForDrag
(
toCapture
,
pointerId
))
{
break
;
}
}
saveLastMotion
(
ev
);
}
break
;
}
case
MotionEventCompat
.
ACTION_POINTER_UP
:
{
final
int
pointerId
=
MotionEventCompat
.
getPointerId
(
ev
,
actionIndex
);
if
(
mDragState
==
STATE_DRAGGING
&&
pointerId
==
mActivePointerId
)
{
// Try to find another pointer that's still holding on to
// the captured view.
int
newActivePointer
=
INVALID_POINTER
;
final
int
pointerCount
=
MotionEventCompat
.
getPointerCount
(
ev
);
for
(
int
i
=
0
;
i
<
pointerCount
;
i
++)
{
final
int
id
=
MotionEventCompat
.
getPointerId
(
ev
,
i
);
if
(
id
==
mActivePointerId
)
{
// This one's going away, skip.
continue
;
}
final
float
x
=
MotionEventCompat
.
getX
(
ev
,
i
);
final
float
y
=
MotionEventCompat
.
getY
(
ev
,
i
);
if
(
findTopChildUnder
((
int
)
x
,
(
int
)
y
)
==
mCapturedView
&&
tryCaptureViewForDrag
(
mCapturedView
,
id
))
{
newActivePointer
=
mActivePointerId
;
break
;
}
}
if
(
newActivePointer
==
INVALID_POINTER
)
{
// We didn't find another pointer still touching the
// view, release it.
releaseViewForPointerUp
();
}
}
clearMotionHistory
(
pointerId
);
break
;
}
case
MotionEvent
.
ACTION_UP
:
{
if
(
mDragState
==
STATE_DRAGGING
)
{
releaseViewForPointerUp
();
}
cancel
();
break
;
}
case
MotionEvent
.
ACTION_CANCEL
:
{
if
(
mDragState
==
STATE_DRAGGING
)
{
dispatchViewReleased
(
0
,
0
);
}
cancel
();
break
;
}
}
}
private
void
reportNewEdgeDrags
(
float
dx
,
float
dy
,
int
pointerId
)
{
int
dragsStarted
=
0
;
if
(
checkNewEdgeDrag
(
dx
,
dy
,
pointerId
,
EDGE_LEFT
))
{
dragsStarted
|=
EDGE_LEFT
;
}
if
(
checkNewEdgeDrag
(
dy
,
dx
,
pointerId
,
EDGE_TOP
))
{
dragsStarted
|=
EDGE_TOP
;
}
if
(
checkNewEdgeDrag
(
dx
,
dy
,
pointerId
,
EDGE_RIGHT
))
{
dragsStarted
|=
EDGE_RIGHT
;
}
if
(
checkNewEdgeDrag
(
dy
,
dx
,
pointerId
,
EDGE_BOTTOM
))
{
dragsStarted
|=
EDGE_BOTTOM
;
}
if
(
dragsStarted
!=
0
)
{
mEdgeDragsInProgress
[
pointerId
]
|=
dragsStarted
;
mCallback
.
onEdgeDragStarted
(
dragsStarted
,
pointerId
);
}
}
private
boolean
checkNewEdgeDrag
(
float
delta
,
float
odelta
,
int
pointerId
,
int
edge
)
{
final
float
absDelta
=
Math
.
abs
(
delta
);
final
float
absODelta
=
Math
.
abs
(
odelta
);
if
((
mInitialEdgeTouched
[
pointerId
]
&
edge
)
!=
edge
||
(
mTrackingEdges
&
edge
)
==
0
||
(
mEdgeDragsLocked
[
pointerId
]
&
edge
)
==
edge
||
(
mEdgeDragsInProgress
[
pointerId
]
&
edge
)
==
edge
||
(
absDelta
<=
mTouchSlop
&&
absODelta
<=
mTouchSlop
))
{
return
false
;
}
if
(
absDelta
<
absODelta
*
0.5f
&&
mCallback
.
onEdgeLock
(
edge
))
{
mEdgeDragsLocked
[
pointerId
]
|=
edge
;
return
false
;
}
return
(
mEdgeDragsInProgress
[
pointerId
]
&
edge
)
==
0
&&
absDelta
>
mTouchSlop
;
}
/**
* Check if we've crossed a reasonable touch slop for the given child view.
* If the child cannot be dragged along the horizontal or vertical axis,
* motion along that axis will not count toward the slop check.
*
* @param child Child to check
* @param dx Motion since initial position along X axis
* @param dy Motion since initial position along Y axis
* @return true if the touch slop has been crossed
*/
private
boolean
checkTouchSlop
(
View
child
,
float
dx
,
float
dy
)
{
if
(
child
==
null
)
{
return
false
;
}
final
boolean
checkHorizontal
=
mCallback
.
getViewHorizontalDragRange
(
child
)
>
0
;
final
boolean
checkVertical
=
mCallback
.
getViewVerticalDragRange
(
child
)
>
0
;
if
(
checkHorizontal
&&
checkVertical
)
{
return
dx
*
dx
+
dy
*
dy
>
mTouchSlop
*
mTouchSlop
;
}
else
if
(
checkHorizontal
)
{
return
Math
.
abs
(
dx
)
>
mTouchSlop
;
}
else
if
(
checkVertical
)
{
return
Math
.
abs
(
dy
)
>
mTouchSlop
;
}
return
false
;
}
/**
* Check if any pointer tracked in the current gesture has crossed the
* required slop threshold.
* <p>
* This depends on internal state populated by
* {@link #shouldInterceptTouchEvent(MotionEvent)} or
* {@link #processTouchEvent(MotionEvent)}. You should only
* rely on the results of this method after all currently available touch
* data has been provided to one of these two methods.
* </p>
*
* @param directions Combination of direction flags, see
* {@link #DIRECTION_HORIZONTAL}, {@link #DIRECTION_VERTICAL},
* {@link #DIRECTION_ALL}
* @return true if the slop threshold has been crossed, false otherwise
*/
public
boolean
checkTouchSlop
(
int
directions
)
{
final
int
count
=
mInitialMotionX
.
length
;
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
if
(
checkTouchSlop
(
directions
,
i
))
{
return
true
;
}
}
return
false
;
}
/**
* Check if the specified pointer tracked in the current gesture has crossed
* the required slop threshold.
* <p>
* This depends on internal state populated by
* {@link #shouldInterceptTouchEvent(MotionEvent)} or
* {@link #processTouchEvent(MotionEvent)}. You should only
* rely on the results of this method after all currently available touch
* data has been provided to one of these two methods.
* </p>
*
* @param directions Combination of direction flags, see
* {@link #DIRECTION_HORIZONTAL}, {@link #DIRECTION_VERTICAL},
* {@link #DIRECTION_ALL}
* @param pointerId ID of the pointer to slop check as specified by
* MotionEvent
* @return true if the slop threshold has been crossed, false otherwise
*/
public
boolean
checkTouchSlop
(
int
directions
,
int
pointerId
)
{
if
(!
isPointerDown
(
pointerId
))
{
return
false
;
}
final
boolean
checkHorizontal
=
(
directions
&
DIRECTION_HORIZONTAL
)
==
DIRECTION_HORIZONTAL
;
final
boolean
checkVertical
=
(
directions
&
DIRECTION_VERTICAL
)
==
DIRECTION_VERTICAL
;
final
float
dx
=
mLastMotionX
[
pointerId
]
-
mInitialMotionX
[
pointerId
];
final
float
dy
=
mLastMotionY
[
pointerId
]
-
mInitialMotionY
[
pointerId
];
if
(
checkHorizontal
&&
checkVertical
)
{
return
dx
*
dx
+
dy
*
dy
>
mTouchSlop
*
mTouchSlop
;
}
else
if
(
checkHorizontal
)
{
return
Math
.
abs
(
dx
)
>
mTouchSlop
;
}
else
if
(
checkVertical
)
{
return
Math
.
abs
(
dy
)
>
mTouchSlop
;
}
return
false
;
}
/**
* Check if any of the edges specified were initially touched in the
* currently active gesture. If there is no currently active gesture this
* method will return false.
*
* @param edges Edges to check for an initial edge touch. See
* {@link #EDGE_LEFT}, {@link #EDGE_TOP}, {@link #EDGE_RIGHT},
* {@link #EDGE_BOTTOM} and {@link #EDGE_ALL}
* @return true if any of the edges specified were initially touched in the
* current gesture
*/
public
boolean
isEdgeTouched
(
int
edges
)
{
final
int
count
=
mInitialEdgeTouched
.
length
;
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
if
(
isEdgeTouched
(
edges
,
i
))
{
return
true
;
}
}
return
false
;
}
/**
* Check if any of the edges specified were initially touched by the pointer
* with the specified ID. If there is no currently active gesture or if
* there is no pointer with the given ID currently down this method will
* return false.
*
* @param edges Edges to check for an initial edge touch. See
* {@link #EDGE_LEFT}, {@link #EDGE_TOP}, {@link #EDGE_RIGHT},
* {@link #EDGE_BOTTOM} and {@link #EDGE_ALL}
* @return true if any of the edges specified were initially touched in the
* current gesture
*/
public
boolean
isEdgeTouched
(
int
edges
,
int
pointerId
)
{
return
isPointerDown
(
pointerId
)
&&
(
mInitialEdgeTouched
[
pointerId
]
&
edges
)
!=
0
;
}
private
void
releaseViewForPointerUp
()
{
mVelocityTracker
.
computeCurrentVelocity
(
1000
,
mMaxVelocity
);
final
float
xvel
=
clampMag
(
VelocityTrackerCompat
.
getXVelocity
(
mVelocityTracker
,
mActivePointerId
),
mMinVelocity
,
mMaxVelocity
);
final
float
yvel
=
clampMag
(
VelocityTrackerCompat
.
getYVelocity
(
mVelocityTracker
,
mActivePointerId
),
mMinVelocity
,
mMaxVelocity
);
dispatchViewReleased
(
xvel
,
yvel
);
}
private
void
dragTo
(
int
left
,
int
top
,
int
dx
,
int
dy
)
{
int
clampedX
=
left
;
int
clampedY
=
top
;
final
int
oldLeft
=
mCapturedView
.
getLeft
();
final
int
oldTop
=
mCapturedView
.
getTop
();
if
(
dx
!=
0
)
{
clampedX
=
mCallback
.
clampViewPositionHorizontal
(
mCapturedView
,
left
,
dx
);
mCapturedView
.
offsetLeftAndRight
(
clampedX
-
oldLeft
);
}
if
(
dy
!=
0
)
{
clampedY
=
mCallback
.
clampViewPositionVertical
(
mCapturedView
,
top
,
dy
);
mCapturedView
.
offsetTopAndBottom
(
clampedY
-
oldTop
);
}
if
(
dx
!=
0
||
dy
!=
0
)
{
final
int
clampedDx
=
clampedX
-
oldLeft
;
final
int
clampedDy
=
clampedY
-
oldTop
;
mCallback
.
onViewPositionChanged
(
mCapturedView
,
clampedX
,
clampedY
,
clampedDx
,
clampedDy
);
}
}
/**
* Determine if the currently captured view is under the given point in the
* parent view's coordinate system. If there is no captured view this method
* will return false.
*
* @param x X position to test in the parent's coordinate system
* @param y Y position to test in the parent's coordinate system
* @return true if the captured view is under the given point, false
* otherwise
*/
public
boolean
isCapturedViewUnder
(
int
x
,
int
y
)
{
return
isViewUnder
(
mCapturedView
,
x
,
y
);
}
/**
* Determine if the supplied view is under the given point in the parent
* view's coordinate system.
*
* @param view Child view of the parent to hit test
* @param x X position to test in the parent's coordinate system
* @param y Y position to test in the parent's coordinate system
* @return true if the supplied view is under the given point, false
* otherwise
*/
public
boolean
isViewUnder
(
View
view
,
int
x
,
int
y
)
{
if
(
view
==
null
)
{
return
false
;
}
return
x
>=
view
.
getLeft
()
&&
x
<
view
.
getRight
()
&&
y
>=
view
.
getTop
()
&&
y
<
view
.
getBottom
();
}
/**
* Find the topmost child under the given point within the parent view's
* coordinate system. The child order is determined using
* @param x X position to test in the parent's coordinate system
* @param y Y position to test in the parent's coordinate system
* @return The topmost child view under (x, y) or null if none found.
*/
public
View
findTopChildUnder
(
int
x
,
int
y
)
{
final
int
childCount
=
mParentView
.
getChildCount
();
for
(
int
i
=
childCount
-
1
;
i
>=
0
;
i
--)
{
final
View
child
=
mParentView
.
getChildAt
(
mCallback
.
getOrderedChildIndex
(
i
));
if
(
x
>=
child
.
getLeft
()
&&
x
<
child
.
getRight
()
&&
y
>=
child
.
getTop
()
&&
y
<
child
.
getBottom
())
{
return
child
;
}
}
return
null
;
}
private
int
getEdgeTouched
(
int
x
,
int
y
)
{
int
result
=
0
;
if
(
x
<
mParentView
.
getLeft
()
+
mEdgeSize
)
result
=
EDGE_LEFT
;
if
(
y
<
mParentView
.
getTop
()
+
mEdgeSize
)
result
=
EDGE_TOP
;
if
(
x
>
mParentView
.
getRight
()
-
mEdgeSize
)
result
=
EDGE_RIGHT
;
if
(
y
>
mParentView
.
getBottom
()
-
mEdgeSize
)
result
=
EDGE_BOTTOM
;
return
result
;
}
}
video/app/src/main/java/com/mints/library/utils/AITextUtil.java
deleted
100755 → 0
View file @
cc7fb9fa
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
;
}
}
video/app/src/main/java/com/mints/library/utils/DensityUtils.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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
video/app/src/main/java/com/mints/library/utils/PhoneParameterUtils.java
deleted
100755 → 0
View file @
cc7fb9fa
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
;
}
}
video/app/src/main/java/com/mints/library/utils/SmartBarUtils.java
deleted
100755 → 0
View file @
cc7fb9fa
/*
* 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.app.ActionBar
;
import
android.content.Context
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.graphics.drawable.Drawable
;
import
android.os.Build
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.WindowManager
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
/**
* 描述:SmartBarUtils
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public
class
SmartBarUtils
{
/**
* 调用 ActionBar.setTabsShowAtBottom(boolean) 方法。 如果
* android:uiOptions="splitActionBarWhenNarrow",则可设置ActionBar Tabs显示在底栏。
* <p/>
* 示例: public class MyActivity extends Activity implements
* ActionBar.TabListener { protected void onCreate(Bundle
* savedInstanceState) { super.onCreate(savedInstanceState); ...
* <p/>
* final ActionBar bar = getActionBar();
* bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
* SmartBarUtils.setActionBarTabsShowAtBottom(bar, true);
* <p/>
* bar.addTab(bar.newTab().setText("tab1").setTabListener(this));
* ... } }
*/
public
static
void
setActionBarTabsShowAtBottom
(
ActionBar
actionbar
,
boolean
showAtBottom
)
{
try
{
Method
method
=
Class
.
forName
(
"android.app.ActionBar"
).
getMethod
(
"setTabsShowAtBottom"
,
new
Class
[]{
boolean
.
class
});
try
{
method
.
invoke
(
actionbar
,
showAtBottom
);
}
catch
(
IllegalArgumentException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
SecurityException
e
)
{
e
.
printStackTrace
();
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 调用 ActionBar.setActionBarViewCollapsable(boolean) 方法。
* 设置ActionBar顶栏无显示内容时是否隐藏。
* <p/>
* 示例:
* <p/>
* public class MyActivity extends Activity {
* <p/>
* protected void onCreate(Bundle savedInstanceState) {
* super.onCreate(savedInstanceState); ...
* <p/>
* final ActionBar bar = getActionBar();
* <p/>
* // 调用setActionBarViewCollapsable,并设置ActionBar没有显示内容,则ActionBar顶栏不显示
* SmartBarUtils.setActionBarViewCollapsable(bar, true);
* bar.setDisplayOptions(0); } }
*/
public
static
void
setActionBarViewCollapsable
(
ActionBar
actionbar
,
boolean
collapsable
)
{
try
{
Method
method
=
Class
.
forName
(
"android.app.ActionBar"
).
getMethod
(
"setActionBarViewCollapsable"
,
new
Class
[]{
boolean
.
class
});
try
{
method
.
invoke
(
actionbar
,
collapsable
);
}
catch
(
IllegalArgumentException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
SecurityException
e
)
{
e
.
printStackTrace
();
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 调用 ActionBar.setActionModeHeaderHidden(boolean) 方法。 设置ActionMode顶栏是否隐藏。
* <p/>
* public class MyActivity extends Activity {
* <p/>
* protected void onCreate(Bundle savedInstanceState) {
* super.onCreate(savedInstanceState); ...
* <p/>
* final ActionBar bar = getActionBar();
* <p/>
* // ActionBar转为ActionMode时,不显示ActionMode顶栏
* SmartBarUtils.setActionModeHeaderHidden(bar, true); } }
*/
public
static
void
setActionModeHeaderHidden
(
ActionBar
actionbar
,
boolean
hidden
)
{
try
{
Method
method
=
Class
.
forName
(
"android.app.ActionBar"
).
getMethod
(
"setActionModeHeaderHidden"
,
new
Class
[]{
boolean
.
class
});
try
{
method
.
invoke
(
actionbar
,
hidden
);
}
catch
(
IllegalArgumentException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
SecurityException
e
)
{
e
.
printStackTrace
();
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 调用ActionBar.setBackButtonDrawable(Drawable)方法
* <p/>
* <p>设置返回键图标
* <p/>
* <p>示例:</p>
* <pre class="prettyprint">
* public class MyActivity extends Activity {
* <p/>
* protected void onCreate(Bundle savedInstanceState) {
* super.onCreate(savedInstanceState);
* ...
* <p/>
* final ActionBar bar = getActionBar();
* // 自定义ActionBar的返回键图标
* SmartBarUtils.setBackIcon(bar, getResources().getDrawable(R.drawable.ic_back));
* ...
* }
* }
* </pre>
*/
public
static
void
setBackIcon
(
ActionBar
actionbar
,
Drawable
backIcon
)
{
try
{
Method
method
=
Class
.
forName
(
"android.app.ActionBar"
).
getMethod
(
"setBackButtonDrawable"
,
new
Class
[]{
Drawable
.
class
});
try
{
method
.
invoke
(
actionbar
,
backIcon
);
}
catch
(
IllegalArgumentException
e
)
{
e
.
printStackTrace
();
}
catch
(
Resources
.
NotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 以下三个方法原作者为c跳跳(http://weibo.com/u/1698085875),
* 由Shawn(http://weibo.com/linshen2011)在其基础上改进了一种判断SmartBar是否存在的方法,
* 注意该方法反射的接口只存在于2013年6月之后魅族的flyme固件中
*/
/**
* 方法一:uc等在使用的方法(新旧版flyme均有效),
* 此方法需要配合requestWindowFeature(Window.FEATURE_NO_TITLE
* )使用,缺点是程序无法使用系统actionbar
*
* @param decorView window.getDecorView
*/
public
static
void
hide
(
View
decorView
)
{
if
(!
hasSmartBar
(
decorView
.
getContext
()))
return
;
try
{
@SuppressWarnings
(
"rawtypes"
)
Class
[]
arrayOfClass
=
new
Class
[
1
];
arrayOfClass
[
0
]
=
Integer
.
TYPE
;
Method
localMethod
=
View
.
class
.
getMethod
(
"setSystemUiVisibility"
,
arrayOfClass
);
Field
localField
=
View
.
class
.
getField
(
"SYSTEM_UI_FLAG_HIDE_NAVIGATION"
);
Object
[]
arrayOfObject
=
new
Object
[
1
];
try
{
arrayOfObject
[
0
]
=
localField
.
get
(
null
);
}
catch
(
Exception
e
)
{
}
localMethod
.
invoke
(
decorView
,
arrayOfObject
);
return
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 方法二:此方法需要配合requestWindowFeature(Window.FEATURE_NO_TITLE)使用
* ,缺点是程序无法使用系统actionbar
*
* @param context
* @param window
*/
public
static
void
hide
(
Context
context
,
Window
window
)
{
hide
(
context
,
window
,
0
);
}
/**
* 获取状态栏高度
*
* @param context
* @return
*/
private
static
int
getStatusBarHeight
(
Context
context
)
{
int
result
=
0
;
int
resourceId
=
context
.
getResources
().
getIdentifier
(
"status_bar_height"
,
"dimen"
,
"android"
);
if
(
resourceId
>
0
)
{
result
=
context
.
getResources
().
getDimensionPixelSize
(
resourceId
);
}
return
result
;
}
/**
* 方法三:需要使用顶部actionbar的应用请使用此方法
*
* @param context
* @param window
* @param smartBarHeight set SmartBarUtils.SMART_BAR_HEIGHT_PIXEL
*/
public
static
void
hide
(
Context
context
,
Window
window
,
int
smartBarHeight
)
{
if
(!
hasSmartBar
(
context
))
{
return
;
}
if
(
context
.
getResources
().
getConfiguration
().
orientation
==
Configuration
.
ORIENTATION_LANDSCAPE
)
{
return
;
}
window
.
setFlags
(
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
,
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
);
window
.
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_FORCE_NOT_FULLSCREEN
);
int
statusBarHeight
=
getStatusBarHeight
(
context
);
window
.
getDecorView
()
.
setPadding
(
0
,
statusBarHeight
,
0
,
-
smartBarHeight
);
}
/**
* 新型号可用反射调用Build.hasSmartBar()来判断有无SmartBar
*
* @return
*/
public
static
boolean
hasSmartBar
(
Context
context
)
{
try
{
Method
method
=
Class
.
forName
(
"android.os.Build"
).
getMethod
(
"hasSmartBar"
);
return
((
Boolean
)
method
.
invoke
(
null
)).
booleanValue
();
}
catch
(
Exception
e
)
{
}
boolean
hasNavigationBar
=
false
;
if
(
Build
.
DEVICE
.
equals
(
"mx2"
))
{
hasNavigationBar
=
true
;
}
else
if
(
Build
.
DEVICE
.
equals
(
"mx"
)
||
Build
.
DEVICE
.
equals
(
"m9"
))
{
hasNavigationBar
=
false
;
}
else
{
Resources
rs
=
context
.
getResources
();
int
id
=
rs
.
getIdentifier
(
"config_showNavigationBar"
,
"bool"
,
"android"
);
if
(
id
>
0
)
{
hasNavigationBar
=
rs
.
getBoolean
(
id
);
}
try
{
Class
systemPropertiesClass
=
Class
.
forName
(
"android.os.SystemProperties"
);
Method
m
=
systemPropertiesClass
.
getMethod
(
"get"
,
String
.
class
);
String
navBarOverride
=
(
String
)
m
.
invoke
(
systemPropertiesClass
,
"qemu.hw.mainkeys"
);
if
(
"1"
.
equals
(
navBarOverride
))
{
hasNavigationBar
=
false
;
}
else
if
(
"0"
.
equals
(
navBarOverride
))
{
hasNavigationBar
=
true
;
}
}
catch
(
Exception
e
)
{
}
}
return
hasNavigationBar
;
}
}
video/app/src/main/java/com/mints/wisdomclean/common/AppConfig.java
View file @
c14e01ff
...
...
@@ -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
;
}
video/app/src/main/java/com/mints/wisdomclean/common/Constant.kt
View file @
c14e01ff
package
com.mints.wisdomclean.common
import
android.view.View
import
com.mints.wisdomclean.mvp.model.AppBean
object
Constant
{
/**
...
...
@@ -12,16 +9,9 @@ object Constant {
const
val
FIRST_GUILD
=
"first_guild"
const
val
FIRST_SPLASH
=
"first_splash"
const
val
IS_FIRST_AGREE_BTN
=
"is_first_agree_btn"
/**
* 获取 TAG NAME
*/
const
val
TAG_NAME
=
"SUN"
const
val
MINTS_APP_NAME
=
"乐看短剧"
const
val
MINTS_PKG_NAME
=
"com.mints.wisdomclean"
/**
* 退出广播tag
*/
const
val
ACTION_EXIT_APP
=
"package.exit"
/**
...
...
@@ -35,30 +25,4 @@ object Constant {
var
REGISTER_URL
=
"http://mints-web.mints-id.com/agreements/wisdomclean/yhxy.html"
//注册协议
var
PRIVACY_URL
=
"http://mints-web.mints-id.com/agreements/wisdomclean/syzc.html"
//隐私协议
var
MEMBERS_URL
=
"https://mints-web.mints-id.com/agreements/wisdomclean/gmxy.html"
//会员付费服务协议
// ******************
object
BeenHolder
{
val
INSTALLED_APPS
:
ArrayList
<
AppBean
>
=
ArrayList
()
val
UNINSTALLED_APPS
:
ArrayList
<
AppBean
>
=
ArrayList
()
}
fun
getUninstalledApps
():
ArrayList
<
AppBean
>
{
return
BeenHolder
.
UNINSTALLED_APPS
}
fun
getInstalledApps
():
ArrayList
<
AppBean
>
{
return
BeenHolder
.
INSTALLED_APPS
}
const
val
File
=
0
const
val
Storage
=
1
const
val
FILE_OBSERVER_BROADCAST
=
"file.manager.category.util.file_observer_broadcast"
const
val
APK_VERSION_LOWER
=
-
1
const
val
APK_VERSION_HIGHER
=
1
const
val
APK_VERSION_EQUAL
=
0
const
val
APK_UNINSTALL
=
-
2
var
button_visibility
=
View
.
GONE
//apps、unused apps
}
\ No newline at end of file
video/app/src/main/java/com/mints/wisdomclean/common/CustomViewExt.kt
deleted
100644 → 0
View file @
cc7fb9fa
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
}
video/app/src/main/java/com/mints/wisdomclean/mvp/model/AppBean.java
deleted
100644 → 0
View file @
cc7fb9fa
package
com
.
mints
.
wisdomclean
.
mvp
.
model
;
/**
* No comments
*/
public
class
AppBean
{
private
long
id
;
private
String
path
;
private
String
fileName
;
//XXX.apk
private
String
name
;
//label
private
String
packageName
;
private
String
versionName
;
private
int
versionCode
;
private
String
cacheSize
;
//缓存大小
private
String
dataSize
;
//数据大小
private
String
codeSize
;
//应用大小
private
String
desc
;
//for example: Mockplus (版本 3.3.3.3) 10.02MB
private
long
firstInstallTime
;
private
long
lastUpdateTime
;
private
long
lastUsedTime
;
private
int
apkStats
;
private
boolean
select
;
private
boolean
isHaveAccess
=
false
;
private
int
timeType
=
0
;
public
final
static
int
inOneMonth
=
0
;
public
final
static
int
overOneMonth
=
1
;
public
final
static
int
overThreeMonth
=
2
;
public
final
static
int
overSixMonth
=
3
;
public
boolean
isHaveAccess
()
{
return
isHaveAccess
;
}
public
void
setHaveAccess
(
boolean
haveAccess
)
{
isHaveAccess
=
haveAccess
;
}
public
int
getTimeType
()
{
return
timeType
;
}
public
void
setTimeType
(
int
timeType
)
{
this
.
timeType
=
timeType
;
}
public
static
int
getInOneMonth
()
{
return
inOneMonth
;
}
public
static
int
getOverOneMonth
()
{
return
overOneMonth
;
}
public
static
int
getOverThreeMonth
()
{
return
overThreeMonth
;
}
public
static
int
getOverSixMonth
()
{
return
overSixMonth
;
}
public
AppBean
()
{
}
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
String
getPath
()
{
return
path
;
}
public
void
setPath
(
String
path
)
{
this
.
path
=
path
;
}
public
String
getFileName
()
{
return
fileName
;
}
public
void
setFileName
(
String
fileName
)
{
this
.
fileName
=
fileName
;
}
public
int
getApkStats
()
{
return
apkStats
;
}
public
void
setApkStats
(
int
apkStats
)
{
this
.
apkStats
=
apkStats
;
}
public
String
getDesc
()
{
return
desc
;
}
public
void
setDesc
(
String
desc
)
{
this
.
desc
=
desc
;
}
public
String
getCacheSize
()
{
return
cacheSize
;
}
public
void
setCacheSize
(
String
cacheSize
)
{
this
.
cacheSize
=
cacheSize
;
}
public
String
getDataSize
()
{
return
dataSize
;
}
public
void
setDataSize
(
String
dataSize
)
{
this
.
dataSize
=
dataSize
;
}
public
String
getCodeSize
()
{
return
codeSize
;
}
public
void
setCodeSize
(
String
codeSize
)
{
this
.
codeSize
=
codeSize
;
}
public
long
getLastUpdateTime
()
{
return
lastUpdateTime
;
}
public
void
setLastUpdateTime
(
long
lastUpdateTime
)
{
this
.
lastUpdateTime
=
lastUpdateTime
;
}
public
long
getFirstInstallTime
()
{
return
firstInstallTime
;
}
public
void
setFirstInstallTime
(
long
firstInstallTime
)
{
this
.
firstInstallTime
=
firstInstallTime
;
}
public
long
getLastUsedTime
()
{
return
lastUsedTime
;
}
public
void
setLastUsedTime
(
long
lastUsedTime
)
{
this
.
lastUsedTime
=
lastUsedTime
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPackageName
()
{
return
packageName
;
}
public
void
setPackageName
(
String
packageName
)
{
this
.
packageName
=
packageName
;
}
public
String
getVersionName
()
{
return
versionName
;
}
public
void
setVersionName
(
String
versionName
)
{
this
.
versionName
=
versionName
;
}
public
int
getVersionCode
()
{
return
versionCode
;
}
public
void
setVersionCode
(
int
versionCode
)
{
this
.
versionCode
=
versionCode
;
}
public
boolean
isSelect
()
{
return
select
;
}
public
void
setSelect
(
boolean
select
)
{
this
.
select
=
select
;
}
@Override
public
String
toString
()
{
return
"AppBean{"
+
"id="
+
id
+
", path='"
+
path
+
'\''
+
", fileName='"
+
fileName
+
'\''
+
", name='"
+
name
+
'\''
+
", packageName='"
+
packageName
+
'\''
+
", versionName='"
+
versionName
+
'\''
+
", versionCode="
+
versionCode
+
", cacheSize='"
+
cacheSize
+
'\''
+
", dataSize='"
+
dataSize
+
'\''
+
", codeSize='"
+
codeSize
+
'\''
+
", desc='"
+
desc
+
'\''
+
", firstInstallTime="
+
firstInstallTime
+
", lastUpdateTime="
+
lastUpdateTime
+
", lastUsedTime="
+
lastUsedTime
+
", apkStats="
+
apkStats
+
", select="
+
select
+
'}'
;
}
}
video/app/src/main/java/com/mints/wisdomclean/mvp/model/DataModel.java
deleted
100755 → 0
View file @
cc7fb9fa
package
com
.
mints
.
wisdomclean
.
mvp
.
model
;
import
java.util.ArrayList
;
public
class
DataModel
{
String
titleGroup
;
ArrayList
<
Duplicate
>
listDuplicate
;
public
String
getTitleGroup
()
{
return
titleGroup
;
}
public
void
setTitleGroup
(
String
str_folder
)
{
this
.
titleGroup
=
str_folder
;
}
public
ArrayList
<
Duplicate
>
getListDuplicate
()
{
return
listDuplicate
;
}
public
void
setListDuplicate
(
ArrayList
<
Duplicate
>
mListDuplicate
)
{
this
.
listDuplicate
=
mListDuplicate
;
}
}
video/app/src/main/java/com/mints/wisdomclean/mvp/model/Duplicate.java
deleted
100755 → 0
View file @
cc7fb9fa
package
com
.
mints
.
wisdomclean
.
mvp
.
model
;
import
static
com
.
mints
.
wisdomclean
.
mvp
.
model
.
TypeFile
.
UNKNOWN
;
import
java.io.File
;
public
class
Duplicate
{
private
File
file
;
private
boolean
isChecked
=
true
;
private
int
typeFile
=
UNKNOWN
;
public
int
getTypeFile
(){
return
this
.
typeFile
;
}
public
int
setTypeFile
(
int
type
){
return
this
.
typeFile
=
type
;
}
public
File
getFile
()
{
return
this
.
file
;
}
public
void
setFile
(
File
file
)
{
this
.
file
=
file
;
}
public
boolean
isChecked
()
{
return
this
.
isChecked
;
}
public
void
setChecked
(
boolean
checked
)
{
this
.
isChecked
=
checked
;
}
}
video/app/src/main/java/com/mints/wisdomclean/mvp/model/EventMessage.java
deleted
100644 → 0
View file @
cc7fb9fa
package
com
.
mints
.
wisdomclean
.
mvp
.
model
;
public
class
EventMessage
<
T
>
{
String
message
;
private
T
content
;
public
EventMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
T
getContent
()
{
return
content
;
}
public
void
setContent
(
T
content
)
{
this
.
content
=
content
;
}
}
video/app/src/main/java/com/mints/wisdomclean/mvp/model/FileBean.kt
deleted
100644 → 0
View file @
cc7fb9fa
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
video/app/src/main/java/com/mints/wisdomclean/mvp/model/Folder.kt
deleted
100644 → 0
View file @
cc7fb9fa
package
com.mints.wisdomclean.mvp.model
class
Folder
{
var
name
:
String
var
images
:
ArrayList
<
Image
>
=
arrayListOf
()
constructor
(
name
:
String
)
{
this
.
name
=
name
}
constructor
(
name
:
String
,
images
:
ArrayList
<
Image
>)
{
this
.
name
=
name
this
.
images
=
images
}
fun
addImage
(
image
:
Image
?)
{
if
(
image
!=
null
&&
image
.
path
.
isEmpty
())
{
if
(
images
==
null
)
{
images
=
ArrayList
()
}
images
.
add
(
image
)
}
}
}
\ No newline at end of file
video/app/src/main/java/com/mints/wisdomclean/mvp/model/GridBean.kt
deleted
100644 → 0
View file @
cc7fb9fa
package
com.mints.wisdomclean.mvp.model
import
java.io.Serializable
/**
*
* @author jyx
* @date 2021/4/21
* @des
*/
data class
GridBean
(
val
imgSrc
:
Any
?,
val
title
:
Int
,
var
isChecked
:
Boolean
=
false
)
:
Serializable
\ No newline at end of file
video/app/src/main/java/com/mints/wisdomclean/mvp/model/Image.kt
deleted
100644 → 0
View file @
cc7fb9fa
package
com.mints.wisdomclean.mvp.model
import
android.net.Uri
import
android.os.Parcel
import
android.os.Parcelable
data class
Image
(
val
path
:
String
,
val
time
:
Long
,
val
name
:
String
,
val
mimeType
:
String
,
val
uri
:
Uri
,
val
size
:
Long
)
:
Parcelable
{
constructor
(
parcel
:
Parcel
)
:
this
(
parcel
.
readString
()
!!
,
parcel
.
readLong
(),
parcel
.
readString
()
!!
,
parcel
.
readString
()
!!
,
parcel
.
readParcelable
<
Uri
>(
Uri
::
class
.
java
.
classLoader
)
as
Uri
,
parcel
.
readLong
()
)
override
fun
writeToParcel
(
dest
:
Parcel
?,
flags
:
Int
)
{
dest
?.
run
{
writeString
(
path
)
writeLong
(
time
)
writeString
(
name
)
writeString
(
mimeType
)
writeParcelable
(
uri
,
0
)
writeLong
(
size
)
}
}
override
fun
describeContents
():
Int
{
return
0
}
companion
object
CREATOR
:
Parcelable
.
Creator
<
Image
>
{
override
fun
createFromParcel
(
parcel
:
Parcel
):
Image
{
return
Image
(
parcel
)
}
override
fun
newArray
(
size
:
Int
):
Array
<
Image
?
>
{
return
arrayOfNulls
(
size
)
}
}
}
\ No newline at end of file
video/app/src/main/java/com/mints/wisdomclean/mvp/model/PkgInfo.java
deleted
100644 → 0
View file @
cc7fb9fa
package
com
.
mints
.
wisdomclean
.
mvp
.
model
;
import
java.io.Serializable
;
public
class
PkgInfo
implements
Serializable
{
private
String
name
;
private
String
pkgName
;
private
long
installTime
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPkgName
()
{
return
pkgName
;
}
public
void
setPkgName
(
String
pkgName
)
{
this
.
pkgName
=
pkgName
;
}
public
long
getInstallTime
()
{
return
installTime
;
}
public
void
setInstallTime
(
long
installTime
)
{
this
.
installTime
=
installTime
;
}
}
video/app/src/main/java/com/mints/wisdomclean/mvp/model/RiskBean.kt
deleted
100644 → 0
View file @
cc7fb9fa
package
com.mints.wisdomclean.mvp.model
import
java.io.Serializable
/**
* 风控
*/
data class
RiskBean
(
val
msg
:
String
=
""
,
//提示msg字段内容
val
isRiskUser
:
Boolean
=
false
,
//true-命中风控
val
isRiskUserCrash
:
Boolean
=
false
,
//true-自动退出
val
jump
:
Int
=
0
//0-不跳转 1-usb 2-辅助
)
:
Serializable
\ No newline at end of file
video/app/src/main/java/com/mints/wisdomclean/mvp/model/TypeFile.java
deleted
100755 → 0
View file @
cc7fb9fa
package
com
.
mints
.
wisdomclean
.
mvp
.
model
;
public
class
TypeFile
{
public
final
static
int
IMAGE
=
0
;
public
final
static
int
AUDIO
=
1
;
public
final
static
int
VIDEO
=
2
;
public
final
static
int
DOCUMENT
=
3
;
public
final
static
int
APK
=
4
;
public
final
static
int
VCF
=
5
;
public
final
static
int
ZIP
=
6
;
public
final
static
int
PDF
=
7
;
public
final
static
int
UNKNOWN
=
8
;
public
static
int
getType
(
String
fileName
)
{
if
(
fileName
.
endsWith
(
".apk"
))
{
return
APK
;
}
else
if
(
fileName
.
endsWith
(
".zip"
))
{
return
ZIP
;
}
else
if
(
fileName
.
endsWith
(
".vcf"
))
{
return
VCF
;
}
else
if
(
fileName
.
endsWith
(
".mp3"
)
||
fileName
.
endsWith
(
".aac"
)
||
fileName
.
endsWith
(
".amr"
)
||
fileName
.
endsWith
(
".m4a"
)
||
fileName
.
endsWith
(
".ogg"
)
||
fileName
.
endsWith
(
".wav"
)
||
fileName
.
endsWith
(
".flac"
))
{
return
AUDIO
;
}
else
if
(
fileName
.
endsWith
(
".3gp"
)
||
fileName
.
endsWith
(
".mp4"
)
||
fileName
.
endsWith
(
".mkv"
)
||
fileName
.
endsWith
(
".webm"
))
{
return
VIDEO
;
}
else
if
(
fileName
.
endsWith
(
".doc"
)
||
fileName
.
endsWith
(
".docx"
)
||
fileName
.
endsWith
(
".html"
)
||
fileName
.
endsWith
(
".txt"
)
||
fileName
.
endsWith
(
".xml"
)
||
fileName
.
endsWith
(
".xlsx"
))
{
return
DOCUMENT
;
}
else
if
(
fileName
.
endsWith
(
".jpg"
)
||
fileName
.
endsWith
(
".jpeg"
)
||
fileName
.
endsWith
(
".png"
)
||
fileName
.
endsWith
(
".bmp"
)
||
fileName
.
endsWith
(
".gif"
))
{
return
IMAGE
;
}
else
if
(
fileName
.
endsWith
(
".pdf"
))
{
return
PDF
;
}
return
UNKNOWN
;
}
}
video/app/src/main/java/com/mints/wisdomclean/mvp/presenters/GuidePresenter.kt
deleted
100644 → 0
View file @
cc7fb9fa
package
com.mints.wisdomclean.mvp.presenters
import
com.mints.wisdomclean.MintsApplication
import
com.mints.wisdomclean.common.DeviceInfo
import
com.mints.wisdomclean.manager.AppHttpManager
import
com.mints.wisdomclean.manager.UserManager
import
com.mints.wisdomclean.mvp.model.BaseResponse
import
com.mints.wisdomclean.mvp.model.UserBean
import
com.mints.wisdomclean.mvp.views.GuideView
import
com.mints.wisdomclean.mvp.views.MyView
import
com.mints.wisdomclean.utils.DeviceUuidFactory
import
com.mints.library.net.neterror.BaseSubscriber
import
com.mints.library.net.neterror.Throwable
class
GuidePresenter
:
BasePresenter
<
GuideView
>()
{
/**
* 游客登录
*/
fun
userLogin
()
{
val
vo
=
HashMap
<
String
,
Any
>()
vo
[
"device"
]
=
DeviceUuidFactory
().
deviceUuid
.
toString
()
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
visitorlogin
(
vo
),
object
:
BaseSubscriber
<
BaseResponse
<
UserBean
>>()
{
override
fun
onCompleted
()
{
if
(
isLinkView
)
return
}
override
fun
onError
(
e
:
Throwable
)
{
if
(
isLinkView
)
return
}
override
fun
onNext
(
baseResponse
:
BaseResponse
<
UserBean
>)
{
if
(
isLinkView
)
return
view
.
hideLoading
()
val
code
=
baseResponse
.
getStatus
()
val
message
=
baseResponse
.
getMessage
()
val
data
:
UserBean
?
=
baseResponse
.
getData
()
when
(
code
)
{
200
->
if
(
data
!=
null
)
{
UserManager
.
getInstance
().
saveUserInfo
(
data
)
saveTerminalInfo
()
}
else
->
view
.
showToast
(
message
)
}
}
})
}
/**
* 提交设备信息
*
* @param context
*/
fun
saveTerminalInfo
()
{
val
vo
=
HashMap
<
String
,
Any
>()
val
deviceInfo
:
DeviceInfo
=
DeviceInfo
.
instance
val
macAddress
:
String
=
deviceInfo
.
getMacAddress
()
val
mac
=
macAddress
.
replace
(
":"
,
""
)
vo
[
"mac"
]
=
mac
vo
[
"mac1"
]
=
macAddress
vo
[
"androidid"
]
=
deviceInfo
.
getAndroidId
(
null
)
vo
[
"imei"
]
=
deviceInfo
.
iMEI
vo
[
"oaid"
]
=
MintsApplication
.
OAID
vo
[
"os"
]
=
if
(
deviceInfo
.
isHarmonyOS
())
"android-HarmonyOS"
else
"android"
vo
[
"model"
]
=
deviceInfo
.
newModel
vo
[
"uuid"
]
=
DeviceUuidFactory
().
deviceUuid
vo
[
"osversion"
]
=
deviceInfo
.
oSVersion
vo
[
"appversion"
]
=
deviceInfo
.
versionName
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
saveTerminalInfo
(
vo
),
object
:
BaseSubscriber
<
BaseResponse
<
Any
>>()
{
override
fun
onCompleted
()
{
if
(
isLinkView
)
return
}
override
fun
onError
(
e
:
Throwable
)
{
if
(
isLinkView
)
return
}
override
fun
onNext
(
baseResponse
:
BaseResponse
<
Any
>)
{
if
(
isLinkView
)
return
val
code
=
baseResponse
.
status
when
(
code
)
{
// 200 -> getHomePageImageList(1, 10)
}
}
})
}
}
\ No newline at end of file
video/app/src/main/java/com/mints/wisdomclean/mvp/views/GuideView.kt
deleted
100644 → 0
View file @
cc7fb9fa
package
com.mints.wisdomclean.mvp.views
interface
GuideView
:
BaseView
{
}
video/app/src/main/java/com/mints/wisdomclean/ui/activitys/GuideActivity.kt
View file @
c14e01ff
...
...
@@ -6,8 +6,6 @@ import android.view.KeyEvent
import
androidx.viewpager.widget.ViewPager
import
com.mints.wisdomclean.R
import
com.mints.wisdomclean.manager.UserManager
import
com.mints.wisdomclean.mvp.presenters.GuidePresenter
import
com.mints.wisdomclean.mvp.views.GuideView
import
com.mints.wisdomclean.ui.activitys.base.BaseActivity
import
com.mints.wisdomclean.ui.adapter.VPAdapter
import
kotlinx.android.synthetic.main.activity_guide.*
...
...
@@ -15,9 +13,8 @@ import kotlinx.android.synthetic.main.activity_guide.*
/**
* 欢迎页
*/
class
GuideActivity
:
BaseActivity
()
,
GuideView
{
class
GuideActivity
:
BaseActivity
()
{
private
val
guidePresenter
by
lazy
{
GuidePresenter
()
}
var
count
=
0
var
layouts
=
intArrayOf
(
R
.
layout
.
item_guide1
,
...
...
@@ -30,8 +27,6 @@ class GuideActivity : BaseActivity(), GuideView {
}
override
fun
initViewsAndEvents
()
{
guidePresenter
.
attachView
(
this
)
guidePresenter
.
userLogin
()
initView
()
}
...
...
@@ -41,7 +36,6 @@ class GuideActivity : BaseActivity(), GuideView {
override
fun
onDestroy
()
{
super
.
onDestroy
()
guidePresenter
.
detachView
()
vp_guide_viewpager
.
setOnPageChangeListener
(
null
)
}
...
...
video/app/src/main/java/com/mints/wisdomclean/ui/activitys/SplashActivity.kt
View file @
c14e01ff
...
...
@@ -82,8 +82,6 @@ class SplashActivity : BaseActivity() {
}
fun
startTimer
()
{
AppConfig
.
mainCleanValue
=
Random
().
nextInt
(
351
)
+
50
// 生成 50-200 之间的随机数
if
(
timer
!=
null
)
{
//防止计时器重复
timer
!!
.
stop
()
timer
=
null
...
...
video/app/src/main/java/com/mints/wisdomclean/ui/activitys/base/BaseActivity.java
View file @
c14e01ff
...
...
@@ -28,7 +28,6 @@ import com.mints.wisdomclean.ui.widgets.LoadingDialog;
import
com.mints.wisdomclean.utils.StatusBarUtil
;
import
com.mints.wisdomclean.utils.ToastUtil
;
import
com.mints.library.base.BaseAppCompatActivity
;
import
com.mints.library.net.netstatus.NetUtils
;
public
abstract
class
BaseActivity
extends
BaseAppCompatActivity
implements
BaseView
{
...
...
@@ -47,11 +46,6 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
TextUtils
.
equals
(
getClass
().
getSimpleName
(),
"GuideActivity"
))
{
getWindow
().
setFlags
(
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
,
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
);
}
else
if
(
TextUtils
.
equals
(
getClass
().
getSimpleName
(),
"VideoActivity"
))
{
StatusBarUtil
.
transparencyBar
(
this
);
//设置状态栏全透明
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
getWindow
().
setNavigationBarColor
(
Color
.
BLACK
);
}
}
else
{
StatusBarUtil
.
transparencyBar
(
this
);
//设置状态栏全透明
StatusBarUtil
.
StatusBarLightMode
(
this
);
//设置白底黑字
...
...
@@ -117,14 +111,6 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
super
.
onDestroy
();
}
/**
* 如果需要在前台做断网判断则需要重写
*/
@Override
protected
void
onNetworkDisConnected
()
{
showToast
(
getString
(
R
.
string
.
netfail
));
}
@Override
protected
boolean
isApplyStatusBarTranslucency
()
{
return
true
;
...
...
@@ -134,15 +120,6 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
protected
void
getBundleExtras
(
Bundle
extras
)
{
}
@Override
protected
View
getLoadingTargetView
()
{
return
null
;
}
@Override
protected
void
onNetworkConnected
(
NetUtils
.
NetType
type
)
{
}
@Override
protected
boolean
toggleOverridePendingTransition
()
{
...
...
video/app/src/main/java/com/mints/wisdomclean/ui/adapter/VPAdapter.kt
View file @
c14e01ff
...
...
@@ -65,7 +65,6 @@ class VPAdapter() : PagerAdapter() {
val
llGuide1Next
=
view
.
findViewById
<
LinearLayout
>(
R
.
id
.
ll_guide1_next
)
val
ivGuideBg
=
view
.
findViewById
<
ImageView
>(
R
.
id
.
iv_guide1_bg
)
val
ivGuideBg2
=
view
.
findViewById
<
ImageView
>(
R
.
id
.
iv_guide2_bg
)
tvGuide1Top
.
text
=
AppConfig
.
mainCleanValue
.
toString
()
+
"MB"
llGuide1Next
.
setOnClickListener
{
mOnItemClickListener
?.
onItemClick
(
realPosition
)
}
...
...
video/app/src/main/res/layout/swipeback_layout.xml
deleted
100755 → 0
View file @
cc7fb9fa
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<com.mints.library.swipeback.SwipeBackLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment