List of usage examples for android.os Message getData
public Bundle getData()
From source file:ch.bfh.evoting.alljoyn.BusHandler.java
@Override public void handleMessage(Message msg) { Status status = null;//from w w w . j av a 2 s.com Intent intent; switch (msg.what) { case INIT: { doInit(); break; } case CREATE_GROUP: { Bundle data = msg.getData(); String groupName = data.getString("groupName"); String groupPassword = data.getString("groupPassword"); status = doCreateGroup(groupName, groupPassword); Log.d(TAG, "status of group creation " + status); switch (status) { case OK: LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("NetworkServiceStarted")); break; case ALLJOYN_JOINSESSION_REPLY_ALREADY_JOINED: LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("NetworkServiceStarted")); break; case INVALID_DATA: //invalid group name intent = new Intent("networkConnectionFailed"); intent.putExtra("error", 1); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); break; case ALREADY_FINDING: //group name already exists intent = new Intent("networkConnectionFailed"); intent.putExtra("error", 2); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); break; default: LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("networkConnectionFailed")); break; } break; } case DESTROY_GROUP: { status = doDestroyGroup((String) msg.obj); break; } case JOIN_GROUP: { Bundle data = msg.getData(); String groupName = data.getString("groupName"); String groupPassword = data.getString("groupPassword"); String saltShortDigest = data.getString("saltShortDigest"); status = doJoinGroup(groupName, groupPassword, saltShortDigest); Log.d(TAG, "status of group join " + status); switch (status) { case OK: LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("NetworkServiceStarted")); break; case ALLJOYN_JOINSESSION_REPLY_ALREADY_JOINED: LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("NetworkServiceStarted")); break; case INVALID_DATA: //invalid group name intent = new Intent("networkConnectionFailed"); intent.putExtra("error", 1); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); break; case ALLJOYN_FINDADVERTISEDNAME_REPLY_FAILED: //group not found intent = new Intent("networkConnectionFailed"); intent.putExtra("error", 3); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); break; case ALLJOYN_JOINSESSION_REPLY_FAILED: //group not joined intent = new Intent("networkConnectionFailed"); intent.putExtra("error", 4); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); break; default: LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("networkConnectionFailed")); break; } break; } case LEAVE_GROUP: { status = doLeaveGroup((String) msg.obj); break; } case UNLOCK_GROUP: { status = doUnlockGroup((String) msg.obj); break; } case LOCK_GROUP: { status = doLockGroup((String) msg.obj); break; } case SET_PORT: { doSetPort((Short) msg.obj); break; } case JOIN_OR_CREATE: { status = doJoinOrCreate((String) msg.obj); break; } case PING: { Bundle data = msg.getData(); String groupName = data.getString("groupName"); String pingString = data.getString("pingString"); boolean encrypted = data.getBoolean("encrypted", true); Type type = (Type) data.getSerializable("type"); doPing(groupName, pingString, encrypted, type); break; } case REPROCESS_MESSAGE: { Bundle data = msg.getData(); AllJoynMessage message = (AllJoynMessage) data.getSerializable("message"); this.processMessage(message); break; } case DISCONNECT: { doDisconnect(); break; } default: break; } }
From source file:count.ly.messaging.TitaniumCountlyAndroidMessagingModule.java
@Kroll.method public void sendNotification() { Log.d(LCAT, "Send Notification"); // Check if Module has Listeners if (hasListeners("receivePush")) { // Log Listeners Found Log.d(LCAT, "Has Listener: receivePush"); // Set Message Message message = TitaniumCountlyAndroidMessagingModule.message; // Create HashMap of Notification info and add data HashMap pushMessage = new HashMap(); pushMessage.put("id", message.getId()); pushMessage.put("message", message.getNotificationMessage()); if (message.hasLink()) { pushMessage.put("type", "hasLink"); pushMessage.put("link", message.getLink()); } else if (message.hasReview()) { pushMessage.put("type", "hasReview"); } else if (message.hasMessage()) { pushMessage.put("type", "hasMessage"); }/* w w w. java2 s . co m*/ if (message.hasSoundUri()) { pushMessage.put("sound", message.getSoundUri()); } pushMessage.put("data", bundleToHashMap(message.getData())); Log.d(LCAT, "pushMessage" + pushMessage); // fireEvent pushCallBack with payload evt fireEvent("receivePush", pushMessage); // Clear TiProperties TiProperties appProperties = TiApplication.getInstance().getAppProperties(); appProperties.setString("pushMessage", ""); } else { // Log No Listener Log.d(LCAT, "No Listener receivePush found"); } }
From source file:de.blinkt.openvpn.ActivityDashboard.java
public void handleMessage(Message msg) { Bundle data = msg.getData(); switch (msg.what) { case RemoteAPI.MessageType: { String method = data.getString("method"); String code = data.getString("code"); String message = data.getString("message"); if (method.equalsIgnoreCase("getUserServices")) { m_waitdlg.cancel();/*from w w w . j a va 2s. c o m*/ if (!(code.equalsIgnoreCase("0") || code.equalsIgnoreCase("4") || code.equalsIgnoreCase("5"))) { Toast toast = Toast.makeText(this, "getUserServices failed, " + message, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } m_package = data.getString("packages"); m_username = data.getString("username"); m_password = data.getString("vpnpassword"); // update login password to vpnpassword. updatePackage(m_package.trim()); } break; } // case VpnStatus.StateListener: { // String log = data.getString("log"); // if(log == null) // return; // // get openvpn state from the log. // if(log.contains("AUTH_FAILED")) { // Toast toast = Toast.makeText(this, "Username or password error.", Toast.LENGTH_SHORT); // toast.setGravity(Gravity.CENTER, 0, 0); // toast.show(); // setStatus(Status.Disconnected); // return; // } // if(log.contains("SIGTERM") || log.contains("exiting")) { // Toast toast = Toast.makeText(this, "Disconnected from server.", Toast.LENGTH_SHORT); // toast.setGravity(Gravity.CENTER, 0, 0); // toast.show(); // // setStatus(Status.Disconnected); // return; // } // if(log.contains("Initialization Sequence Completed")) { // if(m_status == Status.Connecting) // setStatus(Status.Connected); // return; // } // break; } case HandlerDialogClickListener.MessageType: { switch (msg.arg1) { case AlertDialogExitNotify: { switch (msg.arg2) { case AlertDialog.BUTTON_POSITIVE: { Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); startActivity(intent); break; } case AlertDialog.BUTTON_NEGATIVE: { break; } case AlertDialog.BUTTON_NEUTRAL: { if (VpnStatus.isVPNActive()) { if (mService != null) { try { mService.stopVPN(false); } catch (RemoteException e) { VpnStatus.logException(e); } } } setStatus(Status.Disconnected); finish(); break; } } break; } } break; } case NetDisconnectedNotify: { Log.d("ibVPN", "Disconnected by internet lose."); Toast toast = Toast.makeText(this, "VPN connection was lost, please reconnect Wi-Fi/Mobile Data connection.", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); Button button = (Button) findViewById(R.id.button_dashboard_connect); if (button.getText().toString().equalsIgnoreCase(getString(R.string.text_cancel))) { // m_openvpn.cancel(); setStatus(Status.Disconnected); } else if (button.getText().toString().equalsIgnoreCase(getString(R.string.text_disconnect))) { // m_openvpn.disconnect(); setStatus(Status.Disconnected); } break; } default: { Log.d("ibVPN", "Message From Unknown Thread. :)"); break; } } }
From source file:widgets.Graphical_Binary_New.java
public Graphical_Binary_New(tracerengine Trac, Activity context, String address, String name, int id, int dev_id, String state_key, String url, final String usage, String parameters, String model_id, int update, int widgetSize, int session_type, int place_id, String place_type, SharedPreferences params) throws JSONException { super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container); this.Tracer = Trac; this.context = context; this.address = address; this.url = url; this.state_key = state_key; this.dev_id = dev_id; this.id = id; this.usage = usage; this.update = update; this.name = name; this.wname = name; this.myself = this; this.session_type = session_type; this.stateS = getResources().getText(R.string.State).toString(); this.place_id = place_id; this.place_type = place_type; this.params = params; login = params.getString("http_auth_username", null); password = params.getString("http_auth_password", null); mytag = "Graphical_Binary_New(" + dev_id + ")"; //get parameters try {//w w w . ja v a2s . c o m JSONObject jparam = new JSONObject(parameters.replaceAll(""", "\"")); value0 = jparam.getString("value0"); value1 = jparam.getString("value1"); } catch (Exception e) { value0 = "0"; value1 = "1"; } if (usage.equals("light")) { this.Value_0 = getResources().getText(R.string.light_stat_0).toString(); this.Value_1 = getResources().getText(R.string.light_stat_1).toString(); } else if (usage.equals("shutter")) { this.Value_0 = getResources().getText(R.string.shutter_stat_0).toString(); this.Value_1 = getResources().getText(R.string.shutter_stat_1).toString(); } else { this.Value_0 = value0; this.Value_1 = value1; } String[] model = model_id.split("\\."); type = model[0]; Tracer.d(mytag, "model_id = <" + model_id + "> type = <" + type + "> value0 = " + value0 + " value1 = " + value1); //state state = new TextView(context); state.setTextColor(Color.BLACK); state.setText("State :" + this.Value_0); final float scale = getContext().getResources().getDisplayMetrics().density; float dps = 40; int pixels = (int) (dps * scale + 0.5f); //first seekbar on/off ON = new Button(context); ON.setOnClickListener(this); ON.setHeight(pixels); //ON.setWidth(60); ON.setTag("ON"); ON.setText(this.Value_1); ON.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); //ON.setBackgroundResource(R.drawable.boolean_on); //ON.setPadding(10, 0, 10, 0); OFF = new Button(context); OFF.setOnClickListener(this); OFF.setTag("OFF"); OFF.setHeight(pixels); //OFF.setWidth(60); OFF.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); //OFF.setBackgroundResource(R.drawable.boolean_off); OFF.setText(this.Value_0); //OFF.setPadding(0,10,0,10); super.LL_featurePan.addView(ON); super.LL_featurePan.addView(OFF); super.LL_infoPan.addView(state); handler = new Handler() { @Override public void handleMessage(Message msg) { if (activate) { Tracer.d(mytag, "Handler receives a request to die "); if (realtime) { Tracer.get_engine().unsubscribe(session); session = null; realtime = false; } //That seems to be a zombie //removeView(background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } else { try { Bundle b = msg.getData(); if ((b != null) && (b.getString("message") != null)) { if (b.getString("message").equals(value0)) { //state.setText(stateS+value0); state.setText(stateS + Value_0); IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 0)); } else if (b.getString("message").equals(value1)) { //state.setText(stateS+value1); state.setText(stateS + Value_1); IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 2)); } state.setAnimation(animation); } else { if (msg.what == 2) { Toast.makeText(getContext(), "Command Failed", Toast.LENGTH_SHORT).show(); } else if (msg.what == 9999) { //state_engine send us a signal to notify value changed if (session == null) return; String new_val = session.getValue(); Tracer.d(mytag, "Handler receives a new value <" + new_val + ">"); if (new_val.equals(value0)) { state.setText(stateS + Value_0); IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 0)); } else if (new_val.equals(value1)) { state.setText(stateS + Value_1); IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 2)); } else { state.setText(stateS + new_val); } } else if (msg.what == 9998) { // state_engine send us a signal to notify it'll die ! Tracer.d(mytag, "state engine disappeared ===> Harakiri !"); session = null; realtime = false; //removeView(background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } } } catch (Exception e) { Tracer.e(mytag, "Handler error for device " + wname); e.printStackTrace(); } } } }; //================================================================================ /* * New mechanism to be notified by widgetupdate engine when our value is changed * */ WidgetUpdate cache_engine = WidgetUpdate.getInstance(); if (cache_engine != null) { session = new Entity_client(dev_id, state_key, mytag, handler, session_type); if (Tracer.get_engine().subscribe(session)) { realtime = true; //we're connected to engine //each time our value change, the engine will call handler handler.sendEmptyMessage(9999); //Force to consider current value in session } } //================================================================================ //updateTimer(); //Don't use anymore cyclic refresh.... }
From source file:widgets.Graphical_Binary.java
public Graphical_Binary(tracerengine Trac, Activity context, String address, final String name, int id, int dev_id, String state_key, String url, String usage, String parameters, String model_id, int update, int widgetSize, int session_type, int place_id, String place_type, SharedPreferences params) throws JSONException { super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container); this.Tracer = Trac; this.context = context; this.address = address; this.url = url; this.state_key = state_key; this.usage = usage; this.update = update; this.myself = this; this.session_type = session_type; this.stateS = getResources().getText(R.string.State).toString(); this.place_id = place_id; this.place_type = place_type; this.params = params; mytag = "Graphical_Binary(" + dev_id + ")"; //get parameters try {/*from ww w .j a v a 2s .c om*/ JSONObject jparam = new JSONObject(parameters.replaceAll(""", "\"")); value0 = jparam.getString("value0"); value1 = jparam.getString("value1"); } catch (Exception e) { value0 = "0"; value1 = "1"; } if (usage.equals("light")) { this.Value_0 = getResources().getText(R.string.light_stat_0).toString(); this.Value_1 = getResources().getText(R.string.light_stat_1).toString(); } else if (usage.equals("shutter")) { this.Value_0 = getResources().getText(R.string.shutter_stat_0).toString(); this.Value_1 = getResources().getText(R.string.shutter_stat_1).toString(); } else { this.Value_0 = value0; this.Value_1 = value1; } String[] model = model_id.split("\\."); type = model[0]; Tracer.d(mytag, "model_id = <" + model_id + "> type = <" + type + "> value0 = " + value0 + " value1 = " + value1); //state state = new TextView(context); state.setTextColor(Color.BLACK); animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(1000); //first seekbar on/off seekBarOnOff = new SeekBar(context); seekBarOnOff.setProgress(0); seekBarOnOff.setMax(40); Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.bgseekbaronoff); seekBarOnOff.setLayoutParams(new LayoutParams(bMap.getWidth(), bMap.getHeight())); seekBarOnOff.setProgressDrawable(getResources().getDrawable(R.drawable.bgseekbaronoff)); seekBarOnOff.setThumb(getResources().getDrawable(R.drawable.buttonseekbar)); seekBarOnOff.setThumbOffset(0); seekBarOnOff.setOnSeekBarChangeListener(this); seekBarOnOff.setTag("0"); super.LL_infoPan.addView(state); super.LL_featurePan.addView(seekBarOnOff); login = params.getString("http_auth_username", null); password = params.getString("http_auth_password", null); handler = new Handler() { @Override public void handleMessage(Message msg) { if (activate) { Tracer.d(mytag, "Handler receives a request to die "); if (realtime) { Tracer.get_engine().unsubscribe(session); session = null; realtime = false; } //That seems to be a zombie //removeView(background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } else { try { Bundle b = msg.getData(); if ((b != null) && (b.getString("message") != null)) { if (b.getString("message").equals(value0)) { //state.setText(stateS+value0); state.setText(stateS + Value_0); new SBAnim(seekBarOnOff.getProgress(), 0).execute(); } else if (b.getString("message").equals(value1)) { //state.setText(stateS+value1); state.setText(stateS + Value_1); new SBAnim(seekBarOnOff.getProgress(), 40).execute(); } state.setAnimation(animation); } else { if (msg.what == 2) { Toast.makeText(getContext(), "Command Failed", Toast.LENGTH_SHORT).show(); } else if (msg.what == 9999) { //state_engine send us a signal to notify value changed if (session == null) return; String new_val = session.getValue(); Tracer.d(mytag, "Handler receives a new value <" + new_val + ">"); if (new_val.equals(value0)) { state.setText(stateS + Value_0); new SBAnim(seekBarOnOff.getProgress(), 0).execute(); } else if (new_val.equals(value1)) { state.setText(stateS + Value_1); new SBAnim(seekBarOnOff.getProgress(), 40).execute(); } else { state.setText(stateS + new_val); new SBAnim(seekBarOnOff.getProgress(), 0).execute(); } } else if (msg.what == 9998) { // state_engine send us a signal to notify it'll die ! Tracer.d(mytag, "state engine disappeared ===> Harakiri !"); session = null; realtime = false; //removeView(background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } } } catch (Exception e) { Tracer.e(mytag, "Handler error for device " + name); e.printStackTrace(); } } } }; //================================================================================ /* * New mechanism to be notified by widgetupdate engine when our value is changed * */ WidgetUpdate cache_engine = WidgetUpdate.getInstance(); if (cache_engine != null) { session = new Entity_client(dev_id, state_key, mytag, handler, session_type); if (Tracer.get_engine().subscribe(session)) { realtime = true; //we're connected to engine //each time our value change, the engine will call handler handler.sendEmptyMessage(9999); //Force to consider current value in session } } //================================================================================ //updateTimer(); //Don't use anymore cyclic refresh.... }
From source file:net.networksaremadeofstring.cyllell.Search.java
public void MakeHandler() { handler = new Handler() { public void handleMessage(Message msg) { //Once we've checked the data is good to use start processing it if (msg.what == 0) { //TODO ListView population NodeAdapter = new NodeListAdaptor(Search.this, listOfNodes); list.setAdapter(NodeAdapter); //Close the Progress dialog dialog.dismiss();/*from w w w. j av a 2s.co m*/ } else if (msg.what == 200) { dialog.setMessage("Searching for: " + query + "\n\nSending request to Chef..."); } else if (msg.what == 201) { dialog.setMessage("Parsing JSON....."); } else if (msg.what == 202) { dialog.setMessage("Populating UI!"); } else { //Close the Progress dialog dialog.dismiss(); //Alert the user that something went terribly wrong AlertDialog alertDialog = new AlertDialog.Builder(Search.this).create(); alertDialog.setTitle("API Error"); alertDialog.setMessage("There was an error communicating with the API:\n" + msg.getData().getString("exception")); alertDialog.setButton2("Back", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Search.this.finish(); } }); alertDialog.setIcon(R.drawable.error); alertDialog.show(); } } }; }
From source file:com.aegiswallet.actions.MainActivity.java
private void initiateHandlers(final TextView wallet_balance) { balanceHandler = new Handler() { @Override/* ww w . j a v a 2 s . c o m*/ public void handleMessage(Message msg) { final long now = System.currentTimeMillis(); boolean shouldNotify = false; //If the last view update time is less than one second ago we don't do anything. //This is to stop the app from crashing. if (now - lastViewUpdateTime.get() < 1500) { shouldNotify = false; } else shouldNotify = true; Bundle data = msg.getData(); int status = data.getInt("status"); switch (status) { case Constants.WALLET_UPDATE_COINS_RECEIVED: Double amountReceived = data.getDouble("amount"); notifyCoinsReceivedOrSent(amountReceived, true); if (shouldNotify) { updateMainViews(); } break; case Constants.WALLET_UPDATE_COINS_SENT: Double amountSent = data.getDouble("amount"); notifyCoinsReceivedOrSent(amountSent, false); if (shouldNotify) updateMainViews(); break; case Constants.WALLET_UPDATE_REORGANIZED: //Do something upon reorg? //updateMainViews(); if (shouldNotify) updateMainViews(); break; case Constants.WALLET_UPDATE_TRANS_CONFIDENCE: if (shouldNotify) { updateMainViews(); } break; case Constants.WALLET_UPDATE_CHANGED: //Do something upon change? if (shouldNotify) { checkWalletEncryptionStatus(); updateMainViews(); } break; case Constants.WALLET_UPDATE_KEYS_ADDED: if (shouldNotify) { updateMainViews(); } break; default: break; } } }; }
From source file:com.BeatYourRecord.SubmitActivity.java
public void upload(Uri videoUri) { this.dialog = new ProgressDialog(this); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setMessage("uploading ..."); dialog.setCancelable(false);/*from ww w . j av a 2s.co m*/ dialog.show(); Handler handler = new Handler() { @Override public void handleMessage(Message msg) { dialog.dismiss(); String videoId = msg.getData().getString("videoId"); Log.v("Video", videoId); String youtubelink = "http://www.youtube.com/watch?v=" + videoId; SharedPreferences pref = getApplicationContext().getSharedPreferences("TourPref", 0); // 0 - for private mode Editor editor = pref.edit(); editor.putString("myyoutubelink", youtubelink); editor.commit(); DefaultHttpClient client = new DefaultHttpClient(); Log.v("here1233", "here"); Log.v("authtoke", auth); HttpPost post = new HttpPost( "http://ec2-54-212-221-3.us-west-2.compute.amazonaws.com/api/v3/entries?auth_token=" + auth); JSONObject holder = new JSONObject(); JSONObject userObj = new JSONObject(); JSONObject userObj1 = new JSONObject(); JSONObject userObj2 = new JSONObject(); String response = null; JSONObject json = new JSONObject(); try { try { // setup the returned values in case // something goes wrong json.put("success", false); json.put("info", "Something went wrong. Retry!"); // add the user email and password to // the params String k = ""; String k1 = ""; String k2 = ""; //log.v("auth",auth); userObj.put("score", getTitleText()); SharedPreferences pref11 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode Editor editor11 = pref11.edit(); editor11.putString("score", getTitleText()); editor11.commit(); //////////////////////// holder.put("entry", userObj); k = holder.toString(); k = k.substring(0, k.length() - 2); k += ","; userObj1.put("tournament_id", tourid); k1 += userObj1.toString(); k1 = k1.substring(1, k1.length() - 1); k += k1; k += ","; userObj2.put("yt_video", youtubelink); k1 = userObj2.toString(); k1 = k1.substring(1, k1.length()); k += k1; /* double arr[] = new double[2]; arr[0]=lat; arr[1]=lng; JSONObject Array1 = new JSONObject(); Array1.put("geoloc", arr); k1=Array1.toString(); k1=k1.substring(1, k1.length()); k+=k1; userObj2.put("geoloc", String.valueOf(lat) +","+ String.valueOf(lng)); k1 += userObj2.toString(); k1=k1.substring(1, k1.length()); k+=k1;*/ k += "}"; //log.v("holder",k); StringEntity se = new StringEntity(k); post.setEntity(se); // setup the request headers post.setHeader("Content-Type", "application/json"); post.setHeader("Accept", "application/json"); // post.setHeader("Content-Type", "application/json"); //log.v("test1","wearegere"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); response = client.execute(post, responseHandler); json = new JSONObject(response); // test = json.getJSONObject("data").getString("auth_token"); // //log.v("test1",test); } catch (HttpResponseException e) { e.printStackTrace(); Log.e("ClientProtocol", "" + e); json.put("info", "Email and/or password are invalid. Retry!"); } catch (IOException e) { e.printStackTrace(); Log.e("IO", "" + e); } } catch (JSONException e) { e.printStackTrace(); Log.e("JSON", "" + e); } if (!Util.isNullOrEmpty(videoId)) { currentFileSize = 0; totalBytesUploaded = 0; Intent result = new Intent(); result.putExtra("videoId", videoId); Log.v("tired", videoId); setResult(RESULT_OK, result); finish(); } else { String error = msg.getData().getString("error"); if (!Util.isNullOrEmpty(error)) { Toast.makeText(SubmitActivity.this, error, Toast.LENGTH_LONG).show(); } } } }; asyncUpload(videoUri, handler); }
From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventsListFragment.java
private void configureHandlers() { AckSingleEventHandler = new Handler() { public void handleMessage(Message msg) { //Log.e("AckSingleEventHandler",Integer.toString(msg.what) + " / " + Integer.toString(msg.getData().getInt("position"))); switch (msg.what) { case ACKEVENTHANDLER_PROGRESS: { listOfZenossEvents.get(msg.getData().getInt("position")).setProgress(true); if (adapter != null) adapter.notifyDataSetChanged(); }/*from www. ja va 2s. c o m*/ break; case ACKEVENTHANDLER_SUCCESS: { if (null != listOfZenossEvents) { listOfZenossEvents.get(msg.getData().getInt("position")).setProgress(false); listOfZenossEvents.get(msg.getData().getInt("position")).setAcknowledged(); listOfZenossEvents.get(msg.getData().getInt("position")).setownerID("by you"); } RhybuddDataSource datasource = null; try { //TODO maybe do this with the bunch of ack id's we have in the thread? datasource = new RhybuddDataSource(getActivity()); datasource.open(); datasource.UpdateRhybuddEvents(listOfZenossEvents); } catch (Exception e) { e.printStackTrace(); BugSenseHandler.sendExceptionMessage("RhybuddHome", "AckEventHandler", e); } finally { if (null != datasource) datasource.close(); } if (adapter != null) adapter.notifyDataSetChanged(); } break; case ACKEVENTHANDLER_FAILURE: { if (null != listOfZenossEvents) listOfZenossEvents.get(msg.getData().getInt("position")).setProgress(false); if (adapter != null) adapter.notifyDataSetChanged(); try { Toast.makeText(getActivity(), "There was an error trying to ACK those events.", Toast.LENGTH_SHORT).show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("RhybuddHome", "ACKEVENTHANDLER_FAILURE", e); } } break; } } }; AckEventsHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case ACKEVENTHANDLER_PROGRESS: { if (null != listOfZenossEvents) { for (ZenossEvent evt : listOfZenossEvents) { if (!evt.getEventState().equals("Acknowledged")) { evt.setProgress(true); } } } if (adapter != null) adapter.notifyDataSetChanged(); } break; case ACKEVENTHANDLER_SUCCESS: { if (null != listOfZenossEvents) { for (ZenossEvent evt : listOfZenossEvents) { //if(!evt.getEventState().equals("Acknowledged") && evt.getProgress()) if (evt.getProgress()) { evt.setProgress(false); evt.setAcknowledged(); evt.setownerID("by you"); } } } RhybuddDataSource datasource = null; try { //TODO maybe do this with the bunch of ack id's we have in the thread? datasource = new RhybuddDataSource(getActivity()); datasource.open(); datasource.UpdateRhybuddEvents(listOfZenossEvents); } catch (Exception e) { e.printStackTrace(); BugSenseHandler.sendExceptionMessage("RhybuddHome", "AckEventsHandler", e); } finally { if (null != datasource) datasource.close(); } if (adapter != null) adapter.notifyDataSetChanged(); } break; case ACKEVENTHANDLER_FAILURE: { if (null != listOfZenossEvents) { for (ZenossEvent evt : listOfZenossEvents) { if (!evt.getEventState().equals("Acknowledged") && evt.getProgress()) { evt.setProgress(false); } } } if (adapter != null) adapter.notifyDataSetChanged(); try { Toast.makeText(getActivity(), "There was an error trying to ACK that event.", Toast.LENGTH_SHORT).show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("RhybuddHome", "ACKEVENTHANDLER_FAILURE", e); } } break; } } }; eventsListHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case EVENTSLISTHANDLER_DISMISS: { } break; case EVENTSLISTHANDLER_DELAYED_AB_STATUS: { try { if (null != refreshStatus) { refreshStatus.setActionView(abprogress); } else { if (dialog == null || !dialog.isShowing()) { dialog = new ProgressDialog(getActivity()); } dialog.setTitle("Querying Zenoss Directly"); dialog.setMessage("Refreshing Events..."); //ToDo set cancellable if (!dialog.isShowing()) dialog.show(); } } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "EVENTSLISTHANDLER_DELAYED_AB_STATUS", e); } } break; case EVENTSLISTHANDLER_ERROR: { try { Toast.makeText(getActivity(), "An error was encountered;\r\n" + msg.getData().getString("exception"), Toast.LENGTH_LONG).show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "EVENTSLISTHANDLER_ERROR", e); } } break; case EVENTSLISTHANDLER_DIALOGUPDATE: { if (dialog != null && dialog.isShowing()) { try { dialog.setMessage("Refresh Complete!"); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "EVENTSLISTHANDLER_DIALOGUPDATE", e); } try { this.sendEmptyMessageDelayed(EVENTSLISTHANDLER_SUCCESS, 1000); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "EVENTSLISTHANDLER_DIALOGUPDATE", e); } } else { if (null != refreshStatus) { try { refreshStatus.setIcon(R.drawable.ic_action_refresh); getActivity().invalidateOptionsMenu(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "EVENTSLISTHANDLER_DIALOGUPDATE", e); } } } } break; case EVENTSLISTHANDLER_SUCCESS: { if (null != refreshStatus) { try { refreshStatus.setIcon(R.drawable.ic_action_refresh); getActivity().invalidateOptionsMenu(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "EVENTSLISTHANDLER_SUCCESS", e); } } if (dialog != null && dialog.isShowing()) { try { dialog.dismiss(); } catch (Exception e) { e.printStackTrace(); } } try { adapter = new ZenossEventsAdaptor(getActivity(), listOfZenossEvents); setListAdapter(adapter); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "EVENTSLISTHANDLER_SUCCESS", e); } } break; case EVENTSLISTHANDLER_DB_EMPTY: { if (null != refreshStatus) { refreshStatus.setActionView(abprogress); getActivity().invalidateOptionsMenu(); } else { // Log.e("refreshStatus","refreshStatus was null reverting to using dialog"); try { if (dialog != null && dialog.isShowing()) { dialog.setMessage( "DB Cache incomplete.\r\nQuerying Zenoss directly.\r\nPlease wait...."); } else { dialog = new ProgressDialog(getActivity()); dialog.setMessage( "DB Cache incomplete.\r\nQuerying Zenoss directly.\r\nPlease wait...."); //dialog.setCancelable(false); //Log.e("EVENTSLISTHANDLER_DB_EMPTY", "Showing a dialog"); dialog.show(); } } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "EVENTSLISTHANDLER_DB_EMPTY", e); } } } break; case EVENTSLISTHANDLER_NO_EVENTS: { if (null != refreshStatus) { try { refreshStatus.setIcon(R.drawable.ic_action_refresh); getActivity().invalidateOptionsMenu(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("EVENTSLISTHANDLER_NO_EVENTS", "invalidateOptionsMenu", e); } } if (dialog != null && dialog.isShowing()) { try { dialog.dismiss(); } catch (Exception e) { e.printStackTrace(); } } try { listOfZenossEvents.clear(); adapter.notifyDataSetChanged(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("EventsListFragment", "no events adapter notify", e); } try { Toast.makeText(getActivity(), "No events found. Must be a quiet day!", Toast.LENGTH_LONG) .show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("EventsListFragment", "Quiet day Toast", e); } } break; case EVENTSLISTHANDLER_TOTAL_FAILURE: { if (null != refreshStatus) { try { refreshStatus.setIcon(R.drawable.ic_action_refresh); getActivity().invalidateOptionsMenu(); } catch (NullPointerException npe) { //Don't care } catch (Exception e) { BugSenseHandler.sendExceptionMessage("EventsListFragment", "RefreshThreadSleep", e); } } if (null != dialog && dialog.isShowing()) { try { dialog.dismiss(); } catch (Exception e) { e.printStackTrace(); } } try { Toast.makeText(getActivity(), "Last Error: " + API.getLastException(), Toast.LENGTH_LONG); } catch (Exception e) { try { Toast.makeText(getActivity(), "Attempted to show the last received error but it was null.", Toast.LENGTH_LONG); } catch (Exception e1) { BugSenseHandler.sendExceptionMessage("EventsListFragment", "Error toast", e1); } } try { mCallbacks.fetchError(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("EventsListFragment", "Calling mCallbacks.fetchError()", e); } } break; case EVENTSLISTHANDLER_SERVICE_NOT_STARTED: { try { dialog = new ProgressDialog(getActivity()); dialog.setTitle("Querying Zenoss Directly"); //Log.e("Refresh","The service wasn't running for some reason"); dialog.setMessage("The backend service wasn't running.\n\nStarting..."); //ToDo set cancellable if (!dialog.isShowing()) dialog.show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("EventsListFragment", "EVENTSLISTHANDLER_SERVICE_NOT_STARTED", e); } } break; case EVENTSLISTHANDLER_SERVICE_FAILURE: { if (null != refreshStatus) { refreshStatus.setIcon(R.drawable.ic_action_refresh); getActivity().invalidateOptionsMenu(); } if (null != dialog && dialog.isShowing()) { try { dialog.dismiss(); } catch (Exception e) { e.printStackTrace(); } } Toast.makeText(getActivity(), "Rhybudd was unable to reach its internal service.\n\nThis will cause some issues with fetching events", Toast.LENGTH_LONG).show(); } break; case EVENTSLISTHANDLER_REDOREFRESH: { Refresh(); } break; } } }; }
From source file:de.tudresden.inf.rn.mobilis.mxa.XMPPRemoteService.java
/** * Get all packets that are in the LostIQQueue and sends them. Assumes that * for every packet there is a corresponding thread. *///from w w w . jav a 2 s .c om public void resendIQ() { // to the same as sendIQ, but we take the values from the list Log.v(TAG, "start resending iqs"); LostIQQueueEntry e; int size = mIQQueue.getCount(); // try to send each packet only once for (int i = 0; i < size; i++) { e = mIQQueue.getOldestEntry(); if (e == null) return; if (e.mSending) continue; e.mSending = true; Message msg = Message.obtain(e.mMessage); msg.what = ConstMXA.MSG_IQ_RESEND; msg.getData().putLong(ConstMXA.IQ_RESEND_ID, e.mID); IQRunner iqRunJob = new IQRunner(msg); mWriteExecutor.execute(iqRunJob); } Log.v(TAG, "end resending iqs"); }