Java Code Examples for android.widget.TextView.setCompoundDrawablePadding()

The following are Jave code examples for showing how to use setCompoundDrawablePadding() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MVVMFrames   File: ToastBar.java   View Source Code Vote up 6 votes
/**
 * 设置TextView上下左右的图片
 *
 * @param left
 * @param top
 * @param right
 * @param bottom
 * @return ToastBar
 */
public ToastBar setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) {
    TextView message = (TextView) snackbar.getView().findViewById(R.id.snackbar_text);
    LinearLayout.LayoutParams paramsMessage = (LinearLayout.LayoutParams) message.getLayoutParams();
    paramsMessage = new LinearLayout.LayoutParams(paramsMessage.width, paramsMessage.height, 0.0f);
    message.setLayoutParams(paramsMessage);
    message.setCompoundDrawablePadding(message.getPaddingLeft());
    int textSize = (int) message.getTextSize();
    if (left != null) {
        left.setBounds(0, 0, textSize, textSize);
    }
    if (right != null) {
        right.setBounds(0, 0, textSize, textSize);
    }
    message.setCompoundDrawables(left, top, right, bottom);
    LinearLayout.LayoutParams paramsSpace = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
    ((Snackbar.SnackbarLayout) snackbar.getView()).addView(new Space(snackbar.getView().getContext()), 1, paramsSpace);
    return this;
}
 
Example 2
Project: airgram   File: DrawerActionCell.java   View Source Code Vote up 6 votes
public DrawerActionCell(Context context) {
    super(context);

    color= SkinMan.currentSkin.drawerNamesColor();

    //:ramin
    textView = new TextView(context);
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setTextColor(
            //0xff444444
            color
    );

    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
    textView.setCompoundDrawablePadding(AndroidUtilities.dp(34));
    addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 14, 0, 16, 0));
}
 
Example 3
Project: YCDialog   File: DialogAdapter.java   View Source Code Vote up 6 votes
TopHolder(View view) {
    super(view);

    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.width = getScreenWidth(context) / 5;

    item = new TextView(view.getContext());
    item.setLayoutParams(params);
    item.setMaxLines(1);
    item.setEllipsize(TextUtils.TruncateAt.END);
    item.setGravity(Gravity.CENTER);
    item.setTextColor(ContextCompat.getColor(view.getContext(), R.color.gray_dark));
    item.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.app_normal_margin));
    item.setCompoundDrawablePadding(topPadding);
    item.setPadding(0, padding, 0, padding);

    TypedValue typedValue = new TypedValue();
    view.getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
    item.setBackgroundResource(typedValue.resourceId);

    ((LinearLayout) view).addView(item);
}
 
Example 4
Project: PicKing   File: SnackbarUtils.java   View Source Code Vote up 6 votes
/**
 * 设置TextView(@+id/snackbar_text)左右两侧的图片
 *
 * @param leftDrawable
 * @param rightDrawable
 * @return
 */
public SnackbarUtils leftAndRightDrawable(@Nullable Drawable leftDrawable, @Nullable Drawable rightDrawable) {
    if (getSnackbar() != null) {
        TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
        LinearLayout.LayoutParams paramsMessage = (LinearLayout.LayoutParams) message.getLayoutParams();
        paramsMessage = new LinearLayout.LayoutParams(paramsMessage.width, paramsMessage.height, 0.0f);
        message.setLayoutParams(paramsMessage);
        message.setCompoundDrawablePadding(message.getPaddingLeft());
        int textSize = (int) message.getTextSize();
        if (leftDrawable != null) {
            leftDrawable.setBounds(0, 0, textSize, textSize);
        }
        if (rightDrawable != null) {
            rightDrawable.setBounds(0, 0, textSize, textSize);
        }
        message.setCompoundDrawables(leftDrawable, null, rightDrawable, null);
        LinearLayout.LayoutParams paramsSpace = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
        ((Snackbar.SnackbarLayout) getSnackbar().getView()).addView(new Space(getSnackbar().getView().getContext()), 1, paramsSpace);
    }
    return this;
}
 
