Search in sources :

Example 96 with Toast

use of android.widget.Toast in project app by TourLive.

the class JudgmentDetailFragment method saveJudgmnet.

public void saveJudgmnet() {
    Rider rider = riderBasicAdapter.getSelectedRider();
    if (rank != 0) {
        JudgmentRiderConnection judgmentRiderConnection = new JudgmentRiderConnection();
        judgmentRiderConnection.setRank(rank);
        RealmList<Rider> riderToAdd = new RealmList<>();
        riderToAdd.add(rider);
        judgmentRiderConnection.setRider(riderToAdd);
        RealmList<Judgement> judgementToAdd = new RealmList<>();
        judgementToAdd.add(judgement);
        judgmentRiderConnection.setJudgements(judgementToAdd);
        JudgmentRiderConnectionPresenter.getInstance().addJudgmentRiderConnection(judgmentRiderConnection);
        updateRiderStateConnectionWithPerformance(rider, rank);
        textViews.get(rank - 1).setText(String.valueOf(rider.getStartNr()));
        riderBasicAdapter.setColorOnRider(rider.getStartNr());
    } else {
        Toast toast = Toast.makeText(getContext(), getResources().getString(R.string.judgment_text), Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0);
        toast.show();
        Integer integer = rider.getRiderID();
        riderBasicAdapter.removeRiderFromList(integer);
    }
    riderBasicAdapter.resetSelectedRider();
    rank = 0;
}
Also used : RealmList(io.realm.RealmList) Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Toast(android.widget.Toast) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) JudgmentRiderConnection(ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)

Example 97 with Toast

use of android.widget.Toast in project OpenCamera by ageback.

the class Preview method showToast.

private void showToast(final ToastBoxer clear_toast, final String message, final int offset_y_dp) {
    if (!applicationInterface.getShowToastsPref()) {
        return;
    }
    class RotatedTextView extends View {

        private String[] lines;

        private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

        private final Rect bounds = new Rect();

        private final Rect sub_bounds = new Rect();

        private final RectF rect = new RectF();

        public RotatedTextView(String text, Context context) {
            super(context);
            this.lines = text.split("\n");
        }

        void setText(String text) {
            this.lines = text.split("\n");
        }

        @Override
        protected void onDraw(Canvas canvas) {
            final float scale = Preview.this.getResources().getDisplayMetrics().density;
            // convert dps to pixels
            paint.setTextSize(14 * scale + 0.5f);
            paint.setShadowLayer(1, 0, 1, Color.BLACK);
            // paint.getTextBounds(text, 0, text.length(), bounds);
            boolean first_line = true;
            for (String line : lines) {
                paint.getTextBounds(line, 0, line.length(), sub_bounds);
                /*if( MyDebug.LOG ) {
						Log.d(TAG, "line: " + line + " sub_bounds: " + sub_bounds);
					}*/
                if (first_line) {
                    bounds.set(sub_bounds);
                    first_line = false;
                } else {
                    bounds.top = Math.min(sub_bounds.top, bounds.top);
                    bounds.bottom = Math.max(sub_bounds.bottom, bounds.bottom);
                    bounds.left = Math.min(sub_bounds.left, bounds.left);
                    bounds.right = Math.max(sub_bounds.right, bounds.right);
                }
            }
            // above we've worked out the maximum bounds of each line - this is useful for left/right, but for the top/bottom
            // we would rather use a consistent height no matter what the text is (otherwise we have the problem of varying
            // gap between lines, depending on what the characters are).
            final String reference_text = "Ap";
            paint.getTextBounds(reference_text, 0, reference_text.length(), sub_bounds);
            bounds.top = sub_bounds.top;
            bounds.bottom = sub_bounds.bottom;
            /*if( MyDebug.LOG ) {
					Log.d(TAG, "bounds: " + bounds);
				}*/
            // height of each line
            int height = bounds.bottom - bounds.top;
            bounds.bottom += ((lines.length - 1) * height) / 2;
            bounds.top -= ((lines.length - 1) * height) / 2;
            // padding for the shaded rectangle; convert dps to pixels
            final int padding = (int) (14 * scale + 0.5f);
            // convert dps to pixels
            final int offset_y = (int) (offset_y_dp * scale + 0.5f);
            canvas.save();
            canvas.rotate(ui_rotation, canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f);
            rect.left = canvas.getWidth() / 2 - bounds.width() / 2 + bounds.left - padding;
            rect.top = canvas.getHeight() / 2 + bounds.top - padding + offset_y;
            rect.right = canvas.getWidth() / 2 - bounds.width() / 2 + bounds.right + padding;
            rect.bottom = canvas.getHeight() / 2 + bounds.bottom + padding + offset_y;
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(Color.rgb(50, 50, 50));
            // canvas.drawRect(rect, paint);
            // convert dps to pixels
            final float radius = (24 * scale + 0.5f);
            canvas.drawRoundRect(rect, radius, radius, paint);
            paint.setColor(Color.WHITE);
            int ypos = canvas.getHeight() / 2 + offset_y - ((lines.length - 1) * height) / 2;
            for (String line : lines) {
                canvas.drawText(line, canvas.getWidth() / 2 - bounds.width() / 2, ypos, paint);
                ypos += height;
            }
            canvas.restore();
        }
    }
    if (MyDebug.LOG)
        Log.d(TAG, "showToast: " + message);
    final Activity activity = (Activity) this.getContext();
    // We get a crash on emulator at least if Toast constructor isn't run on main thread (e.g., the toast for taking a photo when on timer).
    // Also see http://stackoverflow.com/questions/13267239/toast-from-a-non-ui-thread
    activity.runOnUiThread(new Runnable() {

        public void run() {
            /*if( clear_toast != null && clear_toast.toast != null )
					clear_toast.toast.cancel();

				Toast toast = new Toast(activity);
				if( clear_toast != null )
					clear_toast.toast = toast;*/
            // This method is better, as otherwise a previous toast (with different or no clear_toast) never seems to clear if we repeatedly issue new toasts - this doesn't happen if we reuse existing toasts if possible
            // However should only do this if the previous toast was the most recent toast (to avoid messing up ordering)
            Toast toast;
            if (clear_toast != null && clear_toast.toast != null && clear_toast.toast == last_toast) {
                if (MyDebug.LOG)
                    Log.d(TAG, "reuse last toast: " + last_toast);
                toast = clear_toast.toast;
                // for performance, important to reuse the same view, instead of creating a new one (otherwise we get jerky preview update e.g. for changing manual focus slider)
                RotatedTextView view = (RotatedTextView) toast.getView();
                view.setText(message);
                // make sure the toast is redrawn
                view.invalidate();
                toast.setView(view);
            } else {
                if (clear_toast != null && clear_toast.toast != null) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "cancel last toast: " + clear_toast.toast);
                    clear_toast.toast.cancel();
                }
                toast = new Toast(activity);
                if (MyDebug.LOG)
                    Log.d(TAG, "created new toast: " + toast);
                if (clear_toast != null)
                    clear_toast.toast = toast;
                View text = new RotatedTextView(message, activity);
                toast.setView(text);
            }
            toast.setDuration(Toast.LENGTH_SHORT);
            if (!((Activity) getContext()).isFinishing()) {
                // Workaround for crash due to bug in Android 7.1 when activity is closing whilst toast shows.
                // This was fixed in Android 8, but still good to fix the crash on Android 7.1! See
                // https://stackoverflow.com/questions/47548317/what-belong-is-badtokenexception-at-classes-of-project and
                // https://github.com/drakeet/ToastCompat#why .
                toast.show();
            }
            last_toast = toast;
        }
    });
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Activity(android.app.Activity) Paint(android.graphics.Paint) View(android.view.View) MyTextureView(net.sourceforge.opencamera.Preview.CameraSurface.MyTextureView) TextureView(android.view.TextureView) MySurfaceView(net.sourceforge.opencamera.Preview.CameraSurface.MySurfaceView) Paint(android.graphics.Paint) Point(android.graphics.Point) RectF(android.graphics.RectF) Toast(android.widget.Toast)

