Example usage for android.widget Toast Toast

List of usage examples for android.widget Toast Toast

Introduction

In this page you can find the example usage for android.widget Toast Toast.

Prototype

public Toast(Context context) 

Source Link

Document

Construct an empty Toast object.

Usage

From source file:io.plaidapp.ui.DesignerNewsLogin.java

private void showLoggedInUser() {
    DesignerNewsService designerNewsService = new RestAdapter.Builder()
            .setEndpoint(DesignerNewsService.ENDPOINT)
            .setRequestInterceptor(new ClientAuthInterceptor(designerNewsPrefs.getAccessToken(),
                    BuildConfig.DESIGNER_NEWS_CLIENT_ID))
            .build().create(DesignerNewsService.class);
    designerNewsService.getAuthedUser(new Callback<UserResponse>() {
        @Override/* w w w.j  a v  a2 s .c o  m*/
        public void success(UserResponse userResponse, Response response) {
            final User user = userResponse.user;
            designerNewsPrefs.setLoggedInUser(user);
            Toast confirmLogin = new Toast(getApplicationContext());
            View v = LayoutInflater.from(DesignerNewsLogin.this).inflate(R.layout.toast_logged_in_confirmation,
                    null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.display_name);
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.portrait_url)
                    .placeholder(R.drawable.avatar_placeholder)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DesignerNewsLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void failure(RetrofitError error) {
            Log.e(getClass().getCanonicalName(), error.getMessage(), error);
        }
    });
}

From source file:piuk.blockchain.android.ui.AbstractWalletActivity.java

public final void toast(final String text, final int imageResId, final int duration,
        final Object... formatArgs) {

    if (text == null)
        return;//from  w  w  w .java  2  s  . c  o  m

    final View view = getLayoutInflater().inflate(R.layout.transient_notification, null);
    TextView tv = (TextView) view.findViewById(R.id.transient_notification_text);
    tv.setText(String.format(text, formatArgs));
    tv.setCompoundDrawablesWithIntrinsicBounds(imageResId, 0, 0, 0);

    final Toast toast = new Toast(this);
    toast.setView(view);
    toast.setDuration(duration);
    toast.show();
}

From source file:piuk.blockchain.android.ui.AbstractWalletActivity.java

public final void toast(final int textResId, final int imageResId, final int duration,
        final Object... formatArgs) {
    final View view = getLayoutInflater().inflate(R.layout.transient_notification, null);
    TextView tv = (TextView) view.findViewById(R.id.transient_notification_text);
    tv.setText(getString(textResId, formatArgs));
    tv.setCompoundDrawablesWithIntrinsicBounds(imageResId, 0, 0, 0);

    final Toast toast = new Toast(this);
    toast.setView(view);/*from w w  w.ja v a2  s. com*/
    toast.setDuration(duration);
    toast.show();
}

From source file:csic.ceab.movelab.beepath.Util.java

/**
 * Displays a brief message on the phone screen. Taken from Human Mobility
 * Project code written by Chang Y. Chung and Necati E. Ozgencil.
 * /*ww w  . jav  a2 s.c  o m*/
 * @param context
 *            Interface to application environment
 * @param msg
 *            The message to be displayed to the user
 */
public static void toast(Context context, String msg) {

    TextView tv = new TextView(context);
    tv.setText(msg);
    Drawable bknd = context.getResources().getDrawable(R.drawable.white_border);
    tv.setBackgroundDrawable(bknd);
    tv.setPadding(20, 20, 20, 20);
    tv.setTextSize(20);

    Toast t = new Toast(context);
    t.setDuration(Toast.LENGTH_LONG);
    t.setView(tv);
    t.show();
}

