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.mk4droid.IMC_Activities.FActivity_TabHost.java

/**
 * When changing tab manage the other tabs and change tab button colors
 *///from  ww  w  .ja v a  2 s .co  m
@Override
public void onTabChanged(String arg0) {

    // if setup is pressed return as it is
    if (mTabHost.getCurrentTab() == 4)
        return;

    // remove some irrelevant fragments from previous tabs
    if (prevTab == 1 || prevTab == 0) {
        if (Fragment_Comments.mfrag_comments != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.remove(Fragment_Comments.mfrag_comments);
            ft.commit();
            Fragment_Comments.mfrag_comments = null;
            getSupportFragmentManager().popBackStack();
        }

        if (Fragment_Issue_Details.mfrag_issue_details != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.remove(Fragment_Issue_Details.mfrag_issue_details);
            ft.commit();
            Fragment_Issue_Details.mfrag_issue_details = null;
            getSupportFragmentManager().popBackStack();
        }
    }

    // Stack of tab new Issue: Two maps v2 are not allowed, so remove the
    // newIssueMap
    if (prevTab == 2) {
        if (Fragment_NewIssueB.mfrag_nIssueB != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.remove(Fragment_NewIssueB.mfrag_nIssueB);
            ft.commit();
            Fragment_NewIssueB.mfrag_nIssueB = null;
            getSupportFragmentManager().popBackStack();
        }
        Fragment_NewIssueA.llnewissue_a.setVisibility(View.VISIBLE);
    }

    // --------- Set Color of Tabs ---------------
    for (int i = 0; i < NTabs; i++) {
        LinearLayout ll = (LinearLayout) mTabHost.getTabWidget().getChildAt(i);
        TextView tv = (TextView) ll.findViewWithTag("tv");
        String txt = tv.getText().toString();
        Drawable[] dr = tv.getCompoundDrawables();

        if (mTabHost.getCurrentTab() == i) {
            ll = ActivateColorize(ll, txt, dr[1]);
            FActivity_TabHost.IndexGroup = i;
            prevTab = i;
        } else
            ll = InActivateColorize(ll, txt, dr[1]);
    }
}

