Android Open Source - LASA-Schedules Settings Fragment






From Project

Back to project page LASA-Schedules.

License

The source code is released under:

GNU General Public License

If you think the Android project LASA-Schedules 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

package com.asdar.lasaschedules;
//w w w  .j  a v  a  2 s  .  c o m
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.support.v4.preference.PreferenceFragment;

import com.parse.ParseInstallation;
import com.parse.PushService;

/**
 * Created by Ehsan on 4/2/14.
 */
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceClickListener {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.fragment_settings);
        Preference about= findPreference("about");
        about.setOnPreferenceClickListener(this);
    }
    @Override
    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
        if (key.equals("notification")&& !prefs.getBoolean("notification",true)  ){
            Intent service = new Intent(getActivity(), NotificationService.class);
            getActivity().stopService(service);
        }
        if (key.equals("notification")&& prefs.getBoolean("notification",true) ){
            Intent service = new Intent(getActivity(), NotificationService.class);
            getActivity().stopService(service);
            getActivity().startService(service);
        }
        if (key.equals("updates")&& !prefs.getBoolean("updates",true) ){
            PushService.unsubscribe(getActivity().getApplicationContext(), "updates");
        }
        if (key.equals("updates")&& prefs.getBoolean("notification",true) ){
            PushService.subscribe(getActivity().getApplicationContext(), "updates", MainActivity.class, R.drawable.ic_stat_notification);
            ParseInstallation.getCurrentInstallation().saveInBackground();
        }
    }
    @Override
    public void onResume() {
        super.onResume();
        getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

    }

    @Override
    public void onPause() {
        super.onPause();
        getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
    }

    @Override
    public boolean onPreferenceClick(Preference preference) {
        if (preference.getKey().equals("about")){
            AboutDialog about = new AboutDialog(getActivity());
            about.setTitle("LASA Schdules");
            about.show();
        }
        return false;
    }
}




Java Source Code List

com.asdar.lasaschedules.AboutDialog.java
com.asdar.lasaschedules.AlarmClearIntent.java
com.asdar.lasaschedules.AlarmRespondIntentService.java
com.asdar.lasaschedules.HomeFragment.java
com.asdar.lasaschedules.MainActivity.java
com.asdar.lasaschedules.NotificationServiceReciever.java
com.asdar.lasaschedules.NotificationService.java
com.asdar.lasaschedules.Resources.java
com.asdar.lasaschedules.RobotoTextView.java
com.asdar.lasaschedules.ScheduleAdapter.java
com.asdar.lasaschedules.ScheduleElement.java
com.asdar.lasaschedules.ScheduleFragment.java
com.asdar.lasaschedules.Schedule.java
com.asdar.lasaschedules.SettingsActivity.java
com.asdar.lasaschedules.SettingsFragment.java
com.asdar.lasaschedules.StaticResources.java
com.asdar.lasaschedules.StaticScheduleFragment.java
com.asdar.lasaschedules.StaticSchedules.java
com.asdar.lasaschedules.TodayActivity.java