Android Open Source - SUREwalk_android Parse Handler






From Project

Back to project page SUREwalk_android.

License

The source code is released under:

MIT License

If you think the Android project SUREwalk_android 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 org.utexas.surewalk.controllers;
//from   www  .  j  a v  a2s.c o  m
import android.content.Context;
import android.widget.Toast;

import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.SaveCallback;

import org.utexas.surewalk.R;
import org.utexas.surewalk.data.WalkRequest;


public class ParseHandler {
    //surewalk Parse account keys
    private String APP_KEY;
    private String CLIENT_KEY;

    private static final Class[] PARSE_OBJECT_CLASSES = {WalkRequest.class};

    private Context context;
    private HandlerSaveCallback callback;

    private boolean isParseInit = false;
    private boolean isSaved = false;


    public ParseHandler(Context c) {
        if (c == null)
                throw new IllegalArgumentException("c" +
                        "may not be null.");

        context = c;
        APP_KEY = c.getString(R.string.parse_app_key);
        CLIENT_KEY = c.getString(R.string.parse_client_key);
        
        callback = new HandlerSaveCallback();
    }


    public void initializeParse() {
        isParseInit = true;
        for (Class subclass : PARSE_OBJECT_CLASSES)
                ParseObject.registerSubclass(subclass);
        Parse.initialize(context, APP_KEY, CLIENT_KEY);
    }


    public boolean saveWalkInfo(WalkRequest data) {
        if (!isParseInit)
            throw new IllegalStateException("Must initialize parse first.");
        if (data == null)
            throw new IllegalArgumentException("Data may not be null.");
        return saveInBackground(data);
    }


    private boolean saveInBackground(ParseObject data) {
        if (data == null)
            throw new IllegalArgumentException("Data may not be null.");
        isSaved = false;
        data.saveInBackground(callback);
        return isSaved;
    }


    private class HandlerSaveCallback extends SaveCallback {

        @Override
        public void done(ParseException e) {
            if (e == null) {
                ParseHandler.this.isSaved = true;

                Toast.makeText(ParseHandler.this.context, "Request sent! You'll get a response soon!", Toast.LENGTH_SHORT).show();
            } else {
                ParseHandler.this.isSaved = false;

                Toast.makeText(ParseHandler.this.context, "Unable to send request.", Toast.LENGTH_SHORT).show();
            }
        }
    }
}




Java Source Code List

org.utexas.surewalk.activities.AboutActivity.java
org.utexas.surewalk.activities.MainActivity.java
org.utexas.surewalk.activities.RequestWalkActivity.java
org.utexas.surewalk.activities.SettingsActivity.java
org.utexas.surewalk.classes.MainApplication.java
org.utexas.surewalk.classes.NonSwipeViewPager.java
org.utexas.surewalk.classes.OnFragmentReadyListener.java
org.utexas.surewalk.controllers.FragmentAdapter.java
org.utexas.surewalk.controllers.ParseHandler.java
org.utexas.surewalk.controllers.PreferenceHandler.java
org.utexas.surewalk.data.SureCalendar.java
org.utexas.surewalk.data.WalkRequest.java
org.utexas.surewalk.fragments.DashboardFragment.java
org.utexas.surewalk.fragments.InfoFragment.java
org.utexas.surewalk.fragments.LocationFragment.java
org.utexas.surewalk.fragments.RequestMapFragment.java
org.utexas.surewalk.fragments.ReviewFragment.java