From source file:org.apps8os.motivator.ui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;/*w w  w.j  a  v a  2s  .co m*/
    AlertDialog.Builder builder;
    final Context context = this;
    switch (item.getItemId()) {
    case R.id.action_settings:
        intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
        return true;
    case R.id.action_start_sprint:
        builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.start_a_new_sprint))
                .setMessage(getString(R.string.current_sprint_will_end))
                .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(context, StartingSprintActivity.class);
                        startActivity(intent);
                    }
                }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        Dialog dialog = builder.create();
        dialog.show();
        return true;
    case R.id.action_show_help:
        showHelp();
        return true;
    case R.id.action_info:
        intent = new Intent(this, InfoActivity.class);
        startActivity(intent);
        return true;
    case R.id.action_show_substance_help:
        // Set up a dialog with info on where to get help if user answers everything is not ok
        builder = new AlertDialog.Builder(this);
        LinearLayout helpDialogLayout = (LinearLayout) getLayoutInflater()
                .inflate(R.layout.element_alcohol_help_dialog, null);
        builder.setView(helpDialogLayout);
        builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                View toastLayout = (View) getLayoutInflater().inflate(R.layout.element_mood_toast, null);
                TextView toastText = (TextView) toastLayout.findViewById(R.id.mood_toast_text);
                toastText.setText(getString(R.string.questionnaire_done_toast_bad_mood));
                toastText.setTextColor(Color.WHITE);

                Toast moodToast = new Toast(context);
                moodToast.setDuration(Toast.LENGTH_SHORT);
                moodToast.setView(toastLayout);
                moodToast.show();
            }
        });
        Dialog helpDialog = builder.create();
        helpDialog.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.jesse.barscan.BarcodeCaptureActivity.java

/**
 * onTap returns the tapped barcode result to the calling Activity.
 *///from ww w  .  j  a  v a2 s.  co m
public boolean onTap(float rawX, float rawY) {
    // Find tap point in preview frame coordinates.
    int[] location = new int[2];
    mGraphicOverlay.getLocationOnScreen(location);
    float x = (rawX - location[0]) / mGraphicOverlay.getWidthScaleFactor();
    float y = (rawY - location[1]) / mGraphicOverlay.getHeightScaleFactor();

    // Find the barcode whose center is closest to the tapped point.
    Barcode best = null;
    float bestDistance = Float.MAX_VALUE;
    for (BarcodeGraphic graphic : mGraphicOverlay.getGraphics()) {
        Barcode barcode = graphic.getBarcode();
        if (barcode.getBoundingBox().contains((int) x, (int) y)) {
            // Exact hit, no need to keep looking.
            best = barcode;
            break;
        }
        float dx = x - barcode.getBoundingBox().centerX();
        float dy = y - barcode.getBoundingBox().centerY();
        float distance = (dx * dx) + (dy * dy); // actually squared distance
        if (distance < bestDistance) {
            best = barcode;
            bestDistance = distance;
        }
    }

    if (best != null) {
        Intent data = new Intent();
        data.putExtra(BarcodeObject, best);
        setResult(CommonStatusCodes.SUCCESS, data);

        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.barcode_toast,
                (ViewGroup) findViewById(R.id.custom_toast_container));

        Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
        //Barcode.DriverLicense dlBarcode = barcode.driverLicense;

        Barcode.DriverLicense sample = barcode.driverLicense;

        TextView name = (TextView) layout.findViewById(R.id.name);
        TextView address = (TextView) layout.findViewById(R.id.address);
        TextView cityStateZip = (TextView) layout.findViewById(R.id.cityStateZip);
        TextView gender = (TextView) layout.findViewById(R.id.gender);
        TextView dob = (TextView) layout.findViewById(R.id.dob);
        TableLayout tbl = (TableLayout) layout.findViewById(R.id.tableLayout);

        try {
            int age = DateDifference.generateAge(sample.birthDate);
            if (age < minAge)
                tbl.setBackgroundColor(Color.parseColor("#980517"));
            else
                tbl.setBackgroundColor(Color.parseColor("#617C17"));

        } catch (ParseException e) {
            e.printStackTrace();
        }

        String cityContent = new String(
                sample.addressCity + ", " + sample.addressState + " " + (sample.addressZip).substring(0, 5));

        address.setText(sample.addressStreet);
        cityStateZip.setText(cityContent);

        String genderString;
        if ((sample.gender).equals("1"))
            genderString = "Male";
        else if ((sample.gender).equals("2"))
            genderString = "Female";
        else
            genderString = "Other";

        gender.setText(genderString);

        dob.setText((sample.birthDate).substring(0, 2) + "/" + (sample.birthDate).substring(2, 4) + "/"
                + (sample.birthDate).substring(4, 8));

        String nameString = new String(sample.firstName + " " + sample.middleName + " " + sample.lastName);

        name.setText(nameString);

        Toast toast = new Toast(getApplicationContext());
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(layout);
        toast.show();

        Date today = Calendar.getInstance().getTime();
        String reportDate = df.format(today);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues row = new ContentValues();
        row.put("dateVar", reportDate);
        row.put("dobVar", sample.birthDate);
        row.put("zipVar", sample.addressZip);
        row.put("genderVar", genderString);
        db.insert("test", null, row);
        db.close();

        return true;
    }
    return false;
}

