Android Open Source - RazorRunner-AndroidProject Remove Detection






From Project

Back to project page RazorRunner-AndroidProject.

License

The source code is released under:

Apache License

If you think the Android project RazorRunner-AndroidProject 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 edu.uark.csce.razorrunner;
/* ww  w . j  av  a 2  s . c  o m*/
import android.app.Activity;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.IntentSender;
import android.os.Bundle;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.ActivityRecognitionClient;

import java.sql.Connection;

/**
 * Created by Kai Tribble on 11/28/2014.
 */
public class RemoveDetection implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener{

    private Context context;
    private ActivityRecognitionClient activityRecognitionClient;
    private PendingIntent pendingIntent;

    public RemoveDetection(Context context){
        this.context = context;
        activityRecognitionClient = null;
    }

    public void removeUpdates(PendingIntent reqIntent){
        pendingIntent = reqIntent;
        requestConnection();
    }

    public void requestConnection(){
        getActivityRecognitionClient().connect();
    }

    public ActivityRecognitionClient getActivityRecognitionClient(){
        if(activityRecognitionClient == null){
            setActivityRecognitionClient(new ActivityRecognitionClient(
                    context, this, this));
        }
        return activityRecognitionClient;
    }

    public void requestDisconnection(){
        getActivityRecognitionClient().disconnect();
        setActivityRecognitionClient(null);
    }

    public void setActivityRecognitionClient(ActivityRecognitionClient client){
        activityRecognitionClient = client;
    }

    public void continueRemoveUpdates(){
        activityRecognitionClient.removeActivityUpdates(pendingIntent);
        pendingIntent.cancel();
        requestDisconnection();
    }

    @Override
    public void onConnected(Bundle bundle) {
        continueRemoveUpdates();
    }

    @Override
    public void onDisconnected() {
        activityRecognitionClient = null;
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        if(connectionResult.hasResolution()){
            try {
                connectionResult.startResolutionForResult((Activity) context,
                        ActivityUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST);
            } catch (IntentSender.SendIntentException e){
                e.printStackTrace();
            }
        } else {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
                    connectionResult.getErrorCode(), (Activity) context,
                    ActivityUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST);
            if(dialog != null)
                dialog.show();
        }
    }
}




Java Source Code List

edu.uark.csce.razorrunner.ActivityUtils.java
edu.uark.csce.razorrunner.BuildConfig.java
edu.uark.csce.razorrunner.DistanceNotifier.java
edu.uark.csce.razorrunner.HistoryActivity.java
edu.uark.csce.razorrunner.Manifest.java
edu.uark.csce.razorrunner.OverviewActivity.java
edu.uark.csce.razorrunner.PedometerSettings.java
edu.uark.csce.razorrunner.ProfileActivity.java
edu.uark.csce.razorrunner.RemoveDetection.java
edu.uark.csce.razorrunner.RequestDetection.java
edu.uark.csce.razorrunner.StepDetector.java
edu.uark.csce.razorrunner.StepDisplayer.java
edu.uark.csce.razorrunner.StepListener.java
edu.uark.csce.razorrunner.UserActivityRecognition.java
edu.uark.csce.razorrunner.UserSettingsActivity.java
edu.uark.csce.razorrunner.UserStepRecognition.java
edu.uark.csce.razorrunner.WorkoutActivity.java
edu.uark.csce.razorrunner.WorkoutContentProvider.java
edu.uark.csce.razorrunner.WorkoutData.java
edu.uark.csce.razorrunner.WorkoutItemAdapter.java