Skip to content

Commit

Permalink
Added support for acc -f command
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteCarra committed Mar 3, 2019
1 parent 11ba730 commit a317bf5
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "mattecarra.accapp"
minSdkVersion 16
targetSdkVersion 28
versionCode 4
versionName "1.0.0"
versionCode 5
versionName "1.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":4,"versionName":"1.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":5,"versionName":"1.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
18 changes: 18 additions & 0 deletions app/src/main/java/mattecarra/accapp/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,24 @@ class MainActivity : AppCompatActivity() {
}
}

edit_charging_limit_once_bt.setOnClickListener {
val dialog = MaterialDialog(this).show {
title(R.string.edit_charging_limit_once)
message(R.string.edit_charging_limit_once_dialog_msg)
customView(R.layout.edit_charging_limit_once_dialog)
positiveButton(R.string.apply) {
AccUtils.setChargingLimitForOneCharge(getCustomView().findViewById<NumberPicker>(R.id.charging_limit).value)
Toast.makeText(this@MainActivity, R.string.done, Toast.LENGTH_LONG).show()
}
negativeButton(android.R.string.cancel)
}

val picker = dialog.getCustomView().findViewById<NumberPicker>(R.id.charging_limit)
picker.maxValue = 100
picker.minValue = config.capacity.pauseCapacity
picker.value = 100
}

reset_stats_on_unplugged_switch.setOnCheckedChangeListener { _, isChecked ->
config.resetUnplugged = isChecked
AccUtils.updateResetUnplugged(isChecked)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/mattecarra/accapp/utils/AccUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ object AccUtils {
return Shell.su("acc -s s-").exec().isSuccess
}

fun setChargingLimitForOneCharge(limit: Int): Boolean {
return Shell.su("acc -f $limit").exec().isSuccess
}

fun isAccInstalled(): Boolean {
return Shell.su("which acc 1>/dev/null").exec().isSuccess
}
Expand Down
53 changes: 36 additions & 17 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
android:textSize="16sp"/>
</LinearLayout>


<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
Expand All @@ -124,22 +123,43 @@
android:textSize="16sp"/>
</LinearLayout>


<Button
android:id="@+id/edit_config"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
<!-- Buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/edit_config"
android:layout_gravity="center_horizontal"/>
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="8dp">
<Button
android:id="@+id/edit_config"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="@string/edit_config"/>

<Button
android:id="@+id/edit_charging_switch"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/edit_charging_switch"/>
</LinearLayout>

<Button style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit_charging_limit_once"
android:id="@+id/edit_charging_limit_once_bt"/>
</LinearLayout>



<Button
android:id="@+id/edit_charging_switch"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit_charging_switch"
android:layout_gravity="center_horizontal"/>

</LinearLayout>
</androidx.cardview.widget.CardView>
Expand Down Expand Up @@ -272,14 +292,13 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Switch
android:id="@+id/reset_stats_on_unplugged_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/reset_unplugged"
android:textSize="16sp"
android:layout_marginBottom="10dp" />
android:layout_marginBottom="10dp"/>

<Button style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/layout/edit_charging_limit_once_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<NumberPicker
android:id="@+id/charging_limit"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="3dp"
android:layout_marginLeft="3dp" />

</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<string name="installation_failed">Something went wrong while installing acc. Please ensure that you have a working internet connection. If you continue to see this message please contact us on XDA.</string>
<string name="installation_failed_title">Installation failed</string>
<string name="retry">Retry</string>
<string name="edit_charging_limit_once">Edit limit for one charge</string>
<string name="apply">Apply</string>
<string name="done">Done</string>
<string name="edit_charging_limit_once_dialog_msg">Select the percentage to stop charging. This will only affect one cycle.
</string>

<string-array name="profile_long_press_options">
<item>Edit</item>
Expand Down

0 comments on commit a317bf5

Please sign in to comment.