List of usage examples for android.os Handler sendEmptyMessage
public final boolean sendEmptyMessage(int what)
From source file:com.dedipower.portal.android.CDNLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.cdnlanding); //Progress test list = (ListView) findViewById(R.id.CDNList); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....", true);//from w w w .j av a2s. c o m final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); CDNAdaptor adapter = new CDNAdaptor(CDNLanding.this, listOfCDNs); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { CDNs = API.PortalQuery("cdn", "none"); Success = CDNs.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured."; //UpdateErrorMessage("An unrecoverable JSON Exception occured."); } if (Success.equals("false")) { try { //UpdateErrorMessage(CDNs.getString("msg")); ErrorMessage = CDNs.getString("msg"); } catch (JSONException e) { //UpdateErrorMessage("A JSON parsing error prevented an exact error message to be determined."); ErrorMessage = "A JSON parsing error prevented an exact error message to be determined."; } } else { try { CDNNodes = CDNs.getJSONArray("cdns"); //UpdateErrorMessage(""); ErrorMessage = ""; } catch (JSONException e) { //UpdateErrorMessage("There are no CDN nodes in your account."); ErrorMessage = "There are no CDN nodes in your account."; } int CDNCount = CDNNodes.length(); if (CDNCount == 0) { //UpdateErrorMessage("There are no CDN nodes for your account."); ErrorMessage = "There are no CDN nodes for your account."; Success = "false"; handler.sendEmptyMessage(0); } for (int i = 0; i < CDNCount; i++) { try { CurrentCDN = CDNNodes.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } listOfCDNs.add(new CDN(GetString("name"), GetString("backend"), GetInt("bandwidthemea"), GetInt("bandwidthapac"), GetInt("bandwidthamericas"), GetBool("loadbalanced"))); } } handler.sendEmptyMessage(0); } }; dataPreload.start(); //Progress test /*try { CDNs = API.PortalQuery("cdn", "none"); Success = CDNs.getString("success"); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show(); } if(Success == "false") { try { UpdateErrorMessage(CDNs.getString("msg")); } catch (JSONException e) { UpdateErrorMessage("A JSON parsing error prevented an exact error message to be determined."); } } else { Log.i("APIFuncs",CDNs.toString()); try { CDNNodes = CDNs.getJSONArray("cdns"); UpdateErrorMessage(""); } catch (JSONException e) { UpdateErrorMessage("There are no CDN nodes in your account."); } //OK lets actually do something useful ListView list = (ListView)findViewById(R.id.CDNList); List<CDN> listOfCDNs = new ArrayList<CDN>(); int CDNCount = CDNNodes.length(); if(CDNCount == 0) { UpdateErrorMessage("There are no CDN nodes for your account."); return; } for(int i = 0; i < CDNCount; i++) { try { CurrentCDN = CDNNodes.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs",e1.getMessage()); } listOfCDNs.add(new CDN(GetString("name"), GetString("backend"), GetInt("bandwidthemea"), GetInt("bandwidthapac"), GetInt("bandwidthamericas"), GetBool("loadbalanced"))); } CDNAdaptor adapter = new CDNAdaptor(this, listOfCDNs); list.setAdapter(adapter); }*/ }
From source file:com.nextgis.ngm_clink_monitoring.fragments.CreateObjectFragment.java
protected void createObject() { String fieldName = null;/*from www. jav a2 s. c o m*/ switch (mFoclStructLayerType) { case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CABLE_POINT: if (null == mLayingMethod.getValue()) { fieldName = getActivity().getString(R.string.laying_method); } break; case FoclConstants.LAYERTYPE_FOCL_REAL_FOSC: // if (null == mFoscType.getValue()) { // fieldName = getActivity().getString(R.string.fosc_type); // break; // } if (null == mFoscPlacement.getValue()) { fieldName = getActivity().getString(R.string.fosc_placement); } break; case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CROSS: // if (null == mOpticalCrossType.getValue()) { // fieldName = getActivity().getString(R.string.optical_cross_type); // } break; case FoclConstants.LAYERTYPE_FOCL_REAL_ACCESS_POINT: break; case FoclConstants.LAYERTYPE_FOCL_REAL_SPECIAL_TRANSITION_POINT: if (null == mSpecialLayingMethod.getValue()) { fieldName = getActivity().getString(R.string.special_laying_method); break; } if (null == mMarkType.getValue()) { fieldName = getActivity().getString(R.string.mark_type); } break; } if (null != fieldName) { YesNoDialog dialog = new YesNoDialog(); dialog.setKeepInstance(true).setIcon(R.drawable.ic_action_warning).setTitle(R.string.warning) .setMessage(String.format(getString(R.string.empty_field_warning), fieldName)) .setPositiveText(R.string.ok) .setOnPositiveClickedListener(new YesNoDialog.OnPositiveClickedListener() { @Override public void onPositiveClicked() { // cancel } }).show(getActivity().getSupportFragmentManager(), FoclConstants.FRAGMENT_YES_NO_DIALOG + "FieldsNotNull"); return; // we do not need logcat here } if (!mNewStartPoint && 0 < mObjectCount && FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CABLE_POINT == mFoclStructLayerType && null != mDistance && FoclConstants.MAX_DISTANCE_FROM_PREV_POINT < mDistance) { showDistanceExceededDialog(); return; // we do not need logcat here } if (null == mObjectPhotoFileAdapter || mObjectPhotoFileAdapter.getItemCount() == 0) { YesNoDialog dialog = new YesNoDialog(); dialog.setKeepInstance(true).setIcon(R.drawable.ic_action_warning).setTitle(R.string.warning) .setMessage(getString(R.string.take_photos_to_confirm)).setPositiveText(R.string.ok) .setOnPositiveClickedListener(new YesNoDialog.OnPositiveClickedListener() { @Override public void onPositiveClicked() { // cancel } }).show(getActivity().getSupportFragmentManager(), FoclConstants.FRAGMENT_YES_NO_DIALOG + "TakePhotos"); return; // we do not need logcat here } LayoutInflater inflater = LayoutInflater.from(getActivity()); View view = inflater.inflate(R.layout.dialog_waiting, null); final YesNoDialog waitProgressDialog = new YesNoDialog(); waitProgressDialog.setKeepInstance(true).setIcon(R.drawable.ic_action_data_usage).setTitle(R.string.waiting) .setView(view, true); waitProgressDialog.setCancelable(false); waitProgressDialog.show(getActivity().getSupportFragmentManager(), FoclConstants.FRAGMENT_YES_NO_DIALOG + "WaitProgress"); final Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case CREATE_OBJECT_DONE: waitProgressDialog.dismiss(); break; case CREATE_OBJECT_OK: getActivity().getSupportFragmentManager().popBackStack(); break; case CREATE_OBJECT_FAILED: Toast.makeText(getActivity(), (String) msg.obj, Toast.LENGTH_LONG).show(); waitProgressDialog.dismiss(); break; } } }; RunnableFuture<Void> future = new FutureTask<Void>(new Callable<Void>() { @Override public Void call() throws Exception { createObjectTask(); return null; } }) { @Override protected void done() { super.done(); handler.sendEmptyMessage(CREATE_OBJECT_DONE); } @Override protected void set(Void aVoid) { super.set(aVoid); handler.sendEmptyMessage(CREATE_OBJECT_OK); } @Override protected void setException(Throwable t) { super.setException(t); Message msg = handler.obtainMessage(CREATE_OBJECT_FAILED, t.getLocalizedMessage()); msg.sendToTarget(); } }; new Thread(future).start(); }
From source file:com.ibuildapp.romanblack.TableReservationPlugin.utils.TableReservationHTTP.java
/** * This method call server to send email. * * @param template 1 - send confirmation mail to owner * 2 - send cancellation mail to owner * 3 - send confirmation mail to customer * 4 - send cancellation mail to customer * @param user user// w ww. j a va 2s .c o m * @param orderInfo order info * @param appName application name * @param handler result handler * @return error code */ public static String sendMail(int template, User user, TableReservationInfo orderInfo, String appName, Handler handler) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 15000); HttpConnectionParams.setSoTimeout(httpParameters, 15000); HttpClient httpclient = new DefaultHttpClient(httpParameters); HttpPost httppost = new HttpPost(MAIL_ORDER_URL); Log.e(TAG, "MAIL_ORDER_URL = " + MAIL_ORDER_URL); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); // restaurant details nameValuePairs.add(new BasicNameValuePair("app_name", appName)); nameValuePairs.add(new BasicNameValuePair("restaurant_name", orderInfo.getRestaurantName())); nameValuePairs.add(new BasicNameValuePair("restaurant_address", orderInfo.getRestaurantadress())); nameValuePairs.add(new BasicNameValuePair("restaurant_phone", orderInfo.getRestaurantphone())); // user details String userType = null; if (user.getAccountType() == User.ACCOUNT_TYPES.FACEBOOK) { userType = "facebook"; } else if (user.getAccountType() == User.ACCOUNT_TYPES.TWITTER) { userType = "twitter"; } else if (user.getAccountType() == User.ACCOUNT_TYPES.IBUILDAPP) { userType = "ibuildapp"; } else if (user.getAccountType() == User.ACCOUNT_TYPES.GUEST) { userType = "guest"; } nameValuePairs.add(new BasicNameValuePair("user_type", userType)); nameValuePairs.add(new BasicNameValuePair("user_id", user.getAccountId())); nameValuePairs.add(new BasicNameValuePair("user_name", user.getUserName())); nameValuePairs.add(new BasicNameValuePair("user_first_name", user.getUserFirstName())); nameValuePairs.add(new BasicNameValuePair("user_last_name", user.getUserLastName())); // order details Date tempDate = orderInfo.getOrderDate(); tempDate.setHours(orderInfo.getOrderTime().houres); tempDate.setMinutes(orderInfo.getOrderTime().minutes); String timeZone = timeZoneToString(); nameValuePairs.add(new BasicNameValuePair("time_zone", timeZone)); nameValuePairs.add(new BasicNameValuePair("order_date_time", Long.toString(tempDate.getTime() / 1000))); nameValuePairs.add(new BasicNameValuePair("order_persons", Integer.toString(orderInfo.getPersonsAmount()))); // contacts details nameValuePairs.add(new BasicNameValuePair("customer_email", user.getUserEmail())); nameValuePairs.add(new BasicNameValuePair("owner_email", orderInfo.getRestaurantmail())); nameValuePairs.add(new BasicNameValuePair("mail_type", Integer.toString(template))); // add security part nameValuePairs.add(new BasicNameValuePair("app_id", Statics.appId)); nameValuePairs.add(new BasicNameValuePair("token", Statics.appToken)); try { httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException uEEx) { Log.e("", ""); handler.sendEmptyMessage(3); return "error"; } ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { String strResponseSaveGoal = httpclient.execute(httppost, responseHandler); Log.d("sendMail", ""); return JSONParser.parseQueryError(strResponseSaveGoal); } catch (ConnectTimeoutException conEx) { handler.sendEmptyMessage(3); return "error"; } catch (ClientProtocolException ex) { Log.d("sendMail", ""); handler.sendEmptyMessage(3); return "error"; } catch (IOException ex) { Log.d("sendMail", ""); handler.sendEmptyMessage(3); return "error"; } }
From source file:com.dedipower.portal.android.ColoLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.cololanding_iclone); //Temp/*from ww w .j a v a 2s . c o m*/ list = (ListView) findViewById(R.id.ColoCabList); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....", true); final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); ColoRacksAdaptor adapter = new ColoRacksAdaptor(ColoLanding.this, listOfColoRacks); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { Colo = API.PortalQuery("colocation", "none"); Success = Colo.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occurred."; //UpdateErrorMessage("An unrecoverable JSON Exception occurred."); } if (Success.equals("false")) { try { //UpdateErrorMessage(Colo.getString("msg")); ErrorMessage = Colo.getString("msg"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured."; //UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs", Colo.toString()); try { ColoCabs = Colo.getJSONArray("colocation"); ErrorMessage = ""; //UpdateErrorMessage(""); } catch (JSONException e) { ErrorMessage = "There are no Co-Location Cabinets in your account."; //UpdateErrorMessage("There are no Co-Location Cabinets in your account."); } int ColoCount = ColoCabs.length(); if (ColoCount == 0) { //UpdateErrorMessage("There are no colocation cabinets for your account."); ErrorMessage = "There are no colocation cabinets for your account."; handler.sendEmptyMessage(0); return; } for (int i = 0; i < ColoCount; i++) { JSONObject CurrentColo = null; try { CurrentColo = ColoCabs.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } try { listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"), CurrentColo.getString("servercode"), CurrentColo.getString("facility"), CurrentColo.getInt("bandwidth"), CurrentColo.getString("bandwidthTotal"), CurrentColo.getInt("transferlimit"), CurrentColo.getString("state"))); } catch (JSONException e) { Log.e("APIFuncs", e.getMessage()); } } } handler.sendEmptyMessage(0); } }; dataPreload.start(); //temp /*try { Colo = API.PortalQuery("colocation", "none"); Success = Colo.getString("success"); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show(); } if(Success == "false") { try { UpdateErrorMessage(Colo.getString("msg")); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs",Colo.toString()); try { ColoCabs = Colo.getJSONArray("colocation"); UpdateErrorMessage(""); } catch (JSONException e) { UpdateErrorMessage("There are no Co-Location Cabinets in your account."); } //OK lets actually do something useful ListView list = (ListView)findViewById(R.id.ColoCabList); List<ColoRacks> listOfColoRacks = new ArrayList<ColoRacks>(); int ColoCount = ColoCabs.length(); if(ColoCount == 0) { UpdateErrorMessage("There are no colocation cabinets for your account."); return; } for(int i = 0; i < ColoCount; i++) { JSONObject CurrentColo = null; try { CurrentColo = ColoCabs.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs",e1.getMessage()); } try { listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"), CurrentColo.getString("servercode"), CurrentColo.getString("facility"), CurrentColo.getInt("bandwidth"), CurrentColo.getString("bandwidthTotal"), CurrentColo.getInt("transferlimit"), CurrentColo.getString("state"))); } catch (JSONException e) { Log.e("APIFuncs",e.getMessage()); } } ColoRacksAdaptor adapter = new ColoRacksAdaptor(this, listOfColoRacks); list.setAdapter(adapter); }*/ }
From source file:net.networksaremadeofstring.pulsant.portal.ColoLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.cololanding); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Colocation"); detailsdialog = new Dialog(this); EditHandler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 0) { Toast.makeText(ColoLanding.this, "Description updated successfully!", Toast.LENGTH_SHORT) .show();//from w ww .j av a 2s.com } else { Toast.makeText(ColoLanding.this, "There was an error updating that description", Toast.LENGTH_SHORT).show(); } } }; //Temp list = (ListView) findViewById(R.id.ColoCabList); 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); adapter = new ColoRacksAdaptor(ColoLanding.this, listOfColoRacks); list.setAdapter(adapter); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { Colo = API.PortalQuery("colocation", "none"); Success = Colo.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occurred."; //UpdateErrorMessage("An unrecoverable JSON Exception occurred."); } if (Success.equals("false")) { try { //UpdateErrorMessage(Colo.getString("msg")); ErrorMessage = Colo.getString("msg"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured."; //UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs", Colo.toString()); try { ColoCabs = Colo.getJSONArray("colocation"); ErrorMessage = ""; //UpdateErrorMessage(""); } catch (JSONException e) { ErrorMessage = "There are no Co-Location Cabinets in your account."; //UpdateErrorMessage("There are no Co-Location Cabinets in your account."); } int ColoCount = ColoCabs.length(); if (ColoCount == 0) { //UpdateErrorMessage("There are no colocation cabinets for your account."); ErrorMessage = "There are no colocation cabinets for your account."; handler.sendEmptyMessage(0); return; } for (int i = 0; i < ColoCount; i++) { JSONObject CurrentColo = null; try { CurrentColo = ColoCabs.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } try { listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"), CurrentColo.getString("servercode"), CurrentColo.getString("facility"), CurrentColo.getInt("bandwidth"), CurrentColo.getString("bandwidthTotal"), CurrentColo.getInt("transferlimit"), CurrentColo.getString("state"), CurrentColo.getString("description"))); } catch (JSONException e) { Log.e("APIFuncs", e.getMessage()); } } } handler.sendEmptyMessage(0); } }; dataPreload.start(); }
From source file:com.dedipower.portal.android.ManagedServerLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.managedserverlanding); //temp/*from w w w . j av a 2 s . c om*/ list = (ListView) findViewById(R.id.ManagedServerList); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "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); } 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(); //temp /*try { Servers = API.PortalQuery("servers", "none"); Success = Servers.getString("success"); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); } if(Success == "false") { try { UpdateErrorMessage(Servers.getString("msg")); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs",Servers.toString()); try { ManagedServers = Servers.getJSONArray("servers"); UpdateErrorMessage(""); } catch (JSONException e) { UpdateErrorMessage("There are no Managed servers in your account."); } //OK lets actually do something useful ListView list = (ListView)findViewById(R.id.ManagedServerList); List<ManagedServer> listOfManagedServers = new ArrayList<ManagedServer>(); int ServerCount = ManagedServers.length(); 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"))); } ManagedServerAdaptor adapter = new ManagedServerAdaptor(this, listOfManagedServers, API.SessionID); list.setAdapter(adapter); }*/ }
From source file:eu.dirtyharry.androidopsiadmin.Main.java
public void getOpsiClientsTask() { final ProgressDialog dialog = ProgressDialog.show(Main.this, getString(R.string.gen_title_pleasewait), getString(R.string.pd_getclients), true); final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss();//w ww . j ava 2s .c o m if (GlobalVar.getInstance().getError().equals("null")) { if (doit.equals("true")) { Intent i = new Intent(Main.this, ShowOpsiClientsListView.class); Bundle b = new Bundle(); b.putStringArrayList("allclients", allclients); b.putStringArrayList("clientdescriptions", clientdescription); b.putStringArrayList("clientmacs", clientmac); b.putStringArrayList("clientnotes", clientnotes); b.putStringArrayList("clientips", clientip); b.putStringArrayList("clientinventorys", clientinventory); b.putStringArrayList("clientlastseens", clientlastseen); i.putExtras(b); startActivityForResult(i, GET_OPSI_CLIENT_REQUEST); } else if (doit.equals("serverdown")) { Toast.makeText(Main.this, String.format(getString(R.string.to_servernotrechable), serverip), Toast.LENGTH_LONG).show(); } } else { new Functions().msgBox(Main.this, getString(R.string.gen_title_error), GlobalVar.getInstance().getError(), false); // GlobalVar.getInstance().setError("null"); } } }; checkUpdate = new Thread() { public void run() { Looper.prepare(); if (Networking.isServerUp(serverip, serverport, serverusername, serverpasswd)) { getOpsiClients("rpc", serverip, serverport, "host_getHashes", serverusername, serverpasswd); doit = "true"; } else { doit = "serverdown"; // } handler.sendEmptyMessage(0); } }; checkUpdate.start(); // RTM ???? // checkUpdate.interrupt(); }
From source file:com.dedipower.portal.android.ViewTicket.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.viewticket); list = (ListView) findViewById(R.id.TicketUpdatesList); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....", true);/* w ww . j av a 2 s . c o m*/ final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); TicketUpdatesAdaptor adapter = new TicketUpdatesAdaptor(ViewTicket.this, listOfUpdates, API.SessionID); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { TicketAPI = API.PortalQuery("updates", getIntent().getStringExtra("ticketID")); Success = TicketAPI.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured. Error Code: 1"; Log.e("APIFuncs", e.getMessage()); } if (Success == "false") { try { Log.i("APIFuncs", TicketAPI.toString(3)); ErrorMessage = TicketAPI.getString("msg"); } catch (JSONException e) { Log.e("APIFuncs", e.getMessage()); } } else { Log.i("APIFuncs", TicketAPI.toString()); try { Updates = TicketAPI.getJSONArray("updates"); ErrorMessage = ""; } catch (JSONException e) { ErrorMessage = "There are no updates for this ticket. (Strange!)"; } int TicketCount = Updates.length(); if (TicketCount == 0) { ErrorMessage = "There are no updates for this ticket."; return; } for (int i = 0; i < TicketCount; i++) { try { CurrentTicket = Updates.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } if (CurrentTicket != null) { listOfUpdates.add(new TicketUpdates(GetString("type"), GetString("name"), GetInt("time"), GetString("content"))); } } handler.sendEmptyMessage(0); } } }; dataPreload.start(); Button AddReply = (Button) findViewById(R.id.AddReplyButton); AddReply.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent CreateTicketReplyIntent = new Intent(ViewTicket.this, AddTicketReply.class); CreateTicketReplyIntent.putExtra("sessionid", API.SessionID); CreateTicketReplyIntent.putExtra("ticketid", getIntent().getStringExtra("ticketID")); ViewTicket.this.startActivity(CreateTicketReplyIntent); } }); /* try { TicketAPI = API.PortalQuery("updates", getIntent().getStringExtra("ticketID")); Success = TicketAPI.getString("success"); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured. Error Code: 1"); Log.e("APIFuncs",e.getMessage()); //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show(); } if(Success == "false") { try { Log.i("APIFuncs",TicketAPI.toString(3)); UpdateErrorMessage(TicketAPI.getString("msg")); } catch (JSONException e) { Log.e("APIFuncs",e.getMessage()); UpdateErrorMessage("An unrecoverable JSON Exception occured. Error Code: 2"); } } else { Log.i("APIFuncs",TicketAPI.toString()); try { Updates = TicketAPI.getJSONArray("updates"); UpdateErrorMessage(""); } catch (JSONException e) { UpdateErrorMessage("There are no updates for this ticket. (Strange!)"); } //OK lets actually do something useful List<TicketUpdates> listOfUpdates = new ArrayList<TicketUpdates>(); int TicketCount = Updates.length(); if(TicketCount == 0) { UpdateErrorMessage("There are no updates for this ticket."); return; } for(int i = 0; i < TicketCount; i++) { try { CurrentTicket = Updates.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs",e1.getMessage()); } if(CurrentTicket != null) { listOfUpdates.add(new TicketUpdates(GetString("type"), GetString("name"), GetInt("time"), GetString("content"))); } } TicketUpdatesAdaptor adapter = new TicketUpdatesAdaptor(this, listOfUpdates, API.SessionID); list.setAdapter(adapter); }*/ }
From source file:net.networksaremadeofstring.cyllell.ViewRoles_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { list = (ListView) this.getActivity().findViewById(R.id.rolesListView); settings = this.getActivity().getSharedPreferences("Cyllell", 0); try {/*w w w. j a v a2 s . c om*/ Cut = new Cuts(getActivity()); } catch (Exception e) { e.printStackTrace(); } dialog = new ProgressDialog(getActivity()); dialog.setTitle("Contacting Chef"); dialog.setMessage("Please wait: Prepping Authentication protocols"); dialog.setIndeterminate(true); if (listOfRoles.size() < 1) { dialog.show(); } updateListNotify = new Handler() { public void handleMessage(Message msg) { int tag = msg.getData().getInt("tag", 999999); if (msg.what == 0) { if (tag != 999999) { listOfRoles.get(tag).SetSpinnerVisible(); } } else if (msg.what == 1) { //Get rid of the lock CutInProgress = false; //the notifyDataSetChanged() will handle the rest } else if (msg.what == 99) { if (tag != 999999) { Toast.makeText(ViewRoles_Fragment.this.getActivity(), "An error occured during that operation.", Toast.LENGTH_LONG).show(); listOfRoles.get(tag).SetErrorState(); } } RoleAdapter.notifyDataSetChanged(); } }; final Handler handler = new Handler() { public void handleMessage(Message msg) { //Once we've checked the data is good to use start processing it if (msg.what == 0) { OnClickListener listener = new OnClickListener() { public void onClick(View v) { GetMoreDetails((Integer) v.getTag()); } }; OnLongClickListener listenerLong = new OnLongClickListener() { public boolean onLongClick(View v) { selectForCAB((Integer) v.getTag()); return true; } }; RoleAdapter = new RoleListAdaptor(getActivity(), listOfRoles, listener, listenerLong); list = (ListView) getView().findViewById(R.id.rolesListView); if (list != null) { if (RoleAdapter != null) { list.setAdapter(RoleAdapter); } else { //Log.e("CookbookAdapter","CookbookAdapter is null"); } } else { //Log.e("List","List is null"); } dialog.dismiss(); } else if (msg.what == 200) { dialog.setMessage("Sending request to Chef..."); } else if (msg.what == 201) { dialog.setMessage("Parsing JSON....."); } else if (msg.what == 202) { dialog.setMessage("Populating UI!"); } else { //Close the Progress dialog dialog.dismiss(); //Alert the user that something went terribly wrong AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create(); alertDialog.setTitle("API Error"); alertDialog.setMessage("There was an error communicating with the API:\n" + msg.getData().getString("exception")); alertDialog.setButton2("Back", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //getActivity().finish(); } }); alertDialog.setIcon(R.drawable.icon); alertDialog.show(); } } }; Thread dataPreload = new Thread() { public void run() { if (listOfRoles.size() > 0) { handler.sendEmptyMessage(0); } else { try { handler.sendEmptyMessage(200); Roles = Cut.GetRoles(); handler.sendEmptyMessage(201); JSONArray Keys = Roles.names(); for (int i = 0; i < Keys.length(); i++) { listOfRoles.add(new Role(Keys.getString(i), Roles.getString(Keys.getString(i)) .replaceFirst("^(https://|http://).*/roles/", ""))); } handler.sendEmptyMessage(202); handler.sendEmptyMessage(0); } catch (Exception e) { Message msg = new Message(); Bundle data = new Bundle(); data.putString("exception", e.getMessage()); msg.setData(data); msg.what = 1; handler.sendMessage(msg); } } return; } }; dataPreload.start(); return inflater.inflate(R.layout.roles_landing, container, false); }
From source file:eu.dirtyharry.androidopsiadmin.Main.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == GET_QR && resultCode == RESULT_OK) { contents = data.getExtras().getString("la.droid.qr.result"); if (checkQR(contents)) { try { pc = (JSONObject) new JSONTokener(contents).nextValue(); hosttocheck = pc.getString("dns"); } catch (JSONException e) { e.printStackTrace();//from w w w . ja v a 2 s. c om } final ProgressDialog dialog = ProgressDialog.show(Main.this, getString(R.string.gen_title_pleasewait), String.format(getString(R.string.pd_checkifopsiclientexists), hosttocheck), true); final Handler handler = new Handler() { public void handleMessage(Message msg) { if (hostexistsinopsi && doit.equals("true")) { if (customtags) { Intent i = new Intent(Main.this, ShowBarcodeData.class); Bundle b = new Bundle(); b.putString("qrdata", contents); i.putExtras(b); startActivity(i); } else { Intent i = new Intent(Main.this, ShowOpsiClientOptions.class); Bundle b = new Bundle(); b.putString("qrdata", contents); i.putExtras(b); startActivity(i); } } else if (!hostexistsinopsi) { new Functions().msgBox(Main.this, getString(R.string.gen_title_error), String.format(getString(R.string.general_noopsihost), hosttocheck), false); } else { Toast.makeText(Main.this, String.format(getString(R.string.to_servernotrechable), serverip), Toast.LENGTH_LONG).show(); } dialog.dismiss(); } }; Thread checkUpdate = new Thread() { public void run() { Looper.prepare(); if (eu.dirtyharry.androidopsiadmin.Networking.isServerUp(serverip, serverport, serverusername, serverpasswd)) { doit = "true"; if (eu.dirtyharry.androidopsiadmin.Networking.checkIfHostExistsInOpsi(hosttocheck, serverip, serverport, serverusername, serverpasswd)) { hostexistsinopsi = true; } else { hostexistsinopsi = false; } } else { doit = "serverdown"; } handler.sendEmptyMessage(0); } }; checkUpdate.start(); } else { new Functions().msgBox(Main.this, getString(R.string.gen_title_error), getString(R.string.at_novalidqr), false); } } else if (requestCode == GET_OPSI_CLIENT_REQUEST && resultCode == Activity.RESULT_OK) { if (data.getStringExtra("message").equals("refresh")) { getOpsiClientsTask(); } // } else if (requestCode == SHOW_OPSI_DEPOT_REQUEST // && resultCode == Activity.RESULT_OK) { // resultconfignames = data.getExtras().getStringArrayList( // "choosenones"); // resultconfigvalues = data.getExtras().getStringArrayList( // "choosenonesvalues"); // event_opsisenddepotconfigchanges(); } }