From source file:me.piebridge.prevent.ui.UserGuideActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    ThemeUtils.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);// www.j  av a  2 s . c o  m
    ThemeUtils.fixSmartBar(this);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    WebView webView = (WebView) findViewById(R.id.webview);
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    if ("zh".equals(Locale.getDefault().getLanguage())) {
        webView.loadUrl("file:///android_asset/about.zh.html");
    } else {
        webView.loadUrl("file:///android_asset/about.en.html");
    }
    setView(R.id.alipay, "com.eg.android.AlipayGphone");
    if (hasPermission()) {
        setView(R.id.wechat, "com.tencent.mm");
    } else {
        findViewById(R.id.wechat).setVisibility(View.GONE);
    }
    if (!setView(R.id.paypal, "com.paypal.android.p2pmobile")) {
        TextView paypal = (TextView) findViewById(R.id.paypal);
        paypal.setClickable(true);
        paypal.setOnClickListener(this);
        paypal.setCompoundDrawablesWithIntrinsicBounds(null, cropDrawable(paypal.getCompoundDrawables()[1]),
                null, null);
    }
    if (setView(R.id.play, "com.android.vending")) {
        findViewById(R.id.play).setVisibility(View.GONE);
        checkDonate();
    }
    donateView = findViewById(R.id.donate);
    if (BuildConfig.DONATE && TextUtils.isEmpty(LicenseUtils.getLicense(this))) {
        donateView.setVisibility(View.VISIBLE);
    } else {
        donateView.setVisibility(View.GONE);
    }
    retrieveInfo();
}

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

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

    LayoutInflater inflater = LayoutInflater.from(context);

    TextView routeName = (TextView) view.findViewById(R.id.routeName);
    TextView destination = (TextView) view.findViewById(R.id.routeDestination);

    // TableLayout that we will fill with TableRows of arrival times
    TableLayout arrivalTimesLayout = (TableLayout) view.findViewById(R.id.arrivalTimeLayout);
    arrivalTimesLayout.removeAllViews();

    Resources r = view.getResources();

    ImageButton starBtn = (ImageButton) view.findViewById(R.id.route_star);
    starBtn.setColorFilter(r.getColor(R.color.theme_primary));

    ImageButton mapImageBtn = (ImageButton) view.findViewById(R.id.mapImageBtn);
    mapImageBtn.setColorFilter(r.getColor(R.color.theme_primary));

    ImageButton routeMoreInfo = (ImageButton) view.findViewById(R.id.route_more_info);
    routeMoreInfo.setColorFilter(r.getColor(R.color.switch_thumb_normal_material_dark));

    starBtn.setImageResource(//  w  ww  .j ava2  s.co m
            stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off);

    starBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Show dialog for setting route favorite
            RouteFavoriteDialogFragment dialog = new RouteFavoriteDialogFragment.Builder(
                    stopInfo.getInfo().getRouteId(), stopInfo.getInfo().getHeadsign())
                            .setRouteShortName(stopInfo.getInfo().getShortName())
                            .setRouteLongName(stopInfo.getInfo().getRouteLongName())
                            .setStopId(stopInfo.getInfo().getStopId())
                            .setFavorite(!stopInfo.isRouteAndHeadsignFavorite()).build();

            dialog.setCallback(new RouteFavoriteDialogFragment.Callback() {
                @Override
                public void onSelectionComplete(boolean savedFavorite) {
                    if (savedFavorite) {
                        mFragment.refreshLocal();
                    }
                }
            });
            dialog.show(mFragment.getFragmentManager(), RouteFavoriteDialogFragment.TAG);
        }
    });

    // Setup map
    mapImageBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFragment.showRouteOnMap(stopInfo);
        }
    });

    // Setup more
    routeMoreInfo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFragment.showListItemMenu(view, stopInfo);
        }
    });

    routeName.setText(arrivalInfo.getShortName());
    destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign()));

    // Loop through the arrival times and create the TableRows that contains the data
    for (int i = 0; i < combinedArrivalInfoStyleB.getArrivalInfoList().size(); i++) {
        final ArrivalInfo arrivalRow = combinedArrivalInfoStyleB.getArrivalInfoList().get(i);
        final ObaArrivalInfo tempArrivalInfo = arrivalRow.getInfo();
        long scheduledTime = tempArrivalInfo.getScheduledArrivalTime();

        // Create a new row to be added
        final TableRow tr = (TableRow) inflater.inflate(R.layout.arrivals_list_tr_template_style_b, null);

        // Layout and views to inflate from XML templates
        RelativeLayout layout;
        TextView scheduleView, estimatedView, statusView;
        View divider;

        if (i == 0) {
            // Use larger styled layout/view for next arrival time
            layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_large, null);
            scheduleView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_large, null);
            estimatedView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_large, null);
            statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large,
                    null);
        } else {
            // Use smaller styled layout/view for further out times
            layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_small, null);
            scheduleView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_small, null);
            estimatedView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_small, null);
            statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_small,
                    null);
        }

        // Set arrival times and status in views
        scheduleView.setText(DateUtils.formatDateTime(context, scheduledTime,
                DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT));
        if (arrivalRow.getPredicted()) {
            long eta = arrivalRow.getEta();
            if (eta == 0) {
                estimatedView.setText(R.string.stop_info_eta_now);
            } else {
                estimatedView.setText(eta + " min");
            }
        } else {
            estimatedView.setText(R.string.stop_info_eta_unknown);
        }
        statusView.setText(arrivalRow.getStatusText());
        int colorCode = arrivalRow.getColor();
        statusView.setBackgroundResource(R.drawable.round_corners_style_b_status);
        GradientDrawable d = (GradientDrawable) statusView.getBackground();
        d.setColor(context.getResources().getColor(colorCode));

        int alpha;
        if (i == 0) {
            // Set next arrival
            alpha = (int) (1.0f * 255); // X percent transparency
        } else {
            // Set smaller rows
            alpha = (int) (.35f * 255); // X percent transparency
        }
        d.setAlpha(alpha);

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

        // Add TextViews to layout
        layout.addView(scheduleView);
        layout.addView(statusView);
        layout.addView(estimatedView);

        // Make sure the TextViews align left/center/right of parent relative layout
        RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) scheduleView.getLayoutParams();
        params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        params1.addRule(RelativeLayout.CENTER_VERTICAL);
        scheduleView.setLayoutParams(params1);

        RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) statusView.getLayoutParams();
        params2.addRule(RelativeLayout.CENTER_IN_PARENT);
        // Give status view a little extra margin
        int p = UIUtils.dpToPixels(context, 3);
        params2.setMargins(p, p, p, p);
        statusView.setLayoutParams(params2);

        RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) estimatedView.getLayoutParams();
        params3.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params3.addRule(RelativeLayout.CENTER_VERTICAL);
        estimatedView.setLayoutParams(params3);

        // Add layout to TableRow
        tr.addView(layout);

        // Add the divider, if its not the first row
        if (i != 0) {
            int dividerHeight = UIUtils.dpToPixels(context, 1);
            divider = inflater.inflate(R.layout.arrivals_list_divider_template_style_b, null);
            divider.setLayoutParams(
                    new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, dividerHeight));
            arrivalTimesLayout.addView(divider);
        }

        // Add click listener
        tr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mFragment.showListItemMenu(tr, arrivalRow);
            }
        });

        // Add TableRow to container layout
        arrivalTimesLayout.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                TableLayout.LayoutParams.MATCH_PARENT));
    }

    // Show or hide reminder for this trip
    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 d = reminder.getCompoundDrawables()[0];
        d = DrawableCompat.wrap(d);
        DrawableCompat.setTint(d.mutate(), view.getResources().getColor(R.color.theme_primary));
        reminder.setCompoundDrawables(d, null, null, null);
        reminder.setVisibility(View.VISIBLE);
    } else {
        // Explicitly set reminder to invisible because we might be reusing
        // this view.
        View reminder = view.findViewById(R.id.reminder);
        reminder.setVisibility(View.GONE);
    }
}

