List of usage examples for android.os Handler sendMessage
public final boolean sendMessage(Message msg)
From source file:Main.java
public static void sendMessageHandler(Handler handler, int what, Bundle bundle) { Message message = new Message(); message.what = what;//from w w w .ja v a 2s. com message.setData(bundle); handler.sendMessage(message); }
From source file:Main.java
public static void sendMessageHandler(Handler handler, int what, String key, int value) { Message message = new Message(); message.what = what;//ww w. j a v a2 s . c o m Bundle bundle = new Bundle(); bundle.putInt(key, value); message.setData(bundle); handler.sendMessage(message); }
From source file:Main.java
public static void sendMessageHandler(Handler handler, int what, String key, String value) { Message message = new Message(); message.what = what;//from ww w . j a v a 2 s .c om Bundle bundle = new Bundle(); bundle.putString(key, value); message.setData(bundle); handler.sendMessage(message); }
From source file:net.cs76.projects.student10792819.DrawableManager.java
/** * Fetch drawable on thread. Fetches drawable on a separate thread. * * @param urlString the url string/*from w w w . j av a2 s. c om*/ * @param listingAdapter the listing adapter * @param thumbnailCache the image view * @param position the position */ public static void fetchDrawableOnThread(final String urlString, final ListingAdapter listingAdapter, final Drawable[] thumbnailCache, final int position) { if (drawableMap.containsKey(urlString)) { Drawable o = drawableMap.get(urlString).get(); if (o != null) { thumbnailCache[position] = o; listingAdapter.notifyDataSetChanged(); return; } } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { thumbnailCache[position] = (Drawable) message.obj; listingAdapter.notifyDataSetChanged(); } }; Thread thread = new Thread() { @Override public void run() { Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:com.max2idea.android.fwknop.Fwknop.java
public static void sendHandlerMessage(Handler handler, int message_type) { Message msg1 = handler.obtainMessage(); Bundle b = new Bundle(); b.putInt("message_type", message_type); msg1.setData(b);/*from w w w. j a va 2 s .c om*/ handler.sendMessage(msg1); }
From source file:com.tinyhydra.botd.BotdServerOperations.java
public static void GetTopTen(final Activity activity, final Handler handler, boolean override) { final SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0); final List<JavaShop> TopTen = new ArrayList<JavaShop>(); for (int i = 0; i < 10; i++) { TopTen.add(new JavaShop()); }// w w w .j a va 2s.c o m if (settings.getLong(Const.LastTopTenQueryTime, 0) > (Calendar.getInstance().getTimeInMillis() - 180000) & !override) { Message msg = new Message(); msg.arg1 = Const.CODE_GETTOPTEN; handler.sendMessage(msg); } else new Thread() { @Override public void run() { BufferedReader in = null; try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.setURI(new URI(activity.getResources().getString(R.string.server_url))); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; while ((line = in.readLine()) != null) { sb.append(line); } in.close(); SharedPreferences.Editor editor = settings.edit(); editor.putString(Const.LastTopTenQueryResults, sb.toString()); editor.putLong(Const.LastTopTenQueryTime, Calendar.getInstance().getTimeInMillis()); editor.commit(); Message msg = new Message(); msg.arg1 = Const.CODE_GETTOPTEN; handler.sendMessage(msg); // more generic error handling //TODO: implement better error handling } catch (URISyntaxException usex) { usex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } catch (ClientProtocolException cpex) { cpex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } catch (IOException iex) { iex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }.start(); }
From source file:com.max2idea.android.fwknop.Fwknop.java
public static void sendHandlerMessage(Handler handler, int message_type, String message_var, String message_value) {//from w w w .jav a 2 s .co m Message msg1 = handler.obtainMessage(); Bundle b = new Bundle(); b.putInt("message_type", message_type); b.putString(message_var, message_value); msg1.setData(b); handler.sendMessage(msg1); }
From source file:Main.java
public static void getNewsJSON(final String url, final Handler handler) { new Thread(new Runnable() { @Override/*from ww w. j a va2 s .c o m*/ public void run() { HttpURLConnection conn; InputStream is; try { conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestMethod("GET"); is = conn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = ""; StringBuffer result = new StringBuffer(); while ((line = reader.readLine()) != null) { result.append(line); } Message msg = new Message(); msg.obj = result.toString(); handler.sendMessage(msg); } catch (Exception e) { e.printStackTrace(); } } }).start(); }
From source file:it.cdpaf.helper.DrawableManager.java
public static void fetchDrawableOnThread(final Category cat, final ImageView imageView, final Context ctx) { final String urlString = Const.IMAGE_URL + cat.getNomeImmagine(); if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); //product.setImmagine(drawableMap.get(urlString)); }/*w w w. ja v a 2s .c o m*/ final Handler handler = new Handler() { @Override public void handleMessage(Message message) { Drawable dr = (Drawable) message.obj; imageView.setImageDrawable(dr); cat.setImmagine(dr); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable d = ctx.getResources().getDrawable(R.drawable.ic_launcher); Message messagea = handler.obtainMessage(1, d); handler.sendMessage(messagea); Drawable drawable = fetchDrawable(urlString, ctx); Message messageb = handler.obtainMessage(1, drawable); handler.sendMessage(messageb); } }; thread.start(); }
From source file:it.cdpaf.helper.DrawableManager.java
public static void fetchDrawableOnThread(final Macrocategory mac, final ImageView imageView, final Context ctx) { final String urlString = Const.IMAGE_URL + mac.getNomeImmagine(); if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); //product.setImmagine(drawableMap.get(urlString)); }// w ww . ja v a2 s . co m final Handler handler = new Handler() { @Override public void handleMessage(Message message) { Drawable dr = (Drawable) message.obj; imageView.setImageDrawable(dr); mac.setImmagine(dr); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable d = ctx.getResources().getDrawable(R.drawable.ic_launcher); Message messagea = handler.obtainMessage(1, d); handler.sendMessage(messagea); Drawable drawable = fetchDrawable(urlString, ctx); Message messageb = handler.obtainMessage(1, drawable); handler.sendMessage(messageb); } }; thread.start(); }