Skip to content

Commit

Permalink
Generator bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
audaciouscode committed May 21, 2017
1 parent f30b56b commit 7dcf4e0
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 55 deletions.
9 changes: 6 additions & 3 deletions res/layout/card_generator_sensors_accelerometer.xml
Expand Up @@ -45,14 +45,17 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp">
android:padding="0dp"
android:background="@android:color/black">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/accelerometer_chart"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginBottom="0dp"/>
android:layout_marginBottom="0dp"
android:background="@android:color/black" />
</LinearLayout>
<TextView android:id="@+id/card_empty"
<TextView android:visibility="gone"
android:id="@+id/card_empty"
android:text="@string/message_generator_accelerometer_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
9 changes: 6 additions & 3 deletions res/layout/card_generator_sensors_ambient_light.xml
Expand Up @@ -45,14 +45,17 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp">
android:padding="0dp"
android:background="@android:color/black">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/light_chart"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginBottom="0dp"/>
android:layout_marginBottom="0dp"
android:background="@android:color/black" />
</LinearLayout>
<TextView android:id="@+id/card_empty"
<TextView android:visibility="gone"
android:id="@+id/card_empty"
android:text="@string/message_generator_ambient_light_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions res/values/colors.xml
Expand Up @@ -3,4 +3,6 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>

<color name="pdk_chart_loading_color">#E0E0E0</color>
</resources>
2 changes: 2 additions & 0 deletions res/values/strings.xml
Expand Up @@ -29,5 +29,7 @@

<string name="label_data_collection_description">Data Collection Description</string>
<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>
</resources>

11 changes: 6 additions & 5 deletions src/com/audacious_software/passive_data_kit/PassiveDataKit.java
Expand Up @@ -16,12 +16,13 @@ public class PassiveDataKit {
private boolean mStarted = false;

public void start() {
if (!this.mStarted)
{
Generators.getInstance(this.mContext).start();
Logger.getInstance(this.mContext);
synchronized (this) {
if (!this.mStarted) {
this.mStarted = true;

this.mStarted = true;
Generators.getInstance(this.mContext).start();
Logger.getInstance(this.mContext);
}
}
}

Expand Down
Expand Up @@ -35,49 +35,46 @@ public class Generators {
private HashMap<String, PowerManager.WakeLock> mWakeLocks = new HashMap<>();

public void start() {
if (!this.mStarted)
{
this.mGenerators.clear();
synchronized (this) {
if (!this.mStarted) {
this.mStarted = true;

this.mGenerators.add(AppEvent.class.getCanonicalName());
this.mGenerators.clear();

for (String className : this.mContext.getResources().getStringArray(R.array.pdk_available_generators))
{
this.mGenerators.add(className);
}

for (String className : this.mContext.getResources().getStringArray(R.array.pdk_app_generators))
{
this.mGenerators.add(className);
}

for (String className : this.mGenerators)
{
try {
Class<Generator> probeClass = (Class<Generator>) Class.forName(className);
this.mGenerators.add(AppEvent.class.getCanonicalName());

Method isEnabled = probeClass.getDeclaredMethod("isEnabled", Context.class);
for (String className : this.mContext.getResources().getStringArray(R.array.pdk_available_generators)) {
this.mGenerators.add(className);
}

Boolean enabled = (Boolean) isEnabled.invoke(null, this.mContext);
for (String className : this.mContext.getResources().getStringArray(R.array.pdk_app_generators)) {
this.mGenerators.add(className);
}

if (enabled) {
this.startGenerator(className);
for (String className : this.mGenerators) {
try {
Class<Generator> probeClass = (Class<Generator>) Class.forName(className);

Method isEnabled = probeClass.getDeclaredMethod("isEnabled", Context.class);

Boolean enabled = (Boolean) isEnabled.invoke(null, this.mContext);

if (enabled) {
this.startGenerator(className);
} else {
this.stopGenerator(className);
}
} catch (ClassNotFoundException e) {
Logger.getInstance(this.mContext).logThrowable(e);
} catch (NoSuchMethodException e) {
Logger.getInstance(this.mContext).logThrowable(e);
} catch (InvocationTargetException e) {
Logger.getInstance(this.mContext).logThrowable(e);
} catch (IllegalAccessException e) {
Logger.getInstance(this.mContext).logThrowable(e);
}
else {
this.stopGenerator(className);
}
} catch (ClassNotFoundException e) {
Logger.getInstance(this.mContext).logThrowable(e);
} catch (NoSuchMethodException e) {
Logger.getInstance(this.mContext).logThrowable(e);
} catch (InvocationTargetException e) {
Logger.getInstance(this.mContext).logThrowable(e);
} catch (IllegalAccessException e) {
Logger.getInstance(this.mContext).logThrowable(e);
}
}

this.mStarted = true;
}
}

Expand Down
Expand Up @@ -114,10 +114,6 @@ public static void start(final Context context) {
private void startGenerator() {
final Battery me = this;

final long now = System.currentTimeMillis();

me.mLastTimestamp = now;

this.mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
Expand All @@ -127,6 +123,10 @@ public void onReceive(final Context context, Intent intent) {
return;
}

long now = System.currentTimeMillis();

me.mLastTimestamp = now;

ContentValues values = new ContentValues();
values.put(Battery.HISTORY_OBSERVED, now);

Expand Down
Expand Up @@ -368,6 +368,10 @@ public static void bindViewHolder(final DataPointViewHolder holder) {

dateLabel.setText(Generator.formatTimestamp(context, Accelerometer.latestPointGenerated(generator.mContext) / 1000));

LineChart chart = (LineChart) holder.itemView.findViewById(R.id.accelerometer_chart);
chart.setNoDataText(context.getString(R.string.pdk_generator_chart_loading_data));
chart.setNoDataTextColor(0xFFE0E0E0);

Runnable r = new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -593,6 +597,7 @@ public String getFormattedValue(float value, AxisBase axis) {
chart.getDescription().setEnabled(false);

chart.setVisibleYRange((float) Math.floor(finalMinValue) - 1, (float) Math.ceil(finalMaxValue) + 1, YAxis.AxisDependency.LEFT);
chart.setNoDataText(context.getString(R.string.pdk_generator_chart_loading_data));
chart.setData(chartData);
}

Expand Down
Expand Up @@ -19,7 +19,6 @@
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -46,10 +45,6 @@
import java.util.Date;
import java.util.List;

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

public class AmbientLight extends SensorGenerator implements SensorEventListener {
private static final String GENERATOR_IDENTIFIER = "pdk-sensor-light";

Expand Down Expand Up @@ -286,6 +281,10 @@ public static void bindViewHolder(final DataPointViewHolder holder) {

dateLabel.setText(Generator.formatTimestamp(context, AmbientLight.latestPointGenerated(context) / 1000));

LineChart chart = (LineChart) holder.itemView.findViewById(R.id.light_chart);
chart.setNoDataText(context.getString(R.string.pdk_generator_chart_loading_data));
chart.setNoDataTextColor(0xFFE0E0E0);

Runnable r = new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit 7dcf4e0

Please sign in to comment.