From source file:com.kaku.weac.fragment.AlarmClockOntimeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    LogUtil.d(LOG_TAG, getActivity().toString() + "onCreateView");

    View view = inflater.inflate(R.layout.fm_alarm_clock_ontime, container, false);
    mTimeTv = (TextView) view.findViewById(R.id.ontime_time);
    // //from  w  w  w  .ja  va2 s.com
    mTimeTv.setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date()));
    mCurrentTimeDisplay = mTimeTv.getText().toString();
    // ?
    new Thread(new TimeUpdateThread()).start();

    // 
    TextView tagTv = (TextView) view.findViewById(R.id.ontime_tag);
    tagTv.setText(mAlarmClock.getTag());

    // ??
    TextView napTv = (TextView) view.findViewById(R.id.ontime_nap);
    // ????
    if (mAlarmClock.isNap()) {
        // X???????
        if (mNapTimesRan != mNapTimes) {
            // ??
            napTv.setText(String.format(getString(R.string.touch_here_nap), mNapInterval));
            napTv.setOnClickListener(this);
        } else {
            napTv.setVisibility(View.GONE);
        }
    } else {
        napTv.setVisibility(View.GONE);
    }

    LogUtil.i(LOG_TAG, "??" + mNapTimes);

    // ??
    TextView slidingTipIv = (TextView) view.findViewById(R.id.sliding_tip_tv);
    final AnimationDrawable animationDrawable = (AnimationDrawable) slidingTipIv.getCompoundDrawables()[0];
    // ?4.0
    slidingTipIv.post(new Runnable() {
        @Override
        public void run() {
            animationDrawable.start();
        }
    });

    MySlidingView mySlidingView = (MySlidingView) view.findViewById(R.id.my_sliding_view);
    mySlidingView.setSlidingTipListener(new MySlidingView.SlidingTipListener() {
        @Override
        public void onSlidFinish() {
            // ?
            finishActivity();
        }
    });

    // ??
    if (mAlarmClock.isWeaPrompt()) {
        mWeatherInfoGroup = (ViewGroup) view.findViewById(R.id.weather_info_group);
        mWeatherPbar = (ProgressBar) view.findViewById(R.id.progress_bar);
        mWeatherTypeTv = (TextView) view.findViewById(R.id.weather_type_tv);
        mUmbrellaTv = (TextView) view.findViewById(R.id.umbrella_tv);
        // ?
        initWeather();
    }
    return view;
}

