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:saphion.pageindicators.FixedTabsView.java

/**
 * Initialize and add all tabs to the layout
 *//*w w  w .  ja  va2 s .c om*/
private void initTabs() {

    removeAllViews();
    mTabs.clear();

    if (mAdapter == null)
        return;

    for (int i = 0; i < mPager.getAdapter().getCount(); i++) {

        final int index = i;

        View tab = mAdapter.getView(i);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f);
        tab.setLayoutParams(params);
        this.addView(tab);

        mTabs.add(tab);

        if (i != mPager.getAdapter().getCount() - 1) {
            this.addView(getSeparator());
        }

        tab.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPager.setCurrentItem(index);
            }
        });

        tab.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                //Toast t = new Toast(getContext());
                Toast t = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
                //t.setGravity(Gravity.TOP, v.getRight()/2 - v.getLeft()/2, v.getBottom());
                switch (index) {
                case 0:
                    t.setText("Power Profiles");
                    t.setGravity(Gravity.TOP | Gravity.LEFT, v.getLeft(), v.getBottom());
                    break;
                case 1:
                    t.setText("Battery Info");
                    t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, v.getBottom());
                    break;
                case 2:
                    t.setText("Graph and Stats");
                    t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, v.getBottom());
                    break;
                case 3:
                    t.setText("Battery Alarms");
                    t.setGravity(Gravity.TOP, v.getLeft(), v.getBottom());
                    break;

                }
                t.setDuration(Toast.LENGTH_SHORT);
                t.show();
                return true;
            }
        });

    }

    selectTab(mPager.getCurrentItem());
}

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/*from   w w  w .j  av  a2  s  .co 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:io.plaidapp.ui.DesignerNewsLogin.java

@SuppressLint("InflateParams")
void showLoggedInUser() {
    final Call<User> authedUser = designerNewsPrefs.getApi().getAuthedUser();
    authedUser.enqueue(new Callback<User>() {
        @Override//w  w  w . java2 s.  c  o  m
        public void onResponse(Call<User> call, Response<User> response) {
            if (!response.isSuccessful())
                return;
            final User user = response.body();
            designerNewsPrefs.setLoggedInUser(user);
            final Toast confirmLogin = new Toast(getApplicationContext());
            final 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.toLowerCase());
            // 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 onFailure(Call<User> call, Throwable t) {
            Log.e(getClass().getCanonicalName(), t.getMessage(), t);
        }
    });
}

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

public void displayCustomToast(final String message, final int duration) {
    mHandler.post(new Runnable() {
        @Override//from  w  w w  .java 2  s.c o m
        public void run() {
            LayoutInflater inflater = getLayoutInflater();
            View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));

            TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
            toastText.setText(message);

            final Toast toast = new Toast(getApplicationContext());
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.setDuration(duration);
            toast.setView(layout);
            toast.show();
        }
    });
}

From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java

/**
 * Starts the whole Facebook post process.
 * //from ww w.  j a  va  2 s  . c  om
 * @param session
 */
private void launchPostProcess(final Session session) {

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

    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon_facebook_released);
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText("Publication en cours");

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

    Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {

        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (session == Session.getActiveSession()) {
                if (user != null) {
                    int notificationId = FacebookHelper
                            .showNotificationStartProgress(GameSetHistoryActivity.this);
                    AppContext.getApplication().getNotificationIds().put(tempGameSet.getUuid(), notificationId);

                    AppContext.getApplication().setLoggedFacebookUser(user);
                    UpSyncGameSetTask task = new UpSyncGameSetTask(GameSetHistoryActivity.this, progressDialog);
                    task.setCallback(GameSetHistoryActivity.this.upSyncCallback);
                    task.execute(tempGameSet);
                    currentRunningTask = task;
                }
            }
            if (response.getError() != null) {
                // //progressDialog.dismiss();
                // Session newSession = new
                // Session(GameSetHistoryActivity.this);
                // Session.setActiveSession(newSession);
                // newSession.openForPublish(new
                // Session.OpenRequest(GameSetHistoryActivity.this).setPermissions(Arrays.asList("publish_actions",
                // "email")).setCallback(facebookSessionStatusCallback));
            }
        }
    });
    request.executeAsync();
}

From source file:org.xingjitong.InCallActivity.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 a  2s  .  c  om*/
    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();

}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

private Toast createToastShort(String text) {
    Toast toast = new Toast(this);
    TextView tv = new TextView(this);
    tv.setText(text);//w w  w  .ja  v a 2 s . c  o  m
    tv.setTextColor(ContextCompat.getColor(this, R.color.colorAccent));
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, TOAST_TEXT_SIZE);
    //        int pixel = (int)mWindowDensity * 56;
    int toastMargin = getResources().getDimensionPixelSize(R.dimen.toast_margin_top_bottom);
    tv.setPadding(0, toastMargin, 0, toastMargin);
    toast.setView(tv);
    toast.setGravity(mToastPosition, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);

    return toast;
}

From source file:co.taqat.call.CallActivity.java

public void displayCustomToast(final String message, final int duration) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));

    TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
    toastText.setText(message);/* ww w. ja v a2s  .co  m*/

    final Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(duration);
    toast.setView(layout);
    toast.show();
}

From source file:org.xingjitong.LinphoneActivity.java

public void displayCustomToast(final String message, final int duration) {
    mHandler.post(new Runnable() {
        @Override/* w w  w.ja  v  a2 s  .c  o m*/
        public void run() {
            LayoutInflater inflater = getLayoutInflater();
            View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));

            TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
            toastText.setText(message);
            final Toast toast = new Toast(getApplicationContext());
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.setDuration(duration);
            toast.setView(layout);
            toast.show();
        }
    });
}

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

private void makeToast(String msg, int mode) {

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

    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(R.drawable.ic_launcher);
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(msg);//  w  w w  .  ja  v  a  2s . com

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    if (mode == 1) {
        text.setTextColor(Color.WHITE);
        toast.getView().setBackgroundColor(Color.RED);
        toast.setDuration(Toast.LENGTH_LONG);
    }
    if (mode == 2) {
        text.setTextColor(Color.WHITE);
        toast.getView().setBackgroundColor(Color.GREEN);
    }
    toast.show();
}