List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:com.lucapernini.misapp.Registration.java
public void showToast(String msg) { Log.i(TAG, "Misa Registration, showToast: " + msg); Toast toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show();/*from www . j av a 2 s . c o m*/ }
From source file:com.nokia.example.capturetheflag.Controller.java
@Override public void onUpdatePlayerMessage(UpdatePlayerResponse update) { if (mCurrentGame == null) { return;//from w w w .j a v a 2s. c o m } Player updatedPlayer = update.getUpdatedPlayer(); if (!mCurrentGame.getPlayers().contains(update.getUpdatedPlayer())) { Log.d(TAG, "onUpdatePlayerMessage(): New player"); mCurrentGame.getPlayers().add(updatedPlayer); /* Show a toast message informing the user that a new player has * joined the game. */ final String playerName = updatedPlayer.getName(); mUIHandler.post(new Runnable() { @Override public void run() { String text = getString(R.string.new_player_joined, playerName); Toast toast = Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } }); } else { Log.d(TAG, "onUpdatePlayerMessage(): Existing player"); int i = mCurrentGame.getPlayers().indexOf(updatedPlayer); Player old = mCurrentGame.getPlayers().get(i); mMap.updateMarkerForPlayer(updatedPlayer, old); mCurrentGame.getPlayers().set(i, updatedPlayer); } mMap.updatePlayerMarkerPosition(updatedPlayer); }
From source file:com.facebook.android.MainPage.java
/** Called when the activity is first created. */ @Override// w ww . java 2 s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see Example.java"); } setContentView(R.layout.main); mMovieNameInput = (EditText) findViewById(R.id.title); mMediaSpinner = (Spinner) findViewById(R.id.media); mSearchButton = (Button) findViewById(R.id.search); mFacebook = new Facebook(APP_ID); mAsyncRunner = new AsyncFacebookRunner(mFacebook); SessionStore.restore(mFacebook, this); SessionEvents.addAuthListener(new SampleAuthListener()); SessionEvents.addLogoutListener(new SampleLogoutListener()); // set up the Spinner for the media list selection ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.media_list, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mMediaSpinner.setAdapter(adapter); //for search button final Context context = this; mSearchButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String servletURL; String movieName = mMovieNameInput.getText().toString(); // check the input text of movie, if the text is empty give user alert movieName = movieName.trim(); if (movieName.length() == 0) { Toast toast = Toast.makeText(context, "Please enter a movie name", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 70); toast.show(); } // if movie name is not empty else { // remove any extra whitespace movieName = movieName.replaceAll("\\s+", "+"); String mediaList = mMediaSpinner.getSelectedItem().toString(); if (mediaList.equals("Feature Film")) { mediaList = "feature"; } mediaList = mediaList.replaceAll("\\s+", "+"); // construct the query string // construct the final URL to Servlet //String servletString = "?" + "title=" + movieName + "&" + "title_type=" + mediaList; //servletURL = "http://cs-server.usc.edu:10854/examples/servlet/Amovie" //+ servletString; //String servletString = "?" + "title=" + movieName + "&" + "media=" + mediaList; //servletURL = "http://cs-server.usc.edu:34404/examples/servlet/HelloWorldExample?title=" + movieName + "&" + "media=" + mediaList; //+ servletString; servletURL = "http://cs-server.usc.edu:10854/examples/servlet/Amovie?title=" + movieName + "&" + "title_type=" + mediaList; BufferedReader in = null; try { // REFERENCE: this part of code is modified from: // "Example of HTTP GET Request using HttpClient in Android" // http://w3mentor.com/learn/java/android-development/android-http-services/example-of-http-get-request-using-httpclient-in-android/ // get response (JSON string) from Servlet HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.setURI(new URI(servletURL)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String page = sb.toString(); //test for JSON string /*LinearLayout lView = new LinearLayout(context); TextView myText = new TextView(context); myText.setText(page); lView.addView(myText); setContentView(lView);*/ // convert the JSON string to real JSON and get out the movie JSON array // to check if there is any movie data JSONObject finalJson; JSONObject movieJson; JSONArray movieJsonArray; finalJson = new JSONObject(page); movieJson = finalJson.getJSONObject("results"); //System.out.println(movieJson); movieJsonArray = movieJson.getJSONArray("result"); // if the response contains some movie data if (movieJsonArray.length() != 0) { // start the ListView activity, and pass the JSON string to it Intent intent = new Intent(context, MovieListActivity.class); intent.putExtra("finalJson", page); startActivity(intent); } // if the response does not contain any movie data, // show user that there is no result for this search else { Toast toast = Toast.makeText(getBaseContext(), "No movie found for this search", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } } catch (URISyntaxException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } } }); }
From source file:org.sigimera.app.android.MainActivity.java
@Override public final boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.menu_update_location: LocationUpdaterHttpHelper locUpdater = new LocationUpdaterHttpHelper(); Location loc = LocationController.getInstance().getLastKnownLocation(); if (loc != null) { Toast toast = Toast.makeText(getApplicationContext(), "Trying to update your current location...", Toast.LENGTH_LONG);/*from w w w. ja v a 2s.com*/ toast.setGravity(Gravity.TOP, 0, 0); toast.show(); String latitude = loc.getLatitude() + ""; String longitude = loc.getLongitude() + ""; authToken = ApplicationController.getInstance().getSharedPreferences().getString("auth_token", null); if (authToken != null) { locUpdater.execute(authToken, latitude, longitude); } } else { Toast toast = Toast.makeText(getApplicationContext(), "Not able to update location! " + "Please active location access...", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); } return true; case R.id.menu_update_everything: try { PersistanceController.getInstance().updateEverything(authToken); } catch (InterruptedException e) { Log.e("[MAIN ACTIVITY]", "The thread coudn't sleep betheen api calls."); } return true; case R.id.menu_logout: ApplicationController.getInstance().getSessionHandler().logout(); setTabsBeforeLogin(); return true; case R.id.menu_unregister: GCMRegistrar.unregister(getApplicationContext()); return true; case R.id.about: showAboutDialog(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.peercast.pecaport.PecaPortFragmentBase.java
private void showToast(CharSequence text) { Toast toast = Toast.makeText(getContext(), text, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();// w ww . jav a 2 s . c o m }
From source file:com.ferid.app.notetake.MainActivity.java
/** * Voice listener/* w ww . j a va 2 s . com*/ */ private void listenToUser() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); try { startActivityForResult(intent, SPEECH_REQUEST_CODE); } catch (ActivityNotFoundException e) { Toast toast = Toast.makeText(context, getString(R.string.voiceRecognitionNotSupported), Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } }
From source file:org.madmatrix.zxing.android.CaptureActivity.java
public void showMyToast(String content) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout)); TextView toast_content = (TextView) layout.findViewById(R.id.toast_content); toast_content.setText(content);// ww w . j a v a 2s . co m Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); }
From source file:com.example.jesse.barscan.BarcodeCaptureActivity.java
/** * onTap returns the tapped barcode result to the calling Activity. *//*w ww .jav a2s .c o m*/ public boolean onTap(float rawX, float rawY) { // Find tap point in preview frame coordinates. int[] location = new int[2]; mGraphicOverlay.getLocationOnScreen(location); float x = (rawX - location[0]) / mGraphicOverlay.getWidthScaleFactor(); float y = (rawY - location[1]) / mGraphicOverlay.getHeightScaleFactor(); // Find the barcode whose center is closest to the tapped point. Barcode best = null; float bestDistance = Float.MAX_VALUE; for (BarcodeGraphic graphic : mGraphicOverlay.getGraphics()) { Barcode barcode = graphic.getBarcode(); if (barcode.getBoundingBox().contains((int) x, (int) y)) { // Exact hit, no need to keep looking. best = barcode; break; } float dx = x - barcode.getBoundingBox().centerX(); float dy = y - barcode.getBoundingBox().centerY(); float distance = (dx * dx) + (dy * dy); // actually squared distance if (distance < bestDistance) { best = barcode; bestDistance = distance; } } if (best != null) { Intent data = new Intent(); data.putExtra(BarcodeObject, best); setResult(CommonStatusCodes.SUCCESS, data); LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.barcode_toast, (ViewGroup) findViewById(R.id.custom_toast_container)); Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject); //Barcode.DriverLicense dlBarcode = barcode.driverLicense; Barcode.DriverLicense sample = barcode.driverLicense; TextView name = (TextView) layout.findViewById(R.id.name); TextView address = (TextView) layout.findViewById(R.id.address); TextView cityStateZip = (TextView) layout.findViewById(R.id.cityStateZip); TextView gender = (TextView) layout.findViewById(R.id.gender); TextView dob = (TextView) layout.findViewById(R.id.dob); TableLayout tbl = (TableLayout) layout.findViewById(R.id.tableLayout); try { int age = DateDifference.generateAge(sample.birthDate); if (age < minAge) tbl.setBackgroundColor(Color.parseColor("#980517")); else tbl.setBackgroundColor(Color.parseColor("#617C17")); } catch (ParseException e) { e.printStackTrace(); } String cityContent = new String( sample.addressCity + ", " + sample.addressState + " " + (sample.addressZip).substring(0, 5)); address.setText(sample.addressStreet); cityStateZip.setText(cityContent); String genderString; if ((sample.gender).equals("1")) genderString = "Male"; else if ((sample.gender).equals("2")) genderString = "Female"; else genderString = "Other"; gender.setText(genderString); dob.setText((sample.birthDate).substring(0, 2) + "/" + (sample.birthDate).substring(2, 4) + "/" + (sample.birthDate).substring(4, 8)); String nameString = new String(sample.firstName + " " + sample.middleName + " " + sample.lastName); name.setText(nameString); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); Date today = Calendar.getInstance().getTime(); String reportDate = df.format(today); SQLiteDatabase db = helper.getWritableDatabase(); ContentValues row = new ContentValues(); row.put("dateVar", reportDate); row.put("dobVar", sample.birthDate); row.put("zipVar", sample.addressZip); row.put("genderVar", genderString); db.insert("test", null, row); db.close(); return true; } return false; }
From source file:com.adamas.client.android.ui.ConnectorsFragment.java
private void toast(String msg, ToastType toastType) { LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate the Layout View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) getActivity().findViewById(R.id.custom_toast_layout)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (toastType.equals(ToastType.error)) { layout.setBackground(getActivity().getDrawable(R.drawable.toast_error)); } else if (toastType.equals(ToastType.info)) { layout.setBackground(getActivity().getDrawable(R.drawable.toast_info)); } else if (toastType.equals(ToastType.warning)) { layout.setBackground(getActivity().getDrawable(R.drawable.toast_warning)); } else {// w w w.j ava2s . c o m layout.setBackground(getActivity().getDrawable(R.drawable.toast_info)); } } TextView text = (TextView) layout.findViewById(R.id.textToShow); // Set the Text to show in TextView text.setText(msg); Toast toast = new Toast(getActivity().getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); }
From source file:com.mischivous.wormysharpyloggy.wsl.GameScreen.java
/** * Displays a message to the user in a Toast. * * @param msg The message to display//from www .j a va 2 s . co m */ private void messageUser(@NonNull String msg) { if (msg == null) { throw new NullPointerException("Message to user cannot be null."); } Toast toast = Toast.makeText(this, msg, (msg.length() > 24 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT)); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); }