Example usage for android.widget Toast setDuration

List of usage examples for android.widget Toast setDuration

Introduction

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

Prototype

public void setDuration(@Duration int duration) 

Source Link

Document

Set how long to show the view for.

Usage

From source file:com.commonsdroid.dialoghelper.DialogHelper.java

/**
 * Show custom toast./*from   w  w w.  j av  a 2 s . com*/
 *
 * @param context the context
 * @param view the view
 * @param Duration the duration e.g <code>Toast.LENGTH_SHORT</code> , <code>Toast.LENGTH_LONG</code>
 * @param gravity the gravity e.g <code>GRAVITY.BOTTOM</code> , <code>GRAVITY.CENTER_VERTICAL</code> , etc
 * @param xoffset the x offset
 * @param yoffset the y offset
 */
public static void showCustomToast(Context context, View view, int Duration, int gravity, int xoffset,
        int yoffset) {
    Toast newCustomToast = new Toast(context);
    newCustomToast.setView(view);
    newCustomToast.setDuration(Duration);
    newCustomToast.setGravity(gravity, xoffset, yoffset);
    newCustomToast.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.
 * /*  www  .j  a v  a 2 s  .  co  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:MainActivity.java

public void showToast(View view) {
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.toast_custom, null);
    ((TextView) layout.findViewById(android.R.id.message)).setText("Custom Toast");
    Toast toast = new Toast(this);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);//from  www.  ja  v a  2  s . c o m
    toast.show();
}

From source file:com.accia77.mockey.ui.PapiroActivity.java

@Override
public void onResume() {
    super.onResume();

    setTitle(MyApplication.getInstance().getMainActivityTitle());

    massimaSceltaTextView = (TextView) findViewById(R.id.massimaSceltaTextView);
    String stringaTextView = currentEntry.getUserEditedEntry();

    if (mDoShowAndPlayQuote) {
        // Custom toast con il testo della frase
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.papiro_toast, (ViewGroup) findViewById(R.id.toast_layout_root));

        ImageView image = (ImageView) layout.findViewById(R.id.papiro_toast_image);
        image.setImageResource(R.drawable.ic_small_monkey_head);
        TextView text = (TextView) layout.findViewById(R.id.papiro_toast_text);
        text.setText(stringaTextView);/*from w  w w . jav a2s  .  c om*/

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

        // Playback of the quote
        if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_PURE_TEXT) {
            MyApplication.getInstance().playSelection(currentEntry);
        } else if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_AUDIO) {
            // No playback if the sd card is not mounted
            if (MyApplication.getInstance().isSdCardMounted(false)) {
                MyApplication.getInstance().playSelection(currentEntry);
            }
        }

        mDoShowAndPlayQuote = false;
    }

    if (MyApplication.getInstance().isDefaultPapiroLoaded()) {
        massimaSceltaTextView.setText(stringaTextView);
        massimaSceltaTextView.setVisibility(View.VISIBLE);
    } else
        massimaSceltaTextView.setVisibility(View.INVISIBLE);

}

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

/**
 * Displaying toast after checking events
 *///from   w  w w  .  j a v a2s .  c  o  m
private void eventsChecked() {
    View toastLayout = (View) getLayoutInflater().inflate(R.layout.element_mood_toast,
            (ViewGroup) findViewById(R.id.mood_toast_layout));
    TextView toastText = (TextView) toastLayout.findViewById(R.id.mood_toast_text);
    toastText.setText(getString(R.string.plan_checked));
    toastText.setTextColor(Color.WHITE);

    Toast planChecked = new Toast(getApplicationContext());
    planChecked.setDuration(Toast.LENGTH_SHORT);
    planChecked.setView(toastLayout);
    planChecked.show();

    finish();
}

From source file:com.mb.kids_mind.GcmIntentService.java

public void ToastAll(Context context, String msg) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.toast_layout, null);

    Toast mToast = new Toast(context.getApplicationContext());

    mToast.setGravity(Gravity.CENTER_VERTICAL, 0, 2);
    mToast.setDuration(Toast.LENGTH_SHORT);
    mToast.setView(layout);/*w w w  . j  av  a2  s  . c  o m*/
    if (flag == false) {
        flag = true;
        mToast.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                flag = false;
            }
        }, 2000);//  ?    ?? 2   .
    } else {
        Log.e("", " ?");
    }

}

From source file:com.radicaldynamic.groupinform.application.Collect.java

public void showCustomToast(String message) {
    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 = (TextView) view.findViewById(R.id.message);
    tv.setText(message);/* w w  w  .j a  v a 2s.  com*/

    Toast t = new Toast(this);
    t.setView(view);
    t.setDuration(Toast.LENGTH_SHORT);
    t.setGravity(Gravity.CENTER, 0, 0);
    t.show();
}

From source file:com.android.jhansi.designchallenge.NavigationDrawerActivity.java

private void showCustomToast(int resId) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.custom_toast_layout));

    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(resId);/*from  w  w  w  .jav  a2 s.  com*/

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.TOP, 0, -1);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}

From source file:codepath.watsiapp.activities.BaseFragmentActivity.java

private void showThankYouNote() {
    LayoutInflater inflater = this.getLayoutInflater();
    View view = inflater.inflate(R.layout.toast_thanks_for_donation,
            (ViewGroup) this.findViewById(R.id.thanks_note));
    Toast toast = new Toast(this);
    toast.setView(view);//  www .  j  av a2  s . c o m
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();

}

From source file:org.xingjitong.ui.CallButton.java

private void toastdsp(String str) {

    //LayoutInflater inflater = getLayoutInflater();
    LayoutInflater inflater = LayoutInflater.from(getContext());
    View layout = inflater.inflate(R.layout.customtoast, (ViewGroup) findViewById(R.id.llcustomtoast));

    //ImageView image = (ImageView) layout.findViewById(R.id.customtoast_img);
    //image.setImageResource(R.drawable.status_green); //yypp

    TextView text = (TextView) layout.findViewById(R.id.customtoast_text);
    text.setText(str);//from   w  w  w  .  j  a  v  a2 s .  c  o  m
    //Toast toast = new Toast(getApplicationContext());
    Toast toast = new Toast(getContext());
    toast.setGravity(Gravity.CENTER, 0, 60);
    //toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();

}