Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Additional diagnostics work
  • Loading branch information
audaciouscode committed Dec 29, 2016
1 parent 1c1cc49 commit 2711f7b
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 65 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Expand Up @@ -45,9 +45,9 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-nearby:10.0.1'
Expand Down
Binary file added res/drawable-hdpi/ic_pdk_diagnostic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_pdk_diagnostic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/ic_pdk_diagnostic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/ic_pdk_diagnostic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxxhdpi/ic_pdk_diagnostic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 29 additions & 8 deletions res/layout/card_diagnostic_action.xml
@@ -1,20 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
android:layout_margin="16dp">
<TextView
android:id="@+id/message_action"
android:layout_margin="16dp"
android:layout_margin="8dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content">
<TextView android:id="@+id/action_title"
android:background="#C62828"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|start"
android:layout_weight="1"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="@android:color/white" />
<TextView android:id="@+id/action_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textSize="14sp"
android:textColor="@android:color/black"
android:background="@android:color/white"
android:padding="12dp">
</TextView>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
19 changes: 14 additions & 5 deletions res/layout/layout_diagnostics_pdk.xml
@@ -1,7 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_view"
android:scrollbars="vertical"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/list_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView android:id="@+id/message_no_diagnostics"
android:text="@string/message_no_diagnostic_actions"
android:gravity="center"
android:textSize="14sp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
6 changes: 6 additions & 0 deletions res/menu/diagnostic_menu.xml
@@ -0,0 +1,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_diagnostics"
android:title="@string/action_diagnostics"
app:showAsAction="never" />
</menu>
16 changes: 14 additions & 2 deletions res/values/diagnostics.xml
@@ -1,7 +1,19 @@
<resources>
<string name="diagnostic_missing_msft_band_client">Unable to connect to Microsoft Band.</string>
<string name="diagnostic_missing_msft_band_client_title">Microsoft Band App Not Installed</string>
<string name="diagnostic_missing_msft_band_client">Unable to connect to Microsoft Band. Please install the app and try again.</string>

<string name="diagnostic_missing_msft_band_auth_title">Microsoft Band Permission Required</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_title">Activity Recognition Permission Required</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_title">Call Log Permission Required</string>
<string name="diagnostic_call_log_permission_required">Please grant the app permission to access the phone call logs on this device.</string>

<string name="diagnostic_sms_log_permission_required_title">Text Messaging Permission Required</string>
<string name="diagnostic_sms_log_permission_required">Please all the app permission to access your text messages to gather and report your messaging activity statistics.</string>

<string name="diagnostic_missing_location_permission_title">Location Permission Required</string>
<string name="diagnostic_missing_location_permission">Please grant the app permission to access location services on this device.</string>
</resources>
1 change: 0 additions & 1 deletion res/values/generators.xml
Expand Up @@ -69,7 +69,6 @@
<string name="generator_text_messages_length_format">%1$d chars.</string>

<string name="message_generator_text_messages_empty">No text messages have been sent or received on this device.</string>
<string name="diagnostic_sms_log_permission_required">Please all the app permission to access your text messages to gather and report your messaging activity statistics.</string>

<!-- Phone Call Resources -->
<string name="generator_phone_calls">Phone Calls</string>
Expand Down
5 changes: 5 additions & 0 deletions res/values/strings.xml
Expand Up @@ -15,5 +15,10 @@
<string name="label_today_pdk">Today</string>

<string name="label_never_pdk">Never</string>
<string name="action_diagnostics">Diagnostics</string>
<string name="action_diagnostics_incomplete">Diagnostics (%d)</string>
<string name="title_pdk_diagnostics">Diagnostics</string>

<string name="message_no_diagnostic_actions">The app is set up correctly.\n\nNo further actions are needed.</string>
</resources>

Expand Up @@ -66,25 +66,15 @@ protected void onPause() {

@Override
public void onGeneratorUpdated(String identifier, Bundle data) {
Log.e("PDK", "GOT GENERATOR UPDATE: " + identifier + " -- " + data);

this.mAdapter.notifyDataSetChanged();

final int count = this.mAdapter.getItemCount();

Handler mainHandler = new Handler(Looper.getMainLooper());

final DataStreamActivity me = this;

mainHandler.post(new Runnable() {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
me.mAdapter.notifyDataSetChanged();
int count = me.mAdapter.getItemCount();
me.getSupportActionBar().setSubtitle(me.getResources().getQuantityString(R.plurals.activity_data_stream_subtitle, count, count));
}
});

// RecyclerView listView = (RecyclerView) this.findViewById(R.id.list_view);
// listView.setAdapter(this.mAdapter);
// listView.invalidate();
}
}
@@ -1,11 +1,14 @@
package com.audacious_software.passive_data_kit.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
Expand All @@ -17,6 +20,38 @@
import java.util.ArrayList;

public class DiagnosticsActivity extends AppCompatActivity {
public static void setUpDiagnositicsItem(Activity activity, Menu menu, boolean showAction) {
final ArrayList<DiagnosticAction> actions = PassiveDataKit.diagnostics(activity);

MenuItem item = menu.add(Menu.NONE, R.id.action_diagnostics, 0, activity.getString(R.string.action_diagnostics));

if (actions.size() > 0 && showAction) {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

item.setIcon(R.drawable.ic_pdk_diagnostic);
item.setTitle("" + actions.size());
} else {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

if (actions.size() > 0) {
item.setTitle(activity.getString(R.string.action_diagnostics_incomplete, actions.size()));
}
}
}

public static boolean diagnosticItemSelected(Activity activity, MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_diagnostics) {
Intent diagnosticsIntent = new Intent(activity, DiagnosticsActivity.class);
activity.startActivity(diagnosticsIntent);

return true;
}

return false;
}