Example 5
Project: chromium-for-android-56-debug-video   File: NavigationPopup.java   View Source Code Vote up 6 votes
public TextView createListItem() {
    TextView view = new TextView(mContext);
    view.setFadingEdgeLength(mFadeEdgeLength);
    view.setHorizontalFadingEdgeEnabled(true);
    view.setSingleLine();
    view.setTextSize(TEXT_SIZE_SP);
    view.setMinimumHeight(mListItemHeight);
    view.setGravity(Gravity.CENTER_VERTICAL);
    view.setCompoundDrawablePadding(mPadding);
    if (!mIsLayoutDirectionRTL) {
        view.setPadding(mPadding, 0, mPadding + mFadePadding , 0);
    } else {
        view.setPadding(mPadding + mFadePadding, 0, mPadding, 0);
    }
    return view;
}
 
Example 6
Project: q-mail   File: OpenPgpAppPreference.java   View Source Code Vote up 5 votes
@Override
protected void onPrepareDialogBuilder(Builder builder) {

    // do again, maybe an app has now been installed
    populateAppList();

    // Init ArrayAdapter with OpenPGP Providers
    ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getContext(),
            android.R.layout.select_dialog_singlechoice, android.R.id.text1, mList) {
        public View getView(int position, View convertView, ViewGroup parent) {
            // User 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(mList.get(position).icon, null,
                    null, null);

            // Add margin between image and text (support various screen densities)
            int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp10);

            return v;
        }
    };

    builder.setSingleChoiceItems(adapter, getIndexOfProviderList(mSelectedPackage),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    OpenPgpProviderEntry entry = mList.get(which);

                    if (entry.intent != null) {
                        /*
                         * Intents are called as activity
                         *
                         * Current approach is to assume the user installed the app.
                         * If he does not, the selected package is not valid.
                         *
                         * However  applications should always consider this could happen,
                         * as the user might remove the currently used OpenPGP app.
                         */
                        getContext().startActivity(entry.intent);
                        return;
                    }

                    mSelectedPackage = entry.packageName;

                    /*
                     * Clicking on an item simulates the positive button click, and dismisses
                     * the dialog.
                     */
                    OpenPgpAppPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    dialog.dismiss();
                }
            });

    /*
     * The typical interaction for list-based dialogs is to have click-on-an-item dismiss the
     * dialog instead of the user having to press 'Ok'.
     */
    builder.setPositiveButton(null, null);
}
 
Example 7
Project: RLibrary   File: UIItem.java   View Source Code Vote up 5 votes
private static TextView makeItem(Context context, ItemInfo info) {
    TextView textView = new TextView(context);
    textView.setCompoundDrawablesRelativeWithIntrinsicBounds(info.leftIcoResId == -1 ? null :
                    context.getResources().getDrawable(info.leftIcoResId), null,
            info.rightIcoResId == -1 ? null : context.getResources().getDrawable(info.rightIcoResId), null);
    textView.setText(info.itemText);
    textView.setTextColor(info.textColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, info.textSize);
    textView.setGravity(Gravity.CENTER_VERTICAL);
    textView.setCompoundDrawablePadding((int) dpToPx(context, 8));
    textView.setPadding(0, 0, (int) dpToPx(context, 8), 0);
    textView.setOnClickListener(info.clickListener);
    textView.setBackgroundResource(info.backgroundResId);
    return textView;
}
 
Example 8
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 5 votes
/**
 * 设置左侧图片
 * @param textView
 * @param drawable
 * @param padding
 */
public static void setLeftImage(TextView textView, Drawable drawable, float padding) {
    if (textView != null) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        }
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(drawable, null, null, null);
    }
}
 
Example 9
Project: chromium-for-android-56-debug-video   File: BillingAddressAdapter.java   View Source Code Vote up 5 votes
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View view;

    // Add a "+" icon and a blue tint to the last element.
    if (position == getCount() - 1) {
        view = super.getDropDownView(position, convertView, parent);
        TextView tv = (TextView) view;
        Resources resources = getContext().getResources();

        // Create the "+" icon, put it left of the text and add appropriate padding.
        tv.setCompoundDrawablesWithIntrinsicBounds(
                TintedDrawable.constructTintedDrawable(
                    resources, R.drawable.plus, R.color.light_active_color),
                null, null, null);
        tv.setCompoundDrawablePadding(
                resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing));

        // Set the correct appearance, face and style for the text.
        ApiCompatibilityUtils.setTextAppearance(tv, R.style.PaymentsUiSectionAddButtonLabel);
        tv.setTypeface(Typeface.create(
                resources.getString(R.string.roboto_medium_typeface),
                R.integer.roboto_medium_textstyle));
    } else {
        // Don't use the recycled convertView, as it may have the style of the last element.
        view = super.getDropDownView(position, null, parent);
    }

    return view;
}
 
