List of usage examples for android.widget TextView setCompoundDrawablesRelativeWithIntrinsicBounds
@android.view.RemotableViewMethod public void setCompoundDrawablesRelativeWithIntrinsicBounds(@Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom)
From source file:Main.java
/** * @see android.widget.TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(int, int, int, * int)//from w ww . ja va 2 s. c o m */ public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView, int start, int top, int end, int bottom) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, bottom, end); } else { textView.setCompoundDrawablesWithIntrinsicBounds(start, top, bottom, end); } }
From source file:Main.java
/** * @see android.widget.TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable, * Drawable, Drawable, Drawable)//from www. j a v a 2s . c o m */ public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView, Drawable start, Drawable top, Drawable end, Drawable bottom) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, bottom, end); } else { textView.setCompoundDrawablesWithIntrinsicBounds(start, top, bottom, end); } }
From source file:nl.sebastiaanschool.contact.app.gui.GrabBag.java
/** * Apply a vector drawable, using backwards compatibility as needed. This throws an exception * if your {@code resId} is actually a bitmap drawable. *///from w w w.jav a 2s.c om public static void applyVectorDrawableLeft(TextView view, @DrawableRes int resId) { if (Build.VERSION.SDK_INT >= 21) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0); view.getCompoundDrawablesRelative()[0].setTint(ResourcesCompat.getColor(view.getResources(), R.color.sebastiaan_blue, view.getContext().getTheme())); } else { final Context context = view.getContext(); final Drawable drawable = loadVectorDrawable(context, resId); if (Build.VERSION.SDK_INT >= 17) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null); } else { view.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } } }
From source file:com.silentcircle.common.util.ViewUtil.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private static void setDrawableStartForReal(TextView view, int drawableResourceID) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(drawableResourceID, 0, 0, 0); }
From source file:Main.java
/** * @see android.widget.TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(int, int, int, * int)//w w w . ja v a 2s. c om */ public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView, int start, int top, int end, int bottom) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { // Work around the platform bug described in setCompoundDrawablesRelative() above. boolean isRtl = isLayoutRtl(textView); textView.setCompoundDrawablesWithIntrinsicBounds(isRtl ? end : start, top, isRtl ? start : end, bottom); } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom); } else { textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); } }
From source file:com.google.android.apps.forscience.whistlepunk.metadata.TriggerHelper.java
public static void populateAutoTextViews(TextView autoTextView, String autoText, int drawableId, Resources res) {/*from www.j av a2 s. co m*/ autoTextView.setText(autoText); autoTextView .setContentDescription(res.getString(R.string.trigger_label_icon_content_description, autoText)); Drawable drawable = res.getDrawable(drawableId); DrawableCompat.setTint(drawable.mutate(), res.getColor(R.color.text_color_light_grey)); autoTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null); }
From source file:Main.java
/** * @see android.widget.TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable, * Drawable, Drawable, Drawable)/* w ww. j ava2 s . c o m*/ */ public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView, Drawable start, Drawable top, Drawable end, Drawable bottom) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { // Work around the platform bug described in setCompoundDrawablesRelative() above. boolean isRtl = isLayoutRtl(textView); textView.setCompoundDrawablesWithIntrinsicBounds(isRtl ? end : start, top, isRtl ? start : end, bottom); } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom); } else { textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); } }
From source file:org.odk.collect.android.adapters.IconMenuListAdapter.java
private void refreshView(IconMenuItem item, TextView convertView) { convertView.setText(item.getTextResId()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { convertView.setCompoundDrawablesRelativeWithIntrinsicBounds(item.getImageResId(), 0, 0, 0); } else {//from w ww .j a va 2s . c o m if (ViewCompat.getLayoutDirection(convertView) == ViewCompat.LAYOUT_DIRECTION_LTR) { convertView.setCompoundDrawablesWithIntrinsicBounds(item.getImageResId(), 0, 0, 0); } else { convertView.setCompoundDrawablesWithIntrinsicBounds(0, 0, item.getImageResId(), 0); } } }
From source file:com.androidinspain.deskclock.DeskClock.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.desk_clock); mSnackbarAnchor = findViewById(R.id.content); // Configure the toolbar. final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w ww .j a v a2 s .c o m*/ final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayShowTitleEnabled(false); } // Configure the menu item controllers add behavior to the toolbar. mOptionsMenuManager.addMenuItemController(new NightModeMenuItemController(this), new SettingsMenuItemController(this)); mOptionsMenuManager .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this)); // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu // inflation occurs *after* the initial draw and a second layout pass adds in the menu. onCreateOptionsMenu(toolbar.getMenu()); // Create the tabs that make up the user interface. mTabLayout = (TabLayout) findViewById(R.id.tabs); final int tabCount = UiDataModel.getUiDataModel().getTabCount(); final boolean showTabLabel = getResources().getBoolean(R.bool.showTabLabel); final boolean showTabHorizontally = getResources().getBoolean(R.bool.showTabHorizontally); for (int i = 0; i < tabCount; i++) { final UiDataModel.Tab tabModel = UiDataModel.getUiDataModel().getTab(i); final @StringRes int labelResId = tabModel.getLabelResId(); final TabLayout.Tab tab = mTabLayout.newTab().setTag(tabModel).setIcon(tabModel.getIconResId()) .setContentDescription(labelResId); if (showTabLabel) { tab.setText(labelResId); tab.setCustomView(R.layout.tab_item); @SuppressWarnings("ConstantConditions") final TextView text = (TextView) tab.getCustomView().findViewById(android.R.id.text1); text.setTextColor(mTabLayout.getTabTextColors()); // Bind the icon to the TextView. final Drawable icon = tab.getIcon(); if (showTabHorizontally) { // Remove the icon so it doesn't affect the minimum TabLayout height. tab.setIcon(null); text.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null, null, null); } else { text.setCompoundDrawablesRelativeWithIntrinsicBounds(null, icon, null, null); } } mTabLayout.addTab(tab); } // Configure the buttons shared by the tabs. mFab = (ImageView) findViewById(R.id.fab); mLeftButton = (Button) findViewById(R.id.left_button); mRightButton = (Button) findViewById(R.id.right_button); mFab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onFabClick(mFab); } }); mLeftButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onLeftButtonClick(mLeftButton); } }); mRightButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onRightButtonClick(mRightButton); } }); final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final ValueAnimator hideFabAnimation = getScaleAnimator(mFab, 1f, 0f); final ValueAnimator showFabAnimation = getScaleAnimator(mFab, 0f, 1f); final ValueAnimator leftHideAnimation = getScaleAnimator(mLeftButton, 1f, 0f); final ValueAnimator rightHideAnimation = getScaleAnimator(mRightButton, 1f, 0f); final ValueAnimator leftShowAnimation = getScaleAnimator(mLeftButton, 0f, 1f); final ValueAnimator rightShowAnimation = getScaleAnimator(mRightButton, 0f, 1f); hideFabAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { getSelectedDeskClockFragment().onUpdateFab(mFab); } }); leftHideAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { getSelectedDeskClockFragment().onUpdateFabButtons(mLeftButton, mRightButton); } }); // Build the reusable animations that hide and show the fab and left/right buttons. // These may be used independently or be chained together. mHideAnimation.setDuration(duration).play(hideFabAnimation).with(leftHideAnimation) .with(rightHideAnimation); mShowAnimation.setDuration(duration).play(showFabAnimation).with(leftShowAnimation) .with(rightShowAnimation); // Build the reusable animation that hides and shows only the fab. mUpdateFabOnlyAnimation.setDuration(duration).play(showFabAnimation).after(hideFabAnimation); // Build the reusable animation that hides and shows only the buttons. mUpdateButtonsOnlyAnimation.setDuration(duration).play(leftShowAnimation).with(rightShowAnimation) .after(leftHideAnimation).after(rightHideAnimation); // Customize the view pager. mFragmentTabPagerAdapter = new FragmentTabPagerAdapter(this); mFragmentTabPager = (ViewPager) findViewById(R.id.desk_clock_pager); // Keep all four tabs to minimize jank. mFragmentTabPager.setOffscreenPageLimit(3); // Set Accessibility Delegate to null so view pager doesn't intercept movements and // prevent the fab from being selected. mFragmentTabPager.setAccessibilityDelegate(null); // Mirror changes made to the selected page of the view pager into UiDataModel. mFragmentTabPager.addOnPageChangeListener(new PageChangeWatcher()); mFragmentTabPager.setAdapter(mFragmentTabPagerAdapter); // Mirror changes made to the selected tab into UiDataModel. mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { UiDataModel.getUiDataModel().setSelectedTab((UiDataModel.Tab) tab.getTag()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); // Honor changes to the selected tab from outside entities. UiDataModel.getUiDataModel().addTabListener(mTabChangeWatcher); }
From source file:com.google.android.apps.forscience.whistlepunk.EditNoteDialog.java
@Override public AlertDialog onCreateDialog(Bundle savedInstanceState) { mLabel = getArguments().getParcelable(KEY_SAVED_LABEL); String timeText = getArguments().getString(KEY_SAVED_TIME_TEXT, ""); String timeTextContentDescription = getArguments().getString(KEY_SAVED_TIME_TEXT_DESCRIPTION); mTimestamp = getArguments().getLong(KEY_SAVED_TIMESTAMP); try {// w w w.j ava 2s . co m mSelectedValue = GoosciLabelValue.LabelValue.parseFrom(getArguments().getByteArray(KEY_SELECTED_VALUE)); } catch (InvalidProtocolBufferNanoException ex) { Log.wtf(TAG, "Couldn't parse label value"); } AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); LinearLayout rootView = (LinearLayout) LayoutInflater.from(getActivity()) .inflate(R.layout.run_review_label_edit, null); alertDialog.setView(rootView); ImageView imageView = (ImageView) rootView.findViewById(R.id.picture_note_preview_image); final EditText editText = (EditText) rootView.findViewById(R.id.edit_note_text); TextView autoTextView = (TextView) rootView.findViewById(R.id.auto_note_text); // Use mSelectedValue to load content, because the user may have changed the value since // it was stored in the label. Note that picture labels can't be edited at this time, // but in the future this will apply to picture labels as well. if (mLabel instanceof PictureLabel) { imageView.setVisibility(View.VISIBLE); autoTextView.setVisibility(View.GONE); editText.setText(PictureLabel.getCaption(mSelectedValue)); editText.setHint(R.string.picture_note_caption_hint); Glide.with(getActivity()).load(PictureLabel.getFilePath(mSelectedValue)).into(imageView); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PictureUtils.launchExternalViewer(getActivity(), (PictureLabel.getFilePath(mSelectedValue))); } }); } else if (mLabel instanceof TextLabel) { imageView.setVisibility(View.GONE); autoTextView.setVisibility(View.GONE); editText.setText(TextLabel.getText(mSelectedValue)); } else if (mLabel instanceof SensorTriggerLabel) { imageView.setVisibility(View.GONE); autoTextView.setVisibility(View.VISIBLE); editText.setText(SensorTriggerLabel.getCustomText(mSelectedValue)); String autoText = SensorTriggerLabel.getAutogenText(mSelectedValue); TriggerHelper.populateAutoTextViews(autoTextView, autoText, R.drawable.ic_label_black_24dp, getResources()); } alertDialog.setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mLabel.setTimestamp(mTimestamp); if (mLabel instanceof TextLabel) { ((TextLabel) mLabel).setText(editText.getText().toString()); } else if (mLabel instanceof PictureLabel) { ((PictureLabel) mLabel).setCaption(editText.getText().toString()); } else if (mLabel instanceof SensorTriggerLabel) { ((SensorTriggerLabel) mLabel).setCustomText(editText.getText().toString()); } getDataController().editLabel(mLabel, ((EditNoteDialogListener) getParentFragment()).onLabelEdit(mLabel)); } }); alertDialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.setCancelable(true); TextView timeTextView = (TextView) rootView.findViewById(R.id.edit_note_time); timeTextView.setText(timeText); timeTextView.setContentDescription(timeTextContentDescription); if (labelBelongsToRun() && mLabel.canEditTimestamp()) { timeTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { GoosciLabelValue.LabelValue value = new GoosciLabelValue.LabelValue(); if (mLabel instanceof PictureLabel) { // Captions can be edited, but the picture path cannot be edited at this // time. PictureLabel.populateStorageValue(value, ((PictureLabel) mLabel).getFilePath(), editText.getText().toString()); ((EditNoteDialogListener) getParentFragment()).onEditNoteTimestampClicked(mLabel, value, mTimestamp); } else if (mLabel instanceof TextLabel) { TextLabel.populateStorageValue(value, editText.getText().toString()); ((EditNoteDialogListener) getParentFragment()).onEditNoteTimestampClicked(mLabel, value, mTimestamp); } } }); } else if (labelBelongsToRun()) { Drawable lockDrawable = getResources().getDrawable(R.drawable.ic_lock_black_18dp); DrawableCompat.setTint(lockDrawable, getResources().getColor(R.color.text_color_light_grey)); // There is already a start drawable. Use it again. Drawable[] drawables = timeTextView.getCompoundDrawablesRelative(); timeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawables[0], null, lockDrawable, null); } AlertDialog dialog = alertDialog.create(); if (mLabel instanceof TextLabel || mLabel instanceof SensorTriggerLabel) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); } return dialog; }