mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 17:07:43 +00:00
Add FAB menu
This commit is contained in:
parent
1c7de1d668
commit
856eb479e4
113
app/src/main/java/com/topjohnwu/magisk/FABBehavior.java
Normal file
113
app/src/main/java/com/topjohnwu/magisk/FABBehavior.java
Normal file
@ -0,0 +1,113 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPropertyAnimatorCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.github.clans.fab.FloatingActionMenu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Matteo on 08/08/2015.
|
||||
*
|
||||
* Floating Action Menu Behavior for Clans.FloatingActionButton
|
||||
* https://github.com/Clans/FloatingActionButton/
|
||||
*
|
||||
* Use this behavior as your app:layout_behavior attribute in your Floating Action Menu to use the
|
||||
* FabMenu in a Coordinator Layout.
|
||||
*
|
||||
* Remember to use the correct namespace for the fab:
|
||||
* xmlns:fab="http://schemas.android.com/apk/res-auto"
|
||||
*/
|
||||
public class FABBehavior extends CoordinatorLayout.Behavior {
|
||||
private float mTranslationY;
|
||||
|
||||
public FABBehavior(Context context, AttributeSet attrs) {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
|
||||
return dependency instanceof Snackbar.SnackbarLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
|
||||
if (dependency instanceof Snackbar.SnackbarLayout) {
|
||||
updateTranslation(parent, child);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDependentViewRemoved(CoordinatorLayout parent, View child, View dependency) {
|
||||
if (dependency instanceof Snackbar.SnackbarLayout) {
|
||||
revertTranslation(child);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTranslation(CoordinatorLayout parent, View child) {
|
||||
float translationY = getTranslationY(parent, child);
|
||||
if (translationY != mTranslationY) {
|
||||
ViewPropertyAnimatorCompat anim = ViewCompat.animate(child);
|
||||
anim.cancel();
|
||||
anim.translationY(translationY).setDuration(100);
|
||||
mTranslationY = translationY;
|
||||
}
|
||||
}
|
||||
|
||||
private void revertTranslation(View child) {
|
||||
if (mTranslationY != 0) {
|
||||
ViewPropertyAnimatorCompat anim = ViewCompat.animate(child);
|
||||
anim.cancel();
|
||||
anim.translationY(0).setDuration(100);
|
||||
mTranslationY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private float getTranslationY(CoordinatorLayout parent, View child) {
|
||||
float minOffset = 0.0F;
|
||||
List dependencies = parent.getDependencies(child);
|
||||
int i = 0;
|
||||
|
||||
for (int z = dependencies.size(); i < z; ++i) {
|
||||
View view = (View) dependencies.get(i);
|
||||
if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(child, view)) {
|
||||
minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - (float) view.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
return minOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* onStartNestedScroll and onNestedScroll will hide/show the FabMenu when a scroll is detected.
|
||||
*/
|
||||
@Override
|
||||
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child,
|
||||
View directTargetChild, View target, int nestedScrollAxes) {
|
||||
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL ||
|
||||
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target,
|
||||
nestedScrollAxes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target,
|
||||
int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
|
||||
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
|
||||
dyUnconsumed);
|
||||
FloatingActionMenu fabMenu = (FloatingActionMenu) child;
|
||||
if (dyConsumed > 0 && !fabMenu.isMenuButtonHidden()) {
|
||||
fabMenu.hideMenuButton(true);
|
||||
} else if (dyConsumed < 0 && fabMenu.isMenuButtonHidden()) {
|
||||
fabMenu.showMenuButton(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
@ -15,6 +14,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.clans.fab.FloatingActionButton;
|
||||
import com.ipaulpro.afilechooser.utils.FileUtils;
|
||||
import com.topjohnwu.magisk.adapters.ModulesAdapter;
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
|
9
app/src/main/res/drawable/ic_archive.xml
Normal file
9
app/src/main/res/drawable/ic_archive.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20.54,5.23l-1.39,-1.68C18.88,3.21 18.47,3 18,3H6c-0.47,0 -0.88,0.21 -1.16,0.55L3.46,5.23C3.17,5.57 3,6.02 3,6.5V19c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V6.5c0,-0.48 -0.17,-0.93 -0.46,-1.27zM12,17.5L6.5,12H10v-2h4v2h3.5L12,17.5zM5.12,5l0.81,-1h12l0.94,1H5.12z"/>
|
||||
</vector>
|
@ -2,6 +2,7 @@
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:fab="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/swipeRefreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
@ -12,6 +13,7 @@
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/coordinator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
@ -37,18 +39,40 @@
|
||||
android:textStyle="italic"
|
||||
android:visibility="gone" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_margin="16dp"
|
||||
android:baselineAlignBottom="false"
|
||||
android:clickable="true"
|
||||
android:src="@drawable/ic_add"
|
||||
android:layout_gravity="bottom|center_horizontal" />
|
||||
|
||||
<com.github.clans.fab.FloatingActionMenu
|
||||
android:id="@+id/fabmenu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:layout_marginRight="120dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
app:layout_behavior=".FABBehavior"
|
||||
fab:menu_fab_size="normal"
|
||||
fab:menu_showShadow="true"
|
||||
fab:menu_shadowColor="#66000000"
|
||||
fab:menu_shadowRadius="4dp"
|
||||
fab:menu_shadowXOffset="1dp"
|
||||
fab:menu_shadowYOffset="3dp"
|
||||
fab:menu_colorNormal="#cddc39"
|
||||
fab:menu_colorPressed="#9e9d24"
|
||||
fab:menu_colorRipple="#99FFFFFF"
|
||||
fab:menu_animationDelayPerItem="50"
|
||||
fab:menu_icon="@drawable/ic_add"
|
||||
fab:menu_buttonSpacing="0dp"
|
||||
fab:menu_labels_position="left" >
|
||||
|
||||
<com.github.clans.fab.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:src="@drawable/ic_archive"
|
||||
fab:fab_size="mini"
|
||||
fab:fab_label="@string/fab_flash_zip" />
|
||||
|
||||
</com.github.clans.fab.FloatingActionMenu>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<group android:checkableBehavior="single">
|
||||
<group
|
||||
android:checkableBehavior="single"
|
||||
android:id="@+id/main_group">
|
||||
|
||||
<item
|
||||
android:id="@+id/magisk"
|
||||
android:icon="@drawable/magisk"
|
||||
android:title="@string/magisk"/>
|
||||
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/modules"
|
||||
android:icon="@drawable/ic_extension"
|
||||
@ -30,7 +30,9 @@
|
||||
android:title="@string/log"/>
|
||||
</group>
|
||||
|
||||
<group android:checkableBehavior="none">
|
||||
<group
|
||||
android:checkableBehavior="none"
|
||||
android:id="@+id/second_group">
|
||||
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="disable_file_created">Module will be disabled at next reboot</string>
|
||||
<string name="disable_file_removed">Module will be enabled at next reboot</string>
|
||||
<string name="author">Created by %1$s</string>
|
||||
<string name="fab_flash_zip">Flash Module Zip</string>
|
||||
|
||||
<!--Repo Fragment-->
|
||||
<string name="update_available">Update Available</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user