private class DiagnosticViewHolder extends RecyclerView.ViewHolder {

private View mView = null;
Expand Down Expand Up @@ -44,42 +79,57 @@ public void bindDiagnosticAction(DiagnosticAction action)
{
this.mAction = action;

TextView message = (TextView) this.mView.findViewById(R.id.message_action);
TextView title = (TextView) this.mView.findViewById(R.id.action_title);
title.setText(action.getTitle());

TextView message = (TextView) this.mView.findViewById(R.id.action_message);
message.setText(action.getMessage());
}
}

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.layout_diagnostics_pdk);
this.getSupportActionBar().setTitle(R.string.title_pdk_diagnostics);
}

final ArrayList<DiagnosticAction> actions = PassiveDataKit.diagnostics(this);
protected void onResume() {
super.onResume();

Log.e("PDK", "ACTIONS COUNT: " + actions.size());
final ArrayList<DiagnosticAction> actions = PassiveDataKit.diagnostics(this);

RecyclerView listView = (RecyclerView) this.findViewById(R.id.list_view);
TextView emptyMessage = (TextView) this.findViewById(R.id.message_no_diagnostics);

listView.setLayoutManager(new LinearLayoutManager(this));
if (actions.size() > 0) {
listView.setVisibility(View.VISIBLE);
emptyMessage.setVisibility(View.GONE);

listView.setAdapter(new RecyclerView.Adapter() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_diagnostic_action, parent, false);
listView.setLayoutManager(new LinearLayoutManager(this));

return new DiagnosticViewHolder(v);
}
listView.setAdapter(new RecyclerView.Adapter() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_diagnostic_action, parent, false);

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
DiagnosticViewHolder diagHolder = (DiagnosticViewHolder) holder;
return new DiagnosticViewHolder(v);
}

diagHolder.bindDiagnosticAction(actions.get(position));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
DiagnosticViewHolder diagHolder = (DiagnosticViewHolder) holder;

@Override
public int getItemCount() {
return actions.size();
}
});
diagHolder.bindDiagnosticAction(actions.get(position));
}

@Override
public int getItemCount() {
return actions.size();
}
});
} else {
listView.setVisibility(View.GONE);
emptyMessage.setVisibility(View.VISIBLE);
}
}
}
Expand Up @@ -8,8 +8,10 @@
public class DiagnosticAction {
private String mMessage = null;
private Runnable mAction = null;
private String mTitle = null;

public DiagnosticAction(String message, Runnable action) {
public DiagnosticAction(String title, String message, Runnable action) {
this.mTitle = title;
this.mMessage = message;
this.mAction = action;
}
Expand All @@ -25,4 +27,8 @@ public void run() {
public String getMessage() {
return this.mMessage;
}

public String getTitle() {
return this.mTitle;
}
}
Expand Up @@ -142,6 +142,7 @@ private void startGenerator() {
final Runnable checkLogs = new Runnable() {
@Override
public void run() {
Log.e("PDK", "CHECK PHONE LOGS");
boolean approved = false;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Expand Down Expand Up @@ -365,7 +366,7 @@ public static ArrayList<DiagnosticAction> diagnostics(final Context context) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED){
final Handler handler = new Handler(Looper.getMainLooper());

actions.add(new DiagnosticAction(context.getString(R.string.diagnostic_call_log_permission_required), new Runnable() {
actions.add(new DiagnosticAction(context.getString(R.string.diagnostic_call_log_permission_required_title), context.getString(R.string.diagnostic_call_log_permission_required), new Runnable() {

@Override
public void run() {
Expand Down
Expand Up @@ -16,6 +16,7 @@
import android.os.Looper;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -119,6 +120,9 @@ private void startGenerator() {
final Runnable checkLogs = new Runnable() {
@Override
public void run() {

Log.e("PDK", "CHECK TEXT LOGS");

boolean approved = false;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Expand Down Expand Up @@ -311,7 +315,7 @@ public static ArrayList<DiagnosticAction> diagnostics(final Context context) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED){
final Handler handler = new Handler(Looper.getMainLooper());

actions.add(new DiagnosticAction(context.getString(R.string.diagnostic_sms_log_permission_required), new Runnable() {
actions.add(new DiagnosticAction(context.getString(R.string.diagnostic_sms_log_permission_required_title), context.getString(R.string.diagnostic_sms_log_permission_required), new Runnable() {

@Override
public void run() {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.SwitchCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -230,7 +231,7 @@ private ArrayList<DiagnosticAction> runDiagostics() {
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() {
actions.add(new DiagnosticAction(me.mContext.getString(R.string.diagnostic_missing_location_permission_title), me.mContext.getString(R.string.diagnostic_missing_location_permission), new Runnable() {

@Override
public void run() {
Expand Down Expand Up @@ -281,6 +282,8 @@ public void onConnectionFailed(ConnectionResult connectionResult) {

@Override
public void onLocationChanged(android.location.Location location) {
Log.e("PDK", "LOCATION CHANGED");

if (location == null)
return;

Expand Down

0 comments on commit 2711f7b

Please sign in to comment.