List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:com.sender.team.sender.gcm.MyGcmListenerService.java
private void sendToast(final ChattingReceiveData data, final ChattingReceiveMessage c) { handler.post(new Runnable() { @Override/* www .j a va2s . 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:biz.incomsystems.fwknop2.ConfigDetailFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // This handles the qrcode results if (requestCode == 0) { if (resultCode == Activity.RESULT_OK) { String contents = data.getStringExtra("SCAN_RESULT"); for (String stanzas : contents.split(" ")) { String[] tmp = stanzas.split(":"); if (tmp[0].equalsIgnoreCase("KEY_BASE64")) { txt_KEY.setText(tmp[1]); chkb64key.setChecked(true); } else if (tmp[0].equalsIgnoreCase("KEY")) { txt_KEY.setText(tmp[1]); chkb64key.setChecked(false); } else if (tmp[0].equalsIgnoreCase("HMAC_KEY_BASE64")) { txt_HMAC.setText(tmp[1]); chkb64hmac.setChecked(true); } else if (tmp[0].equalsIgnoreCase("HMAC_KEY")) { txt_HMAC.setText(tmp[1]); chkb64hmac.setChecked(false); }//from w w w.j a v a 2 s. c o m } // end for loop } if (resultCode == Activity.RESULT_CANCELED) { //handle cancel Context context = getActivity(); CharSequence text = " QR Code Canceled"; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout toastLayout = (LinearLayout) toast.getView(); TextView toastTV = (TextView) toastLayout.getChildAt(0); toastTV.setTextSize(30); toast.show(); } } }
From source file:org.codeforafrica.citizenreporter.eNCA.widgets.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); boolean showIcons = (mIcons != null && mIcons.length == adapter.getCount() && mTabViewIconViewId != 0); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;//from w w w . j ava 2s.co m //if (showIcons) { tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); ImageView imgIcon = (ImageView) tabView.findViewById(mTabViewIconViewId); imgIcon.setImageDrawable(getContext().getResources().getDrawable(mIcons[i])); TextView tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); tabTitleView.setText(getContext().getResources().getString(mTitles[i])); // tag the badge for this tab so it can be found by setBadge() //if (mTabBadgeViewId != 0) { // View badgeView = tabView.findViewById(mTabBadgeViewId); // if (badgeView != null) { // badgeView.setTag(makeBadgeTag(i)); // } // } //} /*else { TextView tabTitleView = null; if (mTabViewLayoutId != 0) { tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } else { tabView = createDefaultTabView(getContext()); tabTitleView = (TextView) tabView; } if (tabTitleView != null) { if(mTitles!=null) { tabTitleView.setText(getContext().getResources().getString(mTitles[i])); } } }*/ if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabView.setOnClickListener(tabClickListener); final String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); // show toast with content description on long click tabView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { int offsetX = v.getLeft(); int offsetY = v.getTop() + v.getHeight() + (v.getHeight() / 2); Toast toast = Toast.makeText(v.getContext(), desc, Toast.LENGTH_SHORT); toast.setGravity(Gravity.LEFT | Gravity.TOP, offsetX, offsetY); toast.show(); return true; } }); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
From source file:com.simplelife.seeds.android.utils.gridview.gridviewui.ImageGridFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_addto_fav: { mFavItem = item;/*from w ww . ja v a 2 s . co m*/ addOrCancelFromFavList(item); return true; } case R.id.rss_addtocart: { int tShowId; if (!SeedsRSSList.addSeedToCart(mSeedLocalId)) tShowId = R.string.seeds_rss_toast_addtocartnonecc; else tShowId = R.string.seeds_rss_toast_addtocartdone; Toast toast = Toast.makeText(getActivity(), tShowId, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } case R.id.rss_management: { Intent intent = new Intent(getActivity(), SeedsRSSCartActivity.class); startActivity(intent); return true; } case R.id.download_seed: { // Fetch the download manager to start the download DownloadManager tDownloadMgr = DownloadManager.getDownloadMgr(getActivity().getContentResolver(), getActivity().getPackageName()); tDownloadMgr.startDownload(Images.getSeedsEntity().getSeedTorrentLink(), Images.getSeedsEntity().getSeedPublishDate(), Images.getSeedsEntity().getSeedName()); Toast toast = Toast.makeText(getActivity(), R.string.seeds_download_added, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } case R.id.download_mgt: { Intent intent = new Intent(getActivity(), DownloadList.class); startActivity(intent); return true; } case R.id.clear_cache: { mImageFetcher.clearCache(); Toast.makeText(getActivity(), R.string.clear_cache_complete_toast, Toast.LENGTH_SHORT).show(); return true; } } return true; }
From source file:com.kubotaku.android.code4kyoto5374.fragments.HomeSelectFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_PLACE_PICKER) { if (resultCode == Activity.RESULT_OK) { this.pickedPlace = PlacePicker.getPlace(getContext(), data); if (this.pickedPlace != null) { String address = this.pickedPlace.getAddress().toString(); final String city = AreaUtil.parseCity(address); final String ward = AreaUtil.parseWard(address); final String town = AreaUtil.parseTown(address); if (AreaUtil.isValidCity(city)) { boolean existAreaDays = false; final RealmResults<AreaMaster> areaMasterResult = realm.where(AreaMaster.class) .equalTo("areaName", ward).findAll(); if (areaMasterResult.size() != 0) { final AreaMaster areaMaster = areaMasterResult.first(); final RealmResults<AreaDays> areaDaysResult = realm.where(AreaDays.class) .equalTo("masterAreaID", areaMaster.areaID).contains("areaName", town) .findAll(); if (areaDaysResult.size() > 0) { showPlaceSelector(areaDaysResult); this.areaDaysResults = areaDaysResult; existAreaDays = true; }// w ww .ja v a2 s . c o m } if (!existAreaDays) { final TextView textAreaDays = (TextView) getView() .findViewById(R.id.text_selected_area_days); textAreaDays.setText( "?????????????????"); } address = city + ward + town; } else { // ???? final Toast toast = Toast.makeText(getContext(), "?????????", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } TextView textName = (TextView) getView().findViewById(R.id.text_selected_place); textName.setText(address); } } } super.onActivityResult(requestCode, resultCode, data); }
From source file:saphion.pageindicators.FixedTabsView.java
/** * Initialize and add all tabs to the layout *//*from w w w . j ava2 s. c o m*/ 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: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);/* w w w .ja v a2s. c om*/ 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:com.uproot.trackme.LocationActivity.java
public void Toast(String s, int Xoff, int Yoff) { Context context = getApplicationContext(); CharSequence text = s;/* w w w. j a v a 2s . co m*/ int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.TOP | Gravity.LEFT, Xoff, Yoff); toast.show(); }
From source file:xj.property.activity.HXBaseActivity.HXBaseActivity.java
/** * Toast ,, ?.//from w ww . ja v a2 s . c om * * @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:own.projects.lemiroapp.GameModeActivity.java
protected void showToast(String text) { Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, 0, 0); toast.show();/* w w w. ja v a 2 s. c o m*/ }