List of usage examples for android.os Handler Handler
public Handler()
From source file:palamarchuk.fraudguide.utils.QueryMaster.java
private void initHandler() { this.setPriority(MIN_PRIORITY); handler = new Handler() { @Override//from w ww. ja v a2 s. c o m public void handleMessage(Message msg) { super.handleMessage(msg); if (onCompleteListener != null) { if (msg.what == QUERY_MASTER_COMPLETE) { onCompleteListener.complete(serverResponse); } if (msg.what == QUERY_MASTER_ERROR) { onCompleteListener.error(QUERY_MASTER_ERROR); } if (msg.what == QUERY_MASTER_NETWORK_ERROR) { onCompleteListener.error(QUERY_MASTER_NETWORK_ERROR); } } if (progressDialog != null) { progressDialog.dismiss(); } } }; }
From source file:com.azcltd.android.test.kolesov.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView, final boolean isThumbnail, final boolean forceUpdate) { if (drawableMap.containsKey(urlString) && !forceUpdate) { Drawable image = drawableMap.get(urlString); SetDrawableToImageView(image, imageView, isThumbnail); return;//from www .j a v a2s . co m } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { DrawableWithFlag obj = (DrawableWithFlag) message.obj; Drawable image = obj.image; boolean flag = obj.isNeedThumbnailed; SetDrawableToImageView(image, imageView, flag); } }; Thread thread = new Thread() { @Override public void run() { //setPriority(3); Drawable drawable = fetchDrawable(urlString, forceUpdate); if (drawable != null) { Message message = handler.obtainMessage(1, new DrawableWithFlag(drawable, isThumbnail)); handler.sendMessage(message); // try{ // //sleep(100); // } // catch(Exception ex) { // int i =0; // } } } }; thread.start(); }
From source file:gxu.software_engineering.market.android.activity.UpdateItemActivity.java
@Override protected void onStart() { super.onStart(); spinner.setAdapter(mAdapter);//w w w. j a v a 2 s . c o m new Handler().postDelayed(new Runnable() { @Override public void run() { spinner.setSelection(UpdateItemActivity.this.cid.intValue() - 1); } }, 100); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { UpdateItemActivity.this.cid = id; } @Override public void onNothingSelected(AdapterView<?> parent) { parent.setSelection(UpdateItemActivity.this.cid.intValue()); } }); getSupportLoaderManager().initLoader(0, null, this); }
From source file:org.nasa.openspace.gc.geolocation.LocationActivity.java
/** * This sample demonstrates how to incorporate location based services in your app and * process location updates. The app also shows how to convert lat/long coordinates to * human-readable addresses./*from w w w.j ava 2 s.c o m*/ */ //@SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.geolocation); // Restore apps state (if exists) after rotation. if (savedInstanceState != null) { mUseFine = savedInstanceState.getBoolean(KEY_FINE); mUseBoth = savedInstanceState.getBoolean(KEY_BOTH); } else { mUseFine = false; mUseBoth = false; } TextView tv1 = (TextView) findViewById(R.id.textView1); TextView tv2 = (TextView) findViewById(R.id.textView2); TextView tv3 = (TextView) findViewById(R.id.fileLocation); ImageView iv1 = (ImageView) findViewById(R.id.imageView1); btnUpload = (Button) findViewById(R.id.btnUpload); tv1.setText("Name : " + Session.name); tv2.setText("Caption :" + Session.caption); iv1.setImageBitmap(Session.image); tv3.setVisibility(View.GONE); //tv3.setText(Session.fileLocation2); mLatLng = (TextView) findViewById(R.id.latlng); mAddress = (TextView) findViewById(R.id.address); // Receive location updates from the fine location provider (gps) only. mFineProviderButton = (Button) findViewById(R.id.provider_fine); // Receive location updates from both the fine (gps) and coarse (network) location // providers. mBothProviderButton = (Button) findViewById(R.id.provider_both); // The isPresent() helper method is only available on Gingerbread or above. mGeocoderAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent(); // Handler for updating text fields on the UI like the lat/long and address. mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case UPDATE_ADDRESS: mAddress.setText((String) msg.obj); break; case UPDATE_LATLNG: mLatLng.setText((String) msg.obj); String[] res = ((String) msg.obj).split(","); lat = res[0]; longt = res[1]; break; } } }; // Get a reference to the LocationManager object. mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mBothProviderButton.performClick(); btnUpload.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub try { executeMultipartPost(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }
From source file:net.networksaremadeofstring.rhybudd.ViewZenossEvent.java
/** Called when the activity is first created. */ @Override/*from w w w .j av a 2 s. c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); BugSenseHandler.initAndStartSession(ViewZenossEvent.this, "44a76a8c"); settings = PreferenceManager.getDefaultSharedPreferences(this); setContentView(R.layout.view_zenoss_event); try { actionbar = getActionBar(); actionbar.setDisplayHomeAsUpEnabled(true); actionbar.setHomeButtonEnabled(true); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "OnCreate", e); } try { ((TextView) findViewById(R.id.EventTitle)).setText(getIntent().getStringExtra("Device")); ((TextView) findViewById(R.id.Summary)).setText(Html.fromHtml(getIntent().getStringExtra("Summary"))); ((TextView) findViewById(R.id.LastTime)).setText(getIntent().getStringExtra("LastTime")); ((TextView) findViewById(R.id.EventCount)) .setText("Count: " + Integer.toString(getIntent().getIntExtra("Count", 0))); } catch (Exception e) { //We don't need to much more than report it because the direct API request will sort it out for us. BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "OnCreate", e); } firstLoadHandler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); try { if (EventObject.has("result") && EventObject.getJSONObject("result").getBoolean("success") == true) { //Log.i("Event",EventObject.toString(3)); TextView Title = (TextView) findViewById(R.id.EventTitle); TextView Component = (TextView) findViewById(R.id.Componant); TextView EventClass = (TextView) findViewById(R.id.EventClass); TextView Summary = (TextView) findViewById(R.id.Summary); TextView FirstTime = (TextView) findViewById(R.id.FirstTime); TextView LastTime = (TextView) findViewById(R.id.LastTime); LinearLayout logList; EventDetails = EventObject.getJSONObject("result").getJSONArray("event").getJSONObject(0); try { if (EventDetails.getString("eventState").equals("Acknowledged")) { ((ImageView) findViewById(R.id.ackIcon)) .setImageResource(R.drawable.ic_acknowledged); } } catch (Exception e) { e.printStackTrace(); } //Log.e("EventDetails",EventDetails.toString(3)); try { Title.setText(EventDetails.getString("device_title")); } catch (Exception e) { Title.setText("Unknown Device - Event Details"); } try { Component.setText(EventDetails.getString("component")); } catch (Exception e) { Component.setText("Unknown Component"); } try { EventClass.setText(EventDetails.getString("eventClassKey")); } catch (Exception e) { EventClass.setText("Unknown Event Class"); } try { ImageView img = (ImageView) findViewById(R.id.summaryImage); URLImageParser p = new URLImageParser(img, ViewZenossEvent.this, Summary); Spanned htmlSpan = Html.fromHtml(EventDetails.getString("message"), p, null); Summary.setText(htmlSpan); //Summary.setText(Html.fromHtml(EventDetails.getString("message"))); //((ImageView) findViewById(R.id.summaryImage)).setImageDrawable(p.drawable); //Log.i("Summary",EventDetails.getString("message")); //((TextView) findViewById(R.id.Summary)).setVisibility(View.GONE); //((WebView) findViewById(R.id.summaryWebView)).loadData(EventDetails.getString("message"), "text/html", null); //((WebView) findViewById(R.id.summaryWebView)).loadDataWithBaseURL(null, EventDetails.getString("message"), "text/html", "UTF-8", "about:blank"); try { Summary.setMovementMethod(LinkMovementMethod.getInstance()); } catch (Exception e) { //Worth a shot } } catch (Exception e) { Summary.setText("No Summary available"); } try { FirstTime.setText(EventDetails.getString("firstTime")); } catch (Exception e) { FirstTime.setText("No Start Date Provided"); } try { LastTime.setText(EventDetails.getString("stateChange")); } catch (Exception e) { LastTime.setText("No Recent Date Provided"); } try { ((TextView) findViewById(R.id.EventCount)) .setText("Count: " + EventDetails.getString("count")); } catch (Exception e) { ((TextView) findViewById(R.id.EventCount)).setText("Count: ??"); } try { ((TextView) findViewById(R.id.Agent)).setText(EventDetails.getString("agent")); } catch (Exception e) { ((TextView) findViewById(R.id.Agent)).setText("unknown"); } try { JSONArray Log = EventDetails.getJSONArray("log"); int LogEntryCount = Log.length(); logList = (LinearLayout) findViewById(R.id.LogList); if (LogEntryCount == 0) { /*String[] LogEntries = {"No log entries could be found"}; ((ListView) findViewById(R.id.LogList)).setAdapter(new ArrayAdapter<String>(ViewZenossEvent.this, R.layout.search_simple,LogEntries));*/ TextView newLog = new TextView(ViewZenossEvent.this); newLog.setText("No log entries could be found"); logList.addView(newLog); } else { LogEntries = new String[LogEntryCount]; for (int i = 0; i < LogEntryCount; i++) { //LogEntries[i] = Log.getJSONArray(i).getString(0) + " set " + Log.getJSONArray(i).getString(2) +"\nAt: " + Log.getJSONArray(i).getString(1); TextView newLog = new TextView(ViewZenossEvent.this); newLog.setText(Html.fromHtml("<strong>" + Log.getJSONArray(i).getString(0) + "</strong> wrote " + Log.getJSONArray(i).getString(2) + "\n<br/><strong>At:</strong> " + Log.getJSONArray(i).getString(1))); newLog.setPadding(0, 6, 0, 6); logList.addView(newLog); } /*try { ((ListView) findViewById(R.id.LogList)).setAdapter(new ArrayAdapter<String>(ViewZenossEvent.this, R.layout.search_simple,LogEntries)); } catch(Exception e) { Toast.makeText(getApplicationContext(), "There was an error trying process the log entries for this event.", Toast.LENGTH_SHORT).show(); }*/ } } catch (Exception e) { TextView newLog = new TextView(ViewZenossEvent.this); newLog.setText("No log entries could be found"); newLog.setPadding(0, 6, 0, 6); ((LinearLayout) findViewById(R.id.LogList)).addView(newLog); /*String[] LogEntries = {"No log entries could be found"}; try { ((ListView) findViewById(R.id.LogList)).setAdapter(new ArrayAdapter<String>(ViewZenossEvent.this, R.layout.search_simple,LogEntries)); } catch(Exception e1) { //BugSenseHandler.log("ViewZenossEvent-LogEntries", e1); }*/ } } else { //Log.e("ViewEvent",EventObject.toString(3)); Toast.makeText(ViewZenossEvent.this, "There was an error loading the Event details", Toast.LENGTH_LONG).show(); //finish(); } } catch (Exception e) { Toast.makeText(ViewZenossEvent.this, "An error was encountered parsing the JSON. An error report has been sent.", Toast.LENGTH_LONG).show(); //BugSenseHandler.log("ViewZenossEvent", e); } } }; dialog = new ProgressDialog(this); dialog.setTitle("Contacting Zenoss"); dialog.setMessage("Please wait:\nLoading Event details...."); dialog.show(); dataPreload = new Thread() { public void run() { try { /*if(API == null) { if(settings.getBoolean("httpBasicAuth", false)) { API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""),settings.getString("BAUser", ""), settings.getString("BAPassword", "")); } else { API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", "")); } } EventObject = API.GetEvent(getIntent().getStringExtra("EventID"));*/ if (settings.getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) { API = new ZenossAPIZaas(); } else { API = new ZenossAPICore(); } ZenossCredentials credentials = new ZenossCredentials(ViewZenossEvent.this); API.Login(credentials); EventObject = API.GetEvent(getIntent().getStringExtra("EventID")); } catch (Exception e) { firstLoadHandler.sendEmptyMessage(0); BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "DataPreloadThread", e); } finally { firstLoadHandler.sendEmptyMessage(1); } } }; dataPreload.start(); }
From source file:it.cdpaf.helper.DrawableManager.java
public static void fetchDrawableOnThread(final Product product, final ImageView imageView, final Context ctx) { final String urlString = Const.IMAGE_URL + product.getPercorsoImmagine(); if (drawableMap.containsKey(urlString)) { Log.d(ctx.getClass().getSimpleName(), "DRAWABLE MANAGER FDOT:" + "RIUSO, Size:" + drawableMap.size()); imageView.setImageDrawable(drawableMap.get(urlString)); return;/* w w w. j a v a 2 s. com*/ //product.setImmagine(drawableMap.get(urlString)); } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { Drawable dr = (Drawable) message.obj; imageView.setImageDrawable(dr); product.setImmagine(dr); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable d = ctx.getResources().getDrawable(R.drawable.blank); Message messagea = handler.obtainMessage(1, d); handler.sendMessage(messagea); Drawable drawable = fetchDrawable(urlString, ctx); Message messageb = handler.obtainMessage(1, drawable); handler.sendMessage(messageb); } }; Log.i("DRAWABLE MANAGER:", "LANCIO FDOT, Size:" + drawableMap.size()); thread.start(); }
From source file:self.philbrown.droidQuery.Ajax.java
/** * Constructor/*from w w w .ja v a2s . c om*/ * @param options used to configure this task */ public Ajax(AjaxOptions options) { this.options = options; if (options.url() == null) { throw new NullPointerException("Cannot call Ajax with null URL!"); } this.mHandler = new Handler(); this.executor = Executors.newFixedThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread t = new Thread(runnable); t.setPriority(Ajax.this.options.priority()); return t; } }); }
From source file:com.example.android.abhishek.flikr.SplashScreenActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_screen); fetchDataTask.execute();/*from ww w . ja va 2s .c om*/ new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(SplashScreenActivity.this, ImageGridActivity.class); startActivity(intent); finish(); } }, TIME_OUT); }
From source file:com.fastbootmobile.encore.app.fragments.PlaylistListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); }