Skip to content

Commit

Permalink
8.2
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Franco <[email protected]>
  • Loading branch information
franciscofranco committed May 21, 2020
1 parent 6c66d74 commit 4ff00c8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 63 deletions.
19 changes: 6 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
buildToolsVersion "29.0.3"
viewBinding.enabled = true

defaultConfig {
applicationId 'simple.reboot.com'
minSdkVersion 21
targetSdkVersion 29
versionCode 1803261729
versionName "8.1"
versionCode 1803261730
versionName "8.2"
}

compileOptions {
Expand All @@ -26,11 +27,9 @@ android {

signingConfigs {
debug {

}

release {

}
}

Expand All @@ -50,12 +49,6 @@ android {
}

dependencies {
implementation 'com.google.android.material:material:1.1.0-alpha08'
if (properties.containsKey('android.injected.invoked.from.ide')) {
implementation 'com.jakewharton:butterknife-reflect:10.1.0'
} else {
implementation 'com.jakewharton:butterknife-runtime:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
}
implementation 'com.github.topjohnwu.libsu:core:2.5.0'
implementation 'com.google.android.material:material:1.2.0-alpha06'
implementation 'com.github.topjohnwu.libsu:core:2.5.1'
}
89 changes: 45 additions & 44 deletions app/src/main/java/simple/reboot/com/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@
import android.animation.AnimatorListenerAdapter;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import com.google.android.material.snackbar.Snackbar;
import com.topjohnwu.superuser.Shell;

import butterknife.BindView;
import butterknife.OnClick;
import java.util.List;
import java.util.Locale;

import simple.reboot.com.databinding.ActivityMainBinding;


public class MainActivity extends AppCompatActivity {
@BindView(R.id.coordinator)
protected CoordinatorLayout coordinatorLayout;
@BindView(R.id.container)
protected ViewGroup container;
private ActivityMainBinding b;

// just for safe measure, we don't want any data corruption, right?
private static String[] SHUTDOWN_BROADCAST() {
Expand All @@ -46,50 +43,45 @@ private static String[] SHUTDOWN_BROADCAST() {
private static final String REBOOT_BOOTLOADER_CMD = "reboot bootloader";
private static final String[] REBOOT_SAFE_MODE
= new String[]{"setprop persist.sys.safemode 1", REBOOT_SOFT_REBOOT_CMD};
private static final String REBOOT_SYSTEMUI_CMD = "kill %d";
private static final String PKG_SYSTEMUI = "com.android.systemui";
private static final String PIDOF_SYSTEMUI = "pidof " + PKG_SYSTEMUI;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new MainActivity_ViewBinding(this);
b = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(b.getRoot());

Shell.getShell(shell -> {
if (!shell.isRoot()) {
if (coordinatorLayout != null) {
Snackbar.make(coordinatorLayout, R.string.root_status_no,
if (b != null) {
Snackbar.make(b.coordinator, R.string.root_status_no,
Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.close, view -> finishAnimation()).show();
}
}
});

container.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (container != null) {
container.getViewTreeObserver().removeOnGlobalLayoutListener(this);

container.setTranslationY(coordinatorLayout.getHeight() >> 2);
container.setTranslationX(container.getWidth());
container.animate().cancel();
container.animate().translationX(0f).setStartDelay(100)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
container.setVisibility(View.VISIBLE);
}
})
.start();
b.container.post(() -> {
b.container.setTranslationY(b.coordinator.getHeight() >> 2);
b.container.setTranslationX(b.container.getWidth());
b.container.animate().cancel();
b.container.animate().translationX(0f).setStartDelay(100)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
b.container.setVisibility(View.VISIBLE);
}
}
});
})
.start();
});
}

