List of usage examples for android.os Handler Handler
public Handler()
From source file:com.app.jdy.ui.MyRecordActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_record); initView();/* w w w . ja v a 2 s .c om*/ handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 0: Toast.makeText(MyRecordActivity.this, Constants.NO_INTENT_TIPS, Toast.LENGTH_SHORT).show(); break; case 1: list = new ArrayList<MyRecord>(); try { JSONObject jsonObject = new JSONObject(dataJson); if (jsonObject.getString("moneySum").equals("null")) { my_record_sum.setText("0"); my_record_sum_yuan.setText(""); } else { my_record_sum.setText( ChineseMoneyUtils.numWithDigitArray(jsonObject.getDouble("moneySum"))[0]); my_record_sum_yuan.setText( ChineseMoneyUtils.numWithDigitArray(jsonObject.getDouble("moneySum"))[1]); } JSONArray jsonArray = jsonObject.getJSONArray("list"); for (int i = 0; i < jsonArray.length(); i++) { MyRecord myRecord = new MyRecord(); myRecord.setMoney(jsonArray.getJSONObject(i).getDouble("withdCash")); myRecord.setDopositeTime(jsonArray.getJSONObject(i).getString("applyTime")); myRecord.setMessage(jsonArray.getJSONObject(i).getString("statuts")); list.add(myRecord); } myRecordAdapter = new MyRecordAdapter(MyRecordActivity.this, R.layout.my_order_item, list); my_record_list.setAdapter(myRecordAdapter); } catch (JSONException e) { e.printStackTrace(); } break; default: break; } } }; getData(); mBackImg.setOnClickListener(this); }
From source file:com.example.hotspot.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); }//from www . j a v a2 s . c om final Handler handler = new Handler() { public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; 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.example.prox.model.DrawableLoader.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { imageViewReference = new WeakReference<ImageView>(imageView); if (drawableMap.containsKey(urlString)) { imageViewReference.get().setImageDrawable(drawableMap.get(urlString)); }/* w ww .j a v a 2 s. c om*/ final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageViewReference.get().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:net.networksaremadeofstring.pulsant.portal.ManagedServerLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.managedserverlanding); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Managed Servers"); //temp//w ww . j a v a2 s .c o m list = (ListView) findViewById(R.id.ManagedServerList); final ProgressDialog dialog = ProgressDialog.show(this, "Pulsant Portal", "Please wait: loading data....", true); final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); ManagedServerAdaptor adapter = new ManagedServerAdaptor(ManagedServerLanding.this, listOfManagedServers, API.SessionID); list.setAdapter(adapter); /*list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View view) { if (mActionMode != null) { Log.i("onLongClick","Nuhuh"); return false; } // Start the CAB using the ActionMode.Callback defined above mActionMode = startActionMode(mActionModeCallback); view.setSelected(true); return true; } });*/ } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { int ServerCount = 0; public void run() { try { Servers = API.PortalQuery("servers", "none"); Success = Servers.getString("success"); } catch (JSONException e) { //UpdateErrorMessage("An unrecoverable JSON Exception occured."); ErrorMessage = "An unrecoverable JSON Exception occured."; } if (Success.equals("false")) { try { //UpdateErrorMessage(Servers.getString("msg")); ErrorMessage = Servers.getString("msg"); } catch (JSONException e) { //UpdateErrorMessage("An unrecoverable JSON Exception occured."); ErrorMessage = "An unrecoverable JSON Exception occured."; } } else { Log.i("APIFuncs", Servers.toString()); try { ManagedServers = Servers.getJSONArray("servers"); //UpdateErrorMessage(""); ErrorMessage = ""; } catch (JSONException e) { //UpdateErrorMessage("There are no Managed servers in your account."); ErrorMessage = "There are no Managed servers in your account."; } try { ServerCount = ManagedServers.length(); } catch (Exception e) { ServerCount = 0; } if (ServerCount == 0) { ErrorMessage = "There are no Managed servers for your account."; handler.sendEmptyMessage(0); return; } for (int i = 0; i < ServerCount; i++) { try { CurrentServer = ManagedServers.getJSONObject(i).getJSONObject("Server"); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } //Log.e("APIFuncs",CurrentServer.toString(3)); listOfManagedServers.add(new ManagedServer(GetString("ip"), GetString("servercode"), GetString("description"), GetString("facility"), GetInt("bandwidth"), GetString("bandwidthTotal"), GetBool("monitored"), GetInt("transferlimit"), GetString("software"), GetString("state"), GetBool("managedbackupenabled"))); } } handler.sendEmptyMessage(0); } }; dataPreload.start(); }
From source file:com.scott.crash.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); }// w w w .ja v a 2s. 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.wenwen.chatuidemo.activity.LoginActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ????/* w w w .j a va 2 s. c o m*/ if (DemoHXSDKHelper.getInstance().isLogined()) { autoLogin = true; startActivity(new Intent(LoginActivity.this, MainActivity.class)); return; } setContentView(R.layout.activity_login); usernameEditText = (EditText) findViewById(R.id.username); if (DemoApplication.getInstance().getUserName() != null && !DemoApplication.getInstance().getUserName().equals("")) { usernameEditText.setText(DemoApplication.getInstance().getUserName()); } passwordEditText = (EditText) findViewById(R.id.password); loginhandler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub int key = msg.what; switch (key) { case 1: EMChatManager.getInstance().login(MD5.md5(usernameEditText.getText().toString().trim()), MD5.md5("ys_" + passwordEditText.getText().toString().trim()).toUpperCase(), new EMCallBack() { @Override public void onSuccess() { // ????? DemoApplication.getInstance() .setUserName(usernameEditText.getText().toString().trim()); DemoApplication.getInstance().setPassword( MD5.md5("ys_" + passwordEditText.getText().toString().trim()) .toUpperCase()); startActivity(new Intent(LoginActivity.this, MainActivity.class)); pd.dismiss(); finish(); } @Override public void onProgress(int progress, String status) { } @Override public void onError(final int code, final String message) { // loginFailure2Umeng(start,code,message); } }); break; } super.handleMessage(msg); } }; // ???? usernameEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { passwordEditText.setText(null); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.swavdev.tc.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); }/*from w ww . j av a 2 s.c om*/ final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; executorService.submit(new Thread() { @Override public void run() { Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }); }
From source file:eu.inmite.apps.smsjizdenka.service.UpdateService.java
@Override public void onCreate() { super.onCreate(); mHandler = new Handler(); c = getApplicationContext(); }
From source file:com.ferg.awful.async.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys. if (urlString == null) { imageView.setImageDrawable(null); return;/*from www . ja va 2 s. c om*/ } if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); } 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:net.networksaremadeofstring.rhybudd.RhybuddDream.java
public void onDreamingStarted() { super.onDreamingStarted(); BugSenseHandler.initAndStartSession(RhybuddDream.this, "44a76a8c"); doBindService();/*from w w w . jav a2 s .co m*/ setFullscreen(true); setScreenBright(false); setContentView(R.layout.dream); theGrid = (GridView) findViewById(R.id.DreamGrid); //numGraphs = getResources().getInteger(R.integer.DreamGraphs); newGraphHandler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 0) { adapter.notifyDataSetChanged(); } else if (msg.what == 1) { //newGraphHandler.sendEmptyMessageDelayed(0,(r.nextInt(5000) + 5000)); adapter = new DreamGridAdapter(RhybuddDream.this, mGraphs); theGrid.setAdapter(adapter); newGraphHandler.sendEmptyMessageDelayed(10, refreshDelay); } else { new Thread() { public void run() { ZenossDevice thisDevice = listOfDevices.get(r.nextInt(listOfDevices.size())); try { JSONObject graphURLs = mService.API.GetDeviceGraphs(thisDevice.getuid()); int urlCount = graphURLs.getJSONObject("result").getJSONArray("data").length(); if (urlCount > 0) { for (int i = 0; i < urlCount; i++) { try { JSONObject currentGraph = graphURLs.getJSONObject("result") .getJSONArray("data").getJSONObject(i); if (currentGraph.getString("title").equals("Load Average")) { int posToUpdate = r.nextInt(numGraphs); mGraphs.get(posToUpdate).thisGraph = mService.API .GetGraph(currentGraph.getString("url")); mGraphs.get(posToUpdate).thisHostName = thisDevice.getname(); newGraphHandler.sendEmptyMessage(0); break; } } catch (Exception e) { e.printStackTrace(); } } } } catch (Exception e) { e.printStackTrace(); } finally { newGraphHandler.sendEmptyMessageDelayed(10, refreshDelay); } } }.start(); } } }; new Thread() { public void run() { while (mBound == false || null == mService || null == mService.API) { try { Thread.sleep(500); //Log.i("Sleeping","Sleeping"); } catch (Exception e) { e.printStackTrace(); } } for (int i = 0; i < numGraphs; i++) { if (errors > 10) { //Toast.makeText(RhybuddDream.this,"There was an error trying to display the graphs",Toast.LENGTH_LONG); finish(); } try { ZenossDevice thisDevice = listOfDevices.get(r.nextInt(listOfDevices.size())); //Log.e("Processing",Integer.toString(i) + " / " + thisDevice.getname()); JSONObject graphURLs = mService.API.GetDeviceGraphs(thisDevice.getuid()); int urlCount = graphURLs.getJSONObject("result").getJSONArray("data").length(); if (urlCount > 0) { for (int j = 0; j < urlCount; j++) { try { JSONObject currentGraph = graphURLs.getJSONObject("result").getJSONArray("data") .getJSONObject(j); if (currentGraph.getString("title").equals("Load Average")) { mGraphs.add( new HostGraph(mService.API.GetGraph(currentGraph.getString("url")), thisDevice.getname())); break; } else { continue; } } catch (Exception e) { e.printStackTrace(); //mGraphs.add(new HostGraph(null,"...")); i--; break; } } } else { //mGraphs.add(new HostGraph(null,"...")); i--; } } catch (Exception e) { e.printStackTrace(); //mGraphs.add(new HostGraph(null,"...")); errors++; try { sleep(5000); } catch (InterruptedException ie) { ie.printStackTrace(); } i--; } } newGraphHandler.sendEmptyMessage(1); } }.start(); }