Example 10
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 5 votes
/**
 * 设置顶部图片
 * @param textView
 * @param resId
 * @param padding
 */
public static void setTopImage(TextView textView, int resId, float padding) {
    if (textView != null) {
        Drawable drawable = textView.getContext().getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, drawable, null, null);
    }
}
 
Example 11
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 5 votes
/**
 * 设置右侧图片
 * @param textView
 * @param drawable
 * @param padding
 */
public static void setRightImage(TextView textView, Drawable drawable, float padding) {
    if (textView != null) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        }
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, null, drawable, null);
    }
}
 
Example 12
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 5 votes
/**
 * 设置底部图片
 * @param textView
 * @param drawable
 * @param padding
 */
public static void setBottomImage(TextView textView, Drawable drawable, float padding) {
    if (textView != null) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        }
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, null, null, drawable);
    }
}
 
Example 13
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 5 votes
/**
 * 设置底部图片
 * @param textView
 * @param resId
 * @param padding
 */
public static void setBottomImage(TextView textView, int resId, float padding) {
    if (textView != null) {
        Drawable drawable = textView.getContext().getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, null, null, drawable);
    }
}
 
Example 14
Project: q-mail   File: SMimeAppSelectDialog.java   View Source Code Vote up 4 votes
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle(R.string.account_settings_smime_app);

    // do again, maybe an app has now been installed
    populateAppList();

    // Init ArrayAdapter with S/MIME Providers
    ListAdapter adapter = new ArrayAdapter<SMimeProviderEntry>(getActivity(),
            android.R.layout.select_dialog_singlechoice, android.R.id.text1, sMimeProviderList) {
        public View getView(int position, View convertView, ViewGroup parent) {
            // User 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(sMimeProviderList.get(position).icon, null,
                    null, null);

            // Add margin between image and text (support various screen densities)
            int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp10);

            return v;
        }
    };

    builder.setSingleChoiceItems(adapter, getIndexOfProviderList(selectedPackage),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SMimeProviderEntry entry = sMimeProviderList.get(which);

                    if (entry.intent != null) {
                        /*
                         * Intents are called as activity
                         *
                         * Current approach is to assume the user installed the app.
                         * If he does not, the selected package is not valid.
                         *
                         * However  applications should always consider this could happen,
                         * as the user might remove the currently used S/MIME app.
                         */
                        getActivity().startActivity(entry.intent);
                        return;
                    }

                    selectedPackage = entry.packageName;

                    dialog.dismiss();
                }
            });

    return builder.create();
}
 
Example 15
Project: q-mail   File: OpenPgpAppSelectDialog.java   View Source Code Vote up 4 votes
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle(R.string.account_settings_openpgp_app);

    // do again, maybe an app has now been installed
    populateAppList();

    // Init ArrayAdapter with OpenPGP Providers
    ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getActivity(),
            android.R.layout.select_dialog_singlechoice, android.R.id.text1, openPgpProviderList) {
        public View getView(int position, View convertView, ViewGroup parent) {
            // User 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(openPgpProviderList.get(position).icon, null,
                    null, null);

            // Add margin between image and text (support various screen densities)
            int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp10);

            return v;
        }
    };

    builder.setSingleChoiceItems(adapter, getIndexOfProviderList(selectedPackage),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    OpenPgpProviderEntry entry = openPgpProviderList.get(which);

                    if (entry.intent != null) {
                        /*
                         * Intents are called as activity
                         *
                         * Current approach is to assume the user installed the app.
                         * If he does not, the selected package is not valid.
                         *
                         * However  applications should always consider this could happen,
                         * as the user might remove the currently used OpenPGP app.
                         */
                        getActivity().startActivity(entry.intent);
                        return;
                    }

                    selectedPackage = entry.packageName;

                    dialog.dismiss();
                }
            });

    return builder.create();
}
 
Example 16
Project: airgram   File: ActionBarMenuItem.java   View Source Code Vote up 4 votes
public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setTextColor(0xff212121);
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!LocaleController.isRTL) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!LocaleController.isRTL) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon), null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (LocaleController.isRTL) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}
 
