online/offline notification tray implemented (issue #353)

parent b80d53d5
...@@ -41,14 +41,6 @@ public class NetService implements Runnable { ...@@ -41,14 +41,6 @@ public class NetService implements Runnable {
private NotificationCompat.Builder builder; private NotificationCompat.Builder builder;
public NetService(int delay) { public NetService(int delay) {
this.builder = new NotificationCompat.Builder(PCBcontext.getContext());
Intent resultIntent = new Intent(PCBcontext.getContext(), PictogramActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext());
stackBuilder.addParentStack(PictogramActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
this.builder.setContentIntent(resultPendingIntent);
this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session, new iRestapiListener() { this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session, new iRestapiListener() {
...@@ -118,6 +110,7 @@ public class NetService implements Runnable { ...@@ -118,6 +110,7 @@ public class NetService implements Runnable {
public void error(Exception e) { public void error(Exception e) {
updated = false; updated = false;
Log.i(this.getClass().getName(), "PCB offline because exception happens: " + e.getMessage()); Log.i(this.getClass().getName(), "PCB offline because exception happens: " + e.getMessage());
notifyStatus();
} }
}); });
} }
...@@ -125,11 +118,23 @@ public class NetService implements Runnable { ...@@ -125,11 +118,23 @@ public class NetService implements Runnable {
private void notifyStatus() { private void notifyStatus() {
int notifyID=1; int notifyID=1;
this.builder = new NotificationCompat.Builder(PCBcontext.getContext());
Intent resultIntent = new Intent(PCBcontext.getContext(), PictogramActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext());
stackBuilder.addParentStack(PictogramActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
this.builder.setContentIntent(resultPendingIntent);
if (updated)
this.builder.setSmallIcon(R.drawable.picton)
.setContentTitle("Pictogram online")
.setContentText(PCBcontext.getContext().getResources().getString(R.string.pictogram_online));
else
this.builder.setSmallIcon(R.drawable.pictoff)
.setContentTitle("Pictogram offline")
.setContentText(PCBcontext.getContext().getResources().getString(R.string.pictogram_offline));
this.builder.setSmallIcon(R.drawable.logo_pictogram)
.setContentTitle("Pictogram "+ (updated ? "online" : "offline"))
.setContentText(updated ? PCBcontext.getContext().getResources().getString(R.string.pictogram_online)
: PCBcontext.getContext().getResources().getString(R.string.pictogram_offline));
NotificationManager mNotificationManager = NotificationManager mNotificationManager =
(NotificationManager)PCBcontext.getContext().getSystemService(PCBcontext.getContext().NOTIFICATION_SERVICE); (NotificationManager)PCBcontext.getContext().getSystemService(PCBcontext.getContext().NOTIFICATION_SERVICE);
// mId allows you to update the notification later on. // mId allows you to update the notification later on.
......
...@@ -136,7 +136,6 @@ public class Img { ...@@ -136,7 +136,6 @@ public class Img {
} }
ByteArrayOutputStream outstream = new ByteArrayOutputStream(); ByteArrayOutputStream outstream = new ByteArrayOutputStream();
this.bitmap.setHasAlpha(true); this.bitmap.setHasAlpha(true);
Log.i(this.getClass().getCanonicalName(), "Img Uploading Picto img" + file_name() + " from " + get_type() + "size:" + get_bitmap(PCBcontext.getContext()).getWidth() + " " + get_bitmap(PCBcontext.getContext()).getHeight());
this.bitmap.compress(Bitmap.CompressFormat.PNG, 100, outstream); this.bitmap.compress(Bitmap.CompressFormat.PNG, 100, outstream);
byte[] byteArray = outstream.toByteArray(); byte[] byteArray = outstream.toByteArray();
os.write(byteArray); os.write(byteArray);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
android:layout_height="120px" android:layout_height="120px"
android:contentDescription="@string/app_name" android:contentDescription="@string/app_name"
android:orientation="vertical" android:orientation="vertical"
android:src="@drawable/yottalogo72p" android:src="@drawable/logo"
android:scaleX="0.5" android:scaleX="0.5"
android:scaleY="0.5" android:scaleY="0.5"
android:id="@+id/imageView2" android:id="@+id/imageView2"
......
...@@ -53,5 +53,5 @@ ...@@ -53,5 +53,5 @@
<string name="notNewCats">Including new categories is not allowed</string> <string name="notNewCats">Including new categories is not allowed</string>
<!--online/offline status--> <!--online/offline status-->
<string name="pictogram_offline">Please check your internet connection. </string> <string name="pictogram_offline">Please check your internet connection. </string>
<string name="pictogram_online">Pictogram server connection established. </string> <string name="pictogram_online">Server connection established. </string>
</resources> </resources>
...@@ -57,5 +57,5 @@ ...@@ -57,5 +57,5 @@
<string name="notNewCats">No puede añadir nuevas categorias</string> <string name="notNewCats">No puede añadir nuevas categorias</string>
<!--online/offline status--> <!--online/offline status-->
<string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string> <string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string>
<string name="pictogram_online">Conexón con el servidor Pictogram establecida. </string> <string name="pictogram_online">Conexón con el servidor establecida. </string>
</resources> </resources>
...@@ -70,6 +70,6 @@ ...@@ -70,6 +70,6 @@
completions." completions."
<!--online/offline status--> <!--online/offline status-->
<string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string> <string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string>
<string name="pictogram_online">Conexón con el servidor Pictogram establecida. </string> <string name="pictogram_online">Conexón con el servidor establecida. </string>
</string> </string>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment