List of usage examples for android.widget Toast Toast
public Toast(Context context)
From source file:io.plaidapp.ui.DribbbleLogin.java
private void showLoggedInUser() { Gson gson = new GsonBuilder().setDateFormat(DribbbleService.DATE_FORMAT).create(); RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(DribbbleService.ENDPOINT) .setConverter(new GsonConverter(gson)) .setRequestInterceptor(new AuthInterceptor(dribbblePrefs.getAccessToken())).build(); DribbbleService dribbbleApi = restAdapter.create((DribbbleService.class)); dribbbleApi.getAuthenticatedUser(new Callback<User>() { @Override//from w ww . j av a 2 s . co m public void success(User user, Response response) { dribbblePrefs.setLoggedInUser(user); Toast confirmLogin = new Toast(getApplicationContext()); View v = LayoutInflater.from(DribbbleLogin.this).inflate(R.layout.toast_logged_in_confirmation, null, false); ((TextView) v.findViewById(R.id.name)).setText(user.name); // need to use app context here as the activity will be destroyed shortly Glide.with(getApplicationContext()).load(user.avatar_url).placeholder(R.drawable.ic_player) .transform(new CircleTransform(getApplicationContext())) .into((ImageView) v.findViewById(R.id.avatar)); v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable( ContextCompat.getColor(DribbbleLogin.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) { } }); }
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 w w w . 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:org.apps8os.motivator.ui.AddGoalActivity.java
/** * Sets up the listeners for the buttons. *///from w w w. j av a2s. 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.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 ww .j a v a 2s . c om*/ 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);/*from www. j av a 2 s .c o m*/ toast.setGravity(Gravity.CENTER, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.show(); }
From source file:org.apps8os.motivator.ui.MoodQuestionActivity.java
/** Called when the activity is first created. */ @Override/* w w w .j a v a 2 s .co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mood_question); mDayDataHandler = new DayDataHandler(this); mCardsViewPagerEnergy = (ViewPager) findViewById(R.id.mood_question_viewpager_cards); mCardsViewPagerEnergy.setAdapter(new ImagesPagerAdapter(mImages1, mTitles1, this)); setViewPager(mCardsViewPagerEnergy); mEnergyLevelText = (TextView) findViewById(R.id.mood_question_energylevel_textview); mEnergyLevelText.setText(mCardsViewPagerEnergy.getAdapter().getPageTitle(DEFAULT_MOOD_SELECTION)); // Set an OnPageChangeListener to the ViewPager, change the text when a page is selected mCardsViewPagerEnergy .setOnPageChangeListener(new ViewPageChangeListener(mCardsViewPagerEnergy, mEnergyLevelText)); mCardsViewPagerMood = (ViewPager) findViewById(R.id.mood_question_viewpager_cards2); mCardsViewPagerMood.setAdapter(new ImagesPagerAdapter(mImages2, mTitles2, this)); setViewPager(mCardsViewPagerMood); // Get the text field for energy level mMoodLevelText = (TextView) findViewById(R.id.mood_question_moodlevel_textview); mMoodLevelText.setText(mCardsViewPagerMood.getAdapter().getPageTitle(DEFAULT_MOOD_SELECTION)); // Set an OnPageChangeListener to the ViewPager, change the text when a page is selected mCardsViewPagerMood .setOnPageChangeListener(new ViewPageChangeListener(mCardsViewPagerMood, mMoodLevelText)); final LayoutInflater inflater = getLayoutInflater(); LinearLayout buttons = (LinearLayout) findViewById(R.id.mood_question_buttons); // Change the OK button to next button which opens the checking events activity if there are events to check. final Bundle extras = getIntent().getExtras(); if (extras != null && extras.getBoolean(EventDataHandler.EVENTS_TO_CHECK, false)) { Button nextButton = (Button) inflater.inflate(R.layout.element_ok_button, buttons, false); nextButton.setText(getString(R.string.next)); nextButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { saveMood(v); Intent intent = new Intent(MoodQuestionActivity.this, CheckEventsActivity.class); intent.putExtra(MotivatorEvent.YESTERDAYS_EVENTS, extras.getParcelableArrayList(MotivatorEvent.YESTERDAYS_EVENTS)); startActivity(intent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(NotificationService.NOTIFICATION_ID_MOOD); finish(); } }); buttons.addView(nextButton); } else { Button okButton = (Button) inflater.inflate(R.layout.element_ok_button, buttons, false); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { saveMood(v); String toastMsg; if (mCardsViewPagerMood.getCurrentItem() > 2) { toastMsg = getString(R.string.questionnaire_done_toast_good_mood); } else if (mCardsViewPagerMood.getCurrentItem() == 2) { toastMsg = getString(R.string.questionnaire_done_toast_ok_mood); } else { toastMsg = getString(R.string.questionnaire_done_toast_bad_mood); } View toastLayout = (View) inflater.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(toastMsg); toastText.setTextColor(Color.WHITE); Toast questionnaireDone = new Toast(getApplicationContext()); questionnaireDone.setDuration(Toast.LENGTH_SHORT); questionnaireDone.setView(toastLayout); questionnaireDone.show(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(NotificationService.NOTIFICATION_ID_MOOD); finish(); } }); buttons.addView(okButton); } }
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// www . j av a 2s .co 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.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);//from ww w .j a v a 2 s . c o m Toast t = new Toast(this); t.setView(view); t.setDuration(Toast.LENGTH_SHORT); t.setGravity(Gravity.CENTER, 0, 0); t.show(); }
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.apps8os.motivator.ui.CheckEventsActivity.java
/** * Displaying toast after checking events */// www . j a va 2 s . co 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(); }