private void finishAnimation() {
if (container != null) {
container.animate().cancel();
container.animate().translationX(container.getWidth())
if (b != null) {
b.container.animate().cancel();
b.container.animate().translationX(b.container.getWidth())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
Expand All @@ -110,22 +102,18 @@ private void runCmdWithCallback(Shell.ResultCallback callback, @NonNull final St
Shell.su(cmd).submit(callback);
}

@OnClick(R.id.coordinator)
protected void onParentClick() {
public void onParentClick(View view) {
onBackPressed();
}

@OnClick(R.id.shutdown)
public void onShutdownClick(View view) {
runCmd(SHUTDOWN);
}

@OnClick(R.id.reboot)
public void onRebootClick(View view) {
runCmd(REBOOT_CMD);
}

@OnClick(R.id.soft_reboot)
public void onSoftRebootClick(View view) {
runCmdWithCallback(out -> {
if (out.isSuccess()) {
Expand All @@ -134,7 +122,6 @@ public void onSoftRebootClick(View view) {
}, SHUTDOWN_BROADCAST());
}

@OnClick(R.id.reboot_recovery)
public void onRebootRecoveryClick(View view) {
runCmdWithCallback(out -> {
if (out.isSuccess()) {
Expand All @@ -143,7 +130,6 @@ public void onRebootRecoveryClick(View view) {
}, SHUTDOWN_BROADCAST());
}

@OnClick(R.id.reboot_bootloader)
public void onRebootBootloaderClick(View view) {
runCmdWithCallback(out -> {
if (out.isSuccess()) {
Expand All @@ -152,7 +138,6 @@ public void onRebootBootloaderClick(View view) {
}, SHUTDOWN_BROADCAST());
}

@OnClick(R.id.reboot_safe_mode)
public void onRebootSafeModeClick(View view) {
runCmdWithCallback(out -> {
if (out.isSuccess()) {
Expand All @@ -161,6 +146,22 @@ public void onRebootSafeModeClick(View view) {
}, SHUTDOWN_BROADCAST());
}

public void onRebootSystemUi(View view) {
runCmdWithCallback(out -> {
if (out.isSuccess()) {
List<String> result = out.getOut();

if (result.size() == 1) {
// pidof returns only one line anyway, guard just for safe measures
String stdout = result.get(0).trim();
int pid = Integer.parseInt(stdout);

runCmd(String.format(Locale.getDefault(), REBOOT_SYSTEMUI_CMD, pid));
}
}
}, PIDOF_SYSTEMUI);
}

@Override
public void onBackPressed() {
finishAnimation();
Expand Down
19 changes: 16 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:onClick="onParentClick">

<androidx.cardview.widget.CardView
android:id="@+id/container"
Expand All @@ -25,35 +26,47 @@
<TextView
android:id="@+id/shutdown"
style="@style/TextViewItems"
android:drawablePadding="8dp"
android:drawableTop="@drawable/ic_power_off"
android:drawablePadding="8dp"
android:onClick="onShutdownClick"
android:text="@string/shutdown" />

<TextView
android:id="@+id/reboot"
style="@style/TextViewItems"
android:drawablePadding="8dp"
android:drawableTop="@drawable/ic_restart"
android:drawablePadding="8dp"
android:onClick="onRebootClick"
android:text="@string/reboot" />

<TextView
android:id="@+id/restart_systemui"
style="@style/TextViewItems"
android:onClick="onRebootSystemUi"
android:text="@string/restart_systemui" />

<TextView
android:id="@+id/soft_reboot"
style="@style/TextViewItems"
android:onClick="onSoftRebootClick"
android:text="@string/soft_reboot" />

<TextView
android:id="@+id/reboot_recovery"
style="@style/TextViewItems"
android:onClick="onRebootRecoveryClick"
android:text="@string/reboot_recovery" />

<TextView
android:id="@+id/reboot_bootloader"
style="@style/TextViewItems"
android:onClick="onRebootBootloaderClick"
android:text="@string/reboot_bootloader" />

<TextView
android:id="@+id/reboot_safe_mode"
style="@style/TextViewItems"
android:onClick="onRebootSafeModeClick"
android:text="@string/reboot_safe_mode" />
</LinearLayout>
</androidx.cardview.widget.CardView>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<string name="reboot_safe_mode">Restart to safe mode</string>
<string name="shutdown">Power off</string>
<string name="close">Close</string>
<string name="restart_systemui">Restart SystemUi</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.android.tools.build:gradle:3.6.3'
}
}

Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
org.gradle.daemon=true
android.enableBuildCache=true
org.gradle.parallel=true
android.enableR8=true
org.gradle.caching=true
android.useAndroidX=true
android.enableJetifier=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip

0 comments on commit 4ff00c8

Please sign in to comment.