Skip to content

Commit

Permalink
Implemented additional data disclosure infrastructure for existing ge…
Browse files Browse the repository at this point in the history
…nerators.

* Fixed issue in Foreground Application generator when the package name is null.
  • Loading branch information
audaciouscode committed May 23, 2017
1 parent 5fc567b commit 43e359f
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 69 deletions.
26 changes: 26 additions & 0 deletions assets/html/passive_data_kit/generator_app_events_disclosure.html
@@ -0,0 +1,26 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<style type="text/css">
body,
* {
font-family:-apple-system,Helvetica Neue;
font-size: 16px;
}

body {
background-color: F5F5F5;
}
</style>

</head>
<body>
<p>
<em>TODO: Write disclosure for use of app event data...</em>
</p>

<p>
Place completed file in <code>assets/html/passive_data_kit/generator_app_event_disclosure.html</code> in your project to override this placeholder.
</p>
</body>
</html>
8 changes: 8 additions & 0 deletions res/layout/pdk_placeholder_disclosure_view.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:text="@string/pdk_placeholder_disclosure_not_implemented"
android:padding="64dp">
</TextView>
2 changes: 2 additions & 0 deletions res/values/strings.xml
Expand Up @@ -31,5 +31,7 @@
<string name="label_data_collection_description_more">Tap here to learn how this app uses your data.</string>

<string name="pdk_generator_chart_loading_data">Waiting for chart data&#8230;</string>

