diff --git a/res/layout/card_generator_app_event.xml b/res/layout/card_generator_app_event.xml new file mode 100755 index 0000000..02f65b2 --- /dev/null +++ b/res/layout/card_generator_app_event.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/card_generator_device_battery.xml b/res/layout/card_generator_device_battery.xml new file mode 100755 index 0000000..3244646 --- /dev/null +++ b/res/layout/card_generator_device_battery.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/databases.xml b/res/values/databases.xml index 672f1cd..57f13d5 100755 --- a/res/values/databases.xml +++ b/res/values/databases.xml @@ -16,4 +16,7 @@ CREATE TABLE history(_id INTEGER PRIMARY KEY AUTOINCREMENT, fetched INTEGER, transmitted INTEGER, observed INTEGER, event_name TEXT, event_details TEXT); + + CREATE TABLE history(_id INTEGER PRIMARY KEY AUTOINCREMENT, fetched INTEGER, transmitted INTEGER, observed INTEGER, health TEXT, level INTERGER, plugged TEXT, present INTEGER, scale INTEGER, temperature INTEGER, voltage INTEGER, technology TEXT, status TEXT); + \ No newline at end of file diff --git a/res/values/generators.xml b/res/values/generators.xml index a6e8f0e..03c8ad8 100755 --- a/res/values/generators.xml +++ b/res/values/generators.xml @@ -116,4 +116,12 @@ No phone calls have been made or received on this device. + + Device Battery + No battery levels have been reported yet. + + + App Event History + No app events have been logged yet. + \ No newline at end of file diff --git a/src/com/audacious_software/passive_data_kit/activities/generators/DataPointsAdapter.java b/src/com/audacious_software/passive_data_kit/activities/generators/DataPointsAdapter.java index fd1679d..b60d419 100755 --- a/src/com/audacious_software/passive_data_kit/activities/generators/DataPointsAdapter.java +++ b/src/com/audacious_software/passive_data_kit/activities/generators/DataPointsAdapter.java @@ -2,6 +2,7 @@ import android.content.Context; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -36,6 +37,8 @@ public DataPointViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { Method fetchView = generatorClass.getDeclaredMethod("fetchView", ViewGroup.class); View view = (View) fetchView.invoke(null, parent); + Log.e("PDK", "GENERATOR CLASS: " + generatorClass); + return new DataPointViewHolder(view); } catch (NoSuchMethodException e1) { Logger.getInstance(parent.getContext()).logThrowable(e1); @@ -67,6 +70,8 @@ public void onBindViewHolder(final DataPointViewHolder holder, int position) { Method bindViewHolder = generatorClass.getDeclaredMethod("bindViewHolder", DataPointViewHolder.class); + Log.e("PDK", "GENERATOR CLASS: " + generatorClass); + bindViewHolder.invoke(null, holder); } catch (NoSuchMethodException e1) { Logger.getInstance(holder.itemView.getContext()).logThrowable(e1); diff --git a/src/com/audacious_software/passive_data_kit/generators/Generators.java b/src/com/audacious_software/passive_data_kit/generators/Generators.java index 384e0f1..8924585 100755 --- a/src/com/audacious_software/passive_data_kit/generators/Generators.java +++ b/src/com/audacious_software/passive_data_kit/generators/Generators.java @@ -233,6 +233,9 @@ public List> activeGenerators() { for (String className : this.mActiveGenerators) { try { active.add((Class) Class.forName(className)); + + Log.e("PDK", "ACTIVE GENERATOR CLASS: " + className); + } catch (ClassNotFoundException e) { e.printStackTrace(); } diff --git a/src/com/audacious_software/passive_data_kit/generators/device/Battery.java b/src/com/audacious_software/passive_data_kit/generators/device/Battery.java new file mode 100755 index 0000000..c99b1c1 --- /dev/null +++ b/src/com/audacious_software/passive_data_kit/generators/device/Battery.java @@ -0,0 +1,311 @@ +package com.audacious_software.passive_data_kit.generators.device; + +import android.content.BroadcastReceiver; +import android.content.ContentValues; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.os.BatteryManager; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +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.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 java.io.File; +import java.util.ArrayList; +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"; + + private static final String ENABLED = "com.audacious_software.passive_data_kit.generators.device.Battery.ENABLED"; + private static final boolean ENABLED_DEFAULT = true; + + + private static final String DATABASE_PATH = "pdk-device-battery.sqlite"; + private static final int DATABASE_VERSION = 1; + + public static final String TABLE_HISTORY = "history"; + + public static final String HISTORY_OBSERVED = "observed"; + public static final String HISTORY_HEALTH = "health"; + public static final String HISTORY_LEVEL = "level"; + public static final String HISTORY_PLUGGED = "plugged"; + public static final String HISTORY_PRESENT = "present"; + public static final String HISTORY_SCALE = "scale"; + public static final String HISTORY_TEMPERATURE = "temperature"; + public static final String HISTORY_VOLTAGE = "voltage"; + public static final String HISTORY_TECHNOLOGY = "technology"; + public static final String HISTORY_STATUS = "status"; + + private static final String HEALTH_COLD = "cold"; + private static final String HEALTH_DEAD = "dead"; + private static final String HEALTH_GOOD = "good"; + private static final String HEALTH_OVERHEAT = "overheat"; + private static final String HEALTH_OVER_VOLTAGE = "over-voltage"; + private static final String HEALTH_UNSPECIFIED_FAILURE = "unspecified-failure"; + private static final String HEALTH_UNKNOWN = "unknown"; + + private static final String PLUGGED_AC = "ac"; + private static final String PLUGGED_USB = "usb"; + private static final String PLUGGED_WIRELESS = "wireless"; + private static final String PLUGGED_UNKNOWN = "unknown"; + + private static final String TECHNOLOGY_UNKNOWN = "unknown"; + + private static final String STATUS_CHARGING = "charging"; + private static final String STATUS_DISCHARGING = "discharging"; + private static final String STATUS_FULL = "full"; + private static final String STATUS_NOT_CHARGING = "not-charging"; + private static final String STATUS_UNKNOWN = "unknown"; + + private static Battery sInstance = null; + + private BroadcastReceiver mReceiver = null; + + private SQLiteDatabase mDatabase = null; + + public static Battery getInstance(Context context) { + if (Battery.sInstance == null) { + Battery.sInstance = new Battery(context.getApplicationContext()); + } + + return Battery.sInstance; + } + + public Battery(Context context) { + super(context); + } + + public static void start(final Context context) { + Battery.getInstance(context).startGenerator(); + } + + private void startGenerator() { + final Battery me = this; + + this.mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(final Context context, Intent intent) { + long now = System.currentTimeMillis(); + + ContentValues values = new ContentValues(); + values.put(Battery.HISTORY_OBSERVED, now); + + Bundle update = new Bundle(); + update.putLong(Battery.HISTORY_OBSERVED, now); + + switch (intent.getIntExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN)) { + case BatteryManager.BATTERY_HEALTH_COLD: + values.put(Battery.HISTORY_HEALTH, Battery.HEALTH_COLD); + update.putString(Battery.HISTORY_HEALTH, Battery.HEALTH_COLD); + break; + case BatteryManager.BATTERY_HEALTH_DEAD: + values.put(Battery.HISTORY_HEALTH, Battery.HEALTH_DEAD); + update.putString(Battery.HISTORY_HEALTH, Battery.HEALTH_DEAD); + break; + case BatteryManager.BATTERY_HEALTH_GOOD: + values.put(Battery.HISTORY_HEALTH, Battery.HEALTH_GOOD); + update.putString(Battery.HISTORY_HEALTH, Battery.HEALTH_GOOD); + break; + case BatteryManager.BATTERY_HEALTH_OVERHEAT: + values.put(Battery.HISTORY_HEALTH, Battery.HEALTH_OVERHEAT); + update.putString(Battery.HISTORY_HEALTH, Battery.HEALTH_OVERHEAT); + break; + case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: + values.put(Battery.HISTORY_HEALTH, Battery.HEALTH_OVER_VOLTAGE); + update.putString(Battery.HISTORY_HEALTH, Battery.HEALTH_OVER_VOLTAGE); + break; + case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: + values.put(Battery.HISTORY_HEALTH, Battery.HEALTH_UNSPECIFIED_FAILURE); + update.putString(Battery.HISTORY_HEALTH, Battery.HEALTH_UNSPECIFIED_FAILURE); + break; + default: + values.put(Battery.HISTORY_HEALTH, Battery.HEALTH_UNKNOWN); + update.putString(Battery.HISTORY_HEALTH, Battery.HEALTH_UNKNOWN); + break; + } + + switch (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)) { + case BatteryManager.BATTERY_PLUGGED_AC: + values.put(Battery.HISTORY_PLUGGED, Battery.PLUGGED_AC); + update.putString(Battery.HISTORY_PLUGGED, Battery.PLUGGED_AC); + break; + case BatteryManager.BATTERY_PLUGGED_USB: + values.put(Battery.HISTORY_PLUGGED, Battery.PLUGGED_USB); + update.putString(Battery.HISTORY_PLUGGED, Battery.PLUGGED_USB); + break; + case BatteryManager.BATTERY_PLUGGED_WIRELESS: + values.put(Battery.HISTORY_PLUGGED, Battery.PLUGGED_WIRELESS); + update.putString(Battery.HISTORY_PLUGGED, Battery.PLUGGED_WIRELESS); + break; + default: + values.put(Battery.HISTORY_PLUGGED, Battery.PLUGGED_UNKNOWN); + update.putString(Battery.HISTORY_PLUGGED, Battery.PLUGGED_UNKNOWN); + break; + } + + switch (intent.getIntExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_UNKNOWN)) { + case BatteryManager.BATTERY_STATUS_CHARGING: + values.put(Battery.HISTORY_STATUS, Battery.STATUS_CHARGING); + update.putString(Battery.HISTORY_STATUS, Battery.STATUS_CHARGING); + break; + case BatteryManager.BATTERY_STATUS_DISCHARGING: + values.put(Battery.HISTORY_STATUS, Battery.STATUS_DISCHARGING); + update.putString(Battery.HISTORY_STATUS, Battery.STATUS_DISCHARGING); + break; + case BatteryManager.BATTERY_STATUS_FULL: + values.put(Battery.HISTORY_STATUS, Battery.STATUS_FULL); + update.putString(Battery.HISTORY_STATUS, Battery.STATUS_FULL); + break; + case BatteryManager.BATTERY_STATUS_NOT_CHARGING: + values.put(Battery.HISTORY_STATUS, Battery.STATUS_NOT_CHARGING); + update.putString(Battery.HISTORY_STATUS, Battery.STATUS_NOT_CHARGING); + break; + default: + values.put(Battery.HISTORY_STATUS, Battery.STATUS_UNKNOWN); + update.putString(Battery.HISTORY_STATUS, Battery.STATUS_UNKNOWN); + break; + } + + values.put(Battery.HISTORY_PRESENT, intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)); + update.putBoolean(Battery.HISTORY_PRESENT, intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)); + + values.put(Battery.HISTORY_LEVEL, intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)); + update.putInt(Battery.HISTORY_LEVEL, intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)); + + values.put(Battery.HISTORY_SCALE, intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)); + update.putInt(Battery.HISTORY_SCALE, intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)); + + values.put(Battery.HISTORY_TEMPERATURE, intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)); + update.putInt(Battery.HISTORY_TEMPERATURE, intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)); + + values.put(Battery.HISTORY_VOLTAGE, intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1)); + update.putInt(Battery.HISTORY_VOLTAGE, intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1)); + + values.put(Battery.HISTORY_TECHNOLOGY, Battery.TECHNOLOGY_UNKNOWN); + update.putString(Battery.HISTORY_TECHNOLOGY, Battery.TECHNOLOGY_UNKNOWN); + + me.mDatabase.insert(Battery.TABLE_HISTORY, null, values); + + Generators.getInstance(context).notifyGeneratorUpdated(Battery.GENERATOR_IDENTIFIER, update); + } + }; + + IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + + this.mContext.registerReceiver(this.mReceiver, filter); + + Generators.getInstance(this.mContext).registerCustomViewClass(Battery.GENERATOR_IDENTIFIER, Battery.class); + + File path = PassiveDataKit.getGeneratorsStorage(this.mContext); + + path = new File(path, Battery.DATABASE_PATH); + + this.mDatabase = SQLiteDatabase.openOrCreateDatabase(path, null); + + int version = this.getDatabaseVersion(this.mDatabase); + + switch (version) { + case 0: + this.mDatabase.execSQL(this.mContext.getString(R.string.pdk_generator_device_battery_create_history_table)); + } + + this.setDatabaseVersion(this.mDatabase, Battery.DATABASE_VERSION); + } + + public static boolean isEnabled(Context context) { + SharedPreferences prefs = Generators.getInstance(context).getSharedPreferences(context); + + return prefs.getBoolean(Battery.ENABLED, Battery.ENABLED_DEFAULT); + } + + public static boolean isRunning(Context context) { + if (Battery.sInstance == null) { + return false; + } + + return Battery.sInstance.mReceiver != null; + } + + public static ArrayList diagnostics(Context context) { + return new ArrayList<>(); + } + + public static void bindViewHolder(DataPointViewHolder holder) { + final Context context = holder.itemView.getContext(); + + Battery generator = Battery.getInstance(context); + + Cursor c = generator.mDatabase.query(Battery.TABLE_HISTORY, null, null, null, null, null, Battery.HISTORY_OBSERVED + " DESC"); + + View cardContent = holder.itemView.findViewById(R.id.card_content); + View cardEmpty = holder.itemView.findViewById(R.id.card_empty); + TextView dateLabel = (TextView) holder.itemView.findViewById(R.id.generator_data_point_date); + + if (c.moveToNext()) { + cardContent.setVisibility(View.VISIBLE); + cardEmpty.setVisibility(View.GONE); + + long timestamp = c.getLong(c.getColumnIndex(Battery.HISTORY_OBSERVED)) / 1000; + + dateLabel.setText(Generator.formatTimestamp(context, timestamp)); + + TextView lastLevel = (TextView) holder.itemView.findViewById(R.id.card_last_battery_level); + lastLevel.setText("TODO: LEVEL " + c.getInt(c.getColumnIndex(Battery.HISTORY_LEVEL))); + } else { + cardContent.setVisibility(View.GONE); + cardEmpty.setVisibility(View.VISIBLE); + + dateLabel.setText(R.string.label_never_pdk); + } + + c.close(); + } + + public static View fetchView(ViewGroup parent) + { + return LayoutInflater.from(parent.getContext()).inflate(R.layout.card_generator_device_battery, parent, false); + } + + @Override + public List fetchPayloads() { + return new ArrayList<>(); + } + + public static long latestPointGenerated(Context context) { + long timestamp = 0; + + Battery me = Battery.getInstance(context); + + Cursor c = me.mDatabase.query(Battery.TABLE_HISTORY, null, null, null, null, null, Battery.HISTORY_OBSERVED + " DESC"); + + if (c.moveToNext()) { + timestamp = c.getLong(c.getColumnIndex(Battery.HISTORY_OBSERVED)); + } + + c.close(); + + return timestamp; + } + + public Cursor queryHistory(String[] cols, String where, String[] args, String orderBy) { + return this.mDatabase.query(Battery.TABLE_HISTORY, cols, where, args, null, null, orderBy); + } +} diff --git a/src/com/audacious_software/passive_data_kit/generators/diagnostics/AppEvent.java b/src/com/audacious_software/passive_data_kit/generators/diagnostics/AppEvent.java index e92d291..75c420f 100755 --- a/src/com/audacious_software/passive_data_kit/generators/diagnostics/AppEvent.java +++ b/src/com/audacious_software/passive_data_kit/generators/diagnostics/AppEvent.java @@ -9,6 +9,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import com.audacious_software.passive_data_kit.PassiveDataKit; import com.audacious_software.passive_data_kit.activities.generators.DataPointViewHolder; @@ -96,37 +97,11 @@ public static ArrayList diagnostics(Context context) { } public static void bindViewHolder(DataPointViewHolder holder) { -/* final Context context = holder.itemView.getContext(); + final Context context = holder.itemView.getContext(); - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); + AppEvent generator = AppEvent.getInstance(context); - long zeroStart = cal.getTimeInMillis(); - cal.add(Calendar.DATE, -1); - - LinearLayout zeroTimeline = (LinearLayout) holder.itemView.findViewById(R.id.day_zero_value); - - AppEvents.populateTimeline(context, zeroTimeline, zeroStart); - - long oneStart = cal.getTimeInMillis(); - cal.add(Calendar.DATE, -1); - - LinearLayout oneTimeline = (LinearLayout) holder.itemView.findViewById(R.id.day_one_value); - - AppEvents.populateTimeline(context, oneTimeline, oneStart); - - long twoStart = cal.getTimeInMillis(); - - LinearLayout twoTimeline = (LinearLayout) holder.itemView.findViewById(R.id.day_two_value); - - AppEvents.populateTimeline(context, twoTimeline, twoStart); - - AppEvents generator = AppEvents.getInstance(context); - - Cursor c = generator.mDatabase.query(AppEvents.TABLE_HISTORY, null, null, null, null, null, AppEvents.HISTORY_OBSERVED + " DESC"); + Cursor c = generator.mDatabase.query(AppEvent.TABLE_HISTORY, null, null, null, null, null, AppEvent.HISTORY_OBSERVED + " DESC"); View cardContent = holder.itemView.findViewById(R.id.card_content); View cardEmpty = holder.itemView.findViewById(R.id.card_empty); @@ -136,25 +111,13 @@ public static void bindViewHolder(DataPointViewHolder holder) { cardContent.setVisibility(View.VISIBLE); cardEmpty.setVisibility(View.GONE); - long timestamp = c.getLong(c.getColumnIndex(AppEvents.HISTORY_OBSERVED)) / 1000; + long timestamp = c.getLong(c.getColumnIndex(AppEvent.HISTORY_OBSERVED)) / 1000; dateLabel.setText(Generator.formatTimestamp(context, timestamp)); - cal = Calendar.getInstance(); - DateFormat format = android.text.format.DateFormat.getDateFormat(context); - - TextView zeroDayLabel = (TextView) holder.itemView.findViewById(R.id.day_zero_label); - zeroDayLabel.setText(format.format(cal.getTime())); - - cal.add(Calendar.DATE, -1); - - TextView oneDayLabel = (TextView) holder.itemView.findViewById(R.id.day_one_label); - oneDayLabel.setText(format.format(cal.getTime())); - - cal.add(Calendar.DATE, -1); + TextView eventCount = (TextView) holder.itemView.findViewById(R.id.card_app_event_count); - TextView twoDayLabel = (TextView) holder.itemView.findViewById(R.id.day_two_label); - twoDayLabel.setText(format.format(cal.getTime())); + eventCount.setText("TODO: EVENT VIEW - " + c.getCount()); } else { cardContent.setVisibility(View.GONE); cardEmpty.setVisibility(View.VISIBLE); @@ -163,188 +126,11 @@ public static void bindViewHolder(DataPointViewHolder holder) { } c.close(); - */ - } - - /* - private static void populateTimeline(Context context, LinearLayout timeline, long start) { - timeline.removeAllViews(); - - AppEvents generator = AppEvents.getInstance(context); - - long end = start + (24 * 60 * 60 * 1000); - - String where = AppEvents.HISTORY_OBSERVED + " >= ? AND " + AppEvents.HISTORY_OBSERVED + " < ?"; - String[] args = { "" + start, "" + end }; - - Cursor c = generator.mDatabase.query(AppEvents.TABLE_HISTORY, null, where, args, null, null, AppEvents.HISTORY_OBSERVED); - - ArrayList activeStates = new ArrayList<>(); - ArrayList activeTimestamps = new ArrayList<>(); - - while (c.moveToNext()) { - long timestamp = c.getLong(c.getColumnIndex(AppEvents.HISTORY_OBSERVED)); - - activeTimestamps.add(timestamp); - - String state = c.getString(c.getColumnIndex(AppEvents.HISTORY_STATE)); - activeStates.add(state); - } - - c.close(); - - String lastState = AppEvents.STATE_UNKNOWN; - - String lastWhere = AppEvents.HISTORY_OBSERVED + " < ?"; - String[] lastArgs = { "" + start }; - - c = generator.mDatabase.query(AppEvents.TABLE_HISTORY, null, lastWhere, lastArgs, null, null, AppEvents.HISTORY_OBSERVED + " DESC"); - - if (c.moveToNext()) { - lastState = c.getString(c.getColumnIndex(AppEvents.HISTORY_STATE)); - } - - if (activeStates.size() > 0) { - long firstTimestamp = activeTimestamps.get(0); - long firstState = activeTimestamps.get(0); - - View startView = new View(context); - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { - if (AppEvents.STATE_UNKNOWN.equals(lastState)) { - - } else if (AppEvents.STATE_ON.equals(lastState)) { - startView.setBackgroundColor(0xff4CAF50); - } else if (AppEvents.STATE_OFF.equals(lastState)) { - startView.setBackgroundColor(0xff263238); - } else if (AppEvents.STATE_DOZE.equals(lastState)) { - startView.setBackgroundColor(0xff1b5e20); - } else if (AppEvents.STATE_DOZE_SUSPEND.equals(lastState)) { - startView.setBackgroundColor(0xff1b5e20); - } - } else { - if (AppEvents.STATE_UNKNOWN.equals(lastState)) { - - } else if (AppEvents.STATE_ON.equals(lastState)) { - startView.setBackgroundColor(0xff4CAF50); - } else if (AppEvents.STATE_OFF.equals(lastState)) { - startView.setBackgroundColor(0xff263238); - } - } - - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, firstTimestamp - start); - startView.setLayoutParams(params); - - timeline.addView(startView); - - long now = System.currentTimeMillis(); - - if (activeStates.size() == 1) { - View v = new View(context); - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { - if (AppEvents.STATE_ON.equals(firstState)) { - v.setBackgroundColor(0xff4CAF50); - } else if (AppEvents.STATE_OFF.equals(firstState)) { - v.setBackgroundColor(0xff263238); - } else if (AppEvents.STATE_DOZE.equals(firstState)) { - v.setBackgroundColor(0xff3f51b5); - } else if (AppEvents.STATE_DOZE_SUSPEND.equals(firstState)) { - v.setBackgroundColor(0xff3f51b5); - } - } else { - if (AppEvents.STATE_ON.equals(firstState)) { - v.setBackgroundColor(0xff4CAF50); - } else if (AppEvents.STATE_OFF.equals(firstState)) { - v.setBackgroundColor(0xff263238); - } - } - - if (end > System.currentTimeMillis()) { - params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, now - firstTimestamp); - v.setLayoutParams(params); - } else { - params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, end - firstTimestamp); - v.setLayoutParams(params); - } - - timeline.addView(v); - } else { - for (int i = 1; i < activeStates.size(); i++) { - long currentTimestamp = activeTimestamps.get(i); - - long priorTimestamp = activeTimestamps.get(i - 1); - String priorState = activeStates.get(i - 1); - - View v = new View(context); - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { - if (AppEvents.STATE_ON.equals(priorState)) { - v.setBackgroundColor(0xff4CAF50); - } else if (AppEvents.STATE_OFF.equals(priorState)) { - v.setBackgroundColor(0xff263238); - } else if (AppEvents.STATE_DOZE.equals(priorState)) { - v.setBackgroundColor(0xff3f51b5); - } else if (AppEvents.STATE_DOZE_SUSPEND.equals(priorState)) { - v.setBackgroundColor(0xff3f51b5); - } - } else { - if (AppEvents.STATE_ON.equals(priorState)) { - v.setBackgroundColor(0xff4CAF50); - } else if (AppEvents.STATE_OFF.equals(priorState)) { - v.setBackgroundColor(0xff263238); - } - } - - params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, currentTimestamp - priorTimestamp); - v.setLayoutParams(params); - - timeline.addView(v); - } - - long finalTimestamp = activeTimestamps.get(activeTimestamps.size() - 1); - String finalState = activeStates.get(activeStates.size() - 1); - - View v = new View(context); - - if (AppEvents.STATE_ON.equals(finalState)) { - v.setBackgroundColor(0xff4CAF50); - } else if (AppEvents.STATE_OFF.equals(finalState)) { - v.setBackgroundColor(0xff263238); - } else if (AppEvents.STATE_DOZE.equals(finalState)) { - v.setBackgroundColor(0xff3f51b5); - } else if (AppEvents.STATE_DOZE_SUSPEND.equals(finalState)) { - v.setBackgroundColor(0xff3f51b5); - } - - if (end > now) { - params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, now - finalTimestamp); - v.setLayoutParams(params); - } else { - params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, end - finalTimestamp); - v.setLayoutParams(params); - } - - timeline.addView(v); - } - - if (end > now) { - View v = new View(context); - - params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, end - now); - v.setLayoutParams(params); - - timeline.addView(v); - } - } else { - - } } -*/ public static View fetchView(ViewGroup parent) { - return LayoutInflater.from(parent.getContext()).inflate(R.layout.card_generator_generic, parent, false); + return LayoutInflater.from(parent.getContext()).inflate(R.layout.card_generator_app_event, parent, false); } @Override diff --git a/src/com/audacious_software/passive_data_kit/generators/sensors/Accelerometer.java b/src/com/audacious_software/passive_data_kit/generators/sensors/Accelerometer.java new file mode 100755 index 0000000..3828e56 --- /dev/null +++ b/src/com/audacious_software/passive_data_kit/generators/sensors/Accelerometer.java @@ -0,0 +1,8 @@ +package com.audacious_software.passive_data_kit.generators.sensors; + +/** + * Created by cjkarr on 4/17/2017. + */ + +public class Accelerometer { +} diff --git a/src/com/audacious_software/passive_data_kit/generators/sensors/AmbientLight.java b/src/com/audacious_software/passive_data_kit/generators/sensors/AmbientLight.java new file mode 100755 index 0000000..09c7f3c --- /dev/null +++ b/src/com/audacious_software/passive_data_kit/generators/sensors/AmbientLight.java @@ -0,0 +1,8 @@ +package com.audacious_software.passive_data_kit.generators.sensors; + +/** + * Created by cjkarr on 4/17/2017. + */ + +public class AmbientLight { +}