Example usage for android.widget Toast setView

List of usage examples for android.widget Toast setView

Introduction

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

Prototype

public void setView(View view) 

Source Link

Document

Set the view to show.

Usage

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;/*from  w  w  w .  ja  va2s  .c o 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.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 .ja  v  a2 s  . c  om*/
            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.example.jesse.barscan.BarcodeCaptureActivity.java

/**
 * onTap returns the tapped barcode result to the calling Activity.
 *//*w ww  .j  a v  a  2 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:xj.property.activity.HXBaseActivity.HXBaseActivity.java

/**
 * Toast ,, ?./*from  w  ww .j a  va 2 s  .  co  m*/
 *
 * @param showT   
 * @param gravity ?
 */
protected void showCommonToast(String showT, int gravity) {

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.common_welfare_toast_lay, null);
    TextView title = (TextView) layout.findViewById(R.id.toast_title_tv);
    title.setText(showT);
    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(gravity, 0, 0);
    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);/*  w  w w.  j  a v  a 2 s. com*/
    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.sender.team.sender.gcm.MyGcmListenerService.java

private void sendToast(final ChattingReceiveData data, final ChattingReceiveMessage c) {
    handler.post(new Runnable() {
        @Override//from w w  w  .  java  2s. c  o  m
        public void run() {
            View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.toast_notify, null);
            ImageView imageProfile = (ImageView) view.findViewById(R.id.imageProfile);
            TextView textName = (TextView) view.findViewById(R.id.textName);
            TextView textMessage = (TextView) view.findViewById(R.id.textMessage);
            Glide.with(getApplicationContext()).load(data.getSender().getFileUrl()).into(imageProfile);
            if (!TextUtils.isEmpty(data.getSender().getName())) {
                textName.setText(data.getSender().getName());
            }
            if (!TextUtils.isEmpty(c.getMessage())) {
                textMessage.setText(c.getMessage());
            } else {
                textMessage.setText("");
            }

            Toast toast = new Toast(getApplicationContext());
            float dp = 65;
            int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
                    getResources().getDisplayMetrics());
            toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, pixel);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.setView(view);
            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);
    toast.setDuration(duration);//from  ww w .j  ava2s .  com
    toast.show();
}

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.  j  a v a 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:com.apptentive.android.sdk.module.engagement.interaction.fragment.SurveyFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (interaction == null) {
        getActivity().finish();/*from  www. ja v  a2 s.  co m*/
    }

    List<Question> questions = interaction.getQuestions();
    answers = new LinkedHashMap<String, Object>(questions.size());

    View v = inflater.inflate(R.layout.apptentive_survey, container, false);

    TextView description = (TextView) v.findViewById(R.id.description);
    description.setText(interaction.getDescription());

    final Button send = (Button) v.findViewById(R.id.send);

    String sendText = interaction.getSubmitText();
    if (!TextUtils.isEmpty(sendText)) {
        send.setText(sendText);
    }
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Util.hideSoftKeyboard(getActivity(), view);
            boolean valid = validateAndUpdateState();
            if (valid) {
                if (interaction.isShowSuccessMessage() && !TextUtils.isEmpty(interaction.getSuccessMessage())) {
                    Toast toast = new Toast(getContext());
                    toast.setGravity(Gravity.FILL, 0, 0);
                    toast.setDuration(Toast.LENGTH_SHORT);
                    View toastView = inflater.inflate(R.layout.apptentive_survey_sent_toast,
                            (LinearLayout) getView().findViewById(R.id.survey_sent_toast_root));
                    toast.setView(toastView);
                    TextView actionTV = ((TextView) toastView.findViewById(R.id.survey_sent_action_text));
                    actionTV.setText(interaction.getSuccessMessage());
                    int actionColor = Util.getThemeColor(getContext(),
                            R.attr.apptentiveSurveySentToastActionColor);
                    if (actionColor != 0) {
                        actionTV.setTextColor(actionColor);
                        ImageView actionIcon = (ImageView) toastView.findViewById(R.id.survey_sent_action_icon);
                        actionIcon.setColorFilter(actionColor);
                    }
                    toast.show();
                }
                getActivity().finish();

                EngagementModule.engageInternal(getActivity(), interaction, EVENT_SUBMIT);

                ApptentiveInternal.getInstance().getApptentiveTaskManager()
                        .addPayload(new SurveyResponse(interaction, answers));
                ApptentiveLog.d("Survey Submitted.");
                callListener(true);
            } else {
                Toast toast = new Toast(getContext());
                toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
                toast.setDuration(Toast.LENGTH_SHORT);
                View toastView = inflater.inflate(R.layout.apptentive_survey_invalid_toast,
                        (LinearLayout) getView().findViewById(R.id.survey_invalid_toast_root));
                toast.setView(toastView);
                String validationText = interaction.getValidationError();
                if (!TextUtils.isEmpty(validationText)) {
                    ((TextView) toastView.findViewById(R.id.survey_invalid_toast_text)).setText(validationText);
                }
                toast.show();
            }
        }
    });

    questionsContainer = (LinearLayout) v.findViewById(R.id.questions);
    if (savedInstanceState == null) {
        questionsContainer.removeAllViews();

        // Then render all the questions
        for (int i = 0; i < questions.size(); i++) {
            Question question = questions.get(i);
            BaseSurveyQuestionView surveyQuestionView;
            if (question.getType() == Question.QUESTION_TYPE_SINGLELINE) {
                surveyQuestionView = TextSurveyQuestionView.newInstance((SinglelineQuestion) question);
            } else if (question.getType() == Question.QUESTION_TYPE_MULTICHOICE) {
                surveyQuestionView = MultichoiceSurveyQuestionView.newInstance((MultichoiceQuestion) question);

            } else if (question.getType() == Question.QUESTION_TYPE_MULTISELECT) {
                surveyQuestionView = MultiselectSurveyQuestionView.newInstance((MultiselectQuestion) question);
            } else if (question.getType() == Question.QUESTION_TYPE_RANGE) {
                surveyQuestionView = RangeSurveyQuestionView.newInstance((RangeQuestion) question);
            } else {
                surveyQuestionView = null;
            }
            if (surveyQuestionView != null) {
                surveyQuestionView.setOnSurveyQuestionAnsweredListener(this);
                getRetainedChildFragmentManager().beginTransaction()
                        .add(R.id.questions, surveyQuestionView, Integer.toString(i)).commit();
            }
        }
    } else {
        List<Fragment> fragments = getRetainedChildFragmentManager().getFragments();
        for (Fragment fragment : fragments) {
            BaseSurveyQuestionView questionFragment = (BaseSurveyQuestionView) fragment;
            questionFragment.setOnSurveyQuestionAnsweredListener(this);

        }
    }
    return v;
}

From source file:com.wewow.BaseActivity.java

private void showCacheClearedToast() {

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.clear_cache_toast_view, null);

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();//  ww w . j ava  2 s  . c o  m
}