forked from fossasia/pslab-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
265 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/java/io/pslab/widgets/loggedData/LoggedDataWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.pslab.widgets.loggedData; | ||
|
||
import android.appwidget.AppWidgetManager; | ||
import android.appwidget.AppWidgetProvider; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.widget.RemoteViews; | ||
|
||
import io.pslab.R; | ||
import io.pslab.activity.DataLoggerActivity; | ||
|
||
public class LoggedDataWidget extends AppWidgetProvider { | ||
@Override | ||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | ||
for (int i = 0; i < appWidgetIds.length; i++) { | ||
Intent intent = new Intent(context, logDataWidgetService.class); | ||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); | ||
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); | ||
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.logged_data_widget); | ||
rv.setRemoteAdapter(android.R.id.list, intent); | ||
rv.setEmptyView(android.R.id.list, R.id.data_logger_list_view); | ||
appWidgetManager.updateAppWidget(appWidgetIds[i], rv); | ||
} | ||
|
||
super.onUpdate(context, appWidgetManager, appWidgetIds); | ||
} | ||
} | ||
|
155 changes: 155 additions & 0 deletions
155
app/src/main/java/io/pslab/widgets/loggedData/logDataWidgetList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package io.pslab.widgets.loggedData; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.v7.widget.DividerItemDecoration; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.view.View; | ||
import android.widget.RemoteViews; | ||
import android.widget.RemoteViewsService; | ||
|
||
import io.pslab.R; | ||
import io.pslab.adapters.SensorLoggerListAdapter; | ||
import io.pslab.models.PSLabSensor; | ||
import io.pslab.models.SensorDataBlock; | ||
import io.pslab.others.CSVLogger; | ||
import io.pslab.others.LocalDataLog; | ||
import io.realm.Realm; | ||
import io.realm.RealmResults; | ||
|
||
public class logDataWidgetList implements RemoteViewsService.RemoteViewsFactory { | ||
|
||
private List<SensorDataBlock> results = new ArrayList<>(); | ||
private Context context; | ||
private RealmResults<SensorDataBlock> entities; | ||
private Realm realm; | ||
// private int appWidgetId; | ||
|
||
public logDataWidgetList(Context context, Intent intent) { | ||
|
||
this.context = context; | ||
// appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
refreshEntities(); | ||
} | ||
|
||
private void refreshEntities() { | ||
realm = LocalDataLog.with().getRealm(); | ||
entities = LocalDataLog.with().getAllSensorBlocks(); | ||
} | ||
|
||
@Override | ||
public RemoteViews getViewAt(int position) { | ||
final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.logger_data_item); | ||
final SensorDataBlock block = entities.get(position); | ||
assert block!=null; | ||
switch (block.getSensorType()) { | ||
case PSLabSensor.LUXMETER: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.lux_meter)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_lux_meter_log); | ||
break; | ||
case PSLabSensor.BAROMETER: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.baro_meter)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_barometer_log); | ||
break; | ||
case PSLabSensor.GYROSCOPE: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.gyroscope)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.gyroscope_logo); | ||
break; | ||
case PSLabSensor.COMPASS: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.gyroscope)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.gyroscope_logo); | ||
break; | ||
case PSLabSensor.ACCELEROMETER: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.accelerometer)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_accelerometer); | ||
break; | ||
case PSLabSensor.THERMOMETER: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.thermometer)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.thermometer_logo); | ||
break; | ||
case PSLabSensor.ROBOTIC_ARM: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.robotic_arm)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.robotic_arm); | ||
break; | ||
case PSLabSensor.WAVE_GENERATOR: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.wave_generator)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_wave_generator); | ||
break; | ||
case PSLabSensor.OSCILLOSCOPE: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.oscilloscope)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_oscilloscope); | ||
break; | ||
case PSLabSensor.POWER_SOURCE: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.power_source)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_power_source); | ||
break; | ||
case PSLabSensor.MULTIMETER: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.multimeter)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_multimeter); | ||
break; | ||
case PSLabSensor.LOGIC_ANALYZER: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.logical_analyzer)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_logic_analyzer); | ||
break; | ||
case PSLabSensor.GAS_SENSOR: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.gas_sensor)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_gas); | ||
break; | ||
case PSLabSensor.SOUND_METER: | ||
remoteViews.setTextViewText(R.id.sensor_name,context.getResources().getString(R.string.sound_meter)); | ||
remoteViews.setImageViewResource(R.id.sensor_tile_icon,R.drawable.tile_icon_gas); | ||
break; | ||
default: | ||
break; | ||
} | ||
remoteViews.setTextViewText(R.id.date_time,String.valueOf(CSVLogger.FILE_NAME_FORMAT.format(new Date(block.getBlock())))); | ||
return remoteViews; | ||
} | ||
|
||
@Override | ||
public RemoteViews getLoadingView() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
|
||
return entities.size(); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
|
||
return position; | ||
} | ||
|
||
@Override | ||
public void onDataSetChanged() { | ||
|
||
refreshEntities(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { } | ||
|
||
|
||
@Override | ||
public int getViewTypeCount() { | ||
|
||
return 1; | ||
} | ||
|
||
@Override | ||
public boolean hasStableIds() { | ||
|
||
return false; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/io/pslab/widgets/loggedData/logDataWidgetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.pslab.widgets.loggedData; | ||
|
||
import android.content.Intent; | ||
import android.widget.RemoteViewsService; | ||
|
||
public class logDataWidgetService extends RemoteViewsService { | ||
|
||
@Override | ||
public RemoteViewsFactory onGetViewFactory(Intent intent) { | ||
|
||
return new logDataWidgetList(getApplicationContext(), intent); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="@dimen/widget_margin"> | ||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="?actionBarSize" | ||
android:text="@string/logged_data" | ||
android:background="@color/colorPrimary" | ||
android:textSize="20sp" | ||
android:textColor="@color/white" | ||
android:gravity="center" | ||
android:id="@+id/loggedDataWidget_textView" | ||
/> | ||
<TextView | ||
android:id="@+id/data_logger_blank_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:layout_below="@+id/loggedDataWidget_textView" | ||
android:text="@string/no_logs_to_display" /> | ||
|
||
<ListView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_below="@id/loggedDataWidget_textView" | ||
android:id="@+id/data_logger_list_view" | ||
/> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<!-- | ||
Refer to App Widget Documentation for margin information | ||
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout | ||
--> | ||
<dimen name="widget_margin">0dp</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:initialKeyguardLayout="@layout/logged_data_widget" | ||
android:initialLayout="@layout/logged_data_widget" | ||
android:minWidth="250dp" | ||
android:minHeight="110dp" | ||
android:previewImage="@drawable/example_appwidget_preview" | ||
android:resizeMode="horizontal|vertical" | ||
android:updatePeriodMillis="86400000" | ||
android:widgetCategory="home_screen"></appwidget-provider> |