List of usage examples for android.widget Toast show
public void show()
From source file:com.danielme.muspyforandroid.activities.base.AbstractActivity.java
private void showToast(int msgID, String msg, int duration) { Toast toast = new Toast(this); LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_success, (ViewGroup) findViewById(R.id.lytLayout)); TextView txtMsg = (TextView) layout.findViewById(R.id.toastMessage); if (msg == null) { txtMsg.setText(getString(msgID)); } else {/*from w w w . ja v a2 s. c om*/ txtMsg.setText(msg); } toast.setDuration(duration); toast.setView(layout); toast.show(); }
From source file:mobile.tiis.appv2.LoginActivity.java
/** * This method will check if username and passwords fields * have not been left empty when trying to login * * <p>This method will throw a Toast message on empty field(s) which might * have to be changed to a real message window instead. * * @return boolean result weather both fields are NON-empty *//*from w w w. j a v a2s . co m*/ protected boolean checkRequiredFields() { boolean result = true; Context context = getApplicationContext(); CharSequence text = "Fields missing: "; if (Utils.isStringBlank(username)) { result = false; text = text + " username"; } if (Utils.isStringBlank(password)) { result = false; text = text + " password"; } if (!result) { Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); toast.show(); } return result; }
From source file:com.RSMSA.policeApp.Fragments.PaymentVerifierFragment.java
public void verifyLicenceNumber(String driversLicence) { Log.d(TAG, " drivers licence received == " + driversLicence); licenseEdittext.setText(driversLicence + ""); licenceNumber = driversLicence;/*from www . ja va 2s. c o m*/ if (licenceNumber.equals("")) { Toast toast = Toast.makeText(getActivity(), " Field Empty!", Toast.LENGTH_SHORT); toast.show(); } else { verifyBtn.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); progressBar.bringToFront(); NetAsync(null); } }
From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Home.CarBrowse.java
public void getCars(final Location location) { final String url = API.carsNearby + "/" + location.getLatitude() + "/" + location.getLongitude(); try {//ww w . ja va 2 s . c om final API.doRequest task = new API.doRequest(new API.doRequest.TaskListener() { @Override public void postExecute(JSONArray result) throws JSONException { JSONObject serverResponse = result.getJSONObject(result.length() - 1); int statusCode = serverResponse.getInt("statusCode"); result.remove(result.length() - 1); final FragmentActivity activity = getActivity(); if (activity == null) { return; } final ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar(); if (statusCode == 200) { final View view = getView(); if (view == null) { return; } final ListView listView = (ListView) view.findViewById(R.id.listView); final ArrayList<CarData> carsArray = new ArrayList<CarData>(); for (int i = 0; i < result.length(); i++) { final CarData tempCarData = new CarData(result.getJSONObject(i)); carsArray.add(tempCarData); final LatLng carLocation = new LatLng(tempCarData.lat, tempCarData.lng); mMap.addMarker(new MarkerOptions().position(carLocation).title(tempCarData.title) .icon(BitmapDescriptorFactory.fromResource(R.drawable.models))); } Collections.sort(carsArray, new Comparator<CarData>() { @Override public int compare(CarData lhs, CarData rhs) { return lhs.distance - rhs.distance; } }); final CarDataAdapter adapter = new CarDataAdapter(activity.getApplicationContext(), carsArray); listView.setAdapter(adapter); final ArrayList<CarData> finalCarsArray = carsArray; listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) { final Intent carDetails = new Intent(view.getContext(), CarDetails.class); final Bundle bundle = new Bundle(); bundle.putSerializable("carData", finalCarsArray.get(position)); carDetails.putExtras(bundle); startActivity(carDetails); } }); if (carsArray.size() == 0) { final Toast toast = Toast.makeText(activity.getApplicationContext(), "No car available in this area. Location information may be incorrect. Make sure GPS or Wifi is effective and try again. Or, Free Plan limitation, ask administrator to delete registered cars.", Toast.LENGTH_LONG); toast.show(); supportActionBar.setTitle("No car available."); } else { final String title = (carsArray.size() == 1) ? "1 car found." : carsArray.size() + " cars found."; supportActionBar.setTitle(title); } Log.i("Car Data", result.toString()); } else if (statusCode == 500) { final Toast toast = Toast.makeText(activity.getApplicationContext(), "A server internal error received. Ask your administrator.", Toast.LENGTH_LONG); toast.show(); supportActionBar.setTitle("Error: Server internal error."); } else { final Toast toast = Toast.makeText(activity.getApplicationContext(), "Error: Unable to connect to server.", Toast.LENGTH_LONG); toast.show(); supportActionBar.setTitle("Error: Not connected to server."); } } }); task.execute(url, "GET").get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } }
From source file:com.RSMSA.policeApp.Fragments.PaymentVerifierFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { //retrieve scan result com.google.zxing.integration.android.IntentResult scanningResult = IntentIntegrator .parseActivityResult(requestCode, resultCode, intent); if (resultCode == getActivity().RESULT_OK) { /**/* ww w . j a va 2 s . c o m*/ * getting the scanned licence number to our temporary variable */ scanContent = scanningResult.getContents(); Log.d(TAG, scanContent + " SCANNED"); licenseEdittext.setText(scanContent); } else if (resultCode == getActivity().RESULT_CANCELED) { Toast toast = Toast.makeText(getActivity(), "No scan data received!", Toast.LENGTH_SHORT); toast.show(); } }
From source file:fm.smart.r1.ItemActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ExceptionHandler.register(this); // could check here to see if this was suspended for login and go // straight to add_item ... setContentView(R.layout.item);//w ww. j a v a 2 s.c o m TextView cue_and_pronunciation = (TextView) findViewById(R.id.cue_and_pronunciation); cue_and_pronunciation.setText(item.cue_text); // TODO handle case where // item is null? TextView cue_part_of_speech = (TextView) findViewById(R.id.cue_part_of_speech); if (!TextUtils.equals(item.part_of_speech, "None")) { cue_part_of_speech.setText(item.part_of_speech); } else { cue_part_of_speech.setVisibility(View.INVISIBLE); } TextView response_and_pronunciation = (TextView) findViewById(R.id.response_and_pronunciation); response_and_pronunciation.setText(item.children[0][0]); TextView response_part_of_speech = (TextView) findViewById(R.id.response_part_of_speech); if (item.type != null && item.type.equals("meaning")) { item.type = "Translation"; } response_part_of_speech.setText(item.type); response_part_of_speech.setVisibility(View.INVISIBLE); ImageView cue_sound = (ImageView) findViewById(R.id.cue_sound); try { setSound(cue_sound, item.cue_sound_url, this, R.id.cue_sound, (String) item.item_node.getString("id"), item.cue_text); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } ImageView response_sound = (ImageView) findViewById(R.id.response_sound); try { setSound(response_sound, item.response_sound_url, this, R.id.response_sound, (String) item.item_node.getString("id"), item.response_node.getJSONObject("content").getString("text")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } EfficientAdapter adapter = new EfficientAdapter(ItemActivity.this, item.sentence_vector); cache = new Cache(adapter); setListAdapter(adapter); if (adapter.getCount() == 0 && !ItemActivity.shown_toast) { Toast t = Toast.makeText(this, "Know a good example? Click the menu button to add one", 250); t.setGravity(Gravity.CENTER, 0, 0); t.show(); ItemActivity.shown_toast = true; } // notify(); }
From source file:com.vkassin.mtrade.Common.java
public static void login(final Context ctx) { // ctx = Common.app_ctx; Common.connected = false;/* www. ja v a 2 s.c o m*/ if (inLogin) return; inLogin = true; if (Common.mainActivity != null) Common.mainActivity.handler.sendMessage( Message.obtain(Common.mainActivity.handler, Common.mainActivity.DISMISS_PROGRESS_DIALOG)); // while(true) { final Dialog dialog = new Dialog(ctx); dialog.setContentView(R.layout.login_dialog); dialog.setTitle(R.string.LoginDialogTitle); dialog.setCancelable(false); final EditText nametxt = (EditText) dialog.findViewById(R.id.loginnameedit); final EditText passtxt = (EditText) dialog.findViewById(R.id.passwordedit); final EditText passtxt1 = (EditText) dialog.findViewById(R.id.passwordedit1); final EditText passtxt2 = (EditText) dialog.findViewById(R.id.passwordedit2); final EditText mailtxt = (EditText) dialog.findViewById(R.id.emailedit2); String nam = myaccount.get("name"); Common.oldName = nam; if (nam != null) { nametxt.setText(nam); passtxt.requestFocus(); } Button customDialog_Register = (Button) dialog.findViewById(R.id.goregister); customDialog_Register.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { dialog.setTitle(R.string.LoginDialogTitle1); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.VISIBLE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.GONE); } }); Button customDialog_Register1 = (Button) dialog.findViewById(R.id.goregister1); customDialog_Register1.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { if (mailtxt.getText().length() < 1) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectEmail, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } if (passtxt1.getText().length() < 1) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } if (!passtxt2.getText().toString().equals(passtxt1.getText().toString())) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword1, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } try { Socket sock = new Socket(ip_addr, port_register); JSONObject msg = new JSONObject(); msg.put("objType", Common.MSG_REGISTER); msg.put("time", Calendar.getInstance().getTimeInMillis()); msg.put("user", mailtxt.getText().toString()); msg.put("passwd", passtxt1.getText().toString()); msg.put("version", Common.PROTOCOL_VERSION); msg.put("sign", sign(mailtxt.getText().toString(), passtxt1.getText().toString())); byte[] array = msg.toString().getBytes(); ByteBuffer buff = ByteBuffer.allocate(array.length + 4); buff.putInt(array.length); buff.put(array); sock.getOutputStream().write(buff.array()); ByteBuffer buff1 = ByteBuffer.allocate(4); buff1.put(readMsg(sock.getInputStream(), 4)); buff1.position(0); int pkgSize = buff1.getInt(); // Log.i(TAG, "size = "+pkgSize); String s = new String(readMsg(sock.getInputStream(), pkgSize)); sock.close(); JSONObject jo = new JSONObject(s); Log.i(TAG, "register answer = " + jo); int t = jo.getInt("status"); switch (t) { case 1: Toast toast = Toast.makeText(mainActivity, R.string.RegisterStatus1, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); dialog.setTitle(R.string.LoginDialogTitle); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.GONE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.VISIBLE); nametxt.setText(mailtxt.getText()); break; case -2: Toast toast1 = Toast.makeText(mainActivity, R.string.RegisterStatus3, Toast.LENGTH_LONG); toast1.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast1.show(); break; default: Toast toast2 = Toast.makeText(mainActivity, R.string.RegisterStatus2, Toast.LENGTH_LONG); toast2.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast2.show(); break; } } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "Error in registration process!!", e); Toast toast = Toast.makeText(mainActivity, R.string.ConnectError, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } } }); Button customDialog_CancelReg = (Button) dialog.findViewById(R.id.cancelreg); customDialog_CancelReg.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { dialog.setTitle(R.string.LoginDialogTitle); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.GONE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.VISIBLE); } }); Button customDialog_Dismiss = (Button) dialog.findViewById(R.id.gologin); customDialog_Dismiss.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.lradio0); Common.isSSL = bu0.isChecked(); inLogin = false; JSONObject msg = new JSONObject(); try { msg.put("objType", Common.LOGOUT); msg.put("time", Calendar.getInstance().getTimeInMillis()); msg.put("version", Common.PROTOCOL_VERSION); msg.put("status", 1); mainActivity.writeJSONMsg(msg); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "Error! Cannot create JSON logout object", e); } myaccount.put("name", nametxt.getText().toString()); myaccount.put("password", passtxt.getText().toString()); Log.i(TAG, "myaccount username: " + myaccount.get("name") + " password: " + myaccount.get("password")); dialog.dismiss(); mainActivity.stop(); // saveAccountDetails(); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } loginFromDialog = true; // mainActivity.refresh(); Common.keypassword(ctx); } }); dialog.show(); // Common.confChanged = false; // }//while(true); }
From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { CropImage.ActivityResult result = CropImage.getActivityResult(data); if (resultCode == RESULT_OK) { Uri croppedImageUri = result.getUri(); File croppedImageFile = new File(croppedImageUri.getPath()); annotateImageView.updateCroppedImageHistory(croppedImageFile); } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { Toast toast = Toast.makeText(getApplicationContext(), R.string.supersede_feedbacklibrary_error_text, Toast.LENGTH_SHORT); toast.show(); }/*w w w. j av a 2 s . co m*/ } }
From source file:com.farmerbb.notepad.activity.MainActivity.java
private void showToast(int message) { Toast toast = Toast.makeText(this, getResources().getString(message), Toast.LENGTH_SHORT); toast.show(); }
From source file:com.grass.caishi.cc.activity.AdAddActivity.java
/** * ?uri??//from w w w. ja v a2s. c om * * @param selectedImage */ private String getPicByUri(Uri selectedImage) { // String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex("_data"); String picturePath = cursor.getString(columnIndex); cursor.close(); cursor = null; if (picturePath == null || picturePath.equals("null")) { Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return null; } return picturePath; } else { File file = new File(selectedImage.getPath()); if (!file.exists()) { Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return null; } return file.getAbsolutePath(); } }