Java Code Examples for android.widget.TextView#setCompoundDrawablesWithIntrinsicBounds()

The following examples show how to use android.widget.TextView#setCompoundDrawablesWithIntrinsicBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogHelper.java    From NotificationPeekPort with Apache License 2.0 6 votes vote down vote up
private View create(CharSequence title, CharSequence message) {
    LayoutInflater inflater = LayoutInflater.from(mContext);

    View root = inflater.inflate(R.layout.about_dialog, null);

    // Title.
    TextView titleView = (TextView) root.findViewById(R.id.dialog_title_text);

    Drawable left = (mContext.getResources().getConfiguration().screenLayout &
            Configuration.SCREENLAYOUT_SIZE_MASK) !=
            Configuration.SCREENLAYOUT_SIZE_LARGE ? mIcon : null;
    Drawable top = left == null ? mIcon : null;

    titleView.setText(title);
    titleView.setCompoundDrawablePadding(mContext.getResources().getDimensionPixelSize(R.dimen.item_padding));
    titleView.setCompoundDrawablesWithIntrinsicBounds(left, top, null, null);

    // About message.
    TextView messageView = (TextView) root.findViewById(R.id.dialog_message_text);
    messageView.setText(message);
    messageView.setMovementMethod(LinkMovementMethod.getInstance());


    return root;
}
 
Example 2
Source File: ProjectUserStatus.java    From intra42 with Apache License 2.0 6 votes vote down vote up
static public void setMark(Context context, @Nullable ProjectsUsers projects, TextView textView) {

        if (projects == null) {
            textView.setVisibility(View.GONE);
            return;
        } else
            textView.setVisibility(View.VISIBLE);

        textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        if (projects.status == ProjectsUsers.Status.FINISHED) {
            setMarkText(textView, projects.finalMark, projects.validated, context);
        } else {
            textView.setText(projects.status.getRes());
            textView.setTextColor(context.getResources().getColor(R.color.gray));
        }
    }
 
Example 3
Source File: FragmentAbout.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
@Override
public void findAndBindViews(View contentView) {
    setDefaultImageLeftVisible(true, R.attr.img_nav_back);
    setTitleText(R.string.v_setting_item_about);

    View item_version = contentView.findViewById(R.id.item_version);
    ((TextView) item_version.findViewById(R.id.tv_title)).setText(R.string.v_about_item_check_version);
    tv_check_version = (TextView) item_version.findViewById(R.id.tv_content);
    tv_check_version.setText(CommonUtils.getVersionName(mContext));
    ((TextView) contentView.findViewById(R.id.tv_version)).setText(CommonUtils.getVersionName(mContext));

    item_version.setOnClickListener(this);

    VersionUpdate.VersionInfo info = FileCache.getVersionInfo();
    if (info == null) {
        return;
    }
    String[] vname = info.latest_version.split("[.]");
    int v_code = Integer.parseInt(vname[0]) * 10000 + Integer.parseInt(vname[1]) * 100 + Integer.parseInt(vname[2]);
    if (v_code <= CommonUtils.getVersionCode(getActivity())) {
        FileCache.saveVersionInfo(null);
        return;
    }
    tv_check_version.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.z_shape_msg_red, 0);
}
 
Example 4
Source File: ArrayAdapterWithIcon.java    From FaceT with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);
    TextView textView = (TextView) view.findViewById(android.R.id.text1);

    textView.setTextColor(Color.BLACK);
    textView.setTextSize(17f);
    textView.setPadding(10, 10, 10, 10);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        textView.setCompoundDrawablesRelativeWithIntrinsicBounds(images.get(position), 0, 0, 0);
        textView.setCompoundDrawablePadding(30);
    } else {
        textView.setCompoundDrawablesWithIntrinsicBounds(images.get(position), 0, 0, 0);
        textView.setCompoundDrawablePadding(30);
    }
    textView.setCompoundDrawablePadding(
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getContext().getResources().getDisplayMetrics()));
    return view;
}
 
Example 5
Source File: StatusHelper.java    From MeiBaseModule with Apache License 2.0 6 votes vote down vote up
/**
 * set status args
 *
 * @param view
 * @param args
 */
private void setStatusArgs(TextView view, Object[] args) {
    if (view != null) {
        for (Object arg : args) {
            if (arg instanceof Integer) {
                int resId = (int) arg;
                String typeName = mContext.getResources().getResourceTypeName(resId);
                if ("string".equals(typeName)) {
                    //文字
                    view.setText(resId);
                } else {
                    //图标
                    view.setCompoundDrawablesWithIntrinsicBounds(0, resId, 0, 0);
                }
            } else if (arg instanceof CharSequence) {
                //文字
                view.setText((CharSequence) arg);
            }
        }
    }
}
 
