Android Open Source - Aegis S M S Wipe 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;
//  www  .ja  v  a  2  s . c  om
import android.app.admin.DevicePolicyManager;
import android.content.Intent;
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.AegisActivity;
import com.decad3nce.aegis.R;
import com.decad3nce.aegis.Utils;

/**
 * Created by adnan on 6/13/13.
 */
public class SMSWipeFragment extends PreferenceFragment {

    public static final String PREFERENCES_WIPE_ACTIVATION_SMS = "wipe_activation_sms";
    public static final String PREFERENCES_WIPE_ENABLED = "wipe_toggle";
    public static final String PREFERENCES_WIPE_SDCARD_PREF = "wipe_sdcard";

    private static final String TAG = "aeGis";

    protected static boolean wipeEnabled;
    private Switch mWipeEnabledPreference;
    private DevicePolicyManager devicePolicyManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.wipe_preference);
        setHasOptionsMenu(true);
    }

    @Override
    public void onResume() {
        super.onResume();
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
        wipeEnabled = preferences
                .getBoolean(PREFERENCES_WIPE_ENABLED, getActivity().getResources().getBoolean(R.bool.config_default_wipe_enabled));

        devicePolicyManager = (DevicePolicyManager) getActivity()
                .getSystemService(getActivity().DEVICE_POLICY_SERVICE);
    }

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

        if (devicePolicyManager != null && devicePolicyManager.getActiveAdmins() != null) {
            if (devicePolicyManager.isAdminActive(AegisActivity.DEVICE_ADMIN_COMPONENT) && wipeEnabled) {
                    mWipeEnabledPreference.setChecked(true);
                }
        }

        mWipeEnabledPreference.setOnCheckedChangeListener(wipePreferencesOnChangeListener);
    }

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

    CompoundButton.OnCheckedChangeListener wipePreferencesOnChangeListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView,
                                     boolean isChecked) {
            switch (buttonView.getId()) {
                case R.id.wipe_toggle:
                    if (isChecked && !devicePolicyManager
                            .isAdminActive(AegisActivity.DEVICE_ADMIN_COMPONENT)) {
                        addAdmin();
                    }
                    commitToShared();
                    break;
            }
        }
    };

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

    private void addAdmin() {
        Intent intent = new Intent(
                DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                AegisActivity.DEVICE_ADMIN_COMPONENT);
        intent.putExtra(
                DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                getResources().getString(
                        R.string.device_admin_reason));
        startActivityForResult(intent, AegisActivity.ACTIVATION_REQUEST);
    }

    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