Android Open Source - KendaliPintuAndroid Shared Preferences Manager






From Project

Back to project page KendaliPintuAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project KendaliPintuAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright (c) 2014 Dimas Rullyan Danu
 * //from w w  w .  j  a  v  a 2s.c  o  m
 * Kendali Pintu is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kendali Pintu is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kendali Pintu. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package com.dimasdanz.kendalipintu.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class SharedPreferencesManager {
  public static final String property_hostname = "hostname_prefs";
  public static final String property_receiveNotifications = "notifications_prefs";
  public static final String property_isLoggedIn = "logged_in_prefs";
  public static final String property_usernameId = "username_id_prefs";
  public static final String property_appVersion = "appVersion_prefs";
  public static final String property_regId = "registration_id_prefs";
  public static final String property_adminUsername = "admin_username_prefs";
  public static final String property_isAdmin = "is_admin_prefs";
  public static final String property_firstTime = "first_time_prefs";
  
  private SharedPreferencesManager() {}

    public static SharedPreferences getSharedPreferences(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context);
    }

    public static void setHostnamePrefs(Context context, String string) {
        final SharedPreferences.Editor editor = getSharedPreferences(context).edit();
        editor.putString(property_hostname, string);
        editor.commit();
    }
    
    public static String getHostnamePrefs(Context context) {
      return "http://"+getSharedPreferences(context).getString(property_hostname , "");
  }

  public static void setNotificationPrefs(Context context, Boolean b) {
        final SharedPreferences.Editor editor = getSharedPreferences(context).edit();
        editor.putBoolean(property_receiveNotifications, b);
        editor.commit();
    }

  public static Boolean getNotificationPrefs(Context context) {
      return getSharedPreferences(context).getBoolean(property_receiveNotifications, true);
  }
  
  public static void setLoggedIn(Context context, Boolean b, String s){
    final SharedPreferences.Editor editor = getSharedPreferences(context).edit();
    editor.putBoolean(property_isLoggedIn, b);
    editor.putString(property_usernameId, s);
    editor.commit();
  }
  
  public static Boolean getLoggedInPrefs(Context context){
    return getSharedPreferences(context).getBoolean(property_isLoggedIn, false);
  }
  
  public static String getUsernameIdPrefs(Context context){
    return getSharedPreferences(context).getString(property_usernameId, "");
  }
  
  public static void setRegId(Context context, String regId) {
    final SharedPreferences.Editor editor = getSharedPreferences(context).edit();
        int appVersion = CommonUtilities.getAppVersion(context);
        editor.putString(property_regId, regId);
        editor.putInt(property_appVersion, appVersion);
        editor.commit();
    }
  
  public static String getRegId(Context context) {
    final SharedPreferences prefs = getSharedPreferences(context);
        String registrationId = prefs.getString(property_regId, "");
        if (registrationId.isEmpty()) {
            return "";
        }
        int registeredVersion = prefs.getInt(property_appVersion, Integer.MIN_VALUE);
        int currentVersion = CommonUtilities.getAppVersion(context);
        if (registeredVersion != currentVersion) {
            return "";
        }
        return registrationId;
    }
  
  public static void setAsAdmin(Context context, Boolean b, String s){
    final SharedPreferences.Editor editor = getSharedPreferences(context).edit();
    editor.putBoolean(property_isAdmin, b);
    editor.putString(property_adminUsername, s);
    editor.commit();
  }
  
  public static Boolean getIsAdminPrefs(Context context){
    return getSharedPreferences(context).getBoolean(property_isAdmin, false);
  }
  
  public static String getAdminIdPrefs(Context context){
    return getSharedPreferences(context).getString(property_adminUsername, "Disabled");
  }
  
  public static void setFirstTimePrefs(Context context, Boolean b){
    final SharedPreferences.Editor editor = getSharedPreferences(context).edit();
    editor.putBoolean(property_firstTime, b);
    editor.commit();
  }
  
  public static Boolean getFirstTimePrefs(Context context){
    return getSharedPreferences(context).getBoolean(property_firstTime, true);
  }
}




Java Source Code List

com.dimasdanz.kendalipintu.BarcodeOpenDoorActivity.java
com.dimasdanz.kendalipintu.DeviceStatusActivity.java
com.dimasdanz.kendalipintu.LogActivity.java
com.dimasdanz.kendalipintu.LoginActivity.java
com.dimasdanz.kendalipintu.MainActivity.java
com.dimasdanz.kendalipintu.NFCOpenDoorActivity.java
com.dimasdanz.kendalipintu.RemoteOpenDoor.java
com.dimasdanz.kendalipintu.SettingsActivity.java
com.dimasdanz.kendalipintu.SettingsFragment.java
com.dimasdanz.kendalipintu.SetupActivity.java
com.dimasdanz.kendalipintu.UserActivity.java
com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusLoadData.java
com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusSendData.java
com.dimasdanz.kendalipintu.logmodel.LogAdapter.java
com.dimasdanz.kendalipintu.logmodel.LogLoadData.java
com.dimasdanz.kendalipintu.logmodel.LogLoadDetail.java
com.dimasdanz.kendalipintu.logmodel.LogModel.java
com.dimasdanz.kendalipintu.opendoor.BarcodePreview.java
com.dimasdanz.kendalipintu.usermodel.UserAdapter.java
com.dimasdanz.kendalipintu.usermodel.UserDialogManager.java
com.dimasdanz.kendalipintu.usermodel.UserListView.java
com.dimasdanz.kendalipintu.usermodel.UserLoadData.java
com.dimasdanz.kendalipintu.usermodel.UserModel.java
com.dimasdanz.kendalipintu.usermodel.UserSendData.java
com.dimasdanz.kendalipintu.util.AdminLoginDialog.java
com.dimasdanz.kendalipintu.util.CommonUtilities.java
com.dimasdanz.kendalipintu.util.GcmBroadcastReceiver.java
com.dimasdanz.kendalipintu.util.GcmIntentService.java
com.dimasdanz.kendalipintu.util.JSONParser.java
com.dimasdanz.kendalipintu.util.LoginAuth.java
com.dimasdanz.kendalipintu.util.ServerUtilities.java
com.dimasdanz.kendalipintu.util.SharedPreferencesManager.java
com.dimasdanz.kendalipintu.util.StaticString.java
com.dimasdanz.kendalipintu.util.UniversalDialogManager.java