wirking on notification online/offline tray

parent e96e2819
......@@ -235,7 +235,7 @@ public class Device extends SQLiteOpenHelper {
Vector<User> users=null;
Cursor cursor = db.query("supervisor", null, null, null, null, null, null, null);
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 (cursor.getString(2).equals(apwd)) {
users = recoverStudents(cursor.getInt(0));
......@@ -301,7 +301,7 @@ public class Device extends SQLiteOpenHelper {
"lang_stu='" + user.get_lang_stu() + "', " +
"attributes_stu='" + user.get_json_attrs() + "', " +
"name_sup='" + user.get_name_sup() + "', " +
"nickname_sup='" + user.get_email_sup() + "', " +
"email_sup='" + user.get_email_sup() + "', " +
"pwd_sup='" + user.get_pwd_sup() + "', " +
"surname_sup='" + user.get_surname_sup() + "', " +
"url_img_sup='" + user.get_url_img_sup() + "', " +
......
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 com.yottacode.net.RestapiWrapper;
import com.yottacode.net.iRestapiListener;
import com.yottacode.pictogram.R;
import com.yottacode.pictogram.gui.PictogramActivity;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONArray;
......@@ -32,8 +38,20 @@ public class NetService implements Runnable {
static final String ping_session="server/ping";
private boolean updated;
private NotificationCompat.Builder builder;
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() {
@Override
public void preExecute() {
......@@ -47,11 +65,13 @@ public class NetService implements Runnable {
@Override
public void result(JSONObject result) {
updated=true;
notifyStatus();
}
@Override
public void error(Exception e) {
updated=false;
notifyStatus();
}
});
Log.i(this.getClass().getName(), "Checking Pictogram server access...");
......@@ -91,6 +111,7 @@ public class NetService implements Runnable {
updated = true;
}
Log.i(this.getClass().getName(), "PCB status checked. Updated? " + updated);
notifyStatus();
}
@Override
......@@ -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 @@
<!--Upload local img -->
<string name="enterImgLabel">Enter img label</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>
......@@ -55,5 +55,7 @@
<!--Upload local img -->
<string name="enterImgLabel">Introduzca etiqueta de la imagen</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>
......@@ -68,5 +68,8 @@
<string name="error_field_required">This field is required</string>
<string name="permission_rationale">"Contacts permissions are needed for providing email
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>
</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