List of usage examples for android.widget Toast show
public void show()
From source file:net.phase.wallet.Currency.java
public static void toastMessage(String message) { CharSequence text = message;//from w ww .j a v a 2 s .c om int duration = Toast.LENGTH_SHORT; if (context != null) { Toast toast = Toast.makeText(context, text, duration); toast.show(); } }
From source file:com.example.SmartBoard.MQTTHandler.java
public void connectionLost(Throwable cause) { System.out.println("connection was lost"); Toast lost = Toast.makeText(ctx, "Connection lost", Toast.LENGTH_SHORT); lost.show(); StatusListener.connectFlag = false; //order of execution is important here close();/* w w w .j a va2 s . co m*/ }
From source file:jp.ne.sakura.kkkon.java.net.socketimpl.testapp.android.SocketImplHookTestApp.java
/** Called when the activity is first created. */ @Override/* w w w. j a va 2 s . c om*/ public void onCreate(Bundle savedInstanceState) { final Context context = this.getApplicationContext(); { SocketImplHookFactory.initialize(); } { ProxySelector proxySelector = ProxySelector.getDefault(); Log.d(TAG, "proxySelector=" + proxySelector); if (null != proxySelector) { URI uri = null; try { uri = new URI("http://www.google.com/"); } catch (URISyntaxException e) { Log.d(TAG, e.toString()); } List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { Log.d(TAG, " proxy=" + proxy); } } } } super.onCreate(savedInstanceState); /* Create a TextView and set its content. * the text is retrieved by calling a native * function. */ LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setText("ExceptionHandler"); layout.addView(tv); Button btn1 = new Button(this); btn1.setText("invoke Exception"); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final int count = 2; int[] array = new int[count]; int value = array[count]; // invoke IndexOutOfBOundsException } }); layout.addView(btn1); { Button btn = new Button(this); btn.setText("upload http AsyncTask"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(String... paramss) { Boolean result = true; Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid()); try { //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS) Log.d(TAG, "fng=" + Build.FINGERPRINT); final List<NameValuePair> list = new ArrayList<NameValuePair>(16); list.add(new BasicNameValuePair("fng", Build.FINGERPRINT)); HttpPost httpPost = new HttpPost(paramss[0]); //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) ); httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(5 * 1000)); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(5 * 1000)); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); // <uses-permission android:name="android.permission.INTERNET"/> // got android.os.NetworkOnMainThreadException, run at UI Main Thread HttpResponse response = httpClient.execute(httpPost); Log.d(TAG, "response=" + response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(TAG, "got Exception. msg=" + e.getMessage(), e); result = false; } Log.d(TAG, "upload finish"); return result; } }; asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug"); asyncTask.isCancelled(); } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(0.0.0.0)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { destHost = InetAddress.getByName("0.0.0.0"); if (null != destHost) { try { if (destHost.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + destHost.toString() + " reachable"); } else { Log.d(TAG, "destHost=" + destHost.toString() + " not reachable"); } } catch (IOException e) { } } } catch (UnknownHostException e) { } Log.d(TAG, "destHost=" + destHost); } }); thread.start(); try { thread.join(1000); } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(www.google.com)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { InetAddress dest = InetAddress.getByName("www.google.com"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(kkkon.sakura.ne.jp)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { InetAddress dest = InetAddress.getByName("kkkon.sakura.ne.jp"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } setContentView(layout); }
From source file:edu.missouri.bas.activities.AdminManageActivity.java
private Dialog AdminPinDialog(Context context) { LayoutInflater inflater = LayoutInflater.from(this); final View textEntryView = inflater.inflate(R.layout.pin_login, null); alert_text = (TextView) textEntryView.findViewById(R.id.pin_text); alert_text.setText("Please input PIN for administrator"); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(false);//from w w w .ja va 2 s . com builder.setTitle("Verify Admin PIN"); builder.setView(textEntryView); //builder.setMessage("Please input PIN for administrator"); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //check networking adminPin = (EditText) textEntryView.findViewById(R.id.pin_edit); String AdPin = adminPin.getText().toString(); Log.d(TAG, "get from edittext is " + AdPin); HttpPost request = new HttpPost( "http://dslsrv8.cs.missouri.edu/~rs79c/Server/Crt/validateUser.php"); List<NameValuePair> params = new ArrayList<NameValuePair>(); //file_name params.add(new BasicNameValuePair("userID", "0000")); //function params.add(new BasicNameValuePair("pre", "1")); //data params.add(new BasicNameValuePair("password", AdPin)); try { request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); HttpResponse response = new DefaultHttpClient().execute(request); if (response.getStatusLine().getStatusCode() == 200) { String result = EntityUtils.toString(response.getEntity()); Log.d("~~~~~~~~~~http post result", result); if (result.equals("AdminIsChecked")) { //do nothing //setResult(8); } else if (result.equals("AdminPinIsInvalid")) { imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); Toast toast = Toast.makeText(getApplicationContext(), "Admin PIN is wrong, exit! Please try again.", Toast.LENGTH_SHORT); toast.show(); //set return code /* if(shp.getString(ASID, "").equals("")){ setResult(9); }else{ setResult(Activity.RESULT_CANCELED); }*/ //setResult(9); finish(); } else { imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); Toast toast = Toast.makeText(getApplicationContext(), "Verify failed. Please try again.", Toast.LENGTH_SHORT); toast.show(); //set return code /* if(shp.getString(ASID, "").equals("")){ setResult(9); }else{ setResult(Activity.RESULT_CANCELED); }*/ finish(); } } } catch (Exception e) { // TODO Auto-generated catch block imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); Toast toast = Toast.makeText(getApplicationContext(), "Failed. Please try again, with network connection.", Toast.LENGTH_SHORT); toast.show(); //set return code /* if(shp.getString(ASID, "").equals("")){ setResult(9); }else{ setResult(Activity.RESULT_CANCELED); }*/ finish(); e.printStackTrace(); } } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); //set return code /* if(shp.getString(ASID, "").equals("")){ setResult(9); }else{ setResult(Activity.RESULT_CANCELED); }*/ setResult(9); finish(); } }); return builder.create(); }
From source file:com.cettco.buycar.dealer.activity.OrderDetailActivity.java
private void submit(String url) { System.out.println("url:" + url); String cookieStr = null;/*from w w w. j a va 2 s . c om*/ String cookieName = null; PersistentCookieStore myCookieStore = new PersistentCookieStore(this); if (myCookieStore == null) { System.out.println("cookie store null"); return; } List<Cookie> cookies = myCookieStore.getCookies(); for (Cookie cookie : cookies) { String name = cookie.getName(); cookieName = name; System.out.println(name); if (name.equals("_JustBidIt_session")) { cookieStr = cookie.getValue(); System.out.println("value:" + cookieStr); break; } } if (cookieStr == null || cookieStr.equals("")) { System.out.println("cookie null"); return; } //String insurance = String insurance = insurancEditText.getText().toString(); //String vehicleTax = vechileTaxEditText.getText().toString(); String purchaseTax = purchaseEditText.getText().toString(); String licenseFee = licenseFeEditText.getText().toString(); String miscFee = miscFeEditText.getText().toString(); String price = priceEditText.getText().toString(); String description = descriptionEditText.getText().toString(); if (insurance.equals("") || purchaseTax.equals("") || licenseFee.equals("") || miscFee.equals("") || price.equals("")) { Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT); toast.show(); return; } JSONObject bidJson = new JSONObject(); JSONObject json = new JSONObject(); try { bidJson.put("insurance", insurance); //bidJson.put("vehicle_tax", vehicleTax); bidJson.put("purchase_tax", purchaseTax); bidJson.put("license_fee", licenseFee); bidJson.put("misc_fee", miscFee); bidJson.put("price", price); bidJson.put("description", description); json.put("bid", bidJson); json.put("_method", "patch"); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //Gson gson = new Gson(); StringEntity entity = null; try { System.out.println("patch:" + json.toString()); entity = new StringEntity(json.toString()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } //HttpConnection.getClient().re HttpConnection.getClient().addHeader("x-http-method-override", "PATCH"); HttpConnection.getClient().addHeader("Cookie", cookieName + "=" + cookieStr); progressLayout.setVisibility(View.VISIBLE); HttpConnection.post(this, url, null, entity, "application/json;charset=utf-8", new AsyncHttpResponseHandler() { @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { // TODO Auto-generated method stub progressLayout.setVisibility(View.GONE); System.out.println("fail"); Message message = new Message(); message.what = 5; mHandler.sendMessage(message); } @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { // TODO Auto-generated method stub progressLayout.setVisibility(View.GONE); try { String result = new String(arg2, "UTF-8"); System.out.println("order detail result:" + result); // Type listType = new // TypeToken<ArrayList<OrderItemEntity>>() { // }.getType(); // list = new Gson().fromJson(result, listType); // //System.out.println("size:"+dealerList.size()); Message message = new Message(); message.what = 6; mHandler.sendMessage(message); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }
From source file:com.akop.bach.fragment.xboxlive.AchievementsFragment.java
private void showAchievementDetails(CharSequence title, CharSequence description) { LayoutInflater inflater = getActivity().getLayoutInflater(); View layout = inflater.inflate(R.layout.xbl_achievement_toast, (ViewGroup) getActivity().findViewById(R.id.toast_root)); TextView text = (TextView) layout.findViewById(R.id.achievement_title); text.setText(title);// w w w . jav a2 s.c om text = (TextView) layout.findViewById(R.id.achievement_description); text.setText(description); Toast toast = new Toast(getActivity()); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
From source file:com.RSMSA.policeApp.Fragments.OffenceHistoryFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { contentView = (RelativeLayout) inflater.inflate(R.layout.fragment_offence_history, container, false); /**/* www . ja v a 2 s.c o m*/ * get the instances of the buttons at our view */ progressBar = (ProgressBar) contentView.findViewById(R.id.pbar_main); inputnformation = (RelativeLayout) contentView.findViewById(R.id.input_information); verificationResults = (ScrollView) contentView.findViewById(R.id.verification_results); offenceList = (LinearLayout) contentView.findViewById(R.id.history_list); nameTextView = (TextView) contentView.findViewById(R.id.name); licenseNumberTextView = (TextView) contentView.findViewById(R.id.license_number); addressTextView = (TextView) contentView.findViewById(R.id.address); genderTextView = (TextView) contentView.findViewById(R.id.gender); dateOfBirthTextView = (TextView) contentView.findViewById(R.id.date_of_birth); phoneNumberTextView = (TextView) contentView.findViewById(R.id.phone_number); drivingClassTextVeiw = (TextView) contentView.findViewById(R.id.driving_class); licenceExpiryDate = (TextView) contentView.findViewById(R.id.licence_expiry_date); insuarenceExpiryDate = (TextView) contentView.findViewById(R.id.insuarance_expiry_date); ownersNameTexView = (TextView) contentView.findViewById(R.id.owners_name); vehiclesMakeTextView = (TextView) contentView.findViewById(R.id.make); vehclesColorTextView = (TextView) contentView.findViewById(R.id.color); vehicleInsuarance = (TextView) contentView.findViewById(R.id.insuarance); vehiclesInspection = (TextView) contentView.findViewById(R.id.inspection); vehicleInsuarance = (TextView) contentView.findViewById(R.id.insuarance); vehiclesInspection = (TextView) contentView.findViewById(R.id.inspection); scanBtn = (ImageView) contentView.findViewById(R.id.scan_button); verifyBtn = (Button) contentView.findViewById(R.id.verify); verifyBtn.setTypeface(MainOffence.Rosario_Bold); errorBtn = (ImageView) contentView.findViewById(R.id.error_icon); errorBtn2 = (ImageView) contentView.findViewById(R.id.error_icon_2); reportBtn = (Button) contentView.findViewById(R.id.report_button); reportBtn.setTypeface(MainOffence.Rosario_Bold); paymentBtn = (Button) contentView.findViewById(R.id.payment_button); license = (EditText) contentView.findViewById(R.id.license_); plateNumberEditText = (EditText) contentView.findViewById(R.id.plate_number); license.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { //reportBtn.setVisibility(View.VISIBLE); return false; } }); verifyBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.d(TAG, "verify button clicked"); licenceNumber = license.getText().toString(); plateNumber = plateNumberEditText.getText().toString(); if (!licenceNumber.equals("") || !plateNumber.equals("")) { verifyBtn.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); progressBar.bringToFront(); NetAsync(view); } else { Toast toast = Toast.makeText(getActivity(), " Field Empty", Toast.LENGTH_SHORT); toast.show(); } } }); reportBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //inputnformation.setVisibility(View.VISIBLE); //verificationResults.setVisibility(View.GONE); progressBar.setVisibility(View.INVISIBLE); verifyBtn.setVisibility(View.VISIBLE); Intent intent = new Intent(getActivity(), OffenceReportForm.class); intent.putExtra("name", name); intent.putExtra("licence_number", licenceNumber); intent.putExtra("plate_number", plateNumber); intent.putExtra("invalidLicence", invalidLicence); intent.putExtra("expiredInsuarance", expiredInsuarance); intent.putExtra("vehicleUid", vehicleUid); intent.putExtra("driverUid", driverUid); getActivity().startActivity(intent); } }); paymentBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle bundle = new Bundle(); if (!licenceNumber.equals("")) bundle.putString("licenceNumber", licenceNumber); else bundle.putString("plateNumber", plateNumber); PaymentVerifierFragment nextFrag = new PaymentVerifierFragment(); nextFrag.setArguments(bundle); OffenceHistoryFragment.this.getFragmentManager().beginTransaction() .replace(R.id.activityMain_content_frame, nextFrag, null).addToBackStack(null).commit(); } }); /** * adding the listener to the button */ scanBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IntentIntegrator scanIntegrator = new IntentIntegrator(getActivity()); scanIntegrator.initiateScan(); } }); return contentView; }
From source file:ca.frozen.rpicameraviewer.activities.VideoFragment.java
private void takeSnapshot() { Bitmap image = textureView.getBitmap(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String name = camera.network + "_" + camera.name.replaceAll("\\s+", "") + "_" + sdf.format(new Date()) + ".jpg"; Utils.saveImage(getActivity().getContentResolver(), image, name, null); MediaActionSound sound = new MediaActionSound(); sound.play(MediaActionSound.SHUTTER_CLICK); Toast toast = Toast.makeText(getActivity(), App.getStr(R.string.image_saved), Toast.LENGTH_SHORT); toast.show(); }
From source file:com.jaspersoft.android.jaspermobile.activities.profile.ServerProfileActivity.java
@UiThread protected void checkUniqueConstraintFulfilled(Cursor cursor) { boolean entryExists = cursor.getCount() > 0; getSupportLoaderManager().destroyLoader(QUERY_UNIQUENESS); if (entryExists) { aliasEdit.setError(getString(R.string.sp_error_duplicate_alias)); aliasEdit.requestFocus();/* w w w .ja v a2 s . c om*/ Toast toast = Toast.makeText(this, getString(R.string.sp_error_unique_alias, alias), Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, mActionBarSize + (mActionBarSize / 2)); toast.show(); } else { JsServerProfile oldProfile = jsRestClient.getServerProfile(); if (oldProfile != null && oldProfile.getId() == profileId) { updateServerProfile(oldProfile); } else { persistProfileData(); setOkResult(); finish(); } hideKeyboard(); } }
From source file:ch.luklanis.esscan.history.HistoryActivity.java
@Override public boolean handleMessage(Message message) { int msgId = 0; switch (message.what) { case R.id.history_menu_send_dta_email: { Uri dtaFileUri = (Uri) message.obj; if (dtaFileUri != null) { try { startActivity(createMailIntent(dtaFileUri)); return true; } catch (Exception ex) { msgId = R.string.msg_no_email_client; }//from w w w. j a v a 2 s. c o m } } break; case R.id.history_menu_send_dta_other: { Uri dtaFileUri = (Uri) message.obj; if (dtaFileUri != null) { startActivity(Intent.createChooser(createShareIntent(dtaFileUri), "Send with...")); return true; } } break; case R.id.history_menu_send_dta_save: break; case R.id.es_send_succeeded: { mSendingProgressDialog.dismiss(); HistoryItem historyItem = historyFragment.getHistoryItemOnPosition(message.arg1); if (historyItem != null) { String filename = getResources().getString(R.string.history_item_sent); historyItem.update(new HistoryItem.Builder(historyItem).setDtaFile(filename).create()); mHistoryManager.updateHistoryItemFileName(historyItem.getItemId(), filename); //historyFragment.updatePosition(message.arg1, historyItem); historyFragment.dataChanged(); PsDetailFragment fragment = (PsDetailFragment) getFragmentManager() .findFragmentById(R.id.ps_detail_container); if (fragment != null) { fragment.getHistoryItem().update(historyItem); fragment.updateDtaFilename(fragment.getView()); } } msgId = R.string.msg_coderow_sent; } break; case R.id.es_send_failed: mSendingProgressDialog.dismiss(); msgId = R.string.msg_coderow_not_sent; break; } if (msgId != 0) { Toast toast = Toast.makeText(getApplicationContext(), msgId, Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, 0, 0); toast.show(); return true; } return false; }