Android Open Source - KendaliPintuAndroid Settings Fragment






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   ww w  .j a  v a  2  s .com
 * 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;

import com.dimasdanz.kendalipintu.R;
import com.dimasdanz.kendalipintu.util.AdminLoginDialog;
import com.dimasdanz.kendalipintu.util.SharedPreferencesManager;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

public class SettingsFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener, OnPreferenceClickListener{
  private String hostname_key = SharedPreferencesManager.property_hostname;
  private String notification_key = SharedPreferencesManager.property_receiveNotifications;
  private String admin_username_key = SharedPreferencesManager.property_adminUsername;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        PreferenceManager.setDefaultValues(getActivity(), R.xml.settings, true);
 
        SharedPreferences prefs = SharedPreferencesManager.getSharedPreferences(getActivity());
        prefs.registerOnSharedPreferenceChangeListener(this);
        addPreferencesFromResource(R.xml.settings);
        findPreference(hostname_key).setSummary(SharedPreferencesManager.getHostnamePrefs(getActivity()));
        findPreference(admin_username_key).setSummary(SharedPreferencesManager.getAdminIdPrefs(getActivity()));
        if(SharedPreferencesManager.getNotificationPrefs(getActivity())){
      findPreference(notification_key).setSummary(getActivity().getString(R.string.toast_notification_setting_on));
    }else{
      findPreference(notification_key).setSummary(getActivity().getString(R.string.toast_notification_setting_off));
    }
        findPreference(admin_username_key).setOnPreferenceClickListener(this);
  }

  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if(key.equals(hostname_key)){
      findPreference(key).setSummary(SharedPreferencesManager.getHostnamePrefs(getActivity()));
    }else if(key.equals(notification_key)){
      if(SharedPreferencesManager.getNotificationPrefs(getActivity())){
        findPreference(key).setSummary(getActivity().getString(R.string.toast_notification_setting_on));
      }else{
        findPreference(key).setSummary(getActivity().getString(R.string.toast_notification_setting_off));
      }
    }else if(key.equals(admin_username_key)){
      findPreference(admin_username_key).setSummary(SharedPreferencesManager.getAdminIdPrefs(getActivity()));
    }
  }

  @Override
  public boolean onPreferenceClick(Preference preference) {
    if(preference.getKey().equals(admin_username_key)){
      new AdminLoginDialog(getActivity(), null);
    }
    return false;
  }
  
}




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