Skip to content

Commit

Permalink
Merging build.gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
audaciouscode committed Nov 23, 2016
2 parents 3b4e70c + df9b652 commit 4e05dbb
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 4 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
@@ -1,10 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.audacious_software.pdk.passivedatakit">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<application android:allowBackup="true"
android:label="@string/app_name">
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name="com.audacious_software.passive_data_kit.activities.generators.MicrosoftBandAuthActivity" android:label="@string/app_name" />
<activity android:name="com.audacious_software.passive_data_kit.activities.generators.RequestPermissionActivity" android:label="@string/app_name" />
<activity android:name="com.audacious_software.passive_data_kit.activities.DiagnosticsActivity" android:label="@string/app_name" />
Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Expand Up @@ -22,7 +22,7 @@ android {
useLibrary 'org.apache.http.legacy'

defaultConfig {
minSdkVersion 18
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -50,6 +50,9 @@ android {
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.google.android.gms:play-services-location:10.0.0'
compile 'com.google.android.gms:play-services-maps:10.0.0'
compile 'com.google.android.gms:play-services-nearby:10.0.0'
compile 'com.google.android.gms:play-services-places:10.0.0'
compile 'com.google.android.gms:play-services-awareness:10.0.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'commons-io:commons-io:2.4'
compile 'commons-codec:commons-codec:1.10'
Expand Down
2 changes: 1 addition & 1 deletion res/values/diagnostics.xml
Expand Up @@ -2,6 +2,6 @@
<string name="diagnostic_missing_msft_band_client">Unable to connect to Microsoft Band.</string>
<string name="diagnostic_missing_msft_band_auth">Please grant the app sensor access on the Microsoft Band.</string>
<string name="diagnostic_missing_location_permission">Please grant the app permission to access location services on this device.</string>

<string name="diagnostic_missing_activity_recognition_permission">Please grant the app permission to recognize your activity using data from this device.</string>
<string name="diagnostic_call_log_permission_required">Please grant the app permission to access the phone call logs on this device.</string>
</resources>
1 change: 1 addition & 0 deletions res/values/generators.xml
Expand Up @@ -4,6 +4,7 @@
<item>com.audacious_software.passive_data_kit.generators.device.ScreenState</item>
<item>com.audacious_software.passive_data_kit.generators.communication.PhoneCalls</item>
<item>com.audacious_software.passive_data_kit.generators.wearables.MicrosoftBand</item>
<item>com.audacious_software.passive_data_kit.generators.services.GoogleAwareness</item>
</string-array>

<string-array name="pdk_app_generators"></string-array>
Expand Down
Expand Up @@ -48,6 +48,8 @@ public void start() {
for (String className : this.mGenerators)
{
try {
Log.e("PDK", "TRYING " + className);

Class<Generator> probeClass = (Class<Generator>) Class.forName(className);

Method isEnabled = probeClass.getDeclaredMethod("isEnabled", Context.class);
Expand All @@ -63,12 +65,16 @@ public void start() {
this.stopGenerator(className);
}
} catch (ClassNotFoundException e) {
Log.e("PDK", "ClassNotFoundException " + className);
Logger.getInstance(this.mContext).logThrowable(e);
} catch (NoSuchMethodException e) {
Log.e("PDK", "NoSuchMethodException " + className);
Logger.getInstance(this.mContext).logThrowable(e);
} catch (InvocationTargetException e) {
Log.e("PDK", "InvocationTargetException " + className);
Logger.getInstance(this.mContext).logThrowable(e);
} catch (IllegalAccessException e) {
Log.e("PDK", "IllegalAccessException " + className);
Logger.getInstance(this.mContext).logThrowable(e);
}
}
Expand Down
@@ -0,0 +1,222 @@
package com.audacious_software.passive_data_kit.generators.services;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Log;

import com.audacious_software.passive_data_kit.activities.generators.RequestPermissionActivity;
import com.audacious_software.passive_data_kit.diagnostics.DiagnosticAction;
import com.audacious_software.passive_data_kit.generators.Generator;
import com.audacious_software.passive_data_kit.generators.Generators;
import com.audacious_software.pdk.passivedatakit.R;
import com.google.android.gms.awareness.Awareness;
import com.google.android.gms.awareness.snapshot.DetectedActivityResult;
import com.google.android.gms.awareness.snapshot.HeadphoneStateResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity;

import java.util.ArrayList;

/**
* Created by cjkarr on 6/28/2016.
*/
public class GoogleAwareness extends Generator implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
private static final String GENERATOR_IDENTIFIER = "google-awareness";

private static final String ENABLED = "com.audacious_software.passive_data_kit.generators.services.GoogleAwareness.ENABLED";
private static final boolean ENABLED_DEFAULT = true;
private static final long SENSING_INTERVAL = 60 * 1000;

private static GoogleAwareness sInstance = null;
private GoogleApiClient mGoogleApiClient = null;
private Handler mSensingHandler = null;

public static GoogleAwareness getInstance(Context context) {
if (GoogleAwareness.sInstance == null) {
GoogleAwareness.sInstance = new GoogleAwareness(context.getApplicationContext());
}

return GoogleAwareness.sInstance;
}

public GoogleAwareness(Context context) {
super(context);
}

public static void start(final Context context) {
GoogleAwareness.getInstance(context).startGenerator();
}

private void startGenerator() {
final GoogleAwareness me = this;

Runnable r = new Runnable()
{

@Override
public void run() {
Log.e("PDK", "GA MAKE CLIENT");
if (me.mGoogleApiClient == null) {
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(me.mContext);
builder.addConnectionCallbacks(me);
builder.addOnConnectionFailedListener(me);
builder.addApi(Awareness.API);

me.mGoogleApiClient = builder.build();
me.mGoogleApiClient.connect();
Log.e("PDK", "GA MADE CLIENT");
}
}
};

Thread t = new Thread(r);
t.start();

Generators.getInstance(this.mContext).registerCustomViewClass(GoogleAwareness.GENERATOR_IDENTIFIER, GoogleAwareness.class);
}

public static ArrayList<DiagnosticAction> diagnostics(Context context)
{
return GoogleAwareness.getInstance(context).runDiagostics();
}

private ArrayList<DiagnosticAction> runDiagostics() {
ArrayList<DiagnosticAction> actions = new ArrayList<>();

final GoogleAwareness me = this;

final Handler handler = new Handler(Looper.getMainLooper());

Log.e("PDK", "1");
if (GoogleAwareness.isEnabled(this.mContext)) {
Log.e("PDK", "2");
int permissionCheck = ContextCompat.checkSelfPermission(this.mContext, Manifest.permission.ACCESS_FINE_LOCATION);

if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
actions.add(new DiagnosticAction(me.mContext.getString(R.string.diagnostic_missing_location_permission), new Runnable() {
@Override
public void run() {
handler.post(new Runnable() {

@Override
public void run() {
Intent intent = new Intent(me.mContext, RequestPermissionActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(RequestPermissionActivity.PERMISSION, Manifest.permission.ACCESS_FINE_LOCATION);

me.mContext.startActivity(intent);
}
});
}
}));
}

Log.e("PDK", "3");

permissionCheck = ContextCompat.checkSelfPermission(this.mContext, "com.google.android.gms.permission.ACTIVITY_RECOGNITION");

if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
Log.e("PDK", "3.3");
actions.add(new DiagnosticAction(me.mContext.getString(R.string.diagnostic_missing_activity_recognition_permission), new Runnable() {
@Override
public void run() {
handler.post(new Runnable() {

@Override
public void run() {
Intent intent = new Intent(me.mContext, RequestPermissionActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(RequestPermissionActivity.PERMISSION, "com.google.android.gms.permission.ACTIVITY_RECOGNITION");

me.mContext.startActivity(intent);
}
});
}
}));
Log.e("PDK", "3.7");
}


Log.e("PDK", "4");
}

Log.e("PDK", "5 " + actions.size());

return actions;
}

public static boolean isRunning(Context context) {
if (GoogleAwareness.sInstance == null) {
return false;
}

return (GoogleAwareness.sInstance.mGoogleApiClient != null);
}

public static boolean isEnabled(Context context) {
SharedPreferences prefs = Generators.getInstance(context).getSharedPreferences(context);

return prefs.getBoolean(GoogleAwareness.ENABLED, GoogleAwareness.ENABLED_DEFAULT);
}

@Override
public void onConnected(@Nullable Bundle bundle) {
Log.e("PDK", "GA onConnected");

final GoogleAwareness me = this;

Runnable r = new Runnable() {

@Override
public void run() {
Log.e("PDK", "GA GET ACTIVITY");
Awareness.SnapshotApi.getHeadphoneState(mGoogleApiClient).setResultCallback(new ResultCallback<HeadphoneStateResult>() {
@Override
public void onResult(@NonNull HeadphoneStateResult headphoneStateResult) {
if (!headphoneStateResult.getStatus().isSuccess()) {
Log.e("PDK", "Could not get the current headphone state.");
return;
}

Log.i("PDK", "HEAD: " + headphoneStateResult.getHeadphoneState());
}
});

if (me.mSensingHandler != null) {
me.mSensingHandler.postDelayed(this, GoogleAwareness.SENSING_INTERVAL);
}
}
};

this.mSensingHandler = new Handler();
this.mSensingHandler.post(r);
}

@Override
public void onConnectionSuspended(int i) {
Log.e("PDK", "GA onConnectionSuspended");
if (this.mGoogleApiClient != null && this.mGoogleApiClient.isConnected()) {
this.mGoogleApiClient.disconnect();
}

this.mSensingHandler = null;
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.e("PDK", "GA onConnectionFailed");
this.mGoogleApiClient = null;
}
}

0 comments on commit 4e05dbb

Please sign in to comment.