Example 6
Source File: DemoFragment.java    From static-maps-api with Apache License 2.0 6 votes vote down vote up
private void bindMarkerView(Marker.Style style, GeoPoint point, TextView textView) {
    Character label = style.label();
    String text = point.address();

    if (text == null) {
        text = String.format("%.6f %.6f", point.latitude(), point.longitude());
    }

    if (label != null) {
        text = text + " (" + label + ")";
    }

    textView.setText(text);

    if (style.icon() != null) {
        Glide.with(DemoFragment.this).load(style.icon()).asBitmap().into(new TextViewTarget(textView));
    } else {
        Drawable d = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_maps_marker));
        DrawableCompat.setTint(d, style.color());
        textView.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
    }
}
 
Example 7
Source File: Shadowsocks.java    From Maying with Apache License 2.0 5 votes vote down vote up
/**
 * init toolbar
 */
private void initToolbar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    // non-translatable logo
    toolbar.setTitle("Maying");
    toolbar.setTitleTextAppearance(toolbar.getContext(), R.style.Toolbar_Logo);
    try {
        Field field = Toolbar.class.getDeclaredField("mTitleTextView");
        field.setAccessible(true);
        TextView title = (TextView) field.get(toolbar);
        title.setFocusable(true);
        title.setGravity(0x10);
        title.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Shadowsocks.this, ProfileManagerActivity.class));
            }
        });
        TypedArray typedArray = obtainStyledAttributes(new int[]{R.attr.selectableItemBackgroundBorderless});
        title.setBackgroundResource(typedArray.getResourceId(0, 0));
        typedArray.recycle();
        Typeface tf = Typefaces.get(this, "fonts/Iceland.ttf");
        if (tf != null) {
            title.setTypeface(tf);
        }
        title.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: MediaShortcutActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);
    TextView text = (TextView) view.findViewById(android.R.id.text1);
    text.setTextColor(Color.BLACK);
    text.setCompoundDrawablesWithIntrinsicBounds(
            getResourceForKeyCode(MEDIA_KEYCODES[position]), 0, 0, 0);
    text.setCompoundDrawablePadding(getResources().getDimensionPixelSize(R.dimen.list_fading_edge_length));
    return view;
}
 
Example 9
Source File: DlgChooseDirectory.java    From freemp with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    TextView textview = (TextView) super.getView(position, convertView, parent);

    if (m_entries.get(position) == null) {
        textview.setText("..");
        textview.setCompoundDrawablesWithIntrinsicBounds(m_context.getResources().getDrawable(R.drawable.freemp), null, null, null);
    } else {
        textview.setText(m_entries.get(position).getName());
        textview.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }

    return textview;
}
 
Example 10
Source File: AbstractFieldView.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the {@link FieldDescriptor} for this widget.
 *
 * @param descriptor
 *         The {@link FieldDescriptor} that describes the field this widget shall show.
 * @param options
 *         Any {@link LayoutOptions}.
 */
@SuppressLint("DefaultLocale")
public void setFieldDescription(FieldDescriptor descriptor, LayoutOptions options)
{
    mLayoutOptions = options;
    mFieldDescriptor = descriptor;
    TextView titleId = (TextView) findViewById(android.R.id.title);
    if (titleId != null)
    {
        if (options.getBoolean(LayoutDescriptor.OPTION_NO_TITLE, false))
        {
            titleId.setVisibility(View.GONE);
        }
        else
        {
            titleId.setText(descriptor.getTitle().toUpperCase());
        }
    }

    // set icon if we have any

    // Note that the icon view is actually a TextView, not an ImageView and we just set a compound drawable. That ensures the image is always nicely
    // aligned with the first text line.
    TextView icon = (TextView) findViewById(android.R.id.icon);
    if (icon != null)
    {
        if (descriptor.getIcon() != 0)
        {
            icon.setCompoundDrawablesWithIntrinsicBounds(descriptor.getIcon(), 0, 0, 0);
            icon.setVisibility(View.VISIBLE);
        }
        else
        {
            icon.setVisibility(View.GONE);
        }
    }

}
 
Example 11
Source File: ShareView.java    From ChinaShare with MIT License 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    TextView tView = (TextView) mInflater.inflate(R.layout.share_item, null);
    BaseShareWay info = (BaseShareWay) getItem(position);
    String label = info.getTitle();
    Drawable icon = mContext.getResources().getDrawable(info.getResIcon());
    tView.setText(label);
    tView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
    tView.setTextColor(mContext.getResources().getColor(mShareItemTextColor));
    return tView;
}
 