Example 17
Project: airgram   File: PickerBottomLayout.java   View Source Code Vote up 4 votes
public PickerBottomLayout(Context context, boolean darkTheme) {
    super(context);
    isDarkTheme = darkTheme;

    setBackgroundColor(isDarkTheme ? 0xff1a1a1a : 0xffffffff);

    cancelButton = new TextView(context);
    cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    cancelButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8);
    cancelButton.setGravity(Gravity.CENTER);
    cancelButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false));
    cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
    cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
    cancelButton.setTypeface(FontManager.instance().getTypeface());
    addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    doneButton = new LinearLayout(context);
    doneButton.setOrientation(LinearLayout.HORIZONTAL);
    doneButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false));
    doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
    addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));

    doneButtonBadgeTextView = new TextView(context);
    doneButtonBadgeTextView.setTypeface(FontManager.instance().getTypeface());
    doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    doneButtonBadgeTextView.setTextColor(0xffffffff);
    doneButtonBadgeTextView.setGravity(Gravity.CENTER);
    doneButtonBadgeTextView.setBackgroundResource(isDarkTheme ? R.drawable.photobadge : R.drawable.bluecounter);
    doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23));
    doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1));
    doneButton.addView(doneButtonBadgeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0));

    doneButtonTextView = new TextView(context);
    doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    doneButtonTextView.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8);
    doneButtonTextView.setGravity(Gravity.CENTER);
    doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
    doneButtonTextView.setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
    doneButtonTextView.setTypeface(FontManager.instance().getTypeface());
    doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
}
 
Example 18
Project: KrGallery   File: ActionBarMenuItem.java   View Source Code Vote up 4 votes
public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTextColor(0xff212121);
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!AndroidUtilities.isRTL()) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!AndroidUtilities.isRTL()) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon), null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (AndroidUtilities.isRTL()) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}
 
Example 19
Project: KrGallery   File: PickerBottomLayout.java   View Source Code Vote up 4 votes
public PickerBottomLayout(Context context, boolean darkTheme) {
    super(context);
    isDarkTheme = darkTheme;

    setBackgroundColor(isDarkTheme ? 0xff1a1a1a : 0xffffffff);

    cancelButton = new TextView(context);
    cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    cancelButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff007aff);
    cancelButton.setGravity(Gravity.CENTER);
    cancelButton.setBackgroundDrawable(
            Theme.createBarSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR
                    : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false));
    cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
    cancelButton.setText(R.string.Preview);
    // cancelButton.getPaint().setFakeBoldText(true);
    addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    doneButton = new LinearLayout(context);
    doneButton.setOrientation(LinearLayout.HORIZONTAL);
    doneButton.setBackgroundDrawable(
            Theme.createBarSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR
                    : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false));
    doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
    addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));

    doneButtonBadgeTextView = new TextView(context);
    // doneButtonBadgeTextView.getPaint().setFakeBoldText(true);
    doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    doneButtonBadgeTextView.setTextColor(0xffffffff);
    doneButtonBadgeTextView.setGravity(Gravity.CENTER);
    doneButtonBadgeTextView.setBackgroundResource(
            isDarkTheme ? R.drawable.photobadge_new : R.drawable.photobadge_new);
    doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8),
            AndroidUtilities.dp(1));
    doneButton.addView(doneButtonBadgeTextView,
            LayoutHelper.createLinear(26, 26, Gravity.CENTER_VERTICAL, 0, 0, 10, 0));

    doneButtonTextView = new TextView(context);
    doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    doneButtonTextView.setTextColor(isDarkTheme ? 0xffffffff : 0xff007aff);
    doneButtonTextView.setGravity(Gravity.CENTER);
    doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
    doneButtonTextView.setText(R.string.Send);
    // doneButtonTextView.getPaint().setFakeBoldText(true);
    doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
}
 
Example 20
Project: MySelfDemo   File: SuperTextView.java   View Source Code Vote up 3 votes
/**
 * 设置textView的drawable
 *
 * @param textView        对象
 * @param drawableLeft    左边图标
 * @param drawableRight   右边图标
 * @param drawablePadding 图标距离文字的间距
 */
public void setDefaultDrawable(TextView textView, Drawable drawableLeft, Drawable drawableRight, int drawablePadding) {
    if (drawableLeft != null || drawableRight != null) {
        textView.setVisibility(VISIBLE);
    }
    textView.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, drawableRight, null);
    textView.setCompoundDrawablePadding(drawablePadding);
}