List of usage examples for android.widget Toast show
public void show()
From source file:com.moonpi.swiftnotes.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Bundle mBundle = data.getExtras(); if (mBundle != null) { // If new note was saved if (requestCode == NEW_NOTE_REQUEST) { try { // Add new note to array JSONObject newNote = new JSONObject(); newNote.put("title", mBundle.getString("title")); newNote.put("body", mBundle.getString("body")); newNote.put("colour", mBundle.getString("colour")); newNote.put("favoured", false); newNote.put("fontSize", mBundle.getInt("fontSize")); notes.put(newNote);/*from w ww . j a v a2s . c o m*/ adapter.notifyDataSetChanged(); writeToJSON(); // If no notes, show 'Press + to add new note' text, invisible otherwise if (notes.length() == 0) noNotes.setVisibility(View.VISIBLE); else noNotes.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_new_note), Toast.LENGTH_SHORT); toast.show(); } catch (JSONException e) { e.printStackTrace(); } } // If existing note was saved else { try { // Update array with new data JSONObject newNote = notes.getJSONObject(requestCode); newNote.put("title", mBundle.getString("title")); newNote.put("body", mBundle.getString("body")); newNote.put("colour", mBundle.getString("colour")); newNote.put("fontSize", mBundle.getInt("fontSize")); // Update note at position notes.put(requestCode, newNote); adapter.notifyDataSetChanged(); writeToJSON(); Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_note_saved), Toast.LENGTH_SHORT); toast.show(); } catch (JSONException e) { e.printStackTrace(); } } } } else if (resultCode == RESULT_CANCELED) { Bundle mBundle = null; if (data != null && data.hasExtra("request")) mBundle = data.getExtras(); if (requestCode == NEW_NOTE_REQUEST) { if (mBundle != null) { // If new note discarded, show toast if (mBundle.getString("request").equals("discard")) { Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_empty_note_discarded), Toast.LENGTH_SHORT); toast.show(); } } } else { if (mBundle != null) { // If delete pressed in EditActivity, call deleteNote method with // requestCode as position if (mBundle.getString("request").equals("delete")) deleteNote(this, requestCode); } } } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.ccxt.whl.activity.SettingsFragmentC_0815.java
/** * ?uri?//from w w w . java 2 s . c o m * * @param selectedImage */ private void sendPicByUri(Uri selectedImage) { // String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().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(getActivity(), "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } //copyFile(picturePath,imageUri.getPath()); cropImageUri(selectedImage, 200, 200, USERPIC_REQUEST_CODE_CUT); //sendPicture(picturePath); } else { File file = new File(selectedImage.getPath()); if (!file.exists()) { Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } //copyFile(selectedImage.getPath(),imageUri.getPath()); cropImageUri(selectedImage, 200, 200, USERPIC_REQUEST_CODE_CUT); //sendPicture(file.getAbsolutePath()); } /*if(getpathfromUri(uri)!=null&&getpathfromUri(imageUri)!=null){ copyFile(getpathfromUri(uri),getpathfromUri(imageUri)); }else{ return; }*/ //cropImageUri(selectedImage, 150, 150, USERPIC_REQUEST_CODE_CUT); }
From source file:com.owncloud.android.ui.fragment.FileDetailFragment.java
private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().dismissDialog(/*ww w. j a v a 2 s . c om*/ (inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); if (result.isSuccess()) { Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG); msg.show(); if (inDisplayActivity) { // double pane FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment transaction.commit(); mContainerActivity.onFileStateChanged(); } else { getActivity().finish(); } } else { Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); msg.show(); if (result.isSslRecoverableException()) { // TODO show the SSL warning dialog } } }
From source file:com.undatech.opaque.RemoteCanvasActivity.java
public void displayInputModeInfo(boolean showLonger) { if (showLonger) { final Toast t = Toast.makeText(this, inputHandler.getDescription(), Toast.LENGTH_LONG); TimerTask tt = new TimerTask() { @Override// ww w . j av a 2 s. c o m public void run() { t.show(); try { Thread.sleep(2000); } catch (InterruptedException e) { } t.show(); } }; new Timer().schedule(tt, 2000); t.show(); } else { Toast t = Toast.makeText(this, inputHandler.getDescription(), Toast.LENGTH_SHORT); t.show(); } }
From source file:at.alladin.rmbt.android.test.RMBTTestFragment.java
private void switchToResult() { if (!isVisible()) { return;//from www. j a v a 2 s .c om } if (showQoSErrorToast) { final Toast toast = Toast.makeText(getActivity(), R.string.test_toast_error_text_qos, Toast.LENGTH_LONG); toast.show(); } dismissDialogs(); final String testUuid = rmbtService == null ? null : rmbtService.getTestUuid(true); if (testUuid == null) { showErrorDialog(R.string.test_dialog_error_text); return; } ((RMBTMainActivity) getActivity()).showResultsAfterTest(testUuid); }
From source file:com.RSMSA.policeApp.OffenceReportForm.java
@Override public void onResume() { super.onResume(); startRecording();/*from w ww.j ava2s. c om*/ if (backFromChild) { backFromChild = false; offense_type_text.setText(count + " offenses selected"); if (count == 0) { submit_layout1.setVisibility(View.GONE); offencesSelectedTextView.setVisibility(View.GONE); } else { submit_layout1.setVisibility(View.VISIBLE); offencesSelectedTextView.setText(offencesSelected); } submit_layout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if ((!license.getText().toString().equals("")) && (!plateNo.getText().toString().equals(""))) { NetAsync(view); } else { Toast.makeText(getApplicationContext(), "One or more fields are empty", Toast.LENGTH_SHORT) .show(); } } }); submit_layout1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!plateNumberObtained.equals("") && !dLicense.equals("")) { plateNo.setText(plateNumberObtained); license.setText(dLicense); } else if (plateNumberObtained.equals("") && !plateNumberEdit.getText().toString().equals("")) { plateNumberObtained = plateNumberEdit.getText().toString(); plateNo.setText(plateNumberObtained); } else if (dLicense.equals("") && !licenceNumberEdit.getText().toString().equals("")) { dLicense = licenceNumberEdit.getText().toString(); license.setText(dLicense); } else { Toast toast = Toast.makeText(OffenceReportForm.this, "Please fill the required field", Toast.LENGTH_SHORT); toast.show(); return; } if (commit) chargesAcceptance.setText("Charges Accepted"); else { chargesAcceptance.setText("Going to Court"); } report.setVisibility(View.GONE); summary.setVisibility(View.VISIBLE); } }); } }
From source file:ch.uzh.supersede.feedbacklibrary.FeedbackActivity.java
public void sendButtonClicked(View view) { if (baseURL != null && language != null) { // The mechanism models are updated with the view values for (MechanismView mechanismView : allMechanismViews) { mechanismView.updateModel(); }//from w ww .jav a 2 s . co m final ArrayList<String> messages = new ArrayList<>(); if (validateInput(allMechanisms, messages)) { if (fbAPI == null) { Retrofit rtf = new Retrofit.Builder().baseUrl(baseURL) .addConverterFactory(GsonConverterFactory.create()).build(); fbAPI = rtf.create(feedbackAPI.class); } Call<ResponseBody> checkUpAndRunning = fbAPI.pingRepository(); if (checkUpAndRunning != null) { checkUpAndRunning.enqueue(new Callback<ResponseBody>() { @Override public void onFailure(Call<ResponseBody> call, Throwable t) { Log.e(TAG, "Failed to ping the server. onFailure method called", t); DialogUtils .showInformationDialog(FeedbackActivity.this, new String[] { getResources() .getString(R.string.supersede_feedbacklibrary_error_text) }, true); } @Override public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { if (response.code() == 200) { Feedback feedback = new Feedback(allMechanisms); feedback.setTitle(getResources().getString( R.string.supersede_feedbacklibrary_feedback_title_text, System.currentTimeMillis())); feedback.setApplicationId(orchestratorConfiguration.getId()); feedback.setConfigurationId(activeConfiguration.getId()); feedback.setLanguage(language); feedback.setUserIdentification(Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)); // The JSON string of the feedback GsonBuilder builder = new GsonBuilder(); builder.excludeFieldsWithoutExposeAnnotation(); builder.serializeNulls(); Gson gson = builder.create(); Type feedbackType = new TypeToken<Feedback>() { }.getType(); String feedbackJsonString = gson.toJson(feedback, feedbackType); RequestBody feedbackJSONPart = RequestBody .create(MediaType.parse("multipart/form-data"), feedbackJsonString); Map<String, RequestBody> files = new HashMap<>(); // Audio multipart List<AudioFeedback> audioFeedbackList = feedback.getAudioFeedbacks(); if (audioFeedbackList != null) { for (int pos = 0; pos < audioFeedbackList.size(); ++pos) { RequestBody requestBody = createRequestBody( new File(audioFeedbackList.get(pos).getAudioPath())); String fileName = audioFeedbackList.get(pos).getFileName(); String key = String.format("%1$s\"; filename=\"%2$s", audioFeedbackList.get(pos).getPartString() + String.valueOf(pos), fileName); files.put(key, requestBody); } } // Screenshots multipart List<ScreenshotFeedback> screenshotFeedbackList = feedback.getScreenshotFeedbacks(); if (screenshotFeedbackList != null) { for (int pos = 0; pos < screenshotFeedbackList.size(); ++pos) { RequestBody requestBody = createRequestBody( new File(screenshotFeedbackList.get(pos).getImagePath())); String fileName = screenshotFeedbackList.get(pos).getFileName(); String key = String.format("%1$s\"; filename=\"%2$s", screenshotFeedbackList.get(pos).getPartString() + String.valueOf(pos), fileName); files.put(key, requestBody); } } // Send the feedback Call<JsonObject> result = fbAPI.createFeedbackVariant(language, feedback.getApplicationId(), feedbackJSONPart, files); if (result != null) { result.enqueue(new Callback<JsonObject>() { @Override public void onFailure(Call<JsonObject> call, Throwable t) { Log.e(TAG, "Failed to send the feedback. onFailure method called", t); DialogUtils.showInformationDialog(FeedbackActivity.this, new String[] { getResources().getString( R.string.supersede_feedbacklibrary_error_text) }, true); } @Override public void onResponse(Call<JsonObject> call, Response<JsonObject> response) { if (response.code() == 201) { Log.i(TAG, "Feedback successfully sent"); Toast toast = Toast.makeText(getApplicationContext(), getResources().getString( R.string.supersede_feedbacklibrary_success_text), Toast.LENGTH_SHORT); toast.show(); } else { Log.e(TAG, "Failed to send the feedback. Response code == " + response.code()); DialogUtils.showInformationDialog(FeedbackActivity.this, new String[] { getResources().getString( R.string.supersede_feedbacklibrary_error_text) }, true); } } }); } else { Log.e(TAG, "Failed to send the feebdkack. Call<JsonObject> result is null"); DialogUtils.showInformationDialog(FeedbackActivity.this, new String[] { getResources() .getString(R.string.supersede_feedbacklibrary_error_text) }, true); } } else { Log.e(TAG, "The server is not up and running. Response code == " + response.code()); DialogUtils .showInformationDialog(FeedbackActivity.this, new String[] { getResources() .getString(R.string.supersede_feedbacklibrary_error_text) }, true); } } }); } else { Log.e(TAG, "Failed to ping the server. Call<ResponseBody> checkUpAndRunning result is null"); DialogUtils.showInformationDialog(FeedbackActivity.this, new String[] { getResources().getString(R.string.supersede_feedbacklibrary_error_text) }, true); } } else { Log.v(TAG, "Validation of the mechanism failed"); DialogUtils.showInformationDialog(this, messages.toArray(new String[messages.size()]), false); } } else { if (baseURL == null) { Log.e(TAG, "Failed to send the feedback. baseURL is null"); } else { Log.e(TAG, "Failed to send the feedback. language is null"); } DialogUtils.showInformationDialog(this, new String[] { getResources().getString(R.string.supersede_feedbacklibrary_error_text) }, true); } }
From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java
public void startSpeechRecognition(SpeechRecognitionListener listener) { speechRecognitionListeners.add(listener); Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault().getDisplayName()); try {//from w w w . j a va 2s.c om startActivityForResult(intent, RESULT_SPEECH); } catch (ActivityNotFoundException a) { Toast t = Toast.makeText(getApplicationContext(), R.string.oops_your_device_doesn_t_support_speech_to_text, Toast.LENGTH_SHORT); t.show(); } }
From source file:edu.cmu.mpcs.dashboard.TagViewer.java
void buildTagViews(NdefMessage[] msgs) { if (msgs == null || msgs.length == 0) { return;//from w w w. j av a 2s.c o m } LayoutInflater inflater = LayoutInflater.from(this); // LinearLayout content = mTagContent; // Clear out any old views in the content area, for example if // you scan // two tags in a row. // content.removeAllViews(); // Parse the first message in the list // Build views for all of the sub records Log.i("TEST", "test"); List<ParsedNdefRecord> records = NdefMessageParser.parse(msgs[0]); NdefRecord[] ndefRecords = msgs[0].getRecords(); short tnf = ndefRecords[0].getTnf(); Log.d("RECORD", "tnf is : " + Short.toString(tnf)); byte[] type = ndefRecords[0].getType(); byte[] standard = NdefRecord.RTD_TEXT; System.out.println("printing what we got in the message"); for (byte theByte : type) { System.out.println(Integer.toHexString(theByte)); Log.d("RECORD", Integer.toHexString(theByte)); } System.out.println("printing what the actual val is "); for (byte theByte : standard) { System.out.println(Integer.toHexString(theByte)); Log.d("RECORD", Integer.toHexString(theByte)); } if (ndefRecords[0].getType().equals(standard)) Log.d("RECORD", " type is : RTD_TXT"); else if (ndefRecords[0].getType().equals(NdefRecord.RTD_URI)) Log.d("RECORD", " type is : RTD_URI"); else Log.d("RECORD", " type is : none of the 2"); final int size = records.size(); for (int i = 0; i < size; i++) { ParsedNdefRecord record = records.get(i); Log.i("RECORD", record.toString()); String text; if (record instanceof TextRecord) { TextRecord t = (TextRecord) record; text = t.getText(); } else { UriRecord t = (UriRecord) record; text = t.getUri().toString(); } Log.d("WIFI", text); /* * At this point we have obtained the name of the profile . We * should not append .txt and see if the file exists in the * /mnt/Profile folder. * * If it does exist, then we read the file, and apply various * settings * * If it does note exists, then we show an error message indicating * that the user does not have a profile corresponding to this TAG. * Alternatively: We can take him to the create TAG activity where * he can create a new TAG with this name. */ String contents[] = text.split("#"); String filename = null; if (contents.length > 1) { String readHash = contents[0]; filename = contents[1]; Log.d("TAG_VIEWER", "readHash: " + readHash); Log.d("TAG_VIEWER", "filename: " + filename); if (readHash.equals(Utility.hashOfId)) { Log.d("TAG_VIEWER", "Hash Valid"); File root = Environment.getExternalStorageDirectory(); String path = root + "/Profiles/" + Utility.userUID + "/"; String filePath = path + filename + ".txt"; String settingString = ""; boolean exists = (new File(path).exists()); if (exists) { Log.d("TAG_VIEWER", "Found file:" + filePath); /* * Parse the contents of the file, and apply settings */ try { FileReader logReader = new FileReader(filePath); BufferedReader in = new BufferedReader(logReader); try { settingString = in.readLine(); Log.d("TAG_VIEWER", "In " + filePath + " settingString: " + settingString); } catch (IOException e) { // TODO Auto-generated catch block Log.d("TAG_VIEWER", " read(buf) exception"); e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block Log.d("TAG_VIEWER", "FileReader exception"); e.printStackTrace(); } /* * One call for each setting that we support */ StringBuilder returnVal = new StringBuilder(); returnVal.append(wifiSetting(settingString)); returnVal.append(bluetoothSetting(settingString)); returnVal.append(ringerSetting(settingString)); launchmusicSetting(settingString); returnVal.append(alarmSetting(settingString)); fbSetting(settingString); Log.d("TAG_VIEWER", "the toast should be : " + returnVal.toString()); Context context = getApplicationContext(); CharSequence toastMessage = returnVal; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, toastMessage, duration); toast.show(); } else { /* * Give the user the option of creating a new tag or * ignoring this tag */ } } else { Log.d("TAG_VIEWER", "Hash InValid"); int duration = Toast.LENGTH_LONG; CharSequence msg = "Authentication failure.This tag does not belong to you"; Toast toast = Toast.makeText(TagViewer.this, msg, duration); toast.show(); finish(); // return; } } else { // public tag Log.d("PUBLIC_TAG", "PUBLIC_TAG"); } // For Vibrate mode // /** Sending an SMS to a particular number **/ // Intent intent = new // Intent(Intent.ACTION_VIEW, // Uri.parse("sms:" + "5189515772")); // intent.putExtra("sms_body", // "Hi This is a test message"); // startActivity(intent); /** Toggle Airplane mode **/ // Context context = getApplicationContext(); // boolean isEnabled = // Settings.System.getInt(this.getApplicationContext().getContentResolver(), // Settings.System.AIRPLANE_MODE_ON, 0) == 1; // Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnabled // ? 0 : 1); // Intent intent = new // Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); // intent.putExtra("state", !isEnabled); // sendBroadcast(intent); /** Launching the browser **/ // String url = "http://www.google.com"; // Intent intent = new // Intent(Intent.ACTION_VIEW); // intent.setData(Uri.parse(url)); // startActivity(intent); /** Check into Facebook **/ // Bundle params = new Bundle(); // // //String access_token = // AndroidDashboardActivity.mPrefs.getString("access_token", // null); // //params.putString("access_token", access_token); // params.putString("place", "203682879660695"); // YOUR PLACE // ID // params.putString("Message","I m here in this place"); // JSONObject coordinates = new JSONObject(); // try // { // coordinates.put("latitude", 40.756); // coordinates.put("longitude", -73.987); // } // catch (JSONException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // params.putString("coordinates",coordinates.toString()); // JSONArray frnd_data=new JSONArray(); // params.putString("tags", "waves.mpcs@gmail.com");//where xx // indicates the User Id // String response; // try // { // response = facebook.request("me/checkins", params, "POST"); // Log.d("Response",response); // } // catch (FileNotFoundException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // catch (MalformedURLException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // catch (IOException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // //Log.d("Response",response); /* * TODO: Hashing TODO: Facebook Auth TODO: File Storage (Profile * Storage) TODO: Sample Profiles TODO: Social Network Check in * TODO: Alarms TODO: Airplane Mode (Enabling NFC while switching to * Airplane mode) TODO: NFC Launcher List (Market App) TODO: UI */ // content.addView(record.getView(this, inflater, content, i)); // inflater.inflate(R.layout.tag_divider, content, true); } }
From source file:com.synox.android.ui.activity.FileActivity.java
private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {// ww w.j a v a2 s . c o m OCFile syncedFile = operation.getLocalFile(); if (!result.isSuccess()) { if (result.getCode() == ResultCode.SYNC_CONFLICT) { Intent i = new Intent(this, ConflictsResolveActivity.class); i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile); i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, getAccount()); startActivity(i); } } else { if (!operation.transferWasRequested()) { Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); msg.show(); } invalidateOptionsMenu(); } }