From source file:net.fabiszewski.ulogger.MainActivity.java

/**
 * Set status led color/*from  w w  w  .j  a  va2 s  .  c om*/
 * @param led Led text view
 * @param color Color (red, yellow or green)
 */
private void setLedColor(TextView led, int color) {
    Drawable l;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        l = led.getCompoundDrawables()[0];
    } else {
        l = led.getCompoundDrawablesRelative()[0];
    }
    switch (color) {
    case LED_RED:
        l.setColorFilter(ContextCompat.getColor(this, R.color.colorRed), PorterDuff.Mode.SRC_ATOP);
        break;

    case LED_GREEN:
        l.setColorFilter(ContextCompat.getColor(this, R.color.colorGreen), PorterDuff.Mode.SRC_ATOP);
        break;

    case LED_YELLOW:
        l.setColorFilter(ContextCompat.getColor(this, R.color.colorYellow), PorterDuff.Mode.SRC_ATOP);
        break;
    }
    l.invalidateSelf();
}

From source file:com.android.launcher3.folder.FolderIcon.java

private Drawable getTopDrawable(TextView v) {
    Drawable d = v.getCompoundDrawables()[1];
    return (d instanceof PreloadIconDrawable) ? ((PreloadIconDrawable) d).mIcon : d;
}

From source file:org.mozilla.gecko.tests.BaseTest.java

public void verifyPinned(final boolean isPinned, final String gridItemTitle) {
    boolean viewFound = waitForText(gridItemTitle);
    mAsserter.ok(viewFound, "Found top site title: " + gridItemTitle, null);

    boolean success = waitForCondition(new Condition() {
        @Override/* ww w. j  ava 2s .co m*/
        public boolean isSatisfied() {
            // We set the left compound drawable (index 0) to the pin icon.
            final TextView gridItemTextView = mSolo.getText(gridItemTitle);
            return isPinned == (gridItemTextView.getCompoundDrawables()[0] != null);
        }
    }, MAX_WAIT_MS);
    mAsserter.ok(success, "Top site item was pinned: " + isPinned, null);
}

From source file:io.plaidapp.designernews.ui.story.StoryActivity.java

