[Android General] DJABHipHop:
Need help Updating SharedPreferences on the rootless pixel launcher nougat version I don't know what i'm doing wrong.

SharedPrefrencesHelper.java

package com.android.launcher3;

import android.content.SharedPreferences;
import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

public final class SharedPrefrencesHelper {

/**
* ------------------------------------------------------------
* Shared Preferences Put & Get Type for my two cystom function
* readPrefvalue
* updatePrefvalue
* Preferences value Type
* 1 = Boolean, Boolean value 1 = true & No value / Blank / Any other number then 1 = false
* 2 = Int
* 3 = Float
* 4 = Long
* No value / Blank = String
* -------------------------------------------------------------
*/

// Shared Preferences vaveable
private SharedPreferences sharedPreferences;
private static final String PREF_NAME = "com.android.launcher3.device.prefs";
private static Context context;

private static SharedPreferences getPrefs(Context context) {
return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
}

// Updating Shared Preference value
// Updating Boolean
public static final void updateBoolean(String key, boolean value) {
// Shared Preference Boolean
SharedPreferences.Editor editor = getPrefs(context).edit();
editor.putBoolean(key, value);
editor.apply();
}
// Updating Int
public static final void updateInt(String key, int value) {
// Shared Preference Int
SharedPreferences.Editor editor = getPrefs(context).edit();
editor.putInt(key, value);
editor.apply();
}
// Updating Float
public static final void updateFloat(String key, float value) {
// Shared Preference Float
SharedPreferences.Editor editor = getPrefs(context).edit();
editor.putFloat(key, value);
editor.apply();
}
// Updating Long
public static final void updateLong(String key, long value) {
// Shared Preference Long
SharedPreferences.Editor editor = getPrefs(context).edit();
editor.putLong(key, value);
editor.apply();
}
// Updating String
public static final void updateString(String key, String value) {
// Shared Preference String
SharedPreferences.Editor editor = getPrefs(context).edit();
editor.putString(key, value);
editor.apply();
}

// Reading Shared Preference value
// Read Boolean
public static final boolean readBoolean(String key, boolean value) {
// Shared Preference Boolean
return getPrefs(context).getBoolean(key, value);
}
// Read Int
public static final int readInt(String key, int value) {
// Shared Preference Int
return getPrefs(context).getInt(key, value);
}
// Read Float
public static final float readFloat(String key, float value) {
// Shared Preference Float
return getPrefs(context).getFloat(key, value);
}
// Read Long
public static final long readLong(String key, long value) {
// Shared Preference Long
return getPrefs(context).getLong(key, value);
}
// Read String
public static final String readString(String key, String value) {
// Shared Preference String
return getPrefs(context).getString(key, value);
}
}

SettingsActivity.java

/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.launcher3;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.preference.PreferenceFragment;
import android.preference.SwitchPreference;
import android.preference.TwoStatePreference;
import android.preference.ListPreference;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.provider.Settings;
import android.provider.Settings.System;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.widget.Toast;

import com.android.launcher3.Utilities;
import com.android.launcher3.SharedPrefrencesHelper;

/**
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
*/
public class SettingsActivity extends Activity {
public static Launcher mLauncher;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new LauncherSettingsFragment())
.commit();
}

/**
* This fragment shows the launcher preferences.
*/
public static class LauncherSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener {

private SystemDisplayRotationLockObserver mRotationLockObserver;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
addPreferencesFromResource(R.xml.launcher_preferences);

// Setup allow rotation preference
Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
if (getResources().getBoolean(R.bool.allow_rotation)) {
// Launcher supports rotation by default. No need to show this setting.
getPreferenceScreen().removePreference(rotationPref);
} else {
ContentResolver resolver = getActivity().getContentResolver();
mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver);

// Register a content observer to listen for system setting changes while
// this UI is active.
resolver.registerContentObserver(
Settings.System.getUriFor(System.ACCELEROMETER_ROTATION),
false, mRotationLockObserver);

// Initialize the UI once
mRotationLockObserver.onChange(true);
rotationPref.setDefaultValue(Utilities.getAllowRotationDefaultValue(getActivity()));
}

/**
* Warning: Dont Remove this is unless you know how to remove app Predictions with out losing home overview setting button,
* Removing this can cause a bug to appre & frankly I find this options rather annoying.
* Disable PredictionsBug to avoid a huge bugs
*/
Preference predictionsPref = findPreference(Utilities.SHOW_PREDICTIONS_PREF);
// predictionsPref.setOnPreferenceChangeListener(this);
predictionsPref.setEnabled(false);
getPreferenceScreen().removePreference(predictionsPref);

// Custom Mods
// Todo: Add Ability Hide Google Search like in the LineageOS Default Launcher(Trebuchet)
Preference minusOnePref = findPreference(Utilities.ENABLE_MINUS_ONE_PREF);
minusOnePref.setEnabled(false);

// Todo: Add Theme Support
Preference themeOveridePref = findPreference(Utilities.THEME_OVERRIDE_KEY);
themeOveridePref.setEnabled(false);

// Todo: Add Ability Hide App Search In App Drawer like in the LineageOS Default Launcher(Trebuchet)
Preference appSearchPref = (SwitchPreference) findPreference(Utilities.SHOW_APP_SEARCH);

appSearchPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
/*if (SharedPrefrencesHelper.readBoolean(Utilities.SHOW_APP_SEARCH, true)) {*/
// Toast.makeText(getContext(), "App Search Enabled", Toast.LENGTH_LONG).show();
// SharedPrefrencesHelper.updateBoolean(Utilities.SHOW_APP_SEARCH, true);
// return true;
//} else {
Toast.makeText(getContext(), "App Search Disabled", Toast.LENGTH_LONG).show();
SharedPrefrencesHelper.updateBoolean(Utilities.SHOW_APP_SEARCH, true);
//}
return false;
}
});

}

@Override
public void onResume() {
super.onResume();
// Set up a listener whenever a key changes
/*	getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);*/
}

@Override
public void onPause() {
super.onPause();
// Unregister the listener whenever a key changes
/*	getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
*/	}

@Override
public boolean onPreferenceChange(Preference preference, Object o) {
return false;
}

@Override
public void onDestroy() {
if (mRotationLockObserver != null) {
getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver);
mRotationLockObserver = null;
}
super.onDestroy();
}
}

/**
* Content observer which listens for system auto-rotate setting changes, and enables/disables
* the launcher rotation setting accordingly.
*/
private static class SystemDisplayRotationLockObserver extends ContentObserver {

private final Preference mRotationPref;
private final ContentResolver mResolver;

public SystemDisplayRotationLockObserver(
Preference rotationPref, ContentResolver resolver) {
super(new Handler());
mRotationPref = rotationPref;
mResolver = resolver;
}

@Override
public void onChange(boolean selfChange) {
boolean enabled = Settings.System.getInt(mResolver,
Settings.System.ACCELEROMETER_ROTATION, 1) == 1;
mRotationPref.setEnabled(enabled);
mRotationPref.setSummary(enabled
? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc);
}
}
}

Thanks in Advance