Search in sources :

Example 61 with Toast

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();
}
Also used : Toast(android.widget.Toast) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ODKView(org.odk.collect.android.views.ODKView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 62 with Toast

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;
    });
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) MapLoader(com.peterlaurence.trekadvisor.core.map.maploader.MapLoader) Dialog(android.app.Dialog) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) EditTextPreference(android.preference.EditTextPreference) Map(com.peterlaurence.trekadvisor.core.map.Map) ListPreference(android.preference.ListPreference) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) PreferenceFragment(android.preference.PreferenceFragment) R(com.peterlaurence.trekadvisor.R) Toast(android.widget.Toast) View(android.view.View) DialogFragment(android.app.DialogFragment) WeakReference(java.lang.ref.WeakReference) DialogInterface(android.content.DialogInterface) Toast(android.widget.Toast) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 63 with Toast

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;
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) Toast(android.widget.Toast)

Example 64 with Toast

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;
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) Toast(android.widget.Toast)

Example 65 with Toast

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();
        }
    });
}
Also used : Toast(android.widget.Toast) Contribution(fr.free.nrw.commons.contributions.Contribution)

Aggregations

Toast (android.widget.Toast)485 Context (android.content.Context)89 View (android.view.View)86 TextView (android.widget.TextView)74 Intent (android.content.Intent)55 Rect (android.graphics.Rect)34 LayoutInflater (android.view.LayoutInflater)31 SuppressLint (android.annotation.SuppressLint)30 JSONObject (org.json.JSONObject)23 ImageView (android.widget.ImageView)21 RequestQueue (com.android.volley.RequestQueue)20 Response (com.android.volley.Response)20 EditText (android.widget.EditText)19 JSONException (org.json.JSONException)18 VolleyError (com.android.volley.VolleyError)17 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)17 User (model.User)16 PendingIntent (android.app.PendingIntent)15 File (java.io.File)15 HashMap (java.util.HashMap)15