List of usage examples for android.os Handler Handler
public Handler()
From source file:com.mytutor.search.ImageLoader.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { Log.d("IMG 1", "Getting Image"); imageView.setImageDrawable(drawableMap.get(urlString)); }/*from w w w. ja v a 2 s . co m*/ final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:com.example.hotelapp.DrawableManager.java
@SuppressLint("HandlerLeak") public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); }/*from w w w .jav a2 s. co m*/ final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:com.oonusave.coupon.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); return;/*from w ww . jav a 2 s . co m*/ } if (urlString != null && "".equalsIgnoreCase(urlString)) { return; } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); drawableMap.put(urlString, drawable); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:org.ligi.android.dubwise_uavtalk.dashboard.DownloadDashboardImagesStatusAlertDialog.java
/** * //from w w w. j a v a 2 s .c o m * @param activity * @param autoclose - if the alert should close when connection is established * */ public static void show(Context activity, boolean autoclose, Intent after_connection_intent) { LinearLayout lin = new LinearLayout(activity); lin.setOrientation(LinearLayout.VERTICAL); ScrollView sv = new ScrollView(activity); TextView details_text_view = new TextView(activity); LinearLayout lin_in_scrollview = new LinearLayout(activity); lin_in_scrollview.setOrientation(LinearLayout.VERTICAL); sv.addView(lin_in_scrollview); lin_in_scrollview.addView(details_text_view); details_text_view.setText("no text"); ProgressBar progress = new ProgressBar(activity, null, android.R.attr.progressBarStyleHorizontal); progress.setMax(img_lst.length); lin.addView(progress); lin.addView(sv); new AlertDialog.Builder(activity).setTitle("Download Status").setView(lin) .setPositiveButton("OK", new DialogDiscardingOnClickListener()).show(); class AlertDialogUpdater implements Runnable { private Handler h = new Handler(); private TextView myTextView; private ProgressBar myProgress; public AlertDialogUpdater(TextView ab, ProgressBar progress) { myTextView = ab; myProgress = progress; } public void run() { for (int i = 0; i < img_lst.length; i++) { class MsgUpdater implements Runnable { private int i; public MsgUpdater(int i) { this.i = i; } public void run() { myProgress.setProgress(i + 1); if (i != img_lst.length - 1) myTextView.setText("Downloading " + img_lst[i] + ".png"); else myTextView.setText("Ready - please restart DUBwise to apply changes!"); } } h.post(new MsgUpdater(i)); try { URLConnection ucon = new URL(url_lst[i]).openConnection(); BufferedInputStream bis = new BufferedInputStream(ucon.getInputStream()); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) baf.append((byte) current); File path = new File( Environment.getExternalStorageDirectory() + "/dubwise/images/dashboard"); path.mkdirs(); FileOutputStream fos = new FileOutputStream( new File(path.getAbsolutePath() + "/" + img_lst[i] + ".png")); fos.write(baf.toByteArray()); fos.close(); } catch (Exception e) { } try { Thread.sleep(199); } catch (InterruptedException e) { } } } } new Thread(new AlertDialogUpdater(details_text_view, progress)).start(); }
From source file:com.facebook.android.friendsmash.ScoreboardFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); application = (FriendSmashApplication) getActivity().getApplication(); // Instantiate the handler uiHandler = new Handler(); setRetainInstance(true);/*from w ww. j av a 2 s. co m*/ }
From source file:net.cs76.projects.student10792819.DrawableManager.java
/** * Fetch drawable on thread. Fetches drawable on a separate thread. * * @param urlString the url string// w ww .j av a 2 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.cloudsynch.quickshare.http.AsyncHttpResponseHandler.java
/** * Creates a new AsyncHttpResponseHandler *///from w ww. j a v a 2 s . c o m public AsyncHttpResponseHandler(ResultParser<T> parser) { // Set up a handler to post events back to the correct thread if // possible mParser = parser; if (Looper.myLooper() != null) { handler = new Handler() { @Override public void handleMessage(Message msg) { AsyncHttpResponseHandler.this.handleMessage(msg); } }; } }
From source file:com.chuannuo.tangguo.net.TGHttpResponseHandler.java
/** * Creates a new AsyncHttpResponseHandler *//*from w ww . j ava 2 s . c o m*/ public TGHttpResponseHandler() { // Set up a handler to post events back to the correct thread if possible if (Looper.myLooper() != null) { handler = new Handler() { @Override public void handleMessage(Message msg) { TGHttpResponseHandler.this.handleMessage(msg); } }; } }
From source file:com.android.mail.browse.AttachmentActionHandler.java
public AttachmentActionHandler(Context context, AttachmentViewInterface view) { mCommandHandler = new AttachmentCommandHandler(context); mView = view;//from ww w . j a v a 2 s .co m mContext = context; mHandler = new Handler(); mViewOnFinish = true; }
From source file:com.nonstop.android.SoC.Facebook.Hackbook.java
/** Called when the activity is first created. */ @Override/* w w w. ja v a2s .c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see FbAPIs.java"); return; } setContentView(R.layout.main); mHandler_facebook = new Handler(); mText = (TextView) Hackbook.this.findViewById(R.id.txt); mUserPic = (ImageView) Hackbook.this.findViewById(R.id.user_pic); // Create the Facebook Object using the app id. Utility.mFacebook = new Facebook(APP_ID); // Instantiate the asynrunner object for asynchronous api calls. Utility.mAsyncRunner = new AsyncFacebookRunner(Utility.mFacebook); mLoginButton = (LoginButton) findViewById(R.id.login); // restore session if one exists SessionStore.restore(Utility.mFacebook, this); SessionEvents.addAuthListener(new FbAPIsAuthListener()); SessionEvents.addLogoutListener(new FbAPIsLogoutListener()); /* * Source Tag: login_tag */ mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions); if (Utility.mFacebook.isSessionValid()) { requestUserData(); } list = (ListView) findViewById(R.id.main_list); list.setOnItemClickListener(this); list.setAdapter(new ArrayAdapter<String>(this, R.layout.main_list_item, main_items)); }