Search in sources :

Example 1 with LocalStorage

use of org.flyve.mdm.agent.data.localstorage.LocalStorage in project android-mdm-agent by flyve-mdm.

the class FragmentConfiguration method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    v = inflater.inflate(R.layout.fragment_configuration, container, false);
    cache = new AppData(FragmentConfiguration.this.getContext());
    Switch swNotifications = this.v.findViewById(R.id.swNotifications);
    swNotifications.setChecked(cache.getDisableNotification());
    swNotifications.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            cache.setDisableNotification(b);
        }
    });
    Switch swConnectionNotification = this.v.findViewById(R.id.swConnectionNotification);
    swConnectionNotification.setChecked(cache.getEnableNotificationConnection());
    swConnectionNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            cache.setEnableNotificationConnection(b);
        }
    });
    Switch swDarkTheme = this.v.findViewById(R.id.swDarkTheme);
    swDarkTheme.setChecked(cache.getDarkTheme());
    swDarkTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            cache.setDarkTheme(b);
        }
    });
    // use for lock option
    Switch switchDrawOverlay = this.v.findViewById(R.id.swtDrawOverlay);
    if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        switchDrawOverlay.setChecked(Settings.canDrawOverlays(getActivity()));
        switchDrawOverlay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getActivity().getPackageName()));
                startActivityForResult(intent, REQUEST_DRAWOVERLAY_CODE);
            }
        });
    } else {
        switchDrawOverlay.setVisibility(View.INVISIBLE);
    }
    Button btnClear = v.findViewById(R.id.btnClear);
    btnClear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AlertDialog.Builder builder = new AlertDialog.Builder(FragmentConfiguration.this.getContext());
            builder.setTitle(R.string.danger);
            builder.setMessage(R.string.erase_all_data_question);
            builder.setPositiveButton(R.string.YES, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    LocalStorage localStorage = new LocalStorage(FragmentConfiguration.this.getContext());
                    localStorage.clearSettings();
                    new MqttData(FragmentConfiguration.this.getContext()).deleteAll();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(R.string.NO, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                    dialog.dismiss();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });
    return v;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) MqttData(org.flyve.mdm.agent.data.database.MqttData) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) View(android.view.View) LocalStorage(org.flyve.mdm.agent.data.localstorage.LocalStorage) Switch(android.widget.Switch) AppData(org.flyve.mdm.agent.data.localstorage.AppData) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton)

Aggregations

DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 Switch (android.widget.Switch)1 MqttData (org.flyve.mdm.agent.data.database.MqttData)1 AppData (org.flyve.mdm.agent.data.localstorage.AppData)1 LocalStorage (org.flyve.mdm.agent.data.localstorage.LocalStorage)1