Example usage for android.widget TextView getCompoundDrawables

List of usage examples for android.widget TextView getCompoundDrawables

Introduction

In this page you can find the example usage for android.widget TextView getCompoundDrawables.

Prototype

@NonNull
public Drawable[] getCompoundDrawables() 

Source Link

Document

Returns drawables for the left, top, right, and bottom borders.

Usage

From source file:com.stepstone.stepper.internal.util.TintUtil.java

/**
 * Tints TextView's text color and it's compound drawables
 * @param textview text view to tint/*www  .j a v  a  2 s.c  o  m*/
 * @param tintColor color state list to use for tinting
 */
public static void tintTextView(@NonNull TextView textview, ColorStateList tintColor) {
    textview.setTextColor(tintColor);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Drawable[] drawables = textview.getCompoundDrawablesRelative();
        textview.setCompoundDrawablesRelative(tintDrawable(drawables[0], tintColor),
                tintDrawable(drawables[1], tintColor), tintDrawable(drawables[2], tintColor),
                tintDrawable(drawables[3], tintColor));
    } else {
        Drawable[] drawables = textview.getCompoundDrawables();
        textview.setCompoundDrawables(tintDrawable(drawables[0], tintColor),
                tintDrawable(drawables[1], tintColor), tintDrawable(drawables[2], tintColor),
                tintDrawable(drawables[3], tintColor));
    }
}

From source file:com.bt.download.android.gui.util.UIUtils.java

/**
 * Android devices with SDK below target=11 do not support textView.setAlpha().
 * This is a work around. /*from   w  w w .  j a  va  2  s. co m*/
 * @param v - the text view
 * @param alpha - a value from 0 to 255. (0=transparent, 255=fully visible)
 */
public static void setTextViewAlpha(TextView v, int alpha) {
    v.setTextColor(v.getTextColors().withAlpha(alpha));
    v.setHintTextColor(v.getHintTextColors().withAlpha(alpha));
    v.setLinkTextColor(v.getLinkTextColors().withAlpha(alpha));

    Drawable[] compoundDrawables = v.getCompoundDrawables();
    for (int i = 0; i < compoundDrawables.length; i++) {
        Drawable d = compoundDrawables[i];
        if (d != null) {
            d.setAlpha(alpha);
        }
    }

}

From source file:Main.java

public static boolean drawDrawables(Canvas canvas, @Nonnull TextView textView) {
    final int compoundPaddingLeft = textView.getCompoundPaddingLeft();
    final int compoundPaddingTop = textView.getCompoundPaddingTop();
    final int compoundPaddingRight = textView.getCompoundPaddingRight();
    final int compoundPaddingBottom = textView.getCompoundPaddingBottom();

    final int scrollX = textView.getScrollX();
    final int scrollY = textView.getScrollY();

    final int right = textView.getRight();
    final int left = textView.getLeft();
    final int bottom = textView.getBottom();
    final int top = textView.getTop();

    final Drawable[] drawables = textView.getCompoundDrawables();
    if (drawables != null) {

        int vspace = bottom - top - compoundPaddingBottom - compoundPaddingTop;
        int hspace = right - left - compoundPaddingRight - compoundPaddingLeft;

        Drawable topDr = drawables[1];//from  w  w  w .j  a  va2  s .c  om
        // IMPORTANT: The coordinates computed are also used in invalidateDrawable()
        // Make sure to update invalidateDrawable() when changing this code.
        if (topDr != null) {
            canvas.save();
            canvas.translate(scrollX + compoundPaddingLeft + (hspace - topDr.getBounds().width()) / 2,
                    scrollY + textView.getPaddingTop() + vspace / 2);
            topDr.draw(canvas);
            canvas.restore();
            return true;
        }
    }

    return false;
}

From source file:me.selinali.tribbble.ui.shot.ShotDetailsView.java

public ShotDetailsView(Context context, AttributeSet attrs) {
    super(context, attrs);
    inflate(context, R.layout.shot_details_view, this);
    ButterKnife.bind(this);
    setBackgroundColor(color(R.color.lighterGray));

    for (TextView v : new TextView[] { mLikesTextView, mViewsTextView, mBucketsTextView, mCommentsTextView }) {
        DrawableCompat.setTint(v.getCompoundDrawables()[0], color(R.color.textNormal));
    }/*from  w  w w. j a  v a2s .  c om*/
    DrawableCompat.setTint(mLikesTextView.getCompoundDrawables()[0], color(R.color.textNormal));
    DrawableCompat.setTint(mViewsTextView.getCompoundDrawables()[0], color(R.color.textNormal));
    DrawableCompat.setTint(mBucketsTextView.getCompoundDrawables()[0], color(R.color.textNormal));
    DrawableCompat.setTint(mCommentsTextView.getCompoundDrawables()[0], color(R.color.textNormal));
}

From source file:de.grobox.liberario.fragments.HomePickerDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View v = inflater.inflate(R.layout.fragment_set_home, container);

    // Adapt Title Icon
    final TextView title = (TextView) v.findViewById(R.id.homeTitleView);
    title.setCompoundDrawables(TransportrUtils.getTintedDrawable(getContext(), title.getCompoundDrawables()[0]),
            null, null, null);// w ww .j  a  v  a2 s . co  m

    // Initialize LocationView
    final LocationView loc = (LocationView) v.findViewById(R.id.location_input);
    loc.initialize(getActivity());

    // OK Button
    Button okButton = (Button) v.findViewById(R.id.okButton);
    okButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (loc.getLocation() != null) {
                // save home location in file
                RecentsDB.setHome(v.getContext(), loc.getLocation());

                // call listener if set
                if (listener != null)
                    listener.onHomeChanged(loc.getLocation());

                getDialog().cancel();
            } else {
                Toast.makeText(v.getContext(),
                        getResources().getString(R.string.error_only_autocomplete_station), Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    // Cancel Button
    Button cancelButton = (Button) v.findViewById(R.id.cancelButton);
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getDialog().cancel();
        }
    });
    return v;
}

