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:com.example.util.Utils.java

/**
 * Show toast information/*from  w  ww .  j ava  2s  .  c o m*/
 * 
 * @param context
 *            application context
 * @param text
 *            the information which you want to show
 * @return show toast dialog
 */
public static void makeEventToast(Context context, String text, boolean isLongToast) {

    Toast toast = null;
    if (isLongToast) {
        toast = Toast.makeText(context, "", Toast.LENGTH_LONG);
    } else {
        toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
    }
    View v = LayoutInflater.from(context).inflate(R.layout.toast_view, null);
    TextView textView = (TextView) v.findViewById(R.id.text);
    textView.setText(text);
    toast.setView(v);
    toast.show();
}

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

/**
 * Sets up the listeners for the buttons.
 *///  w  ww  .  j av  a  2 s.co  m
private void setButtons() {
    final Button nextButton = (Button) findViewById(R.id.questions_next_button);
    nextButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1);
        }
    });

    final Button previousButton = (Button) findViewById(R.id.questions_previous_button);
    previousButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1);
        }
    });
    mCompleteButton = (Button) findViewById(R.id.questions_complete_button);
    mCompleteButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            int answers[] = new int[mNumberOfQuestions];
            int amountAnswer = -2;
            for (int i = 0; i < mNumberOfQuestions; i++) {
                answers[i] = mQuestionsPagerAdapter.getFragment(i).getSelectedAnswer();
                if (i == 0) {
                    amountAnswer = mQuestionsPagerAdapter.getFragment(i).getXAmount();
                }
            }
            if (answers[0] < 2 && amountAnswer < 1) {
                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.goal_not_added));
                toastText.setTextColor(Color.WHITE);

                Toast questionnaireDone = new Toast(getApplicationContext());
                questionnaireDone.setDuration(Toast.LENGTH_LONG);
                questionnaireDone.setView(toastLayout);
                questionnaireDone.show();

            } else {
                mGoalDataHandler.insertGoal(System.currentTimeMillis(), answers[1], answers[0], amountAnswer);

                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.goal_added));
                toastText.setTextColor(Color.WHITE);

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

            }
            finish();
        }
    });
    // Disable these buttons at start.
    mCompleteButton.setEnabled(false);
    previousButton.setEnabled(false);

    // Set up a page change listener to enable and disable buttons.
    titleIndicator.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int arg0) {
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int arg0) {
            if (arg0 == mNumberOfQuestions - 1) {
                nextButton.setEnabled(false);
            } else {
                nextButton.setEnabled(true);
            }
            if (arg0 == 0) {
                previousButton.setEnabled(false);
            } else {
                previousButton.setEnabled(true);
            }
        }
    });
}

From source file:com.geomoby.geodeals.DemoService.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.geomoby_main);
    mContext = this;

    mToggle = (CompoundButton) findViewById(R.id.togglebutton);

    spref = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    isCheckedStatus = spref.getBoolean("check", false); //default is false

    /*//  w w  w  . j a  v  a2 s  .c o m
     * Set up toggle status
     */
    if (!isCheckedStatus)
        mToggle.setChecked(false);
    else
        mToggle.setChecked(true);

    /*
     *  Save the tags in the GeoMoby shared preferences in private mode for the user. These tags will be used
     *  to segment your audience when creating your proximity alerts. Please make sure that they match with
     *  the ones configured in your dashboard when you create an alert.
     *  Ex: 'test' is the default tag so make sure that it is set up in your Account page
     */
    SharedPreferences mySharedPreferences = getSharedPreferences(PREF, MODE_PRIVATE);

    // Build the string of tags - empty for testing. Make sure that you create your first geofences with no tags in your dashboard.
    // Add your own logic here: "male,vip,monday"...
    String tags = "";

    // Commit the string
    SharedPreferences.Editor prefEditor = mySharedPreferences.edit();
    prefEditor.putString(SETTING_TAGS, tags);
    prefEditor.commit();

    /*
     *  Monitor the toggle - Our SDK will ensure that all services are running/stopping properly
     */
    mToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked == false) {

                mToggle.setPressed(false);

                // Stop the GeoMoby tracking service
                startService(new Intent(DemoService.this, GeomobyStopService.class));

                SharedPreferences.Editor editor = spref.edit();
                editor.putBoolean("check", false);
                editor.commit();

            } else {

                mToggle.setPressed(true);

                // Start the GeoMoby tracking service
                startService(new Intent(DemoService.this, GeomobyStartService.class));

                SharedPreferences.Editor editor = spref.edit();
                editor.putBoolean("check", true);
                editor.commit();

                LayoutInflater inflater = getLayoutInflater();
                // Inflate the Layout
                View layout = inflater.inflate(R.layout.geomoby_toast,
                        (ViewGroup) findViewById(R.id.custom_toast_layout));

                // Set the Text to show in TextView
                TextView text = (TextView) layout.findViewById(R.id.textToShow);
                text.setText("GREAT! YOU ARE READY TO RECEIVE REAL-TIME NOTIFICATIONS!");
                Typeface face;
                face = Typeface.createFromAsset(getAssets(), "Bitter-Bold.otf");
                text.setTypeface(face);

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

    // Initialise GeoMoby Notification Listener
    GeomobyNotificationsReceiver receiver = new GeomobyNotificationsReceiver();
    receiver.setNotificationListener(this);
}

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

/**
 * Sets up the listeners for the buttons.
 *//*from  w  w  w  . j  a v a  2 s  . c  o  m*/
