Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -71,9 +69,6 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
private RxEvent rxEvent;
private Disposable disposable;




private void initTheme() {
switch(G.getSelectedTheme()) {
case "D":
Expand Down Expand Up @@ -113,11 +108,14 @@ protected void onCreate(Bundle savedInstanceState) {
// set language
Api.updateLanguage(getApplicationContext(), G.locale());
initTheme();

super.onCreate(savedInstanceState);

prepareLayout();
subscribe();
handleIntentExtras();
}

private void handleIntentExtras() {
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
Object data = bundle.get("validate");
Expand Down Expand Up @@ -179,6 +177,8 @@ private void prepareLayout() {

mToolBar = toolbarContainer.findViewById(R.id.toolbar);
mToolBar.setTitle(getTitle() + " " + getString(R.string.preferences));
mToolBar.setNavigationIcon(androidx.appcompat.content.res.AppCompatResources.getDrawable(this,
androidx.appcompat.R.drawable.abc_ic_ab_back_material));
mToolBar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -187,7 +187,6 @@ public void onClick(View v) {
});
}


@Override
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
theme.applyStyle(resid, true);
Expand Down Expand Up @@ -319,34 +318,43 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
rxEvent.publish(new RulesEvent("", ctx));
}

handleNotificationChanges(sharedPreferences, key, ctx);
handleLogServiceChanges(sharedPreferences, key, ctx);
handleProfileAndThemeChanges(key, ctx, isRefreshRequired);

/*if (key.equals("logDmesg")) {
rxEvent.publish(new LogChangeEvent("", ctx));
}*/
}

private void handleNotificationChanges(SharedPreferences prefs, String key, Context ctx) {
if (key.equals("notification_priority")) {
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
Api.updateNotification(Api.isEnabled(ctx), ctx);
}

if(key.equals("activeNotification")) {
boolean enabled = sharedPreferences.getBoolean(key, false);
if(!enabled) {
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
if (key.equals("activeNotification")) {
boolean enabled = prefs.getBoolean(key, false);
if (!enabled) {
NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancelAll();
} else {
Api.updateNotification(Api.isEnabled(ctx), ctx);
}
}
}

private void handleLogServiceChanges(SharedPreferences prefs, String key, Context ctx) {
if(key.equals("logTarget")) {
// Log target changes are now handled by LogPreferenceFragment
// This should not be called anymore due to the OnPreferenceChangeListener
Log.d("PreferencesActivity", "logTarget preference changed: " + sharedPreferences.getString(key, ""));
Log.d("PreferencesActivity", "logTarget preference changed: " + prefs.getString(key, ""));
}

if (key.equals("enableLogService")) {
if(G.logTarget() !=null && !G.logTarget().trim().isEmpty()) {
boolean enabled = sharedPreferences.getBoolean(key, false);
boolean enabled = prefs.getBoolean(key, false);
if (enabled) {
Toast.makeText(getApplicationContext(), getString(R.string.log_service_start), Toast.LENGTH_LONG).show();
Intent intent = new Intent(ctx, LogService.class);
Expand All @@ -361,9 +369,13 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
Toast.makeText(getApplicationContext(), getString(R.string.log_service_select), Toast.LENGTH_LONG).show();
}
}
}

private void handleProfileAndThemeChanges(String key, Context ctx, boolean isRefreshRequired) {
if (key.equals("enableMultiProfile")) {
G.reloadProfile();
}

if (key.equals("theme")) {
initTheme();
recreate();
Expand All @@ -379,7 +391,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
}


@Override
public void onDestroy() {
if (rxEvent != null && disposable != null) {
Expand All @@ -393,5 +404,4 @@ protected void attachBaseContext(Context base) {
super.attachBaseContext(Api.updateBaseContextLocale(base));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -460,55 +460,73 @@ public void onPause() {
super.onPause();
}

@Override
public void onDestroy() {
super.onDestroy();
globalContext = null;
enableAdminPref = null;
enableDeviceCheckPref = null;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (!isAdded()) return;
setupEnableAdmin(findPreference("enableAdmin"));
switch (requestCode) {

case REQ_CREATE_PATTERN: {
ListPreference itemList = (ListPreference) findPreference("passSetting");
if (resultCode == getActivity().RESULT_OK) {
char[] pattern = data.getCharArrayExtra(
EXTRA_PATTERN);
final SharedPreferences.Editor editor = G.sPrefs.edit();
editor.putString("LockPassword", new String(pattern));
editor.commit();
G.enableDeviceCheck(false);
//enable
if (itemList != null) {
final ListPreference patternMaxTry = (ListPreference) findPreference("patternMax");
final CheckBoxPreference stealthMode = (CheckBoxPreference) findPreference("stealthMode");
if (stealthMode != null) stealthMode.setEnabled(true);
if (patternMaxTry != null) patternMaxTry.setEnabled(true);
}

} else {
itemList = (ListPreference) findPreference("passSetting");
if (itemList != null) {
itemList.setValueIndex(0);
}
}
handleCreatePatternResult(resultCode, data);
break;
}

case REQ_ENTER_PATTERN: {
ListPreference itemList = (ListPreference) findPreference("passSetting");
if (resultCode == getActivity().RESULT_OK) {
final SharedPreferences.Editor editor = G.sPrefs.edit();
editor.putString("LockPassword", "");
editor.commit();
itemList = (ListPreference) findPreference("passSetting");
if (itemList != null) {
itemList.setValueIndex(0);
}
} else {
if (itemList != null) {
itemList.setValueIndex(2);
G.enableDeviceCheck(false);
}
}
handleEnterPatternResult(resultCode);
}
}
}

private void handleCreatePatternResult(int resultCode, Intent data) {
ListPreference itemList = (ListPreference) findPreference("passSetting");
if (resultCode == getActivity().RESULT_OK && data != null) {
char[] pattern = data.getCharArrayExtra(EXTRA_PATTERN);
if (pattern != null) {
savePattern(new String(pattern));
enablePatternFeatures();
}
} else {
resetPatternSelection(itemList);
}
}

private void handleEnterPatternResult(int resultCode) {
ListPreference itemList = (ListPreference) findPreference("passSetting");
if (resultCode == getActivity().RESULT_OK) {
G.sPrefs.edit().putString("LockPassword", "").apply();
if (itemList != null) {
itemList.setValueIndex(0);
}
} else {
if (itemList != null) {
itemList.setValueIndex(2);
G.enableDeviceCheck(false);
}
}
}

private void savePattern(String pattern) {
G.sPrefs.edit().putString("LockPassword", pattern).apply();
G.enableDeviceCheck(false);
}

private void enablePatternFeatures() {
final ListPreference patternMaxTry = (ListPreference) findPreference("patternMax");
final CheckBoxPreference stealthMode = (CheckBoxPreference) findPreference("stealthMode");
if (stealthMode != null) stealthMode.setEnabled(true);
if (patternMaxTry != null) patternMaxTry.setEnabled(true);
}

private void resetPatternSelection(ListPreference itemList) {
if (itemList != null) {
itemList.setValueIndex(0);
}
}
}