Android Open Source - Aegis S M S Data Fragment






From Project

Back to project page Aegis.

License

The source code is released under:

GNU General Public License

If you think the Android project Aegis 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.decad3nce.aegis.Fragments;
//from   w  w w .  j  av a2 s .  c o m
import android.app.DialogFragment;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.CompoundButton;
import android.widget.Switch;
import com.decad3nce.aegis.R;
import com.decad3nce.aegis.Utils;


public class SMSDataFragment extends PreferenceFragment implements ChooseBackupProgramDialogFragment.ChooseBackupDialogListener {
    
    public static final String PREFERENCES_DATA_ACTIVATION_SMS = "data_activation_sms";
    public static final String PREFERENCES_BACKUP_CALL_LOGS = "data_backup_call_logs";
    public static final String PREFERENCES_BACKUP_SMS_LOGS = "data_backup_sms_logs";
    public static final String PREFERENCES_DATA_ENABLED = "data_toggle";

    protected static boolean dataEnabled;
    private Switch mDataEnabledPreference;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.data_preference);
        setHasOptionsMenu(true);
    }

    @Override
    public void onResume() {
        super.onResume();
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
        dataEnabled = preferences
                .getBoolean(PREFERENCES_DATA_ENABLED, getActivity().getResources().getBoolean(R.bool.config_default_data_enabled));
    }

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        inflateFullMenu(menu);
        Utils.showItem(R.id.data_menu_settings, menu);
        mDataEnabledPreference = (Switch) menu
                .findItem(R.id.data_menu_settings).getActionView()
                .findViewById(R.id.data_toggle);
        mDataEnabledPreference.setChecked(false);

        if ((isGoogleAuthed() || isDropboxAuthed() && dataEnabled)) {
                mDataEnabledPreference.setChecked(true);
        }

        mDataEnabledPreference.setOnCheckedChangeListener(dataPreferencesOnChangeListener);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
    }

    CompoundButton.OnCheckedChangeListener dataPreferencesOnChangeListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView,
                                     boolean isChecked) {

            switch (buttonView.getId()) {
                case R.id.data_toggle:

                    if (isChecked) {
                        if(isGoogleAuthed() || isDropboxAuthed()) {
                            commitToShared();
                        } else {
                            DialogFragment dialog = new ChooseBackupProgramDialogFragment();
                            dialog.show(getActivity().getFragmentManager(), "ChooseBackupProgramDialogFragment");
                        }
                    } else {
                        commitToShared();
                    }
                    break;
            }
        }
    };

    private void commitToShared() {
        SharedPreferences preferences = PreferenceManager
                .getDefaultSharedPreferences(getActivity());
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(PREFERENCES_DATA_ENABLED, mDataEnabledPreference.isChecked());
        editor.commit();
    }


    protected boolean isGoogleAuthed() {
        SharedPreferences preferences = PreferenceManager
                .getDefaultSharedPreferences(getActivity());
        boolean googleBackup = preferences.getBoolean(
                AdvancedSettingsFragment.PREFERENCES_GOOGLE_BACKUP_CHECKED,
                getResources().getBoolean(
                        R.bool.config_default_google_backup_enabled));
        if(googleBackup){
            return true;
        }
        return false;
    }

    protected boolean isDropboxAuthed() {
        SharedPreferences preferences = PreferenceManager
                .getDefaultSharedPreferences(getActivity());
        boolean dropboxBackup = preferences.getBoolean(
                AdvancedSettingsFragment.PREFERENCES_DROPBOX_BACKUP_CHECKED,
                getResources().getBoolean(
                        R.bool.config_default_dropbox_backup_enabled));
        if (dropboxBackup) {
            return true;
        }
        return false;
    }

    private void inflateFullMenu(Menu menu) {
        MenuInflater inflater = getActivity().getMenuInflater();
        inflater.inflate(R.menu.full_menu, menu);
    }
}




Java Source Code List

com.decad3nce.aegis.AegisActivity.java
com.decad3nce.aegis.AlarmService.java
com.decad3nce.aegis.BackupDropboxAccountsActivity.java
com.decad3nce.aegis.BackupGoogleAccountsActivity.java
com.decad3nce.aegis.BackupUtils.java
com.decad3nce.aegis.DeviceAdmin.java
com.decad3nce.aegis.DialerCodeReceiver.java
com.decad3nce.aegis.DrawerLayoutAdapter.java
com.decad3nce.aegis.FontAdapter.java
com.decad3nce.aegis.LoginActivity.java
com.decad3nce.aegis.PhoneTrackerActivity.java
com.decad3nce.aegis.RegisterActivity.java
com.decad3nce.aegis.RootTask.java
com.decad3nce.aegis.SIMStateReceiver.java
com.decad3nce.aegis.SMSReceiver.java
com.decad3nce.aegis.Utils.java
com.decad3nce.aegis.WipeBaseActivity.java
com.decad3nce.aegis.WipeTask.java
com.decad3nce.aegis.Fragments.AboutFragment.java
com.decad3nce.aegis.Fragments.AdvancedSettingsFragment.java
com.decad3nce.aegis.Fragments.BackupAccountsDialogFragment.java
com.decad3nce.aegis.Fragments.ChooseBackupProgramDialogFragment.java
com.decad3nce.aegis.Fragments.InstallToSystemDialogFragment.java
com.decad3nce.aegis.Fragments.SIMListFragment.java
com.decad3nce.aegis.Fragments.SMSAlarmFragment.java
com.decad3nce.aegis.Fragments.SMSDataFragment.java
com.decad3nce.aegis.Fragments.SMSLocateFragment.java
com.decad3nce.aegis.Fragments.SMSLockFragment.java
com.decad3nce.aegis.Fragments.SMSWipeFragment.java