Skip to content

Commit

Permalink
change FAB with FAM
Browse files Browse the repository at this point in the history
  • Loading branch information
hariimurti committed Apr 29, 2017
1 parent f56c55e commit cff457c
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ dependencies {
testCompile 'junit:junit:4.12'
compile files('libs/RootShell_v1.3.jar')
compile 'com.android.support:design:25.3.1'
compile 'com.github.clans:fab:1.6.4'
}
11 changes: 8 additions & 3 deletions app/src/main/java/net/harimurti/developers/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Intent;
import android.net.Uri;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
Expand All @@ -12,6 +11,8 @@
import android.widget.TextView;
import android.widget.Toast;

import com.github.clans.fab.FloatingActionMenu;
import com.github.clans.fab.FloatingActionButton;
import com.stericson.RootShell.RootShell;

import net.harimurti.developers.methods.ConfigManager;
Expand All @@ -22,6 +23,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private static final String KEEP_SCREEN_ON = "KEEP_SCREEN_ON";
private static final String LEVEL = "LEVEL";
private static final String FULL_STOP = "FULL_STOP";
private static FloatingActionMenu fabMenu;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -91,23 +93,26 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});

fabMenu = (FloatingActionMenu) findViewById(R.id.fabMenu);
fabMenu.setEnabled(isRooted);

FloatingActionButton fabStart = (FloatingActionButton) findViewById(R.id.fabStart);
fabStart.setOnClickListener(this);
fabStart.setEnabled(isRooted);

FloatingActionButton fabStop = (FloatingActionButton) findViewById(R.id.fabStop);
fabStop.setOnClickListener(this);
fabStop.setEnabled(isRooted);
}

public void onClick(View view) {
if (view.getId() == R.id.fabStart) {
PreService.Start(this);
fabMenu.close(true);
}
if (view.getId() == R.id.fabStop) {
if (!PreService.Stop(this)) {
Toast.makeText(this, R.string.toast_notstop, Toast.LENGTH_SHORT).show();
}
fabMenu.close(true);
}
if (view.getId() == R.id.author) {
Intent openWebsite = new Intent(Intent.ACTION_VIEW);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/anim/hide_to_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_quint"
android:fromYDelta="0"
android:toYDelta="30%p"
android:duration="200" />
12 changes: 12 additions & 0 deletions app/src/main/res/anim/jump_from_down.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/overshoot">
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="400" />
<translate
android:fromYDelta="30%p"
android:toYDelta="0"
android:duration="300" />
</set>
14 changes: 14 additions & 0 deletions app/src/main/res/anim/jump_to_down.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/anticipate_interpolator">
<alpha
android:fromAlpha="1"
android:toAlpha="0"
android:duration="200" />
<translate
android:fromYDelta="0"
android:toYDelta="30%p"
android:duration="200" />

</set>
10 changes: 10 additions & 0 deletions app/src/main/res/anim/scale_down.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/overshoot"
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="150" />
10 changes: 10 additions & 0 deletions app/src/main/res/anim/scale_up.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/overshoot"
android:fromXScale="0.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="200" />
6 changes: 6 additions & 0 deletions app/src/main/res/anim/show_from_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_cubic"
android:fromYDelta="30%p"
android:toYDelta="0"
android:duration="300" />
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/fab_label_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true">
<shape>
<solid android:color="#A6000000" />
<padding android:left="8dp" android:top="4dp" android:right="8dp" android:bottom="4dp" />
<corners android:radius="2dp" />
</shape>
</item>

<item>
<shape>
<solid android:color="#99000000" />
<padding android:left="8dp" android:top="4dp" android:right="8dp" android:bottom="4dp" />
<corners android:radius="2dp" />
</shape>
</item>

</selector>
42 changes: 27 additions & 15 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,38 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.FloatingActionButton
android:id="@+id/fabStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
app:srcCompat="@android:drawable/ic_menu_view" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fabStop"
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/fabMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
app:srcCompat="@android:drawable/ic_menu_close_clear_cancel"
tools:ignore="RelativeOverlap" />
app:menu_labels_style="@style/MenuLabelsStyle"
app:menu_labels_showAnimation="@anim/jump_from_down"
app:menu_labels_hideAnimation="@anim/jump_to_down"
app:menu_animationDelayPerItem="0"
app:menu_colorNormal="@color/colorPrimary"
app:menu_colorPressed="@color/colorPrimaryDark"
app:menu_colorRipple="@color/colorPrimary">

<com.github.clans.fab.FloatingActionButton
android:id="@+id/fabStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_view"
app:fab_label="@string/fab_start"
style="@style/MenuButtonsStyle" />

<com.github.clans.fab.FloatingActionButton
android:id="@+id/fabStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_close_clear_cancel"
app:fab_label="@string/fab_stop"
style="@style/MenuButtonsStyle" />

</com.github.clans.fab.FloatingActionMenu>

<LinearLayout
android:id="@+id/author"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<dimen name="margin_top_bottom">20dp</dimen>
<dimen name="margin_sub_label">10dp</dimen>
<dimen name="margin_seekbar">10dp</dimen>
<dimen name="margin_author">40dp</dimen>
<dimen name="label_width">80dp</dimen>
<dimen name="label_space">10dp</dimen>
<dimen name="fab_margin">30dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
<string name="label_titikdua">:</string>
<string name="my_name">Harimurti</string>
<string name="website">http://harimurti.net</string>
<string name="fab_start">Start Service</string>
<string name="fab_stop">Stop Service</string>
</resources>
17 changes: 17 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,21 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="MenuLabelsStyle">
<item name="android:background">@drawable/fab_label_background</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">14sp</item>
<item name="android:maxLines">2</item>
<item name="android:ellipsize">end</item>
</style>

<style name="MenuButtonsStyle">
<item name="fab_size">mini</item>
<item name="fab_showAnimation">@anim/jump_from_down</item>
<item name="fab_hideAnimation">@anim/jump_to_down</item>
<item name="fab_colorNormal">@color/colorPrimary</item>
<item name="fab_colorPressed">@color/colorPrimaryDark</item>
<item name="fab_colorRipple">@color/colorPrimary</item>
</style>

</resources>

0 comments on commit cff457c

Please sign in to comment.