private void setButtons() {
    final Button nextButton = (Button) findViewById(R.id.questions_next_button);
    nextButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mViewPager.getCurrentItem() == 1
                    && mQuestionsPagerAdapter.getFragment(1).getSelectedAnswer() == 1) {
                mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 3);
            } else {
                mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1);
            }
        }
    });

    final Button previousButton = (Button) findViewById(R.id.questions_previous_button);
    previousButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mViewPager.getCurrentItem() == 4
                    && mQuestionsPagerAdapter.getFragment(1).getSelectedAnswer() == 1) {
                mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 3);
            } else {
                mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1);
            }
        }
    });
    mCompleteButton = (Button) findViewById(R.id.questions_complete_button);
    mCompleteButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            int answers[] = new int[mNumberOfQuestions];
            long date = 0L;
            for (int i = 0; i < mNumberOfQuestions; i++) {
                answers[i] = mQuestionsPagerAdapter.getFragment(i).getSelectedAnswer();
                if (i == 0) {
                    if (answers[i] == 3) {
                        date = mQuestionsPagerAdapter.getFragment(i).getSelectedDate();
                    }
                }
            }
            mEventDataHandler.insertEvent(answers[0], answers[1], answers[2], answers[3], answers[4], mName,
                    date);

            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.event_added));
            toastText.setTextColor(Color.WHITE);

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

            //Add a flag for which section the event was added to.
            SharedPreferences motivatorPrefs = getSharedPreferences(MainActivity.MOTIVATOR_PREFS, 0);
            Editor editor = motivatorPrefs.edit();
            if (answers[0] == 1) {
                editor.putInt(EVENT_ADDED, MotivatorEvent.TODAY);
            } else {
                editor.putInt(EVENT_ADDED, MotivatorEvent.PLAN);
            }
            editor.commit();
            finish();
        }
    });
    // Disable these buttons at start.
    mCompleteButton.setEnabled(false);
    previousButton.setEnabled(false);

    // Set up a page change listener to enable and disable buttons.
    titleIndicator.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int arg0) {
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int arg0) {
            if (arg0 == mNumberOfQuestions - 1) {
                nextButton.setEnabled(false);
            } else {
                nextButton.setEnabled(true);
            }
            if (arg0 == 0) {
                previousButton.setEnabled(false);
            } else {
                previousButton.setEnabled(true);
            }
        }
    });
}

From source file:org.silena.main.RegistrationOld.java

private void RenderError(String massage) {

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

    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(massage);//from www. j  a  v  a  2s  . c o  m

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

From source file:net.mypapit.mobile.callsignview.MainActivity.java

private void showToast(String message) {
    Context context = getApplicationContext();
    LayoutInflater inflater = getLayoutInflater();

    View customToastroot = inflater.inflate(R.layout.custom_toast, null);
    TextView tvToast = (TextView) customToastroot.findViewById(R.id.tvToast);
    tvToast.setText(message);/*from   w  ww .j  a  v a 2  s.co  m*/

    Toast customtoast = new Toast(context);

    customtoast.setView(customToastroot);
    customtoast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    customtoast.setDuration(Toast.LENGTH_SHORT);
    customtoast.show();

}

From source file:cz.babi.android.remoteme.service.ConnectionService.java

/**
 * If server is unreachable we need to stop service and notice that to user.
 *///from w ww .  j av a2 s.  c  o m
private void closeConnection() {
    if (Common.DEBUG)
        Log.d(TAG_CLASS_NAME, "[closeConnection]");

    if (clientSocket != null)
        try {
            clientSocket.close();
        } catch (IOException e) {
            if (Common.ERROR)
                Log.e(TAG_CLASS_NAME, "[stopService][Can not close client " + "socket.]");
        }

    ConnectionService.server = null;
    ConnectionService.clientSocket = null;
    ConnectionService.in = null;
    ConnectionService.out = null;
    ConnectionService.needEncryptedCommunication = false;

    LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View toastLayout = mInflater.inflate(R.layout.toast_warning, null);

    TextView text = (TextView) toastLayout.findViewById(R.id.warning_text);
    text.setText(R.string.connection_service_connection_lost_text);

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

    disconnectWithError = true;
}

From source file:cz.babi.android.remoteme.service.ConnectionService.java

@Override
public void onDestroy() {
    if (Common.DEBUG)
        Log.d(TAG_CLASS_NAME, "[onDestroy]");

    /* Cancel the persistent notification. */
    if (isNotificationVisible)
        notificationManager.cancel(NOTIFICATION_ID);

    /* If Wi-Fi is locked we need to unlock it. */
    if (wifiLock.isHeld())
        unlockWifi();/*w w w  . j a va2 s  .  c o  m*/

    /* If there was no error we send 'bye bye' message to server and show toast to user. */
    if (!disconnectWithError) {
        /* Just tell to server that we are disconnecting. */
        SimpleMessage byeBye = Message.BYE_BYE;

        String message = byeBye.toString();
        if (needEncryptedCommunication)
            message = AES128_DEFAULT.encryptText(byeBye.toString());

        out.println(message);
        out.flush();

        /* Tell the user we stopped. */
        LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View toastLayout = mInflater.inflate(R.layout.toast_normal, null);

        TextView text = (TextView) toastLayout.findViewById(R.id.normal_text);
        text.setText(R.string.connection_service_disconnected_text);

        Toast toast = new Toast(this);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(toastLayout);
        toast.show();
    }
}

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);//from  www. ja  va  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:org.madmatrix.zxing.android.CaptureActivity.java

public void showMyToast(String content) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout));

    TextView toast_content = (TextView) layout.findViewById(R.id.toast_content);

    toast_content.setText(content);/*from  w  w  w . j  a va2  s  .  c  om*/

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