List of usage examples for android.widget TextView setCompoundDrawablesWithIntrinsicBounds
@android.view.RemotableViewMethod public void setCompoundDrawablesWithIntrinsicBounds(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom)
From source file:com.example.ngu.slidingtablayouticon.Fragment.SlidingTabLayout.java
private void populateTabStrip() { final MyPagerAdapter adapter = (MyPagerAdapter) mViewPager.getAdapter(); final OnClickListener tabClickListener = (OnClickListener) new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;/*from w w w.j ava 2 s. c o m*/ TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } //Set icon, that can be changeable instead setting text. //I think the text also can setting here from getPageTitle func. //But we interesting only in icon tabTitleView.setCompoundDrawablesWithIntrinsicBounds(adapter.getDrawableId(i), 0, 0, 0); //Select tab if it is current if (mViewPager.getCurrentItem() == i) { tabTitleView.setSelected(true); } tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); //cac selector tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector)); } }
From source file:com.hcpt.fastfood.widget.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//w w w . j a v a2 s . c om } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates // between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } canvas.drawRect(lineLeft, 0, lineRight, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, 0, tabsContainer.getWidth(), height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); TextView text = (TextView) tab; Drawable icon = null; // check for not selected if (i != currentPosition) { text.setTextColor(tabTextColor); icon = getResources().getDrawable(arrTabs.get(i).getIcon()); } else { text.setTextColor(selectedTextColor); icon = getResources().getDrawable(arrTabs.get(i).getSelected()); } text.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null); } }
From source file:drose379.ridefundraiser.homeTabs.SlidingTabLayout.java
private void populateTabStrip() { final ViewPagerAdapterHome adapter = (ViewPagerAdapterHome) mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;//w w w. j a v a 2s . co m TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } tabTitleView.setText(adapter.getTabTitle(i)); tabTitleView.setTypeface(TypeHelper.getTypefaceBold(getContext())); tabTitleView.setTextColor(Color.parseColor("#FFFFFF")); tabTitleView.setCompoundDrawablesWithIntrinsicBounds(0, adapter.getDrawableId(i), 0, 0); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); } }
From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java
private void startNavigation(final Context context) { final NavItem[] items = { new NavItem(" " + getString(R.string.nav_oepnv), R.drawable.ic_directions_bus_gray_24px), new NavItem(" " + getString(R.string.nav_car), R.drawable.ic_directions_car_gray_24px), new NavItem(" " + getString(R.string.nav_bike), R.drawable.ic_directions_bike_gray_24px), new NavItem(" " + getString(R.string.nav_walk), R.drawable.ic_directions_walk_gray_24px), new NavItem(" " + getString(R.string.nav_show), R.drawable.ic_info_gray_24px) }; ListAdapter adapter = new ArrayAdapter<NavItem>(this, android.R.layout.select_dialog_item, android.R.id.text1, items) { public View getView(int position, View convertView, ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); //Put the image on the TextView tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f); int dp7 = (int) (20 * getResources().getDisplayMetrics().density); tv.setCompoundDrawablePadding(dp5); tv.setPadding(dp7, 0, 0, 0); return v; }/*from w w w . java2 s .c o m*/ }; AlertDialog.Builder navBuilder = new AlertDialog.Builder(this); navBuilder.setIcon(R.mipmap.ic_launcher); navBuilder.setTitle(R.string.navMethod); navBuilder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int navItem) { String dlocation = ""; Intent intent = null; switch (navItem) { case 0: dlocation = String.format("google.navigation:ll=%s,%s&mode=Transit", bahnhof.getLat(), bahnhof.getLon()); Log.d("findnavigation case 0", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; case 1: dlocation = String.format("google.navigation:ll=%s,%s&mode=d", bahnhof.getLat(), bahnhof.getLon()); Log.d("findnavigation case 1", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; case 2: dlocation = String.format("google.navigation:ll=%s,%s&mode=b", bahnhof.getLat(), bahnhof.getLon()); Log.d("findnavigation case 2", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; case 3: dlocation = String.format("google.navigation:ll=%s,%s&mode=w", bahnhof.getLat(), bahnhof.getLon()); Log.d("findnavigation case 3", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; case 4: dlocation = String.format("geo:0,0?q=%s,%s(%s)", bahnhof.getLat(), bahnhof.getLon(), bahnhof.getTitle()); Log.d("findnavigation case 4", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; } try { startActivity(intent); } catch (Exception e) { Toast toast = Toast.makeText(context, R.string.activitynotfound, Toast.LENGTH_LONG); toast.show(); } } }).show(); }
From source file:drose379.ridefundraiser.eventoverviewtabs.SlidingTabLayout.java
private void populateTabStrip() { final ViewPagerAdapterOverview adapter = (ViewPagerAdapterOverview) mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;//from w w w . j av a2s . c o m TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } tabTitleView.setText(adapter.getTabTitle(i)); tabTitleView.setTypeface(TypeHelper.getTypefaceBold(getContext())); tabTitleView.setTextColor(Color.parseColor("#FFFFFF")); tabTitleView.setCompoundDrawablesWithIntrinsicBounds(0, adapter.getDrawableId(i), 0, 0); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); } }
From source file:com.box.myview.MyTopSnackBar.TSnackbar.java
/** * @param resource_id/* w ww.j a v a2 s . c om*/ * @return */ public TSnackbar addIcon(int resource_id) { final TextView tv = mView.getMessageView(); tv.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().getDrawable(resource_id), null, null, null); return this; }
From source file:de.baumann.hhsmoodle.data_notes.Notes_Fragment.java
public void setNotesList() { if (isFABOpen) { closeFABMenu();//from w ww . ja v a 2 s . co m } //display data final int layoutstyle = R.layout.list_item_notes; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "note_title", "note_content", "note_creation" }; final Cursor row = db.fetchAllData(getActivity()); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title")); final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content")); final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon")); final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment")); final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes); helper_main.switchIcon(getActivity(), note_icon, "note_icon", iv_icon); switch (note_attachment) { case "": iv_attachment.setVisibility(View.GONE); break; default: iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.ic_attachment); break; } File file = new File(note_attachment); if (!file.exists()) { iv_attachment.setVisibility(View.GONE); } iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green), new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), note_title, note_content, "3", note_attachment, note_creation); setNotesList(); } else if (item == 1) { db.update(Integer.parseInt(_id), note_title, note_content, "2", note_attachment, note_creation); setNotesList(); } else if (item == 2) { db.update(Integer.parseInt(_id), note_title, note_content, "1", note_attachment, note_creation); setNotesList(); } } }).show(); } }); iv_attachment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { helper_main.openAtt(getActivity(), lv, note_attachment); } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_noteBY", "note_title"); sharedPref.edit().putString("filter_noteBY", "note_title").apply(); filter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { if (isFABOpen) { closeFABMenu(); } Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title")); final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content")); final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon")); final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment")); final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation")); final Button attachment; final TextView textInput; LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; final View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent); final String attName = note_attachment.substring(note_attachment.lastIndexOf("/") + 1); final String att = getString(R.string.app_att) + ": " + attName; attachment = (Button) dialogView.findViewById(R.id.button_att); if (attName.equals("")) { attachment.setVisibility(View.GONE); } else { attachment.setText(att); } textInput = (TextView) dialogView.findViewById(R.id.note_text_input); if (note_content.isEmpty()) { textInput.setVisibility(View.GONE); } else { textInput.setText(note_content); Linkify.addLinks(textInput, Linkify.WEB_URLS); } attachment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { helper_main.openAtt(getActivity(), textInput, note_attachment); } }); final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri); final ImageView attImage = (ImageView) dialogView.findViewById(R.id.attImage); File file2 = new File(note_attachment); if (!file2.exists()) { attachment.setVisibility(View.GONE); attImage.setVisibility(View.GONE); } else if (note_attachment.contains(".gif") || note_attachment.contains(".bmp") || note_attachment.contains(".tiff") || note_attachment.contains(".png") || note_attachment.contains(".jpg") || note_attachment.contains(".JPG") || note_attachment.contains(".jpeg") || note_attachment.contains(".mpeg") || note_attachment.contains(".mp4") || note_attachment.contains(".3gp") || note_attachment.contains(".3g2") || note_attachment.contains(".avi") || note_attachment.contains(".flv") || note_attachment.contains(".h261") || note_attachment.contains(".h263") || note_attachment.contains(".h264") || note_attachment.contains(".asf") || note_attachment.contains(".wmv")) { attImage.setVisibility(View.VISIBLE); try { Glide.with(getActivity()).load(note_attachment) // or URI/path .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(attImage); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); attImage.setVisibility(View.GONE); } attImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { helper_main.openAtt(getActivity(), attImage, note_attachment); } }); } switch (note_icon) { case "3": be.setImageResource(R.drawable.circle_green); break; case "2": be.setImageResource(R.drawable.circle_yellow); break; case "1": be.setImageResource(R.drawable.circle_red); break; } android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(getActivity()) .setTitle(note_title).setView(dialogView) .setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sharedPref.edit().putString("handleTextTitle", note_title) .putString("handleTextText", note_content) .putString("handleTextIcon", note_icon).putString("handleTextSeqno", _id) .putString("handleTextAttachment", note_attachment) .putString("handleTextCreate", note_creation).apply(); helper_main.switchToActivity(getActivity(), Activity_EditNote.class, false); } }); dialog.show(); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (isFABOpen) { closeFABMenu(); } Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title")); final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content")); final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon")); final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment")); final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share), getString(R.string.todo_menu), getString(R.string.count_create), getString(R.string.bookmark_createEvent) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { Notes_helper.newNote(getActivity(), note_title, note_content, note_icon, note_attachment, note_creation, _id); } if (options[item].equals(getString(R.string.todo_share))) { File attachment = new File(note_attachment); Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, note_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, note_content); if (attachment.exists()) { Uri bmpUri = Uri.fromFile(attachment); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); } startActivity(Intent.createChooser(sharingIntent, (getString(R.string.note_share_2)))); } if (options[item].equals(getString(R.string.todo_menu))) { Todo_helper.newTodo(getActivity(), note_title, note_content, getActivity().getString(R.string.note_content)); } if (options[item].equals(getString(R.string.count_create))) { Count_helper.newCount(getActivity(), note_title, note_content, getActivity().getString(R.string.note_content), false); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), note_title, note_content); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setNotesList(); } }); snackbar.show(); } } }).show(); return true; } }); }
From source file:pageslidingtabstrip.ConsumingPagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { if (!isDoubleTab) { View v = View.inflate(getContext(), R.layout.tab_desc, null); TextView text = (TextView) v.findViewById(R.id.text); if (iconShowDirection != -1 && positions != null && iconIds != null && positions.length == iconIds.length) { for (int index : positions) { if (index == position) { if (iconShowDirection == LEFT) { text.setCompoundDrawablesWithIntrinsicBounds(iconIds[index], 0, 0, 0); } else { text.setCompoundDrawablesWithIntrinsicBounds(0, 0, iconIds[index], 0); }/*w ww. j av a2 s. com*/ text.setCompoundDrawablePadding(CommonTools.dip2px(context, 5)); break; } } } text.setText(title); addTab(position, v); } else { View view = View.inflate(getContext(), R.layout.layout_text_tab, null); TextView classname = (TextView) view.findViewById(R.id.classname); TextView schoolname = (TextView) view.findViewById(R.id.schoolname); if (title.contains(";")) { String[] strs = title.split(";"); schoolname.setText(strs[0]); classname.setText(strs[1]); addTab(position, view); } else { classname.setText(title.substring(0, title.indexOf("("))); schoolname.setText(title.substring(title.indexOf("(") + 1, title.indexOf(")"))); addTab(position, view); } } }
From source file:org.telegram.ui.ChatProfileActivity.java
@Override public void applySelfActionBar() { if (parentActivity == null) { return;//from ww w .j a v a2 s. co m } ActionBar actionBar = parentActivity.getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayShowCustomEnabled(false); actionBar.setCustomView(null); actionBar.setTitle(getStringEntry(R.string.GroupInfo)); actionBar.setSubtitle(null); TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title); if (title == null) { final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); title = (TextView) parentActivity.findViewById(subtitleId); } if (title != null) { title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); title.setCompoundDrawablePadding(0); } ((ApplicationActivity) parentActivity).fixBackButton(); }
From source file:com.zitech.framework.widget.SlidingTabs.java
/** * add text view type of tab/*from w ww. jav a 2 s . c o m*/ * <p/> * you can set the text view attribute in here * * @param position position * @param title title * @param start start * @param top top * @param end end * @param bottom bottom */ private void addTextTab(final int position, SpannableString title, int start, int top, int end, int bottom) { TextView tab = new TextView(getContext()); tab.setText(title); tab.setGravity(Gravity.CENTER); // You can set the text view single line // tab.setSingleLine(); tab.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); tab.setLineSpacing(8, 1.0f); addTab(position, tab); }