use of android.widget.Toast in project collect by opendatakit.
the class FormEntryActivity method showCustomToast.
/**
* Creates a toast with the specified message.
*/
private void showCustomToast(String message, int duration) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.toast_view, null);
// set the text in the view
TextView tv = view.findViewById(R.id.message);
tv.setText(message);
Toast t = new Toast(this);
t.setView(view);
t.setDuration(duration);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
}
use of android.widget.Toast in project TrekAdvisor by peterLaurence.
the class MapSettingsFragment method initComponents.
private void initComponents() {
ListPreference mCalibrationListPreference = (ListPreference) getPreferenceManager().findPreference(getString(R.string.preference_projection_key));
ListPreference mCalibrationPointsNumberPreference = (ListPreference) getPreferenceManager().findPreference(getString(R.string.preference_numpoints_key));
EditTextPreference mapNamePreference = (EditTextPreference) getPreferenceManager().findPreference(getString(R.string.preference_map_title_key));
Preference calibrationButton = getPreferenceManager().findPreference(getString(R.string.preference_calibration_button_key));
Preference deleteButton = getPreferenceManager().findPreference(getString(R.string.preference_delete_button_key));
/* Set the summaries and the values of preferences according to the Map object */
final Map map = mMapWeakReference.get();
if (map != null) {
String projectionName;
if ((projectionName = map.getProjectionName()) == null) {
projectionName = getString(R.string.projection_none);
}
setListPreferenceSummaryAndValue(mCalibrationListPreference, projectionName);
setListPreferenceSummaryAndValue(mCalibrationPointsNumberPreference, String.valueOf(map.getCalibrationPointsNumber()));
setEditTextPreferenceSummaryAndValue(mapNamePreference, map.getName());
}
calibrationButton.setOnPreferenceClickListener(preference -> {
mMapCalibrationRequestListener.onMapCalibrationRequest();
return true;
});
mCalibrationPointsNumberPreference.setOnPreferenceChangeListener(((preference, newValue) -> {
Map map_ = mMapWeakReference.get();
if (map_ != null) {
switch((String) newValue) {
case "2":
map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.SIMPLE_2_POINTS);
break;
case "3":
map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.CALIBRATION_3_POINTS);
break;
case "4":
map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.CALIBRATION_4_POINTS);
break;
default:
map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.SIMPLE_2_POINTS);
}
return true;
}
return false;
}));
mapNamePreference.setOnPreferenceChangeListener((preference, newValue) -> {
try {
mMapWeakReference.get().setName((String) newValue);
return true;
} catch (Exception e) {
return false;
}
});
mCalibrationListPreference.setOnPreferenceChangeListener((preference, projectionName) -> {
try {
/* If the projection is set to none */
if (getString(R.string.projection_none).equals(projectionName)) {
mMapWeakReference.get().setProjection(null);
return true;
}
if (MapLoader.getInstance().mutateMapProjection(mMapWeakReference.get(), (String) projectionName)) {
String saveOkMsg = getString(R.string.calibration_projection_saved_ok);
Toast toast = Toast.makeText(getContext(), saveOkMsg, Toast.LENGTH_SHORT);
toast.show();
} else {
// TODO : show some warning ("Wrong Projection name").
}
return true;
} catch (Exception e) {
return false;
}
});
deleteButton.setOnPreferenceClickListener(preference -> {
ConfirmDeleteFragment f = new ConfirmDeleteFragment();
f.setMapWeakRef(mMapWeakReference);
f.setDeleteMapListener(mDeleteMapListener);
f.show(getFragmentManager(), "delete");
return true;
});
}
use of android.widget.Toast in project android_frameworks_base by crdroidandroid.
the class ActionMenuItemView method onLongClick.
@Override
public boolean onLongClick(View v) {
if (hasText()) {
// Don't show the cheat sheet for items that already show text.
return false;
}
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 (v.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR) {
final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
// mirror
referenceX = screenWidth - referenceX;
}
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 | Gravity.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;
}
use of android.widget.Toast in project android_frameworks_base by crdroidandroid.
the class MediaRouteButton method performLongClick.
@Override
public boolean performLongClick() {
if (super.performLongClick()) {
return true;
}
if (!mCheatSheetEnabled) {
return false;
}
final CharSequence contentDesc = getContentDescription();
if (TextUtils.isEmpty(contentDesc)) {
// Don't show the cheat sheet if we have no description
return false;
}
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;
final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
Toast cheatSheet = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT);
if (midy < displayFrame.height()) {
// Show along the top; follow action buttons
cheatSheet.setGravity(Gravity.TOP | Gravity.END, screenWidth - screenPos[0] - width / 2, height);
} else {
// Show along the bottom center
cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
}
cheatSheet.show();
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return true;
}
use of android.widget.Toast in project apps-android-commons by commons-app.
the class ShareActivity method uploadBegins.
private void uploadBegins() {
if (locationPermission) {
getFileMetadata(true);
} else {
getFileMetadata(false);
}
Toast startingToast = Toast.makeText(CommonsApplication.getInstance(), R.string.uploading_started, Toast.LENGTH_LONG);
startingToast.show();
if (!cacheFound) {
//Has to be called after apiCall.request()
app.getCacheData().cacheCategory();
Timber.d("Cache the categories found");
}
uploadController.startUpload(title, mediaUri, description, mimeType, source, decimalCoords, new UploadController.ContributionUploadProgress() {
@Override
public void onUploadStarted(Contribution contribution) {
ShareActivity.this.contribution = contribution;
showPostUpload();
}
});
}
Aggregations