From source file:com.akop.bach.fragment.playstation.TrophiesFragment.java

private void showTrophyDetails(CharSequence title, CharSequence description) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View layout = inflater.inflate(R.layout.psn_trophy_toast,
            (ViewGroup) getActivity().findViewById(R.id.toast_root));

    TextView text = (TextView) layout.findViewById(R.id.trophy_title);
    text.setText(title);/*  w w w. j  a  v a  2 s  . c  o  m*/
    text = (TextView) layout.findViewById(R.id.trophy_description);
    text.setText(description);

    Toast toast = new Toast(getActivity());
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);

    toast.show();
}

From source file:com.akop.bach.fragment.xboxlive.AchievementsFragment.java

private void showAchievementDetails(CharSequence title, CharSequence description) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View layout = inflater.inflate(R.layout.xbl_achievement_toast,
            (ViewGroup) getActivity().findViewById(R.id.toast_root));

    TextView text = (TextView) layout.findViewById(R.id.achievement_title);
    text.setText(title);//from  w  ww.  j a  v a 2  s .  co  m
    text = (TextView) layout.findViewById(R.id.achievement_description);
    text.setText(description);

    Toast toast = new Toast(getActivity());
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);

    toast.show();
}

From source file:com.adamas.client.android.ui.ConnectorsFragment.java

private void toast(String msg, ToastType toastType) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    // Inflate the Layout
    View layout = inflater.inflate(R.layout.custom_toast,
            (ViewGroup) getActivity().findViewById(R.id.custom_toast_layout));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (toastType.equals(ToastType.error)) {
            layout.setBackground(getActivity().getDrawable(R.drawable.toast_error));
        } else if (toastType.equals(ToastType.info)) {
            layout.setBackground(getActivity().getDrawable(R.drawable.toast_info));
        } else if (toastType.equals(ToastType.warning)) {
            layout.setBackground(getActivity().getDrawable(R.drawable.toast_warning));
        } else {/*from  w  w  w . j  a  va2s  .c o  m*/
            layout.setBackground(getActivity().getDrawable(R.drawable.toast_info));
        }
    }
    TextView text = (TextView) layout.findViewById(R.id.textToShow);
    // Set the Text to show in TextView
    text.setText(msg);

    Toast toast = new Toast(getActivity().getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}

From source file:com.sim2dial.dialer.StatusFragment.java

private void showZRTPDialog(final LinphoneCall call) {
    boolean authVerified = call.isAuthenticationTokenVerified();
    String format = getString(authVerified ? R.string.reset_sas_fmt : R.string.verify_sas_fmt);

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View layout = inflater.inflate(R.layout.zrtp_dialog,
            (ViewGroup) getActivity().findViewById(R.id.toastRoot));

    TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
    toastText.setText(String.format(format, call.getAuthenticationToken()));

    zrtpToast = new Toast(getActivity());
    zrtpToast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, LinphoneUtils.pixelsToDpi(getResources(), 40));
    zrtpToast.setDuration(Toast.LENGTH_LONG);

    ImageView ok = (ImageView) layout.findViewById(R.id.toastOK);
    ok.setOnClickListener(new OnClickListener() {
        @Override//w  w w .j a v a2s. c  o  m
        public void onClick(View v) {
            if (call != null) {
                call.setAuthenticationTokenVerified(true);
            }
            if (encryption != null) {
                encryption.setImageResource(R.drawable.security_ok);
            }
            hideZRTPDialog();
        }
    });

    ImageView notOk = (ImageView) layout.findViewById(R.id.toastNotOK);
    notOk.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (call != null) {
                call.setAuthenticationTokenVerified(false);
            }
            if (encryption != null) {
                encryption.setImageResource(R.drawable.security_pending);
            }
            hideZRTPDialog();
        }
    });

    zrtpHack = new CountDownTimer(3000, 1000) {
        public void onTick(long millisUntilFinished) {
            if (!hideZrtpToast) {
                zrtpToast.show();
            }
        }

        public void onFinish() {
            if (!hideZrtpToast) {
                zrtpToast.show();
                zrtpHack.start();
            }
        }

    };

    zrtpToast.setView(layout);
    hideZrtpToast = false;
    zrtpToast.show();
    zrtpHack.start();
}