Android Open Source - amulet Logout Dialog Fragment






From Project

Back to project page amulet.

License

The source code is released under:

MIT License

If you think the Android project amulet 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 scamell.michael.amulet;
/* w w  w. j  a va2  s  . c o  m*/
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.Toast;

public class LogoutDialogFragment extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.dialog_logout_message)
                .setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "password");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "logged_in");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "new_login");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "last_task_played");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "last_inspection_task_time");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "last_sequence_task_time");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "task_session_units");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "lastDrinkAdded");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "unitsOfLastDrinkAdded");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "calibration_time_inspection_task");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "calibration_time_sequence_task");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "favourite_drinks");
                        //Try to reupload drink diary and tasks one last time before logging out
                        if (SharedPreferencesWrapper.getFromPrefs(getActivity(), "reUpload_tasks", false)) {
                            TaskEntries taskEntries = TaskEntries.createTaskEntriesFromStorage(getActivity(), "ReUploadTasks.json");
                            if (taskEntries.getNumEntries() > 0) {
                                SendTaskEntriesToServer sendTaskEntriesToServer = new SendTaskEntriesToServer(getActivity(), taskEntries);
                                sendTaskEntriesToServer.sendTaskEntriesToServer();
                            }
                        }
                        TaskEntries taskEntries1 = new TaskEntries();
                        taskEntries1.saveToStorage(getActivity(), "ReUploadTasks.json");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "reUpload_tasks");

                        if (SharedPreferencesWrapper.getFromPrefs(getActivity(), "reUpload_drink_diary", false)) {
                            DrinkDiaryEntries drinkDiaryEntries = DrinkDiaryEntries.createDrinkDiaryEntriesFromStorage(getActivity(), "ReUploadDrinkDiary.json");
                            if (drinkDiaryEntries.getNumEntries() > 0) {
                                SendDrinkDiaryEntriesToServer sendDrinkDiaryEntriesToServer = new SendDrinkDiaryEntriesToServer(getActivity(), drinkDiaryEntries);
                                sendDrinkDiaryEntriesToServer.sendDrinkDiaryEntriesToServer();
                            }
                        }
                        DrinkDiaryEntries drinkDiaryEntries1 = new DrinkDiaryEntries();
                        drinkDiaryEntries1.saveToStorage(getActivity(), "ReUploadDrinkDiary.json");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "reUpload_drink_diary");

                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "new_user");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "first_time_inspection_task");
                        SharedPreferencesWrapper.removeFromPrefs(getActivity(), "first_time_sequence_task");
                        //save over the drink diary entries and Task Entries so they are not shown on a new start
                        DrinkDiaryEntries dDE = new DrinkDiaryEntries();
                        dDE.saveToStorage(getActivity(), "DrinkDiaryEntries.json");
                        TaskEntries taskEntries = new TaskEntries();
                        taskEntries.saveToStorage(getActivity(), "InspectionTaskEntries.json");
                        taskEntries.saveToStorage(getActivity(), "SequenceTaskEntries.json");
                        Intent intent = new Intent(getActivity(), LoginActivity.class);
                        startActivity(intent);
                        Toast.makeText(getActivity(), "You've been logged out", Toast.LENGTH_LONG).show();
                        getActivity().finish();
                    }
                })
                .setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //cancelled
                    }
                });
        return builder.create();
    }
}




Java Source Code List

scamell.michael.amulet.AboutDialogFragment.java
scamell.michael.amulet.AccountDetailsFragment.java
scamell.michael.amulet.ChangePasswordDialogFragment.java
scamell.michael.amulet.CoolveticaTextView.java
scamell.michael.amulet.DateAndTime.java
scamell.michael.amulet.DrinkDiaryEntries.java
scamell.michael.amulet.DrinkDiaryEntryAdapter.java
scamell.michael.amulet.DrinkDiaryEntry.java
scamell.michael.amulet.DrinkDiaryFavouriteDrinksDialogFragment.java
scamell.michael.amulet.DrinkDiaryFragment.java
scamell.michael.amulet.ExampleDrinksDialogFragment.java
scamell.michael.amulet.FavouriteDrinkUtility.java
scamell.michael.amulet.HomeFragment.java
scamell.michael.amulet.InspectionTaskActivity.java
scamell.michael.amulet.InspectionTaskInstructions1Fragment.java
scamell.michael.amulet.InspectionTaskInstructions2Fragment.java
scamell.michael.amulet.LastTaskInstructionFragment.java
scamell.michael.amulet.LoginActivity.java
scamell.michael.amulet.LogoutDialogFragment.java
scamell.michael.amulet.MainActivity.java
scamell.michael.amulet.OnPostHttpData.java
scamell.michael.amulet.OnRetrieveHttpData.java
scamell.michael.amulet.PostHTTPDataAsync.java
scamell.michael.amulet.RegisterActivity.java
scamell.michael.amulet.ResumeTaskDialogFragment.java
scamell.michael.amulet.RetrieveHTTPDataAsync.java
scamell.michael.amulet.RetrieveHTTPData.java
scamell.michael.amulet.RetrieveTaskDataFromServer.java
scamell.michael.amulet.SaveDrinkDiaryUtility.java
scamell.michael.amulet.SendDrinkDiaryEntriesToServer.java
scamell.michael.amulet.SendDrinkDiaryEntryToServer.java
scamell.michael.amulet.SendTaskEntriesToServer.java
scamell.michael.amulet.SendTaskEntryToServer.java
scamell.michael.amulet.SequenceTaskActivity.java
scamell.michael.amulet.SequenceTaskInstruction1Fragment.java
scamell.michael.amulet.SequenceTaskInstruction2Fragment.java
scamell.michael.amulet.SequenceTaskInstruction3Fragment.java
scamell.michael.amulet.SharedPreferencesWrapper.java
scamell.michael.amulet.Sound.java
scamell.michael.amulet.TaskEntries.java
scamell.michael.amulet.TaskEntry.java
scamell.michael.amulet.TaskFinishFragment.java
scamell.michael.amulet.TaskInstructionsActivity.java
scamell.michael.amulet.TaskStartCountdownFragment.java
scamell.michael.amulet.TasksFirstStartWelcomeFragment.java
scamell.michael.amulet.TasksMenuFragment.java
scamell.michael.amulet.UnitCalculatorFavouriteDrinksDialogFragment.java
scamell.michael.amulet.UnitCalculatorFragment.java
scamell.michael.amulet.UnitCalculator.java