List of usage examples for android.os Handler sendEmptyMessage
public final boolean sendEmptyMessage(int what)
From source file:org.privatenotes.sync.web.SnowySyncService.java
public void remoteAuthComplete(final Uri uri, final Handler handler) { execInThread(new Runnable() { public void run() { try { // TODO: might be intelligent to show something like a progress dialog // else the user might try to sync before the authorization process // is complete OAuthConnection auth = getAuthConnection(); boolean result = auth.getAccess(uri.getQueryParameter("oauth_verifier")); if (result) { if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "The authorization process is complete."); } else { Log.e(TAG, "Something went wrong during the authorization process."); }/* w w w. j av a 2s.c o m*/ } catch (UnknownHostException e) { Log.e(TAG, "Internet connection not available"); sendMessage(NO_INTERNET); } // We don't care what we send, just remove the dialog handler.sendEmptyMessage(0); } }); }
From source file:org.privatenotes.sync.web.SnowySyncMethod.java
public void remoteAuthComplete(final Uri uri, final Handler handler) { execInThread(new Runnable() { public void run() { try { // TODO: might be intelligent to show something like a progress dialog // else the user might try to sync before the authorization process // is complete OAuthConnection auth = SyncServer.getAuthConnection(); boolean result = auth.getAccess(uri.getQueryParameter("oauth_verifier")); if (result) { if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "The authorization process is complete."); } else { Log.e(TAG, "Something went wrong during the authorization process."); }/*from w ww . jav a 2s . c o m*/ } catch (UnknownHostException e) { Log.e(TAG, "Internet connection not available"); sendMessage(NO_INTERNET); } // We don't care what we send, just remove the dialog handler.sendEmptyMessage(0); } }); }
From source file:cgeo.geocaching.CacheListActivity.java
private static void clearOfflineLogs(final Handler handler, final List<Geocache> selectedCaches) { Schedulers.io().scheduleDirect(new Runnable() { @Override//from ww w. j a v a 2 s . co m public void run() { DataStore.clearLogsOffline(selectedCaches); handler.sendEmptyMessage(DownloadProgress.MSG_DONE); } }); }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * Submits a Certification Request to the controller *//* w w w . j a va 2 s. c o m*/ private void requestAccess() { final String hostname = AppSettingsActivity.currentServer; if (!TextUtils.isEmpty(hostname)) { final ProgressDialog progress = new ProgressDialog(this); final Handler handler = new Handler() { public void handleMessage(Message msg) { if (progress.isShowing()) { progress.dismiss(); } } }; if (isActivityResumed()) { progress.show(); } new Thread() { public void run() { handler.sendEmptyMessage(ORPKCS10CertificationRequest.getInstance(getApplicationContext()) .submitCertificationRequest(hostname)); } }.start(); } }
From source file:com.df.app.carCheck.VehicleInfoLayout.java
/** * edit/*from w w w. jav a 2 s .c om*/ */ private void showListDialog(int titleId, ArrayAdapter<String> adapter, final Handler handler) { View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null); final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create(); TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea); final ListView listView = new ListView(view1.getContext()); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { handler.sendEmptyMessage(i); dialog.dismiss(); } }); contentArea.addView(listView); setTextView(view1, R.id.title, getResources().getString(titleId)); dialog.show(); }
From source file:com.gimranov.zandy.app.task.APIRequest.java
/** * Set an Android standard handler to be used for the APIEvents * @param handler//from ww w. j a va2 s . c o m */ public void setHandler(Handler handler) { final Handler mHandler = handler; if (this.handler == null) { this.handler = new APIEvent() { @Override public void onComplete(APIRequest request) { mHandler.sendEmptyMessage(BATCH_DONE); } @Override public void onUpdate(APIRequest request) { mHandler.sendEmptyMessage(UPDATED_DATA); } @Override public void onError(APIRequest request, Exception exception) { mHandler.sendEmptyMessage(ERROR_UNKNOWN); } @Override public void onError(APIRequest request, int error) { mHandler.sendEmptyMessage(ERROR_UNKNOWN); } }; return; } Log.e(TAG, "APIEvent handler for request cannot be replaced"); }
From source file:cl.droid.transantiago.activity.TransChooseServiceActivity.java
private Bitmap loadImage(final String URL, final BitmapFactory.Options options) { final Handler handler = new Handler() { // @Override // public void handleMessage(Message msg) { // ads.setImageBitmap(bm); // } };/*from w w w. jav a 2s .c om*/ new Thread(new Runnable() { public void run() { InputStream in = null; try { in = OpenHttpConnection(URL); final Bitmap bitmap = BitmapFactory.decodeStream(in, null, options); in.close(); handler.post(new Runnable() { public void run() { if (ads != null && bitmap != null) { ads.setImageBitmap(bitmap); } } }); } catch (IOException e1) { handler.sendEmptyMessage(0); } catch (Exception e1) { handler.sendEmptyMessage(0); } //return bitmap; } }).start(); return null; }
From source file:org.smart.library.widget.SlideSwitch.java
public void moveToDest(final boolean toRight) { final Handler handler = new Handler() { @Override/* ww w .ja v a 2 s. co m*/ public void handleMessage(Message msg) { if (listener != null) listener.onSlide(SlideSwitch.this, msg.what == 1); } }; new Thread(new Runnable() { @Override public void run() { if (toRight) { while (frontRect_left <= max_left) { alpha = (int) (255 * (float) frontRect_left / (float) max_left); invalidateView(); frontRect_left += 3; try { Thread.sleep(3); } catch (InterruptedException e) { L.e(e.getMessage(), e); } } alpha = 255; frontRect_left = max_left; if (!isOpen) { isOpen = true; if (listener != null) handler.sendEmptyMessage(1); } frontRect_left_begin = max_left; } else { while (frontRect_left >= min_left) { alpha = (int) (255 * (float) frontRect_left / (float) max_left); invalidateView(); frontRect_left -= 3; try { Thread.sleep(3); } catch (InterruptedException e) { L.e(e.getMessage(), e); } } alpha = 0; frontRect_left = min_left; if (isOpen) { isOpen = false; if (listener != null) handler.sendEmptyMessage(0); } frontRect_left_begin = min_left; } } }).start(); }
From source file:com.ibuildapp.romanblack.TableReservationPlugin.utils.TableReservationHTTP.java
/** * This method sends HTTP request to cancel order. * * @param orderUUID order UID//from ww w .ja v a 2s.c om * @param user user * @param handler result handler * @param orderInfo order info */ public static void sendCancelOrderRequest(String orderUUID, User user, Handler handler, TableReservationInfo orderInfo) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 15000); HttpConnectionParams.setSoTimeout(httpParameters, 15000); HttpClient httpclient = new DefaultHttpClient(httpParameters); HttpPost httppost = new HttpPost(CANCEL_ORDER_URL); Log.e(TAG, "CANCEL_ORDER_URL = " + CANCEL_ORDER_URL); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); // order details nameValuePairs.add(new BasicNameValuePair("order_uid", orderUUID)); // user details nameValuePairs.add(new BasicNameValuePair("user_id", user.getAccountId())); String userType = null; if (user.getAccountType() == User.ACCOUNT_TYPES.FACEBOOK) { userType = "facebook"; } else if (user.getAccountType() == User.ACCOUNT_TYPES.TWITTER) { userType = "twitter"; } else if (user.getAccountType() == User.ACCOUNT_TYPES.IBUILDAPP) { userType = "ibuildapp"; } else if (user.getAccountType() == User.ACCOUNT_TYPES.GUEST) { userType = "guest"; } nameValuePairs.add(new BasicNameValuePair("user_type", userType)); // module info nameValuePairs.add(new BasicNameValuePair("app_id", orderInfo.getAppid())); nameValuePairs.add(new BasicNameValuePair("module_id", orderInfo.getModuleid())); // add security part nameValuePairs.add(new BasicNameValuePair("app_id", Statics.appId)); nameValuePairs.add(new BasicNameValuePair("token", Statics.appToken)); try { httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException uEEx) { Log.e("", ""); } ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { String strResponseSaveGoal = httpclient.execute(httppost, responseHandler); Log.d("sendCancelOrderRequest", strResponseSaveGoal); } catch (ConnectTimeoutException conEx) { handler.sendEmptyMessage(CANCEL_REQUEST_ERROR); } catch (ClientProtocolException ex) { Log.d("sendCancelOrderRequest", ""); handler.sendEmptyMessage(CANCEL_REQUEST_ERROR); } catch (IOException ex) { Log.d("sendCancelOrderRequest", ""); handler.sendEmptyMessage(CANCEL_REQUEST_ERROR); } }
From source file:net.networksaremadeofstring.pulsant.portal.ViewTicket.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.viewticket); list = (ListView) findViewById(R.id.TicketUpdatesList); final ProgressDialog dialog = ProgressDialog.show(this, "Pulsant Portal", "Please wait: loading data....", true);//from w w w.j a va 2s . c o m final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); TicketUpdatesAdaptor adapter = new TicketUpdatesAdaptor(ViewTicket.this, listOfUpdates, API.SessionID); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { TicketAPI = API.PortalQuery("updates", getIntent().getStringExtra("ticketID")); Success = TicketAPI.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured. Error Code: 1"; Log.e("APIFuncs", e.getMessage()); } if (Success.equals("false")) { try { Log.i("APIFuncs", TicketAPI.toString(3)); ErrorMessage = TicketAPI.getString("msg"); } catch (JSONException e) { ErrorMessage = e.getMessage(); Log.e("APIFuncs", e.getMessage()); } handler.sendEmptyMessage(0); } else { Log.i("APIFuncs", TicketAPI.toString()); try { Updates = TicketAPI.getJSONArray("updates"); ErrorMessage = ""; } catch (JSONException e) { ErrorMessage = "There are no updates for this ticket. (Strange!)"; } int TicketCount = Updates.length(); if (TicketCount == 0) { ErrorMessage = "There are no updates for this ticket."; return; } for (int i = 0; i < TicketCount; i++) { try { CurrentTicket = Updates.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } if (CurrentTicket != null) { listOfUpdates.add(new TicketUpdates(GetString("type"), GetString("name"), GetInt("time"), GetString("content"))); } } handler.sendEmptyMessage(0); } } }; dataPreload.start(); Button AddReply = (Button) findViewById(R.id.AddReplyButton); AddReply.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent CreateTicketReplyIntent = new Intent(ViewTicket.this, AddTicketReply.class); CreateTicketReplyIntent.putExtra("sessionid", API.SessionID); CreateTicketReplyIntent.putExtra("ticketid", getIntent().getStringExtra("ticketID")); ViewTicket.this.startActivity(CreateTicketReplyIntent); } }); /* try { TicketAPI = API.PortalQuery("updates", getIntent().getStringExtra("ticketID")); Success = TicketAPI.getString("success"); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured. Error Code: 1"); Log.e("APIFuncs",e.getMessage()); //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show(); } if(Success == "false") { try { Log.i("APIFuncs",TicketAPI.toString(3)); UpdateErrorMessage(TicketAPI.getString("msg")); } catch (JSONException e) { Log.e("APIFuncs",e.getMessage()); UpdateErrorMessage("An unrecoverable JSON Exception occured. Error Code: 2"); } } else { Log.i("APIFuncs",TicketAPI.toString()); try { Updates = TicketAPI.getJSONArray("updates"); UpdateErrorMessage(""); } catch (JSONException e) { UpdateErrorMessage("There are no updates for this ticket. (Strange!)"); } //OK lets actually do something useful List<TicketUpdates> listOfUpdates = new ArrayList<TicketUpdates>(); int TicketCount = Updates.length(); if(TicketCount == 0) { UpdateErrorMessage("There are no updates for this ticket."); return; } for(int i = 0; i < TicketCount; i++) { try { CurrentTicket = Updates.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs",e1.getMessage()); } if(CurrentTicket != null) { listOfUpdates.add(new TicketUpdates(GetString("type"), GetString("name"), GetInt("time"), GetString("content"))); } } TicketUpdatesAdaptor adapter = new TicketUpdatesAdaptor(this, listOfUpdates, API.SessionID); list.setAdapter(adapter); }*/ }