Created
June 3, 2014 18:40
-
-
Save snadjafi/455c5eadc17cec3a0905 to your computer and use it in GitHub Desktop.
SharedPreferences example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kuapay.android.kuaClass; | |
| import android.content.Context; | |
| import android.content.SharedPreferences; | |
| import com.kuapay.android.manager.UserManager; | |
| public class DefaultTip | |
| { | |
| //region Constant Variables | |
| private static final String TIP_SETTINGS = "tip_settings"; | |
| private static final String DEFAULT_TIP = "15"; | |
| private static final String DEFAULT_TIP_CHILE_SPAIN = "0"; | |
| //endregion | |
| //region Variables | |
| private SharedPreferences tipSettingsSharedPreferences; | |
| private final SharedPreferences.Editor editor; | |
| //endregion | |
| public DefaultTip(Context context) | |
| { | |
| tipSettingsSharedPreferences = context.getSharedPreferences(TIP_SETTINGS, 0); | |
| editor = tipSettingsSharedPreferences.edit(); | |
| } | |
| public String getTip() | |
| { | |
| String tip = tipSettingsSharedPreferences.getString(UserManager.email,null); | |
| if (tip == null) | |
| { | |
| if(UserManager.homeNode.equals(UserManager.HOME_NODE_CHILE) || UserManager.homeNode.equals(UserManager.HOME_NODE_SPAIN)) | |
| { | |
| editor.putString(UserManager.email, DEFAULT_TIP_CHILE_SPAIN).commit(); | |
| return DEFAULT_TIP_CHILE_SPAIN; | |
| } | |
| else | |
| { | |
| editor.putString(UserManager.email, DEFAULT_TIP).commit(); | |
| return DEFAULT_TIP; | |
| } | |
| } | |
| return tip; | |
| } | |
| public void setTip(String tip) | |
| { | |
| editor.putString(UserManager.email, tip).commit(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment