6.6.3 - Alpha2 - 文件管理器浮动按钮展开后点击其他区域可自动隐藏
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
],
|
||||
"improvement": [
|
||||
"关于应用与开发者页面增加水平布局及小屏布局适配",
|
||||
"文件管理器浮动按钮展开后点击其他区域可自动隐藏",
|
||||
"打包单文件时自动读取并勾选已安装应用的声明权限 _[`issue #362`](http://issues.autojs6.com/362)_",
|
||||
"已忽略更新记录及客户端模式连接地址记录支持清空操作",
|
||||
"版本更新信息支持多语言显示 (与当前显示语言同步)",
|
||||
|
||||
@@ -2,24 +2,24 @@ package org.autojs.autojs.ui.main;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import io.reactivex.subjects.PublishSubject;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
/**
|
||||
* Created by Stardust on Sep 24, 2017.
|
||||
@@ -42,9 +42,12 @@ public class FloatingActionMenu extends FrameLayout implements View.OnClickListe
|
||||
R.string.text_import,
|
||||
R.string.text_project};
|
||||
|
||||
private View mOverlay = null;
|
||||
|
||||
private FloatingActionButton[] mFabs;
|
||||
private View[] mFabContainers;
|
||||
private boolean mExpanded = false;
|
||||
private boolean mShouldCheckExpanded = true;
|
||||
private final int mInterval = 30;
|
||||
private final int mDuration = 250;
|
||||
private final Interpolator mInterpolator = new FastOutSlowInInterpolator();
|
||||
@@ -74,7 +77,12 @@ public class FloatingActionMenu extends FrameLayout implements View.OnClickListe
|
||||
return mExpanded;
|
||||
}
|
||||
|
||||
public boolean shouldCheckExpanded() {
|
||||
return mShouldCheckExpanded;
|
||||
}
|
||||
|
||||
public void expand() {
|
||||
showOverlay();
|
||||
setVisibility(VISIBLE);
|
||||
int h = mFabs[0].getHeight();
|
||||
for (int i = 0; i < mFabContainers.length; i++) {
|
||||
@@ -104,10 +112,12 @@ public class FloatingActionMenu extends FrameLayout implements View.OnClickListe
|
||||
}
|
||||
|
||||
public void collapse() {
|
||||
hideOverlay();
|
||||
animateY(mFabContainers[0], 0, new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
setVisibility(INVISIBLE);
|
||||
mShouldCheckExpanded = true;
|
||||
}
|
||||
});
|
||||
for (int i = 1; i < mFabContainers.length; i++) {
|
||||
@@ -157,7 +167,7 @@ public class FloatingActionMenu extends FrameLayout implements View.OnClickListe
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
collapse();
|
||||
// collapse();
|
||||
if (mOnFloatingActionButtonClickListener != null) {
|
||||
mOnFloatingActionButtonClickListener.onClick((FloatingActionButton) v, (int) v.getTag());
|
||||
}
|
||||
@@ -167,4 +177,39 @@ public class FloatingActionMenu extends FrameLayout implements View.OnClickListe
|
||||
mOnFloatingActionButtonClickListener = onFloatingActionButtonClickListener;
|
||||
}
|
||||
|
||||
private void showOverlay() {
|
||||
if (mOverlay != null && mOverlay.getVisibility() == VISIBLE) return;
|
||||
|
||||
Context context = getContext();
|
||||
|
||||
if (!(context instanceof Activity activity)) return;
|
||||
|
||||
if (!(activity.findViewById(android.R.id.content) instanceof ViewGroup root)) return;
|
||||
|
||||
mOverlay = new View(context) {
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
mShouldCheckExpanded = false;
|
||||
collapse();
|
||||
root.post(() -> root.removeView(this));
|
||||
var replay = MotionEvent.obtain(event);
|
||||
root.post(() -> activity.getWindow().getDecorView().dispatchTouchEvent(replay));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
mOverlay.setLayoutParams(params);
|
||||
mOverlay.setBackgroundColor(Color.TRANSPARENT);
|
||||
|
||||
root.addView(mOverlay);
|
||||
}
|
||||
|
||||
private void hideOverlay() {
|
||||
if (mOverlay == null) return;
|
||||
if (!(mOverlay.getParent() instanceof ViewGroup parent)) return;
|
||||
parent.removeView(mOverlay);
|
||||
mOverlay = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -106,7 +106,8 @@ class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickListen
|
||||
private fun viewFile(item: ExplorerItem) = IntentUtils.viewFile(GlobalAppContext.get(), item.path)
|
||||
|
||||
override fun onFabClick(fab: FloatingActionButton) {
|
||||
initFloatingActionMenuIfNeeded(fab).run { if (isExpanded) collapse() else expand() }
|
||||
// initFloatingActionMenuIfNeeded(fab).run { if (isExpanded) collapse() else expand() }
|
||||
initFloatingActionMenuIfNeeded(fab).run { if (shouldCheckExpanded() && !isExpanded) expand() }
|
||||
}
|
||||
|
||||
private fun initFloatingActionMenuIfNeeded(fab: FloatingActionButton): FloatingActionMenu {
|
||||
|
||||
Reference in New Issue
Block a user