From source file:io.plaidapp.ui.PlayerActivity.java

@OnClick({ R.id.shot_count, R.id.followers_count, R.id.likes_count })
void playerActionClick(TextView view) {
    ((AnimatedVectorDrawable) view.getCompoundDrawables()[1]).start();
    switch (view.getId()) {
    case R.id.followers_count:
        PlayerSheet.start(PlayerActivity.this, player);
        break;//www. j  a  va  2s. c om
    }
}

From source file:owne.android.envmonitor.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);/*from ww w  .ja  va  2 s  . c  o m*/
        mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    mcpItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            Intent action = mcpIntent;
            if (mcpInfo == null)
                action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
            action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivity(action);
            mDrawerLayout.closeDrawers();
        }
    });

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
            }
        });
        container.addView(item);
    }
}

From source file:no.android.proxime.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);/*from   w  w w. j av a 2  s .  co  m*/
        mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    mcpItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            Intent action = mcpIntent;
            if (mcpInfo == null)
                action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
            action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivity(action);
            mDrawerLayout.closeDrawers();
        }
    });

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                mDrawerLayout.closeDrawers();
            }
        });
        container.addView(item);
    }
}

From source file:org.onebusaway.android.ui.ArrivalsListAdapterStyleA.java

@Override
protected void initView(View view, ArrivalInfo stopInfo) {
    final Context context = getContext();
    final ObaArrivalInfo arrivalInfo = stopInfo.getInfo();

    TextView route = (TextView) view.findViewById(R.id.route);
    TextView destination = (TextView) view.findViewById(R.id.destination);
    TextView time = (TextView) view.findViewById(R.id.time);
    TextView status = (TextView) view.findViewById(R.id.status);
    TextView etaView = (TextView) view.findViewById(R.id.eta);
    TextView minView = (TextView) view.findViewById(R.id.eta_min);
    ViewGroup realtimeView = (ViewGroup) view.findViewById(R.id.eta_realtime_indicator);
    ImageView moreView = (ImageView) view.findViewById(R.id.more_horizontal);
    moreView.setColorFilter(context.getResources().getColor(R.color.switch_thumb_normal_material_dark));
    ImageView starView = (ImageView) view.findViewById(R.id.route_favorite);
    starView.setColorFilter(context.getResources().getColor(R.color.navdrawer_icon_tint));
    starView.setImageResource(/*from   w w w .ja  va  2  s  .com*/
            stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off);

    route.setText(arrivalInfo.getShortName());
    destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign()));
    status.setText(stopInfo.getStatusText());

    long eta = stopInfo.getEta();
    if (eta == 0) {
        etaView.setText(R.string.stop_info_eta_now);
        minView.setVisibility(View.GONE);
    } else {
        etaView.setText(String.valueOf(eta));
        minView.setVisibility(View.VISIBLE);
    }

    status.setBackgroundResource(R.drawable.round_corners_style_b_status);
    GradientDrawable d = (GradientDrawable) status.getBackground();

    Integer colorCode = stopInfo.getColor();
    int color = context.getResources().getColor(colorCode);
    if (stopInfo.getPredicted()) {
        // Show real-time indicator
        UIUtils.setRealtimeIndicatorColorByResourceCode(realtimeView, colorCode, android.R.color.transparent);
        realtimeView.setVisibility(View.VISIBLE);
    } else {
        realtimeView.setVisibility(View.INVISIBLE);
    }

    etaView.setTextColor(color);
    minView.setTextColor(color);
    d.setColor(color);

    // Set padding on status view
    int pSides = UIUtils.dpToPixels(context, 5);
    int pTopBottom = UIUtils.dpToPixels(context, 2);
    status.setPadding(pSides, pTopBottom, pSides, pTopBottom);

    time.setText(DateUtils.formatDateTime(context, stopInfo.getDisplayTime(),
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT));

    ContentValues values = null;
    if (mTripsForStop != null) {
        values = mTripsForStop.getValues(arrivalInfo.getTripId());
    }
    if (values != null) {
        String reminderName = values.getAsString(ObaContract.Trips.NAME);

        TextView reminder = (TextView) view.findViewById(R.id.reminder);
        if (reminderName.length() == 0) {
            reminderName = context.getString(R.string.trip_info_noname);
        }
        reminder.setText(reminderName);
        Drawable d2 = reminder.getCompoundDrawables()[0];
        d2 = DrawableCompat.wrap(d2);
        DrawableCompat.setTint(d2.mutate(), view.getResources().getColor(R.color.button_material_dark));
        reminder.setCompoundDrawables(d2, null, null, null);
        reminder.setVisibility(View.VISIBLE);
    } else {
        // Explicitly set this to invisible because we might be reusing
        // this view.
        View reminder = view.findViewById(R.id.reminder);
        reminder.setVisibility(View.GONE);
    }
}

From source file:com.buddi.client.dfu.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);/*from w  w w  .ja  v a 2 s. c  o m*/
        mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    mcpItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            Intent action = mcpIntent;
            if (mcpInfo == null)
                action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
            action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            try {
                startActivity(action);
            } catch (final ActivityNotFoundException e) {
                Toast.makeText(FeaturesActivity.this, R.string.no_application_play, Toast.LENGTH_SHORT).show();
            }
            mDrawerLayout.closeDrawers();
        }
    });

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                mDrawerLayout.closeDrawers();
            }
        });
        container.addView(item);
    }
}