Skip to content

Commit 18cc0f9

Browse files
committed
see 03/19 log
1 parent 340e8c9 commit 18cc0f9

File tree

16 files changed

+487
-221
lines changed

16 files changed

+487
-221
lines changed

launcher/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
android:name="com.blankj.launcher.pkg.MainActivity"
1414
android:configChanges="orientation|keyboardHidden|screenSize"
1515
android:screenOrientation="user"
16+
android:theme="@style/MainActivityTheme"
1617
android:windowSoftInputMode="stateHidden">
1718
<intent-filter>
1819
<action android:name="android.intent.action.MAIN" />

launcher/pkg/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
android:name=".MainActivity"
77
android:configChanges="orientation|keyboardHidden|screenSize"
88
android:screenOrientation="user"
9+
android:theme="@style/MainActivityTheme"
910
android:windowSoftInputMode="stateHidden" />
1011
</application>
1112

lib/base/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies {
1313
api dep.constraint
1414
api dep.kotlin
1515
api dep.free_proguard
16-
api 'com.r0adkll:slidableactivity:2.0.5'
16+
api 'com.r0adkll:slidableactivity:2.0.6'
1717
compileOnly dep.leakcanary.android_no_op
1818
// api 'com.blankj:utilcode:1.23.7'
1919
}
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
package com.blankj.lib.base.slideBack;
2+
3+
import android.content.Context;
4+
import android.support.annotation.NonNull;
5+
import android.support.annotation.Nullable;
6+
import android.support.v4.view.MotionEventCompat;
7+
import android.util.AttributeSet;
8+
import android.view.MotionEvent;
9+
import android.view.VelocityTracker;
10+
import android.view.View;
11+
import android.view.ViewConfiguration;
12+
import android.widget.FrameLayout;
13+
import android.widget.Scroller;
14+
15+
import com.blankj.utilcode.util.LogUtils;
16+
17+
/**
18+
* <pre>
19+
* author: blankj
20+
* blog : http://blankj.com
21+
* time : 2019/03/20
22+
* desc :
23+
* </pre>
24+
*/
25+
public class SlideBackLayout extends FrameLayout {
26+
27+
private View mParentView;
28+
private int mEdgeSlop;
29+
private int mTouchSlop;
30+
31+
private boolean isConsumeDown;
32+
33+
private float mDownX;
34+
private float mDownY;
35+
private float mTempX;
36+
37+
private Scroller mScroller;
38+
39+
private boolean isFinish = false;
40+
41+
private boolean isSliding = false;
42+
43+
private int mViewWidth;
44+
45+
private SlideListener mListener = new SlideListener() {
46+
@Override
47+
public void onStart() {
48+
LogUtils.e("start: ");
49+
}
50+
51+
@Override
52+
public void onChange(float x) {
53+
LogUtils.e("onChange: " + x);
54+
}
55+
56+
@Override
57+
public void onFinish() {
58+
LogUtils.e("onFinish: ");
59+
}
60+
};
61+
62+
private VelocityTracker mVelocityTracker;
63+
64+
public SlideBackLayout(@NonNull Context context) {
65+
this(context, null);
66+
}
67+
68+
public SlideBackLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
69+
super(context, attrs);
70+
71+
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
72+
mEdgeSlop = ViewConfiguration.get(context).getScaledEdgeSlop();
73+
mScroller = new Scroller(context);
74+
}
75+
76+
77+
@Override
78+
protected void onLayout(boolean changed, int l, int t, int r, int b) {
79+
super.onLayout(changed, l, t, r, b);
80+
if (changed) {
81+
mParentView = (View) getParent();
82+
mViewWidth = getWidth();
83+
}
84+
}
85+
86+
@Override
87+
public boolean dispatchTouchEvent(MotionEvent event) {
88+
final int action = event.getAction();
89+
switch (action) {
90+
case MotionEvent.ACTION_DOWN:
91+
if (super.dispatchTouchEvent(event)) {
92+
isConsumeDown = true;
93+
} else {
94+
mDownX = mTempX = event.getRawX();
95+
mDownY = event.getRawY();
96+
}
97+
isSliding = false;
98+
return true;
99+
case MotionEvent.ACTION_MOVE:
100+
if (!isConsumeDown) {
101+
LogUtils.e();
102+
if (isSliding) break;
103+
if (event.getRawX() - mDownX > mTouchSlop) {
104+
isSliding = true;
105+
if (mListener != null) {
106+
mListener.onStart();
107+
}
108+
return true;
109+
}
110+
}
111+
break;
112+
default:
113+
break;
114+
}
115+
return super.dispatchTouchEvent(event);
116+
}
117+
118+
@Override
119+
public boolean onTouchEvent(MotionEvent event) {
120+
LogUtils.e(event);
121+
if (isConsumeDown || !isSliding) return super.onTouchEvent(event);
122+
if (mVelocityTracker == null) {
123+
mVelocityTracker = VelocityTracker.obtain();
124+
}
125+
mVelocityTracker.addMovement(event);
126+
final int action = MotionEventCompat.getActionMasked(event);
127+
switch (action) {
128+
case MotionEvent.ACTION_MOVE:
129+
int moveX = (int) event.getRawX();
130+
if (moveX > mDownX) {
131+
mParentView.scrollBy((int) (mTempX - moveX), 0);
132+
} else if (moveX < mDownX) {
133+
//解决连续滑动Activity无法闭合的问题
134+
mParentView.scrollTo(0, 0);
135+
}
136+
if (mListener != null) {
137+
mListener.onChange(mTempX - moveX);
138+
}
139+
mTempX = moveX;
140+
break;
141+
case MotionEvent.ACTION_UP:
142+
case MotionEvent.ACTION_CANCEL:
143+
startScroll();
144+
break;
145+
}
146+
return true;
147+
}
148+
149+
private void startScroll() {
150+
final VelocityTracker velocityTracker = mVelocityTracker;
151+
velocityTracker.computeCurrentVelocity(1000, ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity());
152+
int xVelocity = (int) velocityTracker.getXVelocity();
153+
LogUtils.e(xVelocity);
154+
155+
if (mParentView.getScrollX() <= -mViewWidth / 2) {
156+
isFinish = true;
157+
scrollToRight();
158+
} else {
159+
isFinish = false;
160+
scrollToOrigin();
161+
}
162+
163+
if (mListener != null) {
164+
mListener.onFinish();
165+
}
166+
}
167+
168+
@Override
169+
public void computeScroll() {
170+
if (mScroller.computeScrollOffset()) {
171+
mParentView.scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
172+
postInvalidate();
173+
if (mScroller.isFinished() && isFinish && mListener != null) {
174+
mListener.onFinish();
175+
}
176+
}
177+
}
178+
179+
private void scrollToOrigin() {
180+
final int delta = mParentView.getScrollX();
181+
mScroller.startScroll(mParentView.getScrollX(), 0, -delta, 0, Math.abs(delta));
182+
postInvalidate();
183+
}
184+
185+
private void scrollToRight() {
186+
final int delta = mViewWidth + mParentView.getScrollX();
187+
mScroller.startScroll(mParentView.getScrollX(), 0, -delta + 1, 0, Math.abs(delta));
188+
postInvalidate();
189+
}
190+
191+
public interface SlideListener {
192+
void onStart();
193+
194+
void onChange(float x);
195+
196+
void onFinish();
197+
}
198+
}

