提交 18cc0f99 编写于 作者: B Blankj

see 03/19 log

上级 340e8c95
......@@ -13,6 +13,7 @@
android:name="com.blankj.launcher.pkg.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="user"
android:theme="@style/MainActivityTheme"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -6,6 +6,7 @@
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="user"
android:theme="@style/MainActivityTheme"
android:windowSoftInputMode="stateHidden" />
</application>
......
......@@ -13,7 +13,7 @@ dependencies {
api dep.constraint
api dep.kotlin
api dep.free_proguard
api 'com.r0adkll:slidableactivity:2.0.5'
api 'com.r0adkll:slidableactivity:2.0.6'
compileOnly dep.leakcanary.android_no_op
// api 'com.blankj:utilcode:1.23.7'
}
\ No newline at end of file
package com.blankj.lib.base.slideBack;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.FrameLayout;
import android.widget.Scroller;
import com.blankj.utilcode.util.LogUtils;
/**
* <pre>
* author: blankj
* blog : http://blankj.com
* time : 2019/03/20
* desc :
* </pre>
*/
public class SlideBackLayout extends FrameLayout {
private View mParentView;
private int mEdgeSlop;
private int mTouchSlop;
private boolean isConsumeDown;
private float mDownX;
private float mDownY;
private float mTempX;
private Scroller mScroller;
private boolean isFinish = false;
private boolean isSliding = false;
private int mViewWidth;
private SlideListener mListener = new SlideListener() {
@Override
public void onStart() {
LogUtils.e("start: ");
}
@Override
public void onChange(float x) {
LogUtils.e("onChange: " + x);
}
@Override
public void onFinish() {
LogUtils.e("onFinish: ");
}
};
private VelocityTracker mVelocityTracker;
public SlideBackLayout(@NonNull Context context) {
this(context, null);
}
public SlideBackLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mEdgeSlop = ViewConfiguration.get(context).getScaledEdgeSlop();
mScroller = new Scroller(context);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (changed) {
mParentView = (View) getParent();
mViewWidth = getWidth();
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
if (super.dispatchTouchEvent(event)) {
isConsumeDown = true;
} else {
mDownX = mTempX = event.getRawX();
mDownY = event.getRawY();
}
isSliding = false;
return true;
case MotionEvent.ACTION_MOVE:
if (!isConsumeDown) {
LogUtils.e();
if (isSliding) break;
if (event.getRawX() - mDownX > mTouchSlop) {
isSliding = true;
if (mListener != null) {
mListener.onStart();
}
return true;
}
}
break;
default:
break;
}
return super.dispatchTouchEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
LogUtils.e(event);
if (isConsumeDown || !isSliding) return super.onTouchEvent(event);
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(event);
final int action = MotionEventCompat.getActionMasked(event);
switch (action) {
case MotionEvent.ACTION_MOVE:
int moveX = (int) event.getRawX();
if (moveX > mDownX) {
mParentView.scrollBy((int) (mTempX - moveX), 0);
} else if (moveX < mDownX) {
//解决连续滑动Activity无法闭合的问题
mParentView.scrollTo(0, 0);
}
if (mListener != null) {
mListener.onChange(mTempX - moveX);
}
mTempX = moveX;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
startScroll();
break;
}
return true;
}
private void startScroll() {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity());
int xVelocity = (int) velocityTracker.getXVelocity();
LogUtils.e(xVelocity);
if (mParentView.getScrollX() <= -mViewWidth / 2) {
isFinish = true;
scrollToRight();
} else {
isFinish = false;
scrollToOrigin();
}
if (mListener != null) {
mListener.onFinish();
}
}
@Override
public void computeScroll() {
if (mScroller.computeScrollOffset()) {
mParentView.scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
postInvalidate();
if (mScroller.isFinished() && isFinish && mListener != null) {
mListener.onFinish();
}
}
}
private void scrollToOrigin() {
final int delta = mParentView.getScrollX();
mScroller.startScroll(mParentView.getScrollX(), 0, -delta, 0, Math.abs(delta));
postInvalidate();
}
private void scrollToRight() {
final int delta = mViewWidth + mParentView.getScrollX();
mScroller.startScroll(mParentView.getScrollX(), 0, -delta + 1, 0, Math.abs(delta));
postInvalidate();
}
public interface SlideListener {
void onStart();
void onChange(float x);
void onFinish();
}
}
......@@ -13,6 +13,10 @@
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="MainActivityTheme" parent="AppTheme">
<item name="android:windowIsTranslucent">false</item>
</style>
<style name="TextStyle">
<item name="android:textSize">@dimen/font_16</item>
<item name="android:textColor">@drawable/base_sel_button_txt_color</item>
......
......@@ -13,6 +13,7 @@
android:name="com.blankj.subutil.pkg.feature.SubUtilActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="user"
android:theme="@style/MainActivityTheme"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -712,6 +712,8 @@ getRomInfo : 获取 ROM 信息
```
getScreenWidth : 获取屏幕的宽度(单位:px)
getScreenHeight : 获取屏幕的高度(单位:px)
getAppScreenWidth : 获取应用屏幕的宽度(单位:px)
getAppScreenHeight : 获取应用屏幕的高度(单位:px)
getScreenDensity : 获取屏幕密度
getScreenDensityDpi: 获取屏幕密度 DPI
setFullScreen : 设置屏幕为全屏
......
......@@ -4,5 +4,5 @@ apply {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(':utilcode-pkg')
implementation project(':utilcode-pkg')
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
android:name="com.blankj.utilcode.pkg.feature.CoreUtilActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="user"
android:theme="@style/MainActivityTheme"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
package com.blankj.utilcode.util;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Application;
import android.app.Application.ActivityLifecycleCallbacks;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.FileProvider;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
......@@ -168,6 +171,26 @@ public final class Utils {
return task;
}
private static void setAnimatorsEnabled() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && ValueAnimator.areAnimatorsEnabled()) {
return;
}
try {
//noinspection JavaReflectionMemberAccess
Field sDurationScaleField = ValueAnimator.class.getDeclaredField("sDurationScale");
sDurationScaleField.setAccessible(true);
float sDurationScale = (Float) sDurationScaleField.get(null);
if (sDurationScale == 0f) {
sDurationScaleField.set(null, 1f);
Log.i("Utils", "setAnimatorsEnabled: Animators are enabled now!");
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
static class ActivityLifecycleImpl implements ActivityLifecycleCallbacks {
final LinkedList<Activity> mActivityList = new LinkedList<>();
......@@ -180,6 +203,7 @@ public final class Utils {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
setAnimatorsEnabled();
setTopActivity(activity);
}
......
......@@ -54,6 +54,10 @@ class CoreUtilActivity : BaseTitleActivity() {
}
}
override fun isSwipeBack(): Boolean {
return false
}
override fun bindTitle(): CharSequence {
return getString(R.string.core_util)
}
......
......@@ -80,13 +80,16 @@ object DialogHelper {
val window = dialog.window
window.requestFeature(Window.FEATURE_NO_TITLE)
dialog.setOnShowListener { KeyboardUtils.fixAndroidBug5497(window) }
dialog.show()
window.setBackgroundDrawable(ColorDrawable(0))
val attributes = dialog.window.attributes
attributes.gravity = Gravity.BOTTOM
attributes.width = ScreenUtils.getAppScreenWidth()
attributes.height = ScreenUtils.getAppScreenHeight() //* 2 / 5
attributes.height = ScreenUtils.getAppScreenHeight() * 2 / 5
attributes.windowAnimations = R.style.BottomDialogAnimation
dialog.window.attributes = attributes
}
......
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromYDelta="100%"
android:toYDelta="0" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromYDelta="0"
android:toYDelta="100%" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.blankj.lib.base.slideBack.SlideBackLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/spacing_16"
android:paddingRight="@dimen/spacing_16">
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="activityClick"
android:text="@string/demo_activity" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="adaptScreenClick"
android:text="@string/demo_adapt_screen" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="appClick"
android:text="@string/demo_app" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="barClick"
android:text="@string/demo_bar" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="brightnessClick"
android:text="@string/demo_brightness" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="busClick"
android:text="@string/demo_bus" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="cleanClick"
android:text="@string/demo_clean" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="crashClick"
android:text="@string/demo_crash" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="deviceClick"
android:text="@string/demo_device" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="flashlightClick"
android:text="@string/demo_flashlight" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="fragmentClick"
android:text="@string/demo_fragment" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="imageClick"
android:text="@string/demo_image" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="keyboardClick"
android:text="@string/demo_keyboard" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logClick"
android:text="@string/demo_log" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="metaDataClick"
android:text="@string/demo_meta_data" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="networkClick"
android:text="@string/demo_network" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="pathClick"
android:text="@string/demo_path" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="permissionClick"
android:text="@string/demo_permission" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="phoneClick"
android:text="@string/demo_phone" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="processClick"
android:text="@string/demo_process" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="reflectClick"
android:text="@string/demo_reflect" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="resourceClick"
android:text="@string/demo_resource" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="romClick"
android:text="@string/demo_rom" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="screenClick"
android:text="@string/demo_screen" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sdcardClick"
android:text="@string/demo_sdcard" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="snackbarClick"
android:text="@string/demo_snackbar" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="spStaticClick"
android:text="@string/demo_spStatic" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="spannableClick"
android:text="@string/demo_span" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toastClick"
android:text="@string/demo_toast" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="vibrateClick"
android:text="@string/demo_vibrate" />
</LinearLayout>
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/spacing_16"
android:paddingRight="@dimen/spacing_16">
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="activityClick"
android:text="@string/demo_activity" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="adaptScreenClick"
android:text="@string/demo_adapt_screen" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="appClick"
android:text="@string/demo_app" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="barClick"
android:text="@string/demo_bar" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="brightnessClick"
android:text="@string/demo_brightness" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="busClick"
android:text="@string/demo_bus" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="cleanClick"
android:text="@string/demo_clean" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="crashClick"
android:text="@string/demo_crash" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="deviceClick"
android:text="@string/demo_device" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="flashlightClick"
android:text="@string/demo_flashlight" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="fragmentClick"
android:text="@string/demo_fragment" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="imageClick"
android:text="@string/demo_image" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="keyboardClick"
android:text="@string/demo_keyboard" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logClick"
android:text="@string/demo_log" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="metaDataClick"
android:text="@string/demo_meta_data" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="networkClick"
android:text="@string/demo_network" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="pathClick"
android:text="@string/demo_path" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="permissionClick"
android:text="@string/demo_permission" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="phoneClick"
android:text="@string/demo_phone" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="processClick"
android:text="@string/demo_process" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="reflectClick"
android:text="@string/demo_reflect" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="resourceClick"
android:text="@string/demo_resource" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="romClick"
android:text="@string/demo_rom" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="screenClick"
android:text="@string/demo_screen" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sdcardClick"
android:text="@string/demo_sdcard" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="snackbarClick"
android:text="@string/demo_snackbar" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="spStaticClick"
android:text="@string/demo_spStatic" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="spannableClick"
android:text="@string/demo_span" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toastClick"
android:text="@string/demo_toast" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="vibrateClick"
android:text="@string/demo_vibrate" />
</LinearLayout>
</com.blankj.lib.base.slideBack.SlideBackLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="BottomDialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_in_bottom_200</item>
<item name="android:windowExitAnimation">@anim/slide_out_bottom_200</item>
</style>
</resources>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册