List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:com.wordpress.jftreading.FragmentMain.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.update_contact: startActivityForResult(new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI), PICK_CONTACT_REQUEST);//from w w w . j ava2 s .c o m break; case R.id.call_btn: // Dial mobile number if (contactUri != null) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + getMobileNumber(contactUri))); startActivity(callIntent); } break; case R.id.send_btn: String stextMessage = textMessage.getText().toString(); if (stextMessage.matches("")) { } else if (contactUri != null) { dialog = ProgressDialog.show(getActivity(), "Sending", "Sending text message"); Thread th = new Thread(new Runnable() { @Override public void run() { // Send text message try { String SENT = "sent"; String DELIVERED = "delivered"; Intent sentIntent = new Intent(SENT); //Create Pending Intents PendingIntent sentPI = PendingIntent.getBroadcast(getActivity().getApplicationContext(), 0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent deliveryIntent = new Intent(DELIVERED); PendingIntent deliverPI = PendingIntent.getBroadcast( getActivity().getApplicationContext(), 0, deliveryIntent, PendingIntent.FLAG_UPDATE_CURRENT); //Register for SMS send action getActivity().registerReceiver(new BroadcastReceiver() { String result = ""; @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK: result = "Message sent"; break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: result = "Sending failed"; break; case SmsManager.RESULT_ERROR_RADIO_OFF: result = "Radio off"; break; case SmsManager.RESULT_ERROR_NULL_PDU: result = "No PDU defined"; break; case SmsManager.RESULT_ERROR_NO_SERVICE: result = "No service"; break; } handler.post(new Runnable() { @Override public void run() { if (result != "") { Toast toast = Toast.makeText(getActivity().getApplicationContext(), result, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); result = ""; } dialog.dismiss(); } }); } }, new IntentFilter(SENT)); //Register for Delivery event getActivity().registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { handler.post(new Runnable() { @Override public void run() { Toast.makeText(getActivity().getApplicationContext(), "Delivered", Toast.LENGTH_LONG).show(); } }); } }, new IntentFilter(DELIVERED)); //Send SMS SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(getMobileNumber(contactUri), null, textMessage.getText().toString(), sentPI, deliverPI); } catch (Exception ex) { final String exception = ex.getMessage().toString(); handler.post(new Runnable() { @Override public void run() { Toast.makeText(getActivity().getApplicationContext(), exception, Toast.LENGTH_LONG).show(); } }); ex.printStackTrace(); dialog.dismiss(); } } }); th.start(); } break; default: break; } }
From source file:edgargtzg.popularmovies.MovieDetailsFragment.java
/** * Updates the content of the view based on the movie data. * * @param movieItem the current movie item. *///from w w w. ja v a2 s .co m private void updateMovieData(MovieItem movieItem) { if (isNetworkAvailable()) { FetchMovieVideosTask fetchMovieVideosTask = new FetchMovieVideosTask(movieItem); fetchMovieVideosTask.execute(); FetchMovieReviewsTask fetchMovieReviewsTask = new FetchMovieReviewsTask(movieItem); fetchMovieReviewsTask.execute(); } else { Toast toast = Toast.makeText(getActivity(), R.string.error_msg_no_network, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); 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();//from w w w. j a va 2s.com 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:no.ntnu.idi.socialhitchhiking.map.MapActivityJourney.java
/** * sends a message to the driver of a journey *///from ww w. ja v a 2 s . co m private void sendMessageToDriver() { final Dialog customDialog = new Dialog(this); customDialog.setContentView(R.layout.custom_dialog_layout); customDialog.setTitle("Message"); final List<String> spinnerArray = new ArrayList<String>(); spinnerArray.add("Everyone"); if (!getApp().getSelectedJourney().getDriver().equals(getApp().getUser())) { spinnerArray.add(getApp().getSelectedJourney().getDriver().getFullName()); } for (int i = 0; i < getApp().getSelectedJourney().getHitchhikers().size(); i++) { if (!getApp().getSelectedJourney().getHitchhikers().get(i).equals(getApp().getUser())) { spinnerArray.add(getApp().getSelectedJourney().getHitchhikers().get(i).getFullName()); } } final Spinner spinner = (Spinner) customDialog.findViewById(R.id.spinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(MapActivityJourney.this, android.R.layout.simple_spinner_item, spinnerArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); ImageView sendBtn = (ImageView) customDialog.findViewById(R.id.sendBtn); final EditText input = (EditText) customDialog.findViewById(R.id.input); sendBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { User mid = getApp().getUser(); if (spinner.getSelectedItem().toString().equals("Everyone")) { if (input.getText().toString().equals("")) { input.setHint("Please fill in your message"); Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); } else { List<User> userList = new ArrayList<User>(); userList.add(getApp().getSelectedJourney().getDriver()); for (int k = 0; k < getApp().getSelectedJourney().getHitchhikers().size(); k++) { userList.add(getApp().getSelectedJourney().getHitchhikers().get(k)); } userList.remove(getApp().getUser()); for (int k = 0; k < userList.size(); k++) { sendMessage(userList.get(k), input); } Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); customDialog.dismiss(); } } else { for (int j = 0; j < getApp().getSelectedJourney().getHitchhikers().size(); j++) { if (spinner.getSelectedItem().toString() .equals(getApp().getSelectedJourney().getHitchhikers().get(j).getFullName())) { mid = getApp().getSelectedJourney().getHitchhikers().get(j); } } if (spinner.getSelectedItem().toString() .equals(getApp().getSelectedJourney().getDriver().getFullName())) { mid = getApp().getSelectedJourney().getDriver(); } if (input.getText().toString().equals("")) { input.setHint("Please fill in your message"); Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); } else { sendMessage(mid, input); Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); customDialog.dismiss(); } } } }); customDialog.show(); }
From source file:org.billthefarmer.shorty.LookupActivity.java
void showToast(String text) { // Make a new toast Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();/*from ww w.j av a2s . c o m*/ }
From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java
private void saveGame(boolean showToast) { GameStateSummary summary = new GameStateSummary(gameStateSlot, System.currentTimeMillis(), lastLocation); gameStateDao.save(summary, level9.getGameState(), graphicsHandlerContext.getBitmap()); if (showToast) { Toast toast = Toast.makeText(getApplicationContext(), "Game saved", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();//w w w . j a va2 s .c o m } }
From source file:de.spiritcroc.ownlog.ui.fragment.LogItemEditFragment.java
@Override public boolean onLongClick(View view) { if (view == mEditTime) { int[] viewPos = new int[2]; view.getLocationInWindow(viewPos); int[] offsetPos = new int[2]; view.getRootView().findViewById(android.R.id.content).getLocationInWindow(offsetPos); Toast toast = Toast.makeText(getActivity(), view.getContentDescription(), Toast.LENGTH_SHORT); toast.setGravity(Gravity.END | Gravity.TOP, 0, viewPos[1] - offsetPos[1] + view.getHeight()); toast.show();/*w w w. jav a 2 s. co m*/ return true; } return false; }
From source file:biz.incomsystems.fwknop2.ConfigDetailFragment.java
public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.detail_help) { Intent detailIntent = new Intent(getActivity(), HelpActivity.class); startActivity(detailIntent);//from w ww. java 2s. co m } else if (id == R.id.qr_code) { try { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes startActivityForResult(intent, 0); } catch (Exception e) { // This is where the play store is called if the app is not installed Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android"); Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); startActivity(marketIntent); } } else if (id == R.id.save) { InetAddressValidator ipValidate = new InetAddressValidator(); Context context = getActivity(); // We know we will use a toast, so set it up now int duration = Toast.LENGTH_LONG; CharSequence text = "Saving config"; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout toastLayout = (LinearLayout) toast.getView(); TextView toastTV = (TextView) toastLayout.getChildAt(0); toastTV.setTextSize(30); //The following is all input validation try { if ((Integer.parseInt(txt_server_port.getText().toString()) > 0) && (Integer.parseInt(txt_server_port.getText().toString()) < 65535)) { // check for valid port txt_server_port.setText(String.valueOf(Integer.parseInt(txt_server_port.getText().toString()))); } else { txt_server_port.setText(String.valueOf(62201)); } } catch (NumberFormatException ex) { txt_server_port.setText(String.valueOf(62201)); } if (txt_NickName.getText().toString().equalsIgnoreCase("")) { // Need to create a new Nick toast.setText("You Must choose a unique Nickname."); // choosing a used nick will just overwrite it. So really toast.show(); } else if (chkb64hmac.isChecked() && txt_HMAC.getText().toString().length() % 4 != 0) { // base64 must have a multiple of 4 length toast.setText("Hmac is not a valid Base64, not a multiple of 4."); toast.show(); } else if (chkb64hmac.isChecked() && !(txt_HMAC.getText().toString().matches("^[A-Za-z0-9+/]+={0,2}$"))) { // looks for disallowed b64 characters toast.setText("Hmac is not a valid Base64, Contains disallowed characters."); toast.show(); } else if (chkb64key.isChecked() && txt_KEY.getText().toString().length() % 4 != 0) { toast.setText("Key is not a valid Base64, not a multiple of 4."); toast.show(); } else if (chkb64key.isChecked() && !(txt_KEY.getText().toString().matches("^[A-Za-z0-9+/]+={0,2}$"))) { // looks for disallowed b64 characters toast.setText("Key is not a valid Base64, Contains disallowed characters."); toast.show(); } else if (!(txt_ports.getText().toString().matches("tcp/\\d.*") || txt_ports.getText().toString().matches("udp/\\d.*"))) { toast.setText("Access ports must be in the form of 'tcp/22'"); toast.show(); } else if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Allow IP") && (!ipValidate.isValid(txt_allowIP.getText().toString()))) { //Have to have a valid ip to allow, if using allow ip toast.setText("You Must supply a valid IP address to 'Allow IP'."); toast.show(); } else if (!ipValidate.isValid(txt_server_ip.getText().toString()) && !DomainValidator.getInstance().isValid(txt_server_ip.getText().toString())) { // check server entry. Must be a valid url or ip. toast.setText("You Must supply a valid server address."); toast.show(); } else if (txt_KEY.getText().toString().equalsIgnoreCase("")) { toast.setText("You Must supply a Rijndael key."); toast.show(); } else if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("Juicessh") && juice_adapt.getConnectionName(spn_juice.getSelectedItemPosition()) == null) { toast.setText("A connection must be saved in Juicessh before being used here."); toast.show(); // //end input validation, actual saving below } else { toast.show(); if (configtype.equalsIgnoreCase("Open Port")) { config.PORTS = txt_ports.getText().toString(); config.SERVER_TIMEOUT = txt_server_time.getText().toString(); } else { config.PORTS = ""; config.SERVER_TIMEOUT = ""; } if (configtype.equalsIgnoreCase("Nat Access")) { config.NAT_IP = txt_nat_ip.getText().toString(); config.NAT_PORT = txt_nat_port.getText().toString(); config.PORTS = txt_ports.getText().toString(); config.SERVER_TIMEOUT = txt_server_time.getText().toString(); } else { config.NAT_IP = ""; config.NAT_PORT = ""; } if (configtype.equalsIgnoreCase("Server Command")) { config.SERVER_CMD = txt_server_cmd.getText().toString(); } else { config.SERVER_CMD = ""; } if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Resolve IP")) { config.ACCESS_IP = spn_allowip.getSelectedItem().toString(); } else if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Source IP")) { config.ACCESS_IP = "0.0.0.0"; } else { config.ACCESS_IP = txt_allowIP.getText().toString(); } config.NICK_NAME = txt_NickName.getText().toString(); config.SERVER_IP = txt_server_ip.getText().toString(); config.SERVER_PORT = txt_server_port.getText().toString(); config.SSH_CMD = ""; if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("SSH Uri")) { config.SSH_CMD = txt_ssh_cmd.getText().toString(); config.juice_uuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); } else if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("Juicessh")) { config.SSH_CMD = "juice:" + juice_adapt.getConnectionName(spn_juice.getSelectedItemPosition()); config.juice_uuid = juice_adapt.getConnectionId(spn_juice.getSelectedItemPosition()); } else { config.juice_uuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); config.SSH_CMD = ""; } config.KEY = txt_KEY.getText().toString(); //key config.KEY_BASE64 = chkb64key.isChecked(); //is key b64 config.HMAC = txt_HMAC.getText().toString(); // hmac key config.HMAC_BASE64 = chkb64hmac.isChecked(); //is hmac base64 mydb.updateConfig(context, config); //this updates the list for one panel mode Activity activity = getActivity(); if (activity instanceof ConfigListActivity) { ConfigListActivity myactivity = (ConfigListActivity) activity; myactivity.onItemSaved(); } else { ConfigDetailActivity myactivity = (ConfigDetailActivity) activity; myactivity.onBackPressed(); } } } else { return false; } return super.onOptionsItemSelected(item); }
From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java
private void loadGame() { GameState gameState = gameStateDao.loadGameState(gameStateSlot); GameStateSummary gameStateSummary = gameStateDao.loadGameStateSummary(gameStateSlot); if (gameState != null) { level9.setGameState(gameState);//from w w w . j a v a 2 s . c o m graphicsHandlerContext.setBitmap(gameStateDao.loadGraphics(gameStateSlot)); imageView.setBitmap(graphicsHandlerContext.getBitmap()); textView.setText(""); processOutputText(gameStateSummary.getLastLocation()); // TODO hacky adding in a sneaky look because VM is not in the correct state for some reason level9.execute("look"); Toast toast = Toast.makeText(getApplicationContext(), "Game loaded", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else { Toast toast = Toast.makeText(getApplicationContext(), "Failed to load game", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } }
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; }/*w w w . j a v a2s . 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; }