lib/base/src/main/res/values/styles.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<item name="android:windowBackground">@android:color/transparent</item>
1414
</style>
1515

16+
<style name="MainActivityTheme" parent="AppTheme">
17+
<item name="android:windowIsTranslucent">false</item>
18+
</style>
19+
1620
<style name="TextStyle">
1721
<item name="android:textSize">@dimen/font_16</item>
1822
<item name="android:textColor">@drawable/base_sel_button_txt_color</item>

subutil/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
android:name="com.blankj.subutil.pkg.feature.SubUtilActivity"
1414
android:configChanges="orientation|keyboardHidden|screenSize"
1515
android:screenOrientation="user"
16+
android:theme="@style/MainActivityTheme"
1617
android:windowSoftInputMode="stateHidden">
1718
<intent-filter>
1819
<action android:name="android.intent.action.MAIN" />

utilcode/README-CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ getRomInfo : 获取 ROM 信息
712712
```
713713
getScreenWidth : 获取屏幕的宽度(单位:px)
714714
getScreenHeight : 获取屏幕的高度(单位:px)
715+
getAppScreenWidth : 获取应用屏幕的宽度(单位:px)
716+
getAppScreenHeight : 获取应用屏幕的高度(单位:px)
715717
getScreenDensity : 获取屏幕密度
716718
getScreenDensityDpi: 获取屏幕密度 DPI
717719
setFullScreen : 设置屏幕为全屏

utilcode/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ apply {
44

55
dependencies {
66
implementation fileTree(dir: 'libs', include: ['*.jar'])
7-
api project(':utilcode-pkg')
7+
implementation project(':utilcode-pkg')
88
}

utilcode/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
android:name="com.blankj.utilcode.pkg.feature.CoreUtilActivity"
1414
android:configChanges="orientation|keyboardHidden|screenSize"
1515
android:screenOrientation="user"
16+
android:theme="@style/MainActivityTheme"
1617
android:windowSoftInputMode="stateHidden">
1718
<intent-filter>
1819
<action android:name="android.intent.action.MAIN" />

utilcode/lib/src/main/java/com/blankj/utilcode/util/Utils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package com.blankj.utilcode.util;
22

3+
import android.animation.ValueAnimator;
34
import android.annotation.SuppressLint;
45
import android.app.Activity;
56
import android.app.ActivityManager;
67
import android.app.Application;
78
import android.app.Application.ActivityLifecycleCallbacks;
89
import android.content.Context;
10+
import android.os.Build;
911
import android.os.Bundle;
1012
import android.os.Handler;
1113
import android.os.Looper;
1214
import android.support.v4.content.FileProvider;
15+
import android.util.Log;
1316
import android.view.View;
1417
import android.view.inputmethod.InputMethodManager;
1518

@@ -168,6 +171,26 @@ static <T> Task<T> doAsync(final Task<T> task) {
168171
return task;
169172
}
170173

174+
private static void setAnimatorsEnabled() {
175+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && ValueAnimator.areAnimatorsEnabled()) {
176+
return;
177+
}
178+
try {
179+
//noinspection JavaReflectionMemberAccess
180+
Field sDurationScaleField = ValueAnimator.class.getDeclaredField("sDurationScale");
181+
sDurationScaleField.setAccessible(true);
182+
float sDurationScale = (Float) sDurationScaleField.get(null);
183+
if (sDurationScale == 0f) {
184+
sDurationScaleField.set(null, 1f);
185+
Log.i("Utils", "setAnimatorsEnabled: Animators are enabled now!");
186+
}
187+
} catch (NoSuchFieldException e) {
188+
e.printStackTrace();
189+
} catch (IllegalAccessException e) {
190+
e.printStackTrace();
191+
}
192+
}
193+
171194
static class ActivityLifecycleImpl implements ActivityLifecycleCallbacks {
172195

173196
final LinkedList<Activity> mActivityList = new LinkedList<>();
@@ -180,6 +203,7 @@ static class ActivityLifecycleImpl implements ActivityLifecycleCallbacks {
180203

181204
@Override
182205
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
206+
setAnimatorsEnabled();
183207
setTopActivity(activity);
184208
}
185209

utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/CoreUtilActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class CoreUtilActivity : BaseTitleActivity() {
5454
}
5555
}
5656

57+
override fun isSwipeBack(): Boolean {
58+
return false
59+
}
60+
5761
override fun bindTitle(): CharSequence {
5862
return getString(R.string.core_util)
5963
}

utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ object DialogHelper {
8080
val window = dialog.window
8181
window.requestFeature(Window.FEATURE_NO_TITLE)
8282

83+
dialog.setOnShowListener { KeyboardUtils.fixAndroidBug5497(window) }
84+
8385
dialog.show()
8486

8587
window.setBackgroundDrawable(ColorDrawable(0))
8688
val attributes = dialog.window.attributes
8789
attributes.gravity = Gravity.BOTTOM
8890
attributes.width = ScreenUtils.getAppScreenWidth()
89-
attributes.height = ScreenUtils.getAppScreenHeight() //* 2 / 5
91+
attributes.height = ScreenUtils.getAppScreenHeight() * 2 / 5
92+
attributes.windowAnimations = R.style.BottomDialogAnimation
9093
dialog.window.attributes = attributes
9194
}
9295

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:duration="200"
5+
android:fromYDelta="100%"
6+
android:toYDelta="0" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:duration="200"
5+
android:fromYDelta="0"
6+
android:toYDelta="100%" />

0 commit comments

Comments
 (0)