<string name="pdk_placeholder_disclosure_not_implemented">A disclosure view is not implemented for this generator.\n\nContact the app developer for assistance&#8230;</string>
</resources>

Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -84,8 +83,6 @@ public View getView (int position, View convertView, ViewGroup parent) {
actionsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Log.e("PDK", "TAPPED: " + position);

Action action = actions.get(position);

FrameLayout dataView = (FrameLayout) me.findViewById(R.id.data_view);
Expand Down
@@ -1,6 +1,5 @@
package com.audacious_software.passive_data_kit.activities;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
Expand All @@ -9,16 +8,13 @@
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.Menu;
import android.view.MenuItem;

import com.audacious_software.passive_data_kit.activities.generators.DataPointsAdapter;
import com.audacious_software.passive_data_kit.generators.Generators;
import com.audacious_software.pdk.passivedatakit.R;

import java.util.ArrayList;

public class DataStreamActivity extends AppCompatActivity implements Generators.GeneratorUpdatedListener {
private DataPointsAdapter mAdapter = null;
private Menu mMenu = null;
Expand Down Expand Up @@ -82,7 +78,13 @@ public void onGeneratorUpdated(String identifier, long timestamp, Bundle data) {
@Override
public void run() {
me.mAdapter.sortGenerators();
me.mAdapter.notifyDataSetChanged();

try {
me.mAdapter.notifyDataSetChanged();
} catch (IllegalStateException e) {
// Do nothing - recycler is already updating...
}

int count = me.mAdapter.getItemCount();
me.getSupportActionBar().setSubtitle(me.getResources().getQuantityString(R.plurals.activity_data_stream_subtitle, count, count));

Expand Down
Expand Up @@ -3,14 +3,8 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.audacious_software.passive_data_kit.generators.wearables.WithingsDevice;
import com.audacious_software.pdk.passivedatakit.R;

/**
* Created by cjkarr on 3/18/2017.
*/

public class OAuthResponseActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -22,9 +16,6 @@ protected void onResume() {

Uri u = this.getIntent().getData();

Log.e("PDK", "CALLBACK FROM OAUTH: " + u);
Log.e("PDK", "PATH: " + u.getPath());

if (u.getPath().startsWith(WithingsDevice.API_OAUTH_CALLBACK_PATH)) {
WithingsDevice.getInstance(this).finishAuthentication(u);
}
Expand Down
Expand Up @@ -4,13 +4,13 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.audacious_software.passive_data_kit.Logger;
import com.audacious_software.passive_data_kit.generators.Generator;
import com.audacious_software.passive_data_kit.generators.Generators;
import com.audacious_software.passive_data_kit.generators.diagnostics.AppEvent;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -75,6 +75,8 @@ public void onBindViewHolder(final DataPointViewHolder holder, int position) {
Method bindViewHolder = generatorClass.getDeclaredMethod("bindViewHolder", DataPointViewHolder.class);
bindViewHolder.invoke(null, holder);
} catch (Exception e) {
AppEvent.getInstance(this.mContext).logThrowable(e);

try {
generatorClass = Generator.class;

Expand Down
Expand Up @@ -3,12 +3,12 @@
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.TextView;

import com.audacious_software.passive_data_kit.Logger;
import com.audacious_software.passive_data_kit.activities.DataDisclosureDetailActivity;
Expand All @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;

public class GeneratorsAdapter extends RecyclerView.Adapter<GeneratorViewHolder> {
private Context mContext = null;
Expand All @@ -43,26 +44,14 @@ public void onBindViewHolder(final GeneratorViewHolder holder, int position) {

Class<? extends Generator> generatorClass = activeGenerators.get(position);

Log.e("PDK", "GENERATOR CLASS: " + generatorClass);

try {
Method bindViewHolder = generatorClass.getDeclaredMethod("bindDisclosureViewHolder", GeneratorViewHolder.class);
bindViewHolder.invoke(null, holder);
} catch (Exception e) {
// e.printStackTrace();
try {
generatorClass = Generator.class;

Method bindViewHolder = generatorClass.getDeclaredMethod("bindDisclosureViewHolder", GeneratorViewHolder.class);

bindViewHolder.invoke(null, holder);
} catch (NoSuchMethodException e1) {
Logger.getInstance(holder.itemView.getContext()).logThrowable(e1);
} catch (InvocationTargetException e1) {
Logger.getInstance(holder.itemView.getContext()).logThrowable(e1);
} catch (IllegalAccessException e1) {
Logger.getInstance(holder.itemView.getContext()).logThrowable(e1);
}
TextView generatorLabel = (TextView) holder.itemView.findViewById(R.id.label_generator);

String[] tokens = generatorClass.getName().split(Pattern.quote("."));
generatorLabel.setText(tokens[tokens.length - 1] + "*");
}

final Class<? extends Generator> finalClass = generatorClass;
Expand All @@ -72,23 +61,40 @@ public void onBindViewHolder(final GeneratorViewHolder holder, int position) {
public void onClick(View view) {
me.mDataView.removeAllViews();

View dataView = LayoutInflater.from(holder.itemView.getContext()).inflate(R.layout.pdk_placeholder_disclosure_view, null);

try {
Method bindViewHolder = finalClass.getDeclaredMethod("getDisclosureDataView", GeneratorViewHolder.class);

View dataView = (View) bindViewHolder.invoke(null, holder);
me.mDataView.addView(dataView);
dataView = (View) bindViewHolder.invoke(null, holder);
} catch (NoSuchMethodException e1) {
Logger.getInstance(holder.itemView.getContext()).logThrowable(e1);
} catch (InvocationTargetException e1) {
Logger.getInstance(holder.itemView.getContext()).logThrowable(e1);
} catch (IllegalAccessException e1) {
Logger.getInstance(holder.itemView.getContext()).logThrowable(e1);
}

me.mDataView.addView(dataView);
}
});

ImageView settingsButton = (ImageView) holder.itemView.findViewById(R.id.button_disclosure_item);

settingsButton.setVisibility(View.GONE);

try {
Method getDisclosureActions = finalClass.getDeclaredMethod("getDisclosureActions", Context.class);

final List<DataDisclosureDetailActivity.Action> actions = (List<DataDisclosureDetailActivity.Action>) getDisclosureActions.invoke(null, holder.itemView.getContext());

if (actions.size() > 0) {
settingsButton.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
// Do nothing - leave invisible...
}

settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -98,7 +104,6 @@ public void onClick(View view) {
holder.itemView.getContext().startActivity(intent);
}
});

}

@Override
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.audacious_software.passive_data_kit.PassiveDataKit;
import com.audacious_software.passive_data_kit.activities.generators.DataPointViewHolder;
import com.audacious_software.passive_data_kit.activities.generators.GeneratorViewHolder;
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;
Expand All @@ -37,10 +38,6 @@
import java.util.Date;
import java.util.List;

/**
* Created by cjkarr on 4/17/2017.
*/

public class Battery extends Generator {
private static final String GENERATOR_IDENTIFIER = "pdk-device-battery";

Expand Down Expand Up @@ -280,6 +277,16 @@ public static ArrayList<DiagnosticAction> diagnostics(Context context) {
return new ArrayList<>();
}

public static String getGeneratorTitle(Context context) {
return context.getString(R.string.generator_device_battery);
}

public static void bindDisclosureViewHolder(final GeneratorViewHolder holder) {
TextView generatorLabel = (TextView) holder.itemView.findViewById(R.id.label_generator);

generatorLabel.setText(Battery.getGeneratorTitle(holder.itemView.getContext()));
}

public static void bindViewHolder(DataPointViewHolder holder) {
final Context context = holder.itemView.getContext();

Expand Down
Expand Up @@ -12,7 +12,6 @@
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -24,6 +23,7 @@

import com.audacious_software.passive_data_kit.PassiveDataKit;
import com.audacious_software.passive_data_kit.activities.generators.DataPointViewHolder;
import com.audacious_software.passive_data_kit.activities.generators.GeneratorViewHolder;
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;
Expand All @@ -38,10 +38,6 @@
import java.util.HashMap;
import java.util.List;

/**
* Created by cjkarr on 5/10/2017.
*/

public class ForegroundApplication extends Generator{

private static final String GENERATOR_IDENTIFIER = "pdk-foreground-application";
Expand Down Expand Up @@ -190,6 +186,16 @@ public void run() {
return actions;
}

public static String getGeneratorTitle(Context context) {
return context.getString(R.string.generator_foreground_application);
}

public static void bindDisclosureViewHolder(final GeneratorViewHolder holder) {
TextView generatorLabel = (TextView) holder.itemView.findViewById(R.id.label_generator);

generatorLabel.setText(ForegroundApplication.getGeneratorTitle(holder.itemView.getContext()));
}

public static void bindViewHolder(DataPointViewHolder holder) {
final Context context = holder.itemView.getContext();

Expand Down Expand Up @@ -345,27 +351,37 @@ public int compare(HashMap<String, Double> mapOne, HashMap<String, Double> mapTw
}

for (int i = 0; i < whenAppRowIds.length && i < latest.size(); i++) {
String appPackage = latest.get(i);
int appRowId = whenAppRowIds[i];

View row = cardContent.findViewById(appRowId);
row.setVisibility(View.VISIBLE);

TextView appName = (TextView) row.findViewById(R.id.app_name);
ImageView appIcon = (ImageView) row.findViewById(R.id.application_icon);
String appPackage = latest.get(i);

try {
String name = packageManager.getApplicationLabel(packageManager.getApplicationInfo(appPackage, PackageManager.GET_META_DATA)).toString();
while (appPackage == null && i < latest.size() - 1) {
i += 1;

appName.setText(name);
Drawable icon = packageManager.getApplicationIcon(appPackage);
appIcon.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException e) {
AppEvent.getInstance(context).logThrowable(e);
appPackage = latest.get(i);
}

TextView appWhen = (TextView) row.findViewById(R.id.app_last_used);
appWhen.setText(Generator.formatTimestamp(context, appWhens.get(appPackage) / 1000));
if (appPackage != null) {
View row = cardContent.findViewById(appRowId);
row.setVisibility(View.VISIBLE);

TextView appName = (TextView) row.findViewById(R.id.app_name);
ImageView appIcon = (ImageView) row.findViewById(R.id.application_icon);

try {
String name = packageManager.getApplicationLabel(packageManager.getApplicationInfo(appPackage, PackageManager.GET_META_DATA)).toString();

appName.setText(name);
Drawable icon = packageManager.getApplicationIcon(appPackage);
appIcon.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException e) {
appName.setText("" + appPackage);
appIcon.setImageDrawable(null);
}

TextView appWhen = (TextView) row.findViewById(R.id.app_last_used);
appWhen.setText(Generator.formatTimestamp(context, appWhens.get(appPackage) / 1000));
}
}

cardContent.setVisibility(View.VISIBLE);
Expand Down

0 comments on commit 43e359f

Please sign in to comment.