wirking on notification online/offline tray

parent e96e2819
...@@ -235,7 +235,7 @@ public class Device extends SQLiteOpenHelper { ...@@ -235,7 +235,7 @@ public class Device extends SQLiteOpenHelper {
Vector<User> users=null; Vector<User> users=null;
Cursor cursor = db.query("supervisor", null, null, null, null, null, null, null); Cursor cursor = db.query("supervisor", null, null, null, null, null, null, null);
while (cursor.moveToNext() && users == null && !user_found) { while (cursor.moveToNext() && users == null && !user_found) {
user_found = cursor.getString(10).equalsIgnoreCase(auser); user_found = cursor.getString(1).equalsIgnoreCase(auser);
if (user_found) if (user_found)
if (cursor.getString(2).equals(apwd)) { if (cursor.getString(2).equals(apwd)) {
users = recoverStudents(cursor.getInt(0)); users = recoverStudents(cursor.getInt(0));
...@@ -301,7 +301,7 @@ public class Device extends SQLiteOpenHelper { ...@@ -301,7 +301,7 @@ public class Device extends SQLiteOpenHelper {
"lang_stu='" + user.get_lang_stu() + "', " + "lang_stu='" + user.get_lang_stu() + "', " +
"attributes_stu='" + user.get_json_attrs() + "', " + "attributes_stu='" + user.get_json_attrs() + "', " +
"name_sup='" + user.get_name_sup() + "', " + "name_sup='" + user.get_name_sup() + "', " +
"nickname_sup='" + user.get_email_sup() + "', " + "email_sup='" + user.get_email_sup() + "', " +
"pwd_sup='" + user.get_pwd_sup() + "', " + "pwd_sup='" + user.get_pwd_sup() + "', " +
"surname_sup='" + user.get_surname_sup() + "', " + "surname_sup='" + user.get_surname_sup() + "', " +
"url_img_sup='" + user.get_url_img_sup() + "', " + "url_img_sup='" + user.get_url_img_sup() + "', " +
......
package com.yottacode.pictogram.net; package com.yottacode.pictogram.net;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import com.yottacode.net.RestapiWrapper; import com.yottacode.net.RestapiWrapper;
import com.yottacode.net.iRestapiListener; import com.yottacode.net.iRestapiListener;
import com.yottacode.pictogram.R; import com.yottacode.pictogram.R;
import com.yottacode.pictogram.gui.PictogramActivity;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -32,8 +38,20 @@ public class NetService implements Runnable { ...@@ -32,8 +38,20 @@ public class NetService implements Runnable {
static final String ping_session="server/ping"; static final String ping_session="server/ping";
private boolean updated; private boolean updated;
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() {
@Override @Override
public void preExecute() { public void preExecute() {
...@@ -47,11 +65,13 @@ public class NetService implements Runnable { ...@@ -47,11 +65,13 @@ public class NetService implements Runnable {
@Override @Override
public void result(JSONObject result) { public void result(JSONObject result) {
updated=true; updated=true;
notifyStatus();
} }
@Override @Override
public void error(Exception e) { public void error(Exception e) {
updated=false; updated=false;
notifyStatus();
} }
}); });
Log.i(this.getClass().getName(), "Checking Pictogram server access..."); Log.i(this.getClass().getName(), "Checking Pictogram server access...");
...@@ -91,6 +111,7 @@ public class NetService implements Runnable { ...@@ -91,6 +111,7 @@ public class NetService implements Runnable {
updated = true; updated = true;
} }
Log.i(this.getClass().getName(), "PCB status checked. Updated? " + updated); Log.i(this.getClass().getName(), "PCB status checked. Updated? " + updated);
notifyStatus();
} }
@Override @Override
...@@ -101,4 +122,20 @@ public class NetService implements Runnable { ...@@ -101,4 +122,20 @@ public class NetService implements Runnable {
}); });
} }
private void notifyStatus() {
int notifyID=1;
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)PCBcontext.getContext().getSystemService(PCBcontext.getContext().NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(notifyID, this.builder.build());
}
} }
\ No newline at end of file
...@@ -51,5 +51,7 @@ ...@@ -51,5 +51,7 @@
<!--Upload local img --> <!--Upload local img -->
<string name="enterImgLabel">Enter img label</string> <string name="enterImgLabel">Enter img label</string>
<string name="notNewCats">Including new categories is not allowed</string> <string name="notNewCats">Including new categories is not allowed</string>
<!--online/offline status-->
<string name="pictogram_offline">Please check your internet connection. </string>
<string name="pictogram_online">Pictogram server connection established. </string>
</resources> </resources>
...@@ -55,5 +55,7 @@ ...@@ -55,5 +55,7 @@
<!--Upload local img --> <!--Upload local img -->
<string name="enterImgLabel">Introduzca etiqueta de la imagen</string> <string name="enterImgLabel">Introduzca etiqueta de la imagen</string>
<string name="notNewCats">No puede añadir nuevas categorias</string> <string name="notNewCats">No puede añadir nuevas categorias</string>
<!--online/offline status-->
<string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string>
<string name="pictogram_online">Conexón con el servidor Pictogram establecida. </string>
</resources> </resources>
...@@ -68,5 +68,8 @@ ...@@ -68,5 +68,8 @@
<string name="error_field_required">This field is required</string> <string name="error_field_required">This field is required</string>
<string name="permission_rationale">"Contacts permissions are needed for providing email <string name="permission_rationale">"Contacts permissions are needed for providing email
completions." completions."
<!--online/offline status-->
<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> </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