Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

Commit

Permalink
boot/call actions are exclusive, don't allow setting both via UI
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rken committed May 14, 2017
1 parent 52edb85 commit 43e5d3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
38 changes: 19 additions & 19 deletions app/src/main/java/eu/thedarken/wl/dialogs/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

import eu.thedarken.wl.R;
Expand All @@ -29,11 +29,15 @@ public Options(Context context) {
settings = PreferenceManager.getDefaultSharedPreferences(getContext());
prefEditor = settings.edit();

CheckBox cbNotification = (CheckBox) findViewById(R.id.notification);
cbNotification.setOnClickListener(new android.view.View.OnClickListener() {
final CheckBox cbNotification = (CheckBox) findViewById(R.id.notification);
final CheckBox cbOnboot = (CheckBox) findViewById(R.id.autostart);
final CheckBox cbOnCall = (CheckBox) findViewById(R.id.oncall);

cbNotification.setChecked(settings.getBoolean("notifaction.enabled", true));
cbNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked) {
prefEditor.putBoolean("notifaction.enabled", true);
prefEditor.commit();
Toast.makeText(getContext(), "Notification enabled", Toast.LENGTH_SHORT).show();
Expand All @@ -44,43 +48,39 @@ public void onClick(View v) {
}
}
});
cbNotification.setChecked(settings.getBoolean("notifaction.enabled", true));

final PackageManager packageManager = getContext().getPackageManager();

final ComponentName autostart = new ComponentName(getContext(), ReceiverAutostart.class);
CheckBox cbOnboot = (CheckBox) findViewById(R.id.autostart);
cbOnboot.setOnClickListener(new android.view.View.OnClickListener() {
cbOnboot.setChecked((packageManager.getComponentEnabledSetting(autostart) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED));
cbOnboot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onClick(View v) {

if (((CheckBox) v).isChecked()) {
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked) {
packageManager.setComponentEnabledSetting(autostart, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(getContext(), "Autostart enabled", Toast.LENGTH_SHORT).show();
if (cbOnCall.isChecked()) cbOnCall.setChecked(false);
} else {
packageManager.setComponentEnabledSetting(autostart, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(getContext(), "Autostart disabled", Toast.LENGTH_SHORT).show();
}
}
});
cbOnboot.setChecked((packageManager.getComponentEnabledSetting(autostart) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED));

final ComponentName oncall = new ComponentName(getContext(), ReceiverCall.class);
CheckBox cbOnCall = (CheckBox) findViewById(R.id.oncall);
cbOnCall.setOnClickListener(new android.view.View.OnClickListener() {
cbOnCall.setChecked((packageManager.getComponentEnabledSetting(oncall) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED));
cbOnCall.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onClick(View v) {

if (((CheckBox) v).isChecked()) {
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked) {
packageManager.setComponentEnabledSetting(oncall, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(getContext(), "OnCallLocking enabled", Toast.LENGTH_SHORT).show();
if (cbOnboot.isChecked()) cbOnboot.setChecked(false);
} else {
packageManager.setComponentEnabledSetting(oncall, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(getContext(), "OnCallLocking disabled", Toast.LENGTH_SHORT).show();
}
}
});
cbOnCall.setChecked((packageManager.getComponentEnabledSetting(oncall) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED));
}

}
2 changes: 2 additions & 0 deletions app/src/main/res/layout/dialog_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:id="@+id/notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/option_notification_title"/>

<TextView
Expand All @@ -27,6 +28,7 @@
android:id="@+id/oncall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/option_call_title"/>

<TextView
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<string name="option_notification_title">Notification</string>
<string name="option_notification_desc">Without notification, the system might kill the service holding the wakelock to free resources.</string>
<string name="option_call_title">Acquire/release lock before/after call</string>
<string name="option_call_desc">User request for screen issues during calls on GT-I9100 devices. The lock will be acquired when the device starts ringing and is released when the call ends.</string>
<string name="option_call_desc">The lock will be acquired when the device starts ringing and is released when the call ends.</string>
<string name="buy_donation_version">Buy donation version</string>
<string name="locktype_none">None</string>
<string name="about_text"><![CDATA[This app allows you to acquire wakelocks from Androids PowerManager.\n\nIt is free of charge and without ads. If this app helped you, consider buying the \'Donate Version\' on Google Play.\n\nReach me under [email protected]]]></string>
Expand Down

0 comments on commit 43e5d3e

Please sign in to comment.