Android Open Source - amulet Retrieve Task Data From Server






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;
/*from ww  w .  j a va 2 s  .c o  m*/

import android.content.Context;
import android.util.Log;

import java.text.SimpleDateFormat;


public class RetrieveTaskDataFromServer implements OnRetrieveHttpData {

    private final Context context;

    RetrieveTaskDataFromServer(Context context) {
        this.context = context;
    }

    protected void retrieveInspectionTaskEntries() {
        RetrieveHTTPDataAsync retrieveTaskEntries = new RetrieveHTTPDataAsync(this);
        String mEmail = SharedPreferencesWrapper.getFromPrefs(context, "email", "NO_EMAIL");
        String mPassword = SharedPreferencesWrapper.getFromPrefs(context, "password", "NO_PASSWORD");
        retrieveTaskEntries.execute("http://08309.net.dcs.hull.ac.uk/api/admin/taskhistory?username=" + mEmail + "&password=" + mPassword + "&tasktype=inspection");
    }

    protected void retrieveSequenceTaskEntries() {
        RetrieveHTTPDataAsync retrieveTaskEntries = new RetrieveHTTPDataAsync(this);
        String mEmail = SharedPreferencesWrapper.getFromPrefs(context, "email", "NO_EMAIL");
        String mPassword = SharedPreferencesWrapper.getFromPrefs(context, "password", "NO_PASSWORD");
        retrieveTaskEntries.execute("http://08309.net.dcs.hull.ac.uk/api/admin/taskhistory?username=" + mEmail + "&password=" + mPassword + "&tasktype=sequence");
    }

    @Override
    public void onRetrieveTaskCompleted(String httpData) {
        Log.i("Server Response", httpData);
        processTaskEntries(httpData);
    }

    private void processTaskEntries(String httpData) {
        SimpleDateFormat convertToDate = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        TaskEntries taskEntries = new TaskEntries();
        taskEntries = TaskEntries.createDDEntriesFromWebServer(httpData);
        int numEntries = taskEntries.getNumEntries();
        //if the number of entries isn't 0 then save to local storage. Otherwise it is a completely
        //new user and there's nothing to save yet.
        if (numEntries != 0) {
            //find the task type of the data returned to determine if we are looking for an inspection
            //calibration time or sequence calibration time
            String taskType = taskEntries.getEntry(0).taskType;
            if (taskType.equals("sequence")) {
                float sequenceTaskCalibrationTime = taskEntries.findTaskCalibrationTime();
                if (sequenceTaskCalibrationTime != 0) {
                    SharedPreferencesWrapper.saveToPrefs(context, "calibration_time_sequence_task", String.valueOf(sequenceTaskCalibrationTime));
                }
                taskEntries.saveToStorage(context, "SequenceTaskEntries.json");
            } else if (taskType.equals("inspection")) {
                float inspectionTaskCalibrationTime = taskEntries.findTaskCalibrationTime();
                if (inspectionTaskCalibrationTime != 0) {
                    SharedPreferencesWrapper.saveToPrefs(context, "calibration_time_inspection_task", (int) inspectionTaskCalibrationTime);
                }
                taskEntries.saveToStorage(context, "InspectionTaskEntries.json");
            }
        }
    }
}




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