List of usage examples for android.os Handler Handler
public Handler()
From source file:zjut.soft.finalwork.fragment.PageFragment1.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.page1, null); tv = (TextView) view.findViewById(R.id.page1_textview); mHandler = new Handler(); return view;//from ww w . j a v a2 s .c om }
From source file:org.ametro.util.WebUtil.java
public static void downloadFileAsync(final Context appContext, final File path, final URI uri, final File temp) { final DownloadContext context = new DownloadContext(); context.Path = path;/* www . j ava2s .com*/ context.IsCanceled = false; context.IsUnpackFinished = false; context.IsFailed = false; final NotificationManager notificationManager = (NotificationManager) appContext .getSystemService(Context.NOTIFICATION_SERVICE); final Handler handler = new Handler(); final Runnable updateProgress = new Runnable() { public void run() { if (context.Notification == null) { context.Notification = new Notification(android.R.drawable.stat_sys_download, "Downloading icons", System.currentTimeMillis()); context.Notification.flags = Notification.FLAG_NO_CLEAR; Intent notificationIntent = new Intent(); context.ContentIntent = PendingIntent.getActivity(appContext, 0, notificationIntent, 0); } if (context.IsFailed) { notificationManager.cancelAll(); context.Notification = new Notification(android.R.drawable.stat_sys_warning, "Icons download failed", System.currentTimeMillis()); context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons downloaded failed", context.ContentIntent); notificationManager.notify(2, context.Notification); } else if (context.IsUnpackFinished) { notificationManager.cancelAll(); context.Notification = new Notification(android.R.drawable.stat_sys_download_done, "Icons unpacked", System.currentTimeMillis()); context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons downloaded and unpacked.", context.ContentIntent); notificationManager.notify(3, context.Notification); } else if (context.Position == 0 && context.Total == 0) { context.Notification.setLatestEventInfo(appContext, "aMetro", "Download icons: connecting server", context.ContentIntent); notificationManager.notify(1, context.Notification); } else if (context.Position < context.Total) { context.Notification.setLatestEventInfo(appContext, "aMetro", "Download icons: " + context.Position + "/" + context.Total, context.ContentIntent); notificationManager.notify(1, context.Notification); } else { context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons unpacking", context.ContentIntent); notificationManager.notify(1, context.Notification); } } }; final Thread async = new Thread() { public void run() { WebUtil.downloadFile(context, uri, temp, false, new IDownloadListener() { public void onBegin(Object context, File file) { DownloadContext downloadContext = (DownloadContext) context; downloadContext.Total = 0; downloadContext.Position = 0; handler.removeCallbacks(updateProgress); handler.post(updateProgress); } public boolean onUpdate(Object context, long position, long total) { DownloadContext downloadContext = (DownloadContext) context; downloadContext.Total = total; downloadContext.Position = position; handler.removeCallbacks(updateProgress); handler.post(updateProgress); return !downloadContext.IsCanceled; } public void onDone(Object context, File file) throws Exception { DownloadContext downloadContext = (DownloadContext) context; File path = downloadContext.Path; ZipUtil.unzip(file, path); downloadContext.IsUnpackFinished = true; handler.removeCallbacks(updateProgress); handler.post(updateProgress); } public void onCanceled(Object context, File file) { DownloadContext downloadContext = (DownloadContext) context; downloadContext.IsCanceled = true; handler.removeCallbacks(updateProgress); handler.post(updateProgress); } public void onFailed(Object context, File file, Throwable reason) { DownloadContext downloadContext = (DownloadContext) context; downloadContext.IsFailed = true; handler.removeCallbacks(updateProgress); handler.post(updateProgress); } }); }; }; async.start(); }
From source file:de.quadrillenschule.azocamsynca.job.JobProcessor.java
public JobProcessor(Activity ac) { handler = new Handler(); this.activity = ac; }
From source file:com.fly1tkg.streamfileupload.FileUploadFacade.java
public FileUploadFacade(HttpClient httpClient) { mHttpClient = httpClient; mHandler = new Handler(); }
From source file:uk.ac.horizon.ubihelper.ui.TestActivity.java
/** Called when the activity is first created. */ @Override/*w w w . ja va 2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); setContentView(R.layout.main); text = (TextView) findViewById(R.id.test_text); Button test = (Button) findViewById(R.id.test_button); test.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { new Thread() { public void run() { doTest(); } }.start(); } }); }
From source file:com.samsung.locator.SamiActivity.java
/** * Setup UI, start available location providers and connect to SAMI * @param savedInstanceState/*from w ww . jav a2 s .c o m*/ */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sami); if (Config.ACCESS_TOKEN == null || Config.DEVICE_ID == null) { Toast.makeText(this, R.string.configure, Toast.LENGTH_LONG).show(); return; } handler = new Handler(); webView = (WebView) findViewById(R.id.webView); Config.setWebViewSettings(webView); locationWatcher = new LocationWatcher(this); locationWatcher.start(new LocationEvents.Listener() { @Override public void onNewLocation(final Location location, long ts) { //Avoid blocking here, UI and network jobs ahead handler.postDelayed(new Runnable() { @Override public void run() { connectWebsocketAndSendLocation(location); } }, 10); handler.postDelayed(new Runnable() { @Override public void run() { connectLiveWebsocket(); } }, 10); } }); }
From source file:nya.miku.wishmaster.http.recaptcha.RecaptchaAjax.java
public static void init() { sHandler = new Handler(); }
From source file:com.facebook.samples.socialcafe.MenuFragmentActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);//from w w w. j ava 2 s. co m setRetainInstance(true); mHandler = new Handler(); userName = ((SocialCafeApplication) getActivity().getApplication()).userName; userPic = ((SocialCafeApplication) getActivity().getApplication()).userPic; if (userName == null || userPic == null) { requestUserData(); } }
From source file:com.facebook.android.UploadPhotoResultDialog.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); setContentView(R.layout.upload_photo_response); LayoutParams params = getWindow().getAttributes(); params.width = LayoutParams.FILL_PARENT; params.height = LayoutParams.FILL_PARENT; getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); mOutput = (TextView) findViewById(R.id.apiOutput); mUsefulTip = (TextView) findViewById(R.id.usefulTip); mViewPhotoButton = (Button) findViewById(R.id.view_photo_button); mTagPhotoButton = (Button) findViewById(R.id.tag_photo_button); mUploadedPhoto = (ImageView) findViewById(R.id.uploadedPhoto); JSONObject json;/* ww w . j a va 2 s. co m*/ try { json = Util.parseJson(response); final String photo_id = json.getString("id"); this.photo_id = photo_id; mOutput.setText(json.toString(2)); mUsefulTip.setText(activity.getString(R.string.photo_tip)); Linkify.addLinks(mUsefulTip, Linkify.WEB_URLS); mViewPhotoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (hidePhoto) { mViewPhotoButton.setText(R.string.view_photo); hidePhoto = false; mUploadedPhoto.setImageBitmap(null); } else { hidePhoto = true; mViewPhotoButton.setText(R.string.hide_photo); /* * Source tag: view_photo_tag */ Bundle params = new Bundle(); params.putString("fields", "picture"); dialog = ProgressDialog.show(activity, "", activity.getString(R.string.please_wait), true, true); dialog.show(); Utility.mAsyncRunner.request(photo_id, params, new ViewPhotoRequestListener()); } } }); mTagPhotoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /* * Source tag: tag_photo_tag */ setTag(); } }); } catch (JSONException e) { setText(activity.getString(R.string.exception) + e.getMessage()); } catch (FacebookError e) { setText(activity.getString(R.string.facebook_error) + e.getMessage()); } }
From source file:com.mobilesolutionworks.android.httpcache.WorksHttpCacheService.java
@Override public void onCreate() { super.onCreate(); mHandler = new Handler(); mQueues = new HashSet<String>(); mExecutors = Executors.newCachedThreadPool(); mConfiguration = HttpCacheConfiguration.configure(this); }