private void bindDescription() {
    final TextView storyComment = header.findViewById(R.id.story_comment);
    if (!TextUtils.isEmpty(story.getComment())) {

        ColorStateList linksColor = ContextCompat.getColorStateList(this, R.color.designer_news_links);
        int highlightColor = ContextCompat.getColor(this, io.plaidapp.R.color.designer_news_link_highlight);

        CharSequence text = HtmlUtils.parseMarkdownAndPlainLinks(story.getComment(), markdown, linksColor,
                highlightColor,/*www  .j  av a 2s.c  o  m*/
                (src, loadingSpan) -> GlideApp.with(StoryActivity.this).asBitmap().load(src)
                        .transition(BitmapTransitionOptions.withCrossFade())
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new ImageSpanTarget(storyComment, loadingSpan)));

        HtmlUtils.setTextWithNiceLinks(storyComment, text);

    } else {
        storyComment.setVisibility(View.GONE);
    }

    upvoteStory = header.findViewById(R.id.story_vote_action);
    storyUpvoted(story.getVoteCount());
    upvoteStory.setOnClickListener(v -> upvoteStory());

    final TextView share = header.findViewById(R.id.story_share_action);
    share.setOnClickListener(v -> {
        ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
        ShareCompat.IntentBuilder.from(StoryActivity.this).setText(story.getUrl()).setType("text/plain")
                .setSubject(story.getTitle()).startChooser();
    });

    TextView storyPosterTime = header.findViewById(R.id.story_poster_time);
    if (story.getUserDisplayName() != null && story.getUserJob() != null) {
        CharSequence storyPosterTimeText = getStoryPosterTimeText(story.getUserDisplayName(),
                story.getUserJob(), story.getCreatedAt());
        storyPosterTime.setText(storyPosterTimeText);
    }
    ImageView avatar = header.findViewById(R.id.story_poster_avatar);
    if (!TextUtils.isEmpty(story.getUserPortraitUrl())) {
        GlideApp.with(this).load(story.getUserPortraitUrl()).transition(withCrossFade())
                .placeholder(io.plaidapp.R.drawable.avatar_placeholder).circleCrop().into(avatar);
    } else {
        avatar.setVisibility(View.GONE);
    }
}

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

private void bindDescription() {
    final TextView storyComment = (TextView) header.findViewById(R.id.story_comment);
    if (!TextUtils.isEmpty(story.comment)) {
        HtmlUtils.parseMarkdownAndSetText(storyComment, story.comment, markdown,
                new Bypass.LoadImageCallback() {
                    @Override//  w ww .j av  a2 s .  c  o  m
                    public void loadImage(String src, ImageLoadingSpan loadingSpan) {
                        Glide.with(DesignerNewsStory.this).load(src).asBitmap()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .into(new ImageSpanTarget(storyComment, loadingSpan));
                    }
                });
    } else {
        storyComment.setVisibility(View.GONE);
    }

    upvoteStory = (TextView) header.findViewById(R.id.story_vote_action);
    upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, story.vote_count,
            NumberFormat.getInstance().format(story.vote_count)));
    upvoteStory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            upvoteStory();
        }
    });

    final TextView share = (TextView) header.findViewById(R.id.story_share_action);
    share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
            startActivity(ShareCompat.IntentBuilder.from(DesignerNewsStory.this).setText(story.url)
                    .setType("text/plain").setSubject(story.title).getIntent());
        }
    });

    TextView storyPosterTime = (TextView) header.findViewById(R.id.story_poster_time);
    SpannableString poster = new SpannableString(story.user_display_name.toLowerCase());
    poster.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_CommentAuthor), 0, poster.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    CharSequence job = !TextUtils.isEmpty(story.user_job) ? "\n" + story.user_job.toLowerCase() : "";
    CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(),
            System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase();
    storyPosterTime.setText(TextUtils.concat(poster, job, "\n", timeAgo));
    ImageView avatar = (ImageView) header.findViewById(R.id.story_poster_avatar);
    if (!TextUtils.isEmpty(story.user_portrait_url)) {
        Glide.with(this).load(story.user_portrait_url).placeholder(R.drawable.avatar_placeholder)
                .transform(circleTransform).into(avatar);
    } else {
        avatar.setVisibility(View.GONE);
    }
}

From source file:com.github.topbottomsnackbar.TBSnackbar.java

public TBSnackbar setIconLeft(@DrawableRes int drawableRes, float sizeDp) {
    final TextView tv = mView.getMessageView();
    Drawable drawable = ContextCompat.getDrawable(mContext, drawableRes);
    if (drawable != null) {
        drawable = fitDrawable(drawable, (int) convertDpToPixel(sizeDp, mContext));
    } else {//from ww w  . j  av  a  2 s.c  om
        throw new IllegalArgumentException("resource_id is not a valid drawable!");
    }
    final Drawable[] compoundDrawables = tv.getCompoundDrawables();
    tv.setCompoundDrawables(drawable, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]);
    return this;
}