Example 12
Source File: StatusArrayAdapter.java    From BLEMeshChat with Mozilla Public License 2.0 5 votes vote down vote up
public View getCustomView(int position, View convertView, ViewGroup parent) {

        Context context = parent.getContext();

        // Get the data item for this position
        String status = getItem(position);
        // Check if an existing view is being reused, otherwise inflate the view
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_spinner_dropdown_item, parent, false);
            ((TextView) convertView).setCompoundDrawablePadding((int) dipToPixels(context, 8));
        }

        TextView statusLabel = (TextView) convertView;
        statusLabel.setText(status);

        String[] choices = context.getResources().getStringArray(R.array.status_options);
        if (status.equals(choices[0])) { // Always online
            statusLabel.setCompoundDrawablesWithIntrinsicBounds(context.getDrawable(R.drawable.status_always_online), null, null, null);
        }
        else if (status.equals(choices[1])) { // Online when using app
            statusLabel.setCompoundDrawablesWithIntrinsicBounds(context.getDrawable(R.drawable.status_online_in_foreground), null, null, null);
        } else if (status.equals(choices[2])) { // Offline
            statusLabel.setCompoundDrawablesWithIntrinsicBounds(context.getDrawable(R.drawable.status_offline), null, null, null);
        } else {
            Timber.e("Unknown status. Cannot set adapter view correctly");
            statusLabel.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        }

        return convertView;
    }
 
Example 13
Source File: FileBrowserActivity.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder) {
    text = (TextView) viewHolder.itemView.findViewById(R.id.text);
    text.setText(file.getName());
    text.setCompoundDrawablesWithIntrinsicBounds(file.isDirectory() ? R.drawable.ic_folder : R.drawable.ic_file,
            0, 0, 0);

    if (Utils.isTV(viewHolder.itemView.getContext())) {
        viewHolder.itemView.setFocusable(true);
        viewHolder.itemView.setFocusableInTouchMode(true);
    }
}
 
Example 14
Source File: TSnackbar.java    From TSnackBar with Apache License 2.0 5 votes vote down vote up
@Deprecated
public TSnackbar addIcon(int resource_id, int size) {
    final TextView tv = mView.getMessageView();

    tv.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(Bitmap.createScaledBitmap(((BitmapDrawable) (mContext.getResources()
            .getDrawable(resource_id))).getBitmap(), size, size, true)), null, null, null);

    return this;
}
 
Example 15
Source File: Utils.java    From bottomsheets with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the {@link TextView}'s left {@link Drawable}.
 */
public static void setDrawableLeft(@NonNull TextView textView, @Nullable Drawable drawable) {
    Preconditions.nonNull(textView);

    textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
}
 
Example 16
Source File: DkDropDownMenu.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public void setTextDrawables(TextView textview, boolean close) {
    textview.setCompoundDrawablesWithIntrinsicBounds(mOrientation.getLeft(close), mOrientation.getTop(close),
            mOrientation.getRight(close), mOrientation.getBottom(close));
}
 
Example 17
Source File: LMvdActivity.java    From Beedio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    webBox = findViewById(R.id.web);
    webBox.setOnEditorActionListener(this);

    ImageButton go = findViewById(R.id.go);
    go.setOnClickListener(this);

    if ((browserManager = (BrowserManager) getFragmentManager().findFragmentByTag("BM")) == null) {
        getFragmentManager().beginTransaction().add(browserManager = new BrowserManager(),
                "BM").commit();
    }

    // ATTENTION: This was auto-generated to handle app links.
    Intent appLinkIntent = getIntent();
    //String appLinkAction = appLinkIntent.getAction();
    appLinkData = appLinkIntent.getData();

    layout = findViewById(R.id.drawer);
    ImageView menu = findViewById(R.id.menuButton);
    menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            layout.openDrawer(GravityCompat.START);
        }
    });

    ListView listView = findViewById(R.id.menu);
    String[] menuItems = new String[]{"Home", "Browser", "Downloads", "Bookmarks",
            "History", "About", "Options"};
    ArrayAdapter listAdapter = new ArrayAdapter<String>(this, android.R.layout
            .simple_list_item_1, menuItems) {
        @NonNull
        @Override
        public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            TextView textView = view.findViewById(android.R.id.text1);
            textView.setTextColor(Color.WHITE);

            int iconId = 0;
            switch (position) {
                case 0:
                    iconId = R.drawable.ic_home_white_24dp;
                    break;
                case 1:
                    iconId = R.drawable.ic_globe_white_24dp;
                    break;
                case 2:
                    iconId = R.drawable.ic_download_white_24dp;
                    break;
                case 3:
                    iconId = R.drawable.ic_star_white_24dp;
                    break;
                case 4:
                    iconId = R.drawable.ic_history_white_24dp;
                    break;
                case 5:
                    iconId = R.drawable.ic_info_outline_white_24dp;
                    break;
                case 6:
                    iconId = R.drawable.ic_settings_white_24dp;
            }
            if (iconId != 0) {
                Drawable icon = AppCompatResources.getDrawable(getContext(), iconId);
                textView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
                textView.setCompoundDrawablePadding((int) (16 * getResources().getDisplayMetrics().density));
            }

            return view;
        }
    };
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(this);

    RecyclerView videoSites = findViewById(R.id.homeSites);
    videoSites.setAdapter(new VideoStreamingSitesList(this));
    videoSites.setLayoutManager(new LinearLayoutManager(this));
}
 
