|
|
@@ -1,24 +1,29 @@
|
|
|
package com.usai.apex;
|
|
|
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
+import com.usai.util.Crypto;
|
|
|
import com.usai.util.Network;
|
|
|
+import com.usai.util.dbUtil;
|
|
|
|
|
|
+import android.app.Notification;
|
|
|
+import android.app.NotificationManager;
|
|
|
+import android.app.PendingIntent;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.content.SharedPreferences;
|
|
|
+import android.database.sqlite.SQLiteDatabase;
|
|
|
import android.os.AsyncTask;
|
|
|
-import android.os.Bundle;
|
|
|
+import android.os.SystemClock;
|
|
|
import android.util.Log;
|
|
|
|
|
|
public class Alarmreceiver extends BroadcastReceiver
|
|
|
{
|
|
|
- private SearchTask m_task = null;
|
|
|
-
|
|
|
- public void checkpush()
|
|
|
+ private SearchTask m_task = null;
|
|
|
+
|
|
|
+ public void checkpush(Context context)
|
|
|
{
|
|
|
|
|
|
if (m_task != null)
|
|
|
@@ -27,19 +32,26 @@ public class Alarmreceiver extends BroadcastReceiver
|
|
|
}
|
|
|
// mStatusMessageView.setText(R.string.str_Loading);
|
|
|
// showProgress(true);
|
|
|
- m_task = new SearchTask();
|
|
|
+ m_task = new SearchTask(context);
|
|
|
|
|
|
-// TextView text_page = (TextView) view_page_footer
|
|
|
-// .findViewById(R.id.text_page);
|
|
|
-// text_page.setText("Loading...");
|
|
|
-// text_page.setEnabled(false);
|
|
|
+ // TextView text_page = (TextView) view_page_footer
|
|
|
+ // .findViewById(R.id.text_page);
|
|
|
+ // text_page.setText("Loading...");
|
|
|
+ // text_page.setEnabled(false);
|
|
|
m_task.execute();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
class SearchTask extends AsyncTask<Void, Void, Boolean>
|
|
|
{
|
|
|
int errorcode;
|
|
|
- boolean bfinish = false;
|
|
|
+ String content = null;
|
|
|
+ Context mcontext;
|
|
|
+
|
|
|
+ public SearchTask(Context context)
|
|
|
+ {
|
|
|
+ mcontext = context;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
protected Boolean doInBackground(Void... params)
|
|
|
@@ -53,10 +65,10 @@ public class Alarmreceiver extends BroadcastReceiver
|
|
|
}
|
|
|
String jstr = "";
|
|
|
jstr = Network.check_push();
|
|
|
-// if (module_name.equals("Announcements"))
|
|
|
-// jstr = Network.get_announcements(lastid, limit);
|
|
|
-// else
|
|
|
-// jstr = Network.get_marketnews(lastid, limit);
|
|
|
+ // if (module_name.equals("Announcements"))
|
|
|
+ // jstr = Network.get_announcements(lastid, limit);
|
|
|
+ // else
|
|
|
+ // jstr = Network.get_marketnews(lastid, limit);
|
|
|
if (jstr == null || jstr.length() <= 0)
|
|
|
{
|
|
|
// Log.d(TAG, "json is wrong");
|
|
|
@@ -65,36 +77,8 @@ public class Alarmreceiver extends BroadcastReceiver
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- JSONObject jsobj;
|
|
|
- //
|
|
|
- // array = new JSONArray(json);
|
|
|
- try
|
|
|
- {
|
|
|
- jsobj = new JSONObject(jstr);
|
|
|
- // if (searchresult.get_fieldscount() == 0)
|
|
|
- // {
|
|
|
- // JSONObject objfields = jsobj.getJSONObject("fields");
|
|
|
- // if (objfields != null)
|
|
|
- // searchresult.init_fields(objfields.toString());
|
|
|
- // }
|
|
|
-// int count = jsobj.getInt("total");
|
|
|
-// if (count < limit)
|
|
|
-// bfinish = true;
|
|
|
-// JSONObject objrecords = jsobj.getJSONObject("records");
|
|
|
-// if (objrecords != null)
|
|
|
-// searchresult.add_records(objrecords.toString(), count);
|
|
|
-// errorcode = Network.RESULT_TRUE;
|
|
|
-
|
|
|
- return true;
|
|
|
-
|
|
|
- }
|
|
|
- catch (JSONException e)
|
|
|
- {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- errorcode = Network.RESULT_NET_ERROR;
|
|
|
- return false;
|
|
|
+ content = jstr;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -104,68 +88,148 @@ public class Alarmreceiver extends BroadcastReceiver
|
|
|
m_task = null;
|
|
|
// showProgress(false);
|
|
|
|
|
|
- switch (errorcode)
|
|
|
- {
|
|
|
-// case Network.RESULT_NET_NOTAVAILABLE:
|
|
|
-// {
|
|
|
-// Toast toast = Toast.makeText(
|
|
|
-// ApexTrackingApplication.get_instance(),
|
|
|
-// getText(R.string.msg_connection_none),
|
|
|
-// Toast.LENGTH_LONG);
|
|
|
-// toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
-// toast.show();
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// case Network.RESULT_NET_ERROR:
|
|
|
-// {
|
|
|
-// Toast toast = Toast.makeText(
|
|
|
-// ApexTrackingApplication.get_instance(),
|
|
|
-// getText(R.string.msg_net_error), Toast.LENGTH_LONG);
|
|
|
-// toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
-// toast.show();
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// case Network.RESULT_ERROR:
|
|
|
-// // case Network.RESULT_RESPONSE_NULL:
|
|
|
-// {
|
|
|
-// Toast toast = Toast.makeText(
|
|
|
-// ApexTrackingApplication.get_instance(),
|
|
|
-// getText(R.string.msg_net_resulterror),
|
|
|
-// Toast.LENGTH_LONG);
|
|
|
-// toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
-// toast.show();
|
|
|
-// break;
|
|
|
-// }
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+ // switch (errorcode)
|
|
|
+ // {
|
|
|
+ // // case Network.RESULT_NET_NOTAVAILABLE:
|
|
|
+ // // {
|
|
|
+ // // Toast toast = Toast.makeText(
|
|
|
+ // // ApexTrackingApplication.get_instance(),
|
|
|
+ // // getText(R.string.msg_connection_none),
|
|
|
+ // // Toast.LENGTH_LONG);
|
|
|
+ // // toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+ // // toast.show();
|
|
|
+ // // break;
|
|
|
+ // // }
|
|
|
+ // // case Network.RESULT_NET_ERROR:
|
|
|
+ // // {
|
|
|
+ // // Toast toast = Toast.makeText(
|
|
|
+ // // ApexTrackingApplication.get_instance(),
|
|
|
+ // // getText(R.string.msg_net_error), Toast.LENGTH_LONG);
|
|
|
+ // // toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+ // // toast.show();
|
|
|
+ // // break;
|
|
|
+ // // }
|
|
|
+ // // case Network.RESULT_ERROR:
|
|
|
+ // // // case Network.RESULT_RESPONSE_NULL:
|
|
|
+ // // {
|
|
|
+ // // Toast toast = Toast.makeText(
|
|
|
+ // // ApexTrackingApplication.get_instance(),
|
|
|
+ // // getText(R.string.msg_net_resulterror),
|
|
|
+ // // Toast.LENGTH_LONG);
|
|
|
+ // // toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+ // // toast.show();
|
|
|
+ // // break;
|
|
|
+ // // }
|
|
|
+ //
|
|
|
+ // default:
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
|
|
|
if (success)
|
|
|
{
|
|
|
+ JSONObject jsobj;
|
|
|
+ //
|
|
|
+ // array = new JSONArray(json);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ jsobj = new JSONObject(content);
|
|
|
|
|
|
-// if (bfinish)
|
|
|
-// {
|
|
|
-// // getListView().removeFooterView(view_page_footer);
|
|
|
-// // Toast.makeText(AnnouncementActivity.this, "Load all!",
|
|
|
-// // Toast.LENGTH_LONG).show();
|
|
|
-//
|
|
|
-// TextView tv = (TextView) view_page_footer
|
|
|
-// .findViewById(R.id.text_page);
|
|
|
-// tv.setText("No more items");
|
|
|
-// tv.setEnabled(false);
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// TextView tv = (TextView) view_page_footer
|
|
|
-// .findViewById(R.id.text_page);
|
|
|
-// tv.setText("More...");
|
|
|
-// tv.setEnabled(true);
|
|
|
-// }
|
|
|
-// adapter.notifyDataSetChanged();
|
|
|
-// // getListAdapter().notifyDataSetChanged;
|
|
|
-// // BaseAdapter mJson = null;
|
|
|
-// // mJson.notifyDataSetChanged();
|
|
|
+ String message = jsobj.getString("message");
|
|
|
+ String date = jsobj.getString("date");
|
|
|
+ String s_id = jsobj.getString("s_id");
|
|
|
+ String e_id = jsobj.getString("e_id");
|
|
|
+ int count = jsobj.getInt("count");
|
|
|
+ SQLiteDatabase db = dbUtil.OpenDB(
|
|
|
+ ApexTrackingApplication.get_instance(), null, true);
|
|
|
+ db.execSQL("insert into push_message(s_id,e_id,msgcount,message,h_time,user,read) values('"
|
|
|
+ + s_id
|
|
|
+ + "','"
|
|
|
+ + e_id
|
|
|
+ + "',"
|
|
|
+ + count
|
|
|
+ + ",'"
|
|
|
+ + message
|
|
|
+ + "','"
|
|
|
+ + date
|
|
|
+ + "','"
|
|
|
+ + ApexTrackingApplication.get_user() + "'" + ",0)");
|
|
|
+ dbUtil.CloseDB(db);
|
|
|
+
|
|
|
+ NotificationManager nManager = (NotificationManager) mcontext
|
|
|
+ .getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
+
|
|
|
+ Notification notification = new Notification(
|
|
|
+ R.drawable.ic_launcher,
|
|
|
+ mcontext.getString(R.string.str_notification_title),
|
|
|
+ System.currentTimeMillis());
|
|
|
+ Intent intent = new Intent(mcontext,
|
|
|
+ FunctionSelectActivity.class);
|
|
|
+ intent.putExtra("launcher", "notification");
|
|
|
+
|
|
|
+ PendingIntent pintent = PendingIntent.getActivity(mcontext,
|
|
|
+ 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
+ notification.defaults = Notification.DEFAULT_ALL;
|
|
|
+ notification.flags = Notification.FLAG_AUTO_CANCEL;
|
|
|
+ notification.number = ApexTrackingApplication.ncount++;
|
|
|
+ if (notification.number > 1)
|
|
|
+ notification
|
|
|
+ .setLatestEventInfo(
|
|
|
+ mcontext,
|
|
|
+ notification.number
|
|
|
+ + ApexTrackingApplication
|
|
|
+ .get_instance()
|
|
|
+ .getString(
|
|
|
+ R.string.str_mnotification_title),
|
|
|
+ ApexTrackingApplication
|
|
|
+ .get_instance()
|
|
|
+ .getString(
|
|
|
+ R.string.str_notification_text)
|
|
|
+ + date, pintent);
|
|
|
+ else
|
|
|
+ notification
|
|
|
+ .setLatestEventInfo(
|
|
|
+ mcontext,
|
|
|
+ ApexTrackingApplication
|
|
|
+ .get_instance()
|
|
|
+ .getString(
|
|
|
+ R.string.str_notification_title),
|
|
|
+ ApexTrackingApplication
|
|
|
+ .get_instance()
|
|
|
+ .getString(
|
|
|
+ R.string.str_notification_text)
|
|
|
+ + date, pintent);
|
|
|
+ nManager.notify(R.layout.activity_apex, notification);
|
|
|
+
|
|
|
+ // notification
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (JSONException e)
|
|
|
+ {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // if (bfinish)
|
|
|
+ // {
|
|
|
+ // // getListView().removeFooterView(view_page_footer);
|
|
|
+ // // Toast.makeText(AnnouncementActivity.this, "Load all!",
|
|
|
+ // // Toast.LENGTH_LONG).show();
|
|
|
+ //
|
|
|
+ // TextView tv = (TextView) view_page_footer
|
|
|
+ // .findViewById(R.id.text_page);
|
|
|
+ // tv.setText("No more items");
|
|
|
+ // tv.setEnabled(false);
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // TextView tv = (TextView) view_page_footer
|
|
|
+ // .findViewById(R.id.text_page);
|
|
|
+ // tv.setText("More...");
|
|
|
+ // tv.setEnabled(true);
|
|
|
+ // }
|
|
|
+ // adapter.notifyDataSetChanged();
|
|
|
+ // // getListAdapter().notifyDataSetChanged;
|
|
|
+ // // BaseAdapter mJson = null;
|
|
|
+ // // mJson.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
super.onPostExecute(success);
|
|
|
@@ -178,29 +242,52 @@ public class Alarmreceiver extends BroadcastReceiver
|
|
|
// showProgress(false);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent)
|
|
|
{
|
|
|
String tag = "onReceive@Alarmreceiver";
|
|
|
- if (intent.getAction().equals("com.usai.apex.push")) {
|
|
|
-// Bundle b = intent.getExtras();
|
|
|
-// Set<String> keySet = b.keySet();
|
|
|
-// for(String key : keySet) {
|
|
|
-// Log.e(tag, key);
|
|
|
-// }
|
|
|
-// String s =b.getString("caller");
|
|
|
- Log.d(tag, "receive alarm broadcast caller =="+intent.getStringExtra("caller"));
|
|
|
-
|
|
|
- checkpush();
|
|
|
-// Intent i = new Intent();
|
|
|
-// i.setClass(context, DaemonService.class);
|
|
|
-// // 启动service
|
|
|
-// // 多次调用startService并不会启动多个service 而是会多次调用onStart
|
|
|
-// context.startService(i);
|
|
|
- }
|
|
|
+ if (intent.getAction().equals("com.usai.apex.push"))
|
|
|
+ {
|
|
|
+ if(true)
|
|
|
+ return;
|
|
|
+ // Bundle b = intent.getExtras();
|
|
|
+ // Set<String> keySet = b.keySet();
|
|
|
+ // for(String key : keySet) {
|
|
|
+ // Log.e(tag, key);
|
|
|
+ // }
|
|
|
+ // String s =b.getString("caller");
|
|
|
+ Log.d(tag,
|
|
|
+ "receive alarm broadcast caller =="
|
|
|
+ + intent.getStringExtra("caller"));
|
|
|
+
|
|
|
+ checkpush(context);
|
|
|
+ // Intent i = new Intent();
|
|
|
+ // i.setClass(context, DaemonService.class);
|
|
|
+ // // 启动service
|
|
|
+ // // 多次调用startService并不会启动多个service 而是会多次调用onStart
|
|
|
+ // context.startService(i);
|
|
|
+ }
|
|
|
+ else if (intent.getAction().equals("com.usai.apex.push.cancel"))
|
|
|
+ {
|
|
|
+ if (m_task != null)
|
|
|
+ m_task.cancel(true);
|
|
|
+ NotificationManager nManager = (NotificationManager) context
|
|
|
+ .getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
+ nManager.cancel(R.layout.activity_apex);
|
|
|
+ ApexTrackingApplication.cancelalarm();
|
|
|
+// ApexTrackingApplication.put_password("");
|
|
|
+// ApexTrackingApplication.put_sessionid("");
|
|
|
+// ApexTrackingApplication.put_user("");
|
|
|
+ ApexTrackingApplication.logout();
|
|
|
+
|
|
|
+ SharedPreferences pref = ApexTrackingApplication.get_instance()
|
|
|
+ .getSharedPreferences("Apex", 0);
|
|
|
+ SharedPreferences.Editor editor = pref.edit();
|
|
|
+
|
|
|
+ editor.putBoolean("autologin", false);
|
|
|
+ editor.commit();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|