Skip to content

Commit

Permalink
showLauncher
Browse files Browse the repository at this point in the history
toggle alarmclock launcher enabled / disabled with an option (#305)
  • Loading branch information
forrestguice committed Apr 1, 2019
1 parent a861184 commit bcde831
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -53,7 +52,6 @@
import android.widget.Toast;

import com.forrestguice.suntimeswidget.alarmclock.AlarmSettings;
import com.forrestguice.suntimeswidget.alarmclock.ui.AlarmClockActivity;
import com.forrestguice.suntimeswidget.calculator.core.SuntimesCalculator;

import com.forrestguice.suntimeswidget.calculator.SuntimesCalculatorDescriptor;
Expand Down Expand Up @@ -1396,6 +1394,28 @@ private static void initPref_alarms(final PreferenceFragment fragment)
removePrefFromCategory(batteryOptimization, alarmsCategory); // battery optimization is api 23+
}
}

Preference showLauncher = fragment.findPreference(AlarmSettings.PREF_KEY_ALARM_SHOWLAUNCHER);
if (showLauncher != null)
{
showLauncher.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
if (context != null)
{
ComponentName componentName = new ComponentName(context, "com.forrestguice.suntimeswidget.alarmclock.ui.AlarmClockActivityLauncher");
int state = (Boolean)newValue ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
PackageManager packageManager = context.getPackageManager();
packageManager.setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP);
Toast.makeText(context, context.getString(R.string.reboot_required_message), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});
}
}

private static void removePrefFromCategory(Preference pref, PreferenceCategory category)
Expand Down

0 comments on commit bcde831

Please sign in to comment.