Example 98 with Toast

use of android.widget.Toast in project CryptoBuddy by Patchett.

the class FavoriteCurrencyListFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.sort_favs_button:
            int sortType = sharedPreferences.getInt(SORT_SETTING, 1);
            new MaterialDialog.Builder(getActivity()).title(R.string.sort_by).items(R.array.sort_options).buttonRippleColor(getContext().getResources().getColor(R.color.colorPrimary)).itemsCallbackSingleChoice(sortType, new MaterialDialog.ListCallbackSingleChoice() {

                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sortList(adapter.getCurrencyList(), which);
                    adapter.notifyDataSetChanged();
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putInt(SORT_SETTING, which);
                    editor.apply();
                    favsUpdateCallback.performAllCoinsSort();
                    Toast toast = Toast.makeText(getContext(), "Sorting by: " + text, Toast.LENGTH_SHORT);
                    toast.show();
                    return true;
                }
            }).show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Toast(android.widget.Toast) SharedPreferences(android.content.SharedPreferences) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 99 with Toast

use of android.widget.Toast in project NewPipe by TeamNewPipe.

the class PermissionHelper method showPopupEnablementToast.

public static void showPopupEnablementToast(Context context) {
    Toast toast = Toast.makeText(context, R.string.msg_popup_permission, Toast.LENGTH_LONG);
    TextView messageView = toast.getView().findViewById(android.R.id.message);
    if (messageView != null)
        messageView.setGravity(Gravity.CENTER);
    toast.show();
}
Also used : Toast(android.widget.Toast) TextView(android.widget.TextView)

Example 100 with Toast

use of android.widget.Toast in project SpaghettiCodeHQ by CMPUT301W18T16.

the class AddTaskActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_task);
    // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    // setSupportActionBar(toolbar);
    done = (Button) findViewById(R.id.done1);
    done.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            title = (EditText) findViewById(R.id.title);
            description = (EditText) findViewById(R.id.desc);
            status = (EditText) findViewById(R.id.status);
            error1 = (TextView) findViewById(R.id.error1);
            newTask = new Task(title.getText().toString(), description.getText().toString(), status.getText().toString());
            // Toast toast = Toast.makeText(getApplicationContext(), newTask.getTitle() + newTask.getDescription() + newTask.getStatus(),
            // Toast.LENGTH_LONG);
            Toast toast = Toast.makeText(getApplicationContext(), "New Task Added", Toast.LENGTH_SHORT);
            toast.show();
            ElasticFactory.AddingTasks addTask = new ElasticFactory.AddingTasks();
            addTask.execute(newTask);
            finish();
        }
    });
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });
}
Also used : EditText(android.widget.EditText) Toast(android.widget.Toast) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

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