List of usage examples for android.widget TextView setCompoundDrawables
public void setCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom)
From source file:com.google.android.gms.samples.wallet.CartDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_cart_detail, container, false); ItemInfo itemInfo = Constants.ITEMS_FOR_SALE[mItemId]; TextView itemName = (TextView) view.findViewById(R.id.text_item_name); itemName.setText(itemInfo.name);//from w ww.j a v a2 s .co m Drawable itemImage = getResources().getDrawable(itemInfo.imageResourceId); int imageSize = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size); int actualWidth = itemImage.getIntrinsicWidth(); int actualHeight = itemImage.getIntrinsicHeight(); int scaledHeight = imageSize; int scaledWidth = (int) (((float) actualWidth / actualHeight) * scaledHeight); itemImage.setBounds(0, 0, scaledWidth, scaledHeight); itemName.setCompoundDrawables(itemImage, null, null, null); TextView itemPrice = (TextView) view.findViewById(R.id.text_item_price); itemPrice.setText(Util.formatPrice(getActivity(), itemInfo.priceMicros)); TextView shippingCost = (TextView) view.findViewById(R.id.text_shipping_price); TextView tax = (TextView) view.findViewById(R.id.text_tax_price); TextView total = (TextView) view.findViewById(R.id.text_total_price); if ((mItemId == Constants.PROMOTION_ITEM) && getApplication().isAddressValidForPromo()) { shippingCost.setText(Util.formatPrice(getActivity(), 0L)); } else { shippingCost.setText(Util.formatPrice(getActivity(), itemInfo.shippingPriceMicros)); } tax.setText(Util.formatPrice(getActivity(), itemInfo.taxMicros)); total.setText(Util.formatPrice(getActivity(), itemInfo.getTotalPrice())); return view; }
From source file:com.kaku.weac.activities.MainActivity.java
/** * Tab/*w w w .jav a2 s. com*/ * * @param iconId Tab * @param textView Tab * @param color Tab */ private void setTextView(int iconId, TextView textView, int color) { @SuppressWarnings("deprecation") Drawable drawable = getResources().getDrawable(iconId); if (drawable != null) { drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); // textView.setCompoundDrawables(null, drawable, null, null); } // textView.setTextColor(color); }
From source file:org.onebusaway.android.ui.TripResultsFragment.java
private void setTabDrawable(TabLayout.Tab tab, @DrawableRes int res) { View view = tab.getCustomView(); TextView tv = ((TextView) view.findViewById(android.R.id.text1)); Drawable drawable = getResources().getDrawable(res); int dp = (int) getResources().getDimension(R.dimen.trip_results_icon_size); drawable.setBounds(0, 0, dp, dp);//from ww w .j a v a2 s .c o m drawable.setColorFilter(getResources().getColor(R.color.trip_option_icon_tint), PorterDuff.Mode.SRC_IN); tv.setCompoundDrawables(drawable, null, null, null); }
From source file:com.open.file.manager.MainActivity.java
/** * Show info dialog for file//from www . java 2s. c o m * @param file */ protected void getFileInfo(File file) { IconLoader loader = new IconLoader(actcontext); AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View infodialogview = inflater.inflate(R.layout.fileinfo, null); builder.setView(infodialogview); builder.setTitle(R.string.info); TextView infotv = (TextView) infodialogview.findViewById(R.id.infofile); infotv.setText(operator.getfileinfo(file)); infotv.setCompoundDrawables(null, loader.loadConflictico(file), null, null); builder.setPositiveButton("OK", null); builder.create().show(); }
From source file:com.open.file.manager.MainActivity.java
/** * Show current conflict in a dialog//from w w w .j a v a 2s .c o m * @param conflict * @return the builder for the dialog */ public Builder showConflictdialog(FileDuplicate conflict) { AlertDialog.Builder builder; File src = conflict.src; File dst = conflict.dst; IconLoader loader = new IconLoader(actcontext); if (conflict.type == Consts.CONFLICT_FILE_DIR) { String fileordir, filename, messageformat, messagetxt; if (dst.isDirectory()) { fileordir = "directory"; } else { fileordir = "file"; } filename = src.getName(); messageformat = getResources().getString(R.string.filefolderconflict); messagetxt = String.format(messageformat, fileordir, filename); builder = getTextDialog(messagetxt, filename); } else { builder = new AlertDialog.Builder(this); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View askdialogview = inflater.inflate(R.layout.conflictdialog, null); builder.setView(askdialogview); builder.setTitle(R.string.duplicatefound); TextView srcdescr = (TextView) askdialogview.findViewById(R.id.srcdescr); srcdescr.setText(operator.getfileinfo(src)); srcdescr.setCompoundDrawables(null, loader.loadConflictico(src), null, null); TextView dstdescr = (TextView) askdialogview.findViewById(R.id.dstdescr); dstdescr.setText(operator.getfileinfo(dst)); dstdescr.setCompoundDrawables(null, loader.loadConflictico(dst), null, null); CheckBox overwriteall = (CheckBox) askdialogview.findViewById(R.id.overwritecheck); overwriteall.setText(R.string.overwritefile); } return builder; }
From source file:com.android.launcher3.Hotseat.java
void resetLayout() { mContent.removeAllViewsInLayout();//from w w w . ja v a 2s . c om if (!FeatureFlags.NO_ALL_APPS_ICON) { // Add the Apps button Context context = getContext(); int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank(); LayoutInflater inflater = LayoutInflater.from(context); TextView allAppsButton = (TextView) inflater.inflate(R.layout.all_apps_button, mContent, false); Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon); mLauncher.resizeIconDrawable(d); int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down); Rect bounds = d.getBounds(); d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx, bounds.bottom - scaleDownPx / 2); allAppsButton.setCompoundDrawables(null, d, null, null); allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label)); allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener()); if (mLauncher != null) { mLauncher.setAllAppsButton(allAppsButton); allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); allAppsButton.setOnClickListener(mLauncher); allAppsButton.setOnLongClickListener(mLauncher); allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler); } // Note: We do this to ensure that the hotseat is always laid out in the orientation of // the hotseat in order regardless of which orientation they were added int x = getCellXFromOrder(allAppsButtonRank); int y = getCellYFromOrder(allAppsButtonRank); CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1); lp.canReorder = false; mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true); } }
From source file:org.ohmage.app.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mNavigationItems = getResources().getStringArray(R.array.navigation_items); mNavigationIcons = getResources().obtainTypedArray(R.array.navigation_icons); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the list view ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_activated_1, mNavigationItems) {/* w w w . ja va 2 s. c o m*/ @Override public View getView(int position, View convertView, ViewGroup parent) { // Set the left drawable of the text view to be the icon for that item TextView view = (TextView) super.getView(position, convertView, parent); Drawable d = getResources().getDrawable(mNavigationIcons.getResourceId(position, -1)); if (d != null && view != null) { int bounds = getResources().getDimensionPixelSize(R.dimen.navigation_icon_bounds); d.setBounds(0, 0, bounds, bounds); view.setCompoundDrawables(d, null, null, null); } return view; } }; mDrawerList.setAdapter(adapter); // Set the list's click listener mDrawerList.setOnItemClickListener(this); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close); // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); if (savedInstanceState == null) { if (getIntent().getBooleanExtra(EXTRA_VIEW_STREAMS, false)) { setFragment(getString(R.string.streams)); } else { if (!handleNewIntent(getIntent())) { setFragment(0); } } } }
From source file:com.smartcodeunited.demo.bluetooth.activity.BaseActivity.java
/** * @param view//w ww . ja va 2s . c om * @param position To the left of the image position 0 and 1 on the right side * @param textResId * @param drawableResId */ private void setButton(View view, int position, int textResId, int drawableResId) { if (view != null) { if (view instanceof TextView) { TextView tv = (TextView) view; if (textResId > 0) { tv.setText(textResId); } else { tv.setText(""); } if (drawableResId > 0) { Drawable drawable = getCompondDrawable(drawableResId); if (position == 0) { tv.setCompoundDrawables(drawable, null, null, null); } else { tv.setCompoundDrawables(null, null, drawable, null); } } else { tv.setCompoundDrawables(null, null, null, null); } } else if (view instanceof ImageView) { ImageView iv = (ImageView) view; if (drawableResId > 0) { iv.setImageResource(drawableResId); } else { iv.setImageDrawable(null); } } } }
From source file:in.shick.diode.common.Common.java
/** * Helper function to display a list of URLs. * @param theContext The current application context. * @param settings The settings to use regarding the browser component. * @param theItem The ThingInfo item to get URLs from. *//*from w w w . j a va2s . c om*/ public static void showLinksDialog(final Context theContext, final RedditSettings settings, final ThingInfo theItem) { assert (theContext != null); assert (theItem != null); assert (settings != null); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<MarkdownURL> vtUrls = theItem.getUrls(); for (MarkdownURL vtUrl : vtUrls) { urls.add(vtUrl.url); } ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(theContext, android.R.layout.select_dialog_item, vtUrls) { public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { tv = (TextView) ((LayoutInflater) theContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(android.R.layout.select_dialog_item, null); } else { tv = (TextView) convertView; } String url = getItem(position).url; String anchorText = getItem(position).anchorText; // if (Constants.LOGGING) Log.d(TAG, "links url="+url + " anchorText="+anchorText); Drawable d = null; try { d = theContext.getPackageManager() .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (PackageManager.NameNotFoundException ignore) { } if (d != null) { d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight()); tv.setCompoundDrawablePadding(10); tv.setCompoundDrawables(d, null, null, null); } final String telPrefix = "tel:"; if (url.startsWith(telPrefix)) { url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length())); } if (anchorText != null) tv.setText(Html.fromHtml("<span>" + anchorText + "</span><br /><small>" + url + "</small>")); else tv.setText(Html.fromHtml(url)); return tv; } }; AlertDialog.Builder b = new AlertDialog.Builder( new ContextThemeWrapper(theContext, settings.getDialogTheme())); DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { if (which >= 0) { Common.launchBrowser(settings, theContext, urls.get(which), Util.createThreadUri(theItem).toString(), false, false, settings.isUseExternalBrowser(), settings.isSaveHistory()); } } }; b.setTitle(R.string.select_link_title); b.setCancelable(true); b.setAdapter(adapter, click); b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); b.show(); }
From source file:nl.privacybarometer.privacyvandaag.adapter.FeedsCursorAdapter.java
@Override protected void bindChildView(View view, Context context, Cursor cursor) { view.findViewById(R.id.indicator).setVisibility(View.INVISIBLE); TextView textView = ((TextView) view.findViewById(android.R.id.text1)); // if FetchMode is 99 then DO-NOT-REFRESH feed channel. activeFeedChannel = false; boolean activeFeedChannel = !(cursor.getInt(mFetchModePos) == FETCHMODE_DO_NOT_FETCH); // Use icons in package instead of fetching favicons from internet. See comment below. Drawable mDrawable;/*from w w w . ja va 2s. c o m*/ int mIconResourceId = cursor.getInt(mIconId); if (mIconResourceId > 0) { mDrawable = ContextCompat.getDrawable(context, mIconResourceId); } else { mDrawable = ContextCompat.getDrawable(context, R.drawable.logo_icon_pv); } mDrawable.setBounds(0, 0, 50, 50); // define the size of the drawable textView.setCompoundDrawables(mDrawable, null, null, null); // Code not needed since we no longer use favicons retrieved from the internet, //but use the logo's included in the resource directory of the app using the code above. /* final long feedId = cursor.getLong(mIdPos); Bitmap bitmap = UiUtils.getFaviconBitmap(feedId, cursor, mIconPos); if ((bitmap != null) && (activeFeedChannel)) { // if a favicon is available, show it next to the feed name. textView.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(context.getResources(), bitmap), null, null, null); } else { textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } */ textView.setText((cursor.isNull(mNamePos) ? cursor.getString(mLinkPos) : cursor.getString(mNamePos))); // if FetchMode is 99 then DO-NOT-REFRESH is active. Add remark and change style if (activeFeedChannel) { textView.setTextColor(ACTIVE_TEXT_COLOR); } else { // inactive feed channel. Is not refreshed. textView.append(" - niet volgen"); textView.setTextColor(DO_NOT_FETCH_COLOR_TEXT_COLOR); } }