Example 18
Source File: Help.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Bind the fiew to the help entry content
 * @param v the view to bind info to
 * @param he the help entry to display info of
 */
private void bindView(View v, HelpEntry he) {
	TextView tv = (TextView) v;
	tv.setText(he.textRes);
	tv.setCompoundDrawablesWithIntrinsicBounds(he.iconRes, 0, 0, 0);
}
 
Example 19
Source File: HomeActivity.java    From TouchNews with Apache License 2.0 4 votes vote down vote up
@Override
    public void setNavigation(final Weather weather) {
//                Log.e("setNavigation", weather.getBasic().getCity());
        if (weather != null && weather.getNow() != null) {
            View headerView = mNavigationView.getHeaderView(0);
//                ImageView iconWeather = ( ( ImageView ) headerView.findViewById ( R.id.iv_weather_icon ) );
            //天气类型 - 晴、多云
            TextView tvTypeText = ((TextView) headerView.findViewById(R.id.tv_weather_txt));
            //当前气温 - 32 *C
            TextView tvTemperature = ((TextView) headerView.findViewById(R.id.tv_weather_temperature));
            //城市位置 - 广州
            TextView tvPosition = ((TextView) headerView.findViewById(R.id.tv_weather_position));
            //天气类型代码
            int weatherCode = Integer.valueOf(weather.getNow().getCond().getCode());
            int[] weatherCodeArr = getResources().getIntArray(R.array.weather_code);
            tvTypeText.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.weather_999, 0, 0);
            TypedArray ar = getResources().obtainTypedArray(R.array.weather_icon);
            int len = ar.length();
            int[] weatherDrawableID = new int[len];
            for (int i = 0; i < len; i++) {
                weatherDrawableID[i] = ar.getResourceId(i, 0);
            }
            ar.recycle();
            //设置天气类型图标
            for (int i = 0; i < weatherCodeArr.length; i++) {
                if (weatherCodeArr[i] == weatherCode) {
                    tvTypeText.setCompoundDrawablesWithIntrinsicBounds(0, weatherDrawableID[i], 0, 0);
                }
            }
            tvTypeText.setText(weather.getNow().getCond().getTxt());
            tvTemperature.setText(weather.getNow().getTmp());
            tvPosition.setText(weather.getBasic().getCity());
            headerView.findViewById(R.id.layout_drawer_header_weather).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(HomeActivity.this, WeatherDetailActivity.class);
                    intent.putExtra("data", new Gson().toJson(weather));
                    startActivity(intent);
                }
            });
        }
    }
 
Example 20
Source File: ChartHeaderView.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public ChartHeaderView(Context context) {
    super(context);
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(14);
    textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textMargin = (int) textPaint.measureText("00 MMM 0000 - 00 MMM 000");

    title = new TextView(context);
    title.setTextSize(15);
    title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addView(title, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 16, 0, textMargin, 0));

    back = new TextView(context);
    back.setTextSize(15);
    back.setTypeface(Typeface.DEFAULT_BOLD);
    back.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    addView(back, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 8, 0, 8, 0));

    dates = new TextView(context);
    dates.setTextSize(13);
    dates.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dates.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(dates, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));

    datesTmp = new TextView(context);
    datesTmp.setTextSize(13);
    datesTmp.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    datesTmp.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(datesTmp, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));
    datesTmp.setVisibility(View.GONE);


    back.setVisibility(View.GONE);
    back.setText(LocaleController.getString("ZoomOut", R.string.ZoomOut));
    zoomIcon = ContextCompat.getDrawable(getContext(), R.drawable.stats_zoom);
    back.setCompoundDrawablesWithIntrinsicBounds(zoomIcon, null, null, null);
    back.setCompoundDrawablePadding(AndroidUtilities.dp(4));
    back.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(4), AndroidUtilities.dp(8), AndroidUtilities.dp(4));
    back.setBackground(Theme.getRoundRectSelectorDrawable(Theme.getColor(Theme.key_featuredStickers_removeButtonText)));

    datesTmp.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        datesTmp.setPivotX(datesTmp.getMeasuredWidth() * 0.7f);
        dates.setPivotX(dates.getMeasuredWidth() * 0.7f);
    });
    recolor();
}