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

The following examples show how to use android.widget.TextView#setBackgroundResource() . These examples are extracted from open source projects. 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 Project: timecat   File: TimeCatLayout.java    License: Apache License 2.0 6 votes vote down vote up
public void addTextItem(String text) {
        mNeedReDetectInMeasure = true;
//        if (TextUtils.isEmpty(text) || text.equals(" ")) {
        if (TextUtils.isEmpty(text)) {
            return;
        }
        if (text.contains(TAB)) {
            return;
        }
        TextView view = new TextView(getContext());
        view.setText(text);
        view.setBackgroundResource(mTextBgRes);
        if (mColorStateList == null) {
            view.setTextColor(ContextCompat.getColorStateList(getContext(), mTextColorRes));
        } else {
            view.setTextColor(mColorStateList);
        }
        view.setTextSize(mTextSize);
        view.setPadding(mTextPadding, mTextPaddingPort, mTextPadding, mTextPaddingPort);
        view.setGravity(Gravity.CENTER);
        addView(view);
    }
 
Example 2
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
                outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
 
Example 3
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
                outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
 
Example 4
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
                outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
 
Example 5
public void addHintIcon(int drawableId)
{
	if (this.mHintIconArray.indexOfKey(drawableId) == -1)
	{
		this.mHintIconArray.put(drawableId, drawableId);
		
		TextView tv = new TextView(mContext);
		tv.setTag(drawableId);
		tv.setGravity(Gravity.CENTER);
		ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		tv.setLayoutParams(lp);
		tv.setBackgroundResource(drawableId);
		tv.setIncludeFontPadding(false);
		
		this.mHintIcons.addView(tv);
	}
}
 
Example 6
Source Project: imsdk-android   File: PhotosAdapter.java    License: MIT License 6 votes vote down vote up
private void updateSelector(TextView tvSelector, boolean selected, Photo photo, int position) {
    if (selected) {
        String number = Result.getSelectorNumber(photo);
        if (number.equals("0")) {
            tvSelector.setBackgroundResource(R.drawable.bg_select_false_easy_photos);
            tvSelector.setText(null);
            return;
        }
        tvSelector.setText(number);
        tvSelector.setBackgroundResource(R.drawable.bg_select_true_easy_photos);
        if (isSingle) {
            singlePosition = position;
            tvSelector.setText("1");
        }
    } else {
        if (unable) {
            tvSelector.setBackgroundResource(R.drawable.bg_select_false_unable_easy_photos);
        } else {
            tvSelector.setBackgroundResource(R.drawable.bg_select_false_easy_photos);
        }
        tvSelector.setText(null);
    }
}
 
Example 7
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
            outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
 
Example 8
public void addTextItem(String text) {
        mNeedReDetectInMeasure=true;
//        if (TextUtils.isEmpty(text) || text.equals(" ")) {
        if (TextUtils.isEmpty(text)) {
            return;
        }
        if (text.contains(TAB)) {
            return;
        }
        TextView view = new TextView(getContext());
        view.setText(text);
        view.setBackgroundResource(mTextBgRes);
        if (mColorStateList == null) {
            view.setTextColor(ContextCompat.getColorStateList(getContext(), mTextColorRes));
        } else {
            view.setTextColor(mColorStateList);
        }
        view.setTextSize(mTextSize);
        if (RegexUtil.isSymbol(text)) {
            view.setPadding(mSymbolTextPadding, mTextPaddingPort,mSymbolTextPadding, mTextPaddingPort);
        } else {
            view.setPadding(mTextPadding, mTextPaddingPort,mTextPadding, mTextPaddingPort);
        }
        view.setGravity(Gravity.CENTER);
        addView(view);
    }
 
Example 9
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
            outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
 
Example 10
Source Project: YCDialog   File: DialogAdapter.java    License: Apache License 2.0 6 votes vote down vote up
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 11
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
            outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
 
Example 12
private void centerButton(TextView button) {
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) button.getLayoutParams();
    params.gravity = Gravity.CENTER_HORIZONTAL;
    params.weight = 0.5f;
    button.setLayoutParams(params);
    button.setBackgroundResource(R.drawable.common_button);
}
 
Example 13
Source Project: AndroidProject   File: AddressDialog.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
    TextView textView = new TextView(parent.getContext());
    textView.setGravity(Gravity.CENTER_VERTICAL);
    textView.setBackgroundResource(R.drawable.selector_transparent);
    textView.setTextColor(0xFF222222);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setPadding((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()));
    return new ViewHolder(textView);
}
 
Example 14
Source Project: FlowLayout   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private TextView buildLabel(String text) {
    TextView textView = new TextView(this);
    textView.setText(text);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    textView.setPadding((int)dpToPx(16), (int)dpToPx(8), (int)dpToPx(16), (int)dpToPx(8));
    textView.setBackgroundResource(R.drawable.label_bg);

    return textView;
}
 
Example 15
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
                outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    boolean phone = getResources().getBoolean(R.bool.portrait_only);
    Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getRealSize(size);
    int width = size.x;
    int height = size.y;
    // special case for 7' inch tablets
    // if we leave padding to 16 the text title on the viewPager will be cut
    if (!phone && ((width == 1024 && height == 600) || (height == 1024 && width == 600)))
        TAB_VIEW_PADDING_DIPS = 14;


    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
 
Example 16
Source Project: imsdk-android   File: SmartTabLayout.java    License: MIT License 5 votes vote down vote up
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(CharSequence title) {
  TextView textView = new TextView(getContext());
  textView.setGravity(Gravity.CENTER);
  textView.setText(title);
  textView.setTextColor(tabViewTextColors);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
  textView.setTypeface(Typeface.DEFAULT_BOLD);
  textView.setLayoutParams(new LinearLayout.LayoutParams(
      LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));

  if (tabViewBackgroundResId != NO_ID) {
    textView.setBackgroundResource(tabViewBackgroundResId);
  } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    // If we're running on Honeycomb or newer, then we can use the Theme's
    // selectableItemBackground to ensure that the View has a pressed state
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
        outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
  }

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
    textView.setAllCaps(tabViewTextAllCaps);
  }

  textView.setPadding(
      tabViewTextHorizontalPadding, 0,
      tabViewTextHorizontalPadding, 0);

  if (tabViewTextMinWidth > 0) {
    textView.setMinWidth(tabViewTextMinWidth);
  }

  return textView;
}
 
Example 17
protected TextView createDefaultTabView(Context context, int i) {

        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);

        if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP * 2);
        } else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (TAB_VIEW_TEXT_SIZE_SP * 1.5));
        } else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        } else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (TAB_VIEW_TEXT_SIZE_SP * .75));
        } else {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        }

        //    textView.setTypeface(custom_font);
        textView.setTextColor(Color.WHITE);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {// allcaps is for api 14 and upper
            textView.setAllCaps(false);
        }

        if (i == 0) {
            textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 8.5f));
        } else if (i == 1) {
            textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 8.5f));
        } else if (i == 2) {
            textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 8.5f));
        } else {
            textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 8.5f));
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            TypedValue outValue = new TypedValue();
            getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
            textView.setBackgroundResource(outValue.resourceId);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style

        }

        float dp = getResources().getDisplayMetrics().density;
        textView.setPadding(2, (int) (20 * dp), 2, (int) (20 * dp));

        return textView;
    }
 
Example 18
Source Project: edx-app-android   File: PlayerFragment.java    License: Apache License 2.0 4 votes vote down vote up
private void showSettingsPopup(final Point p) {
    try{
        if(player!=null){
            player.getController().setAutoHide(!getTouchExploreEnabled());
            Activity context = getActivity();

            float popupHeight =  getResources().getDimension(R.dimen.settings_popup_height);
            float popupWidth =  getResources().getDimension(R.dimen.settings_popup_width);

            // Inflate the popup_layout.xml
            LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.setting_popup);
            LayoutInflater layoutInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = layoutInflater.inflate(R.layout.panel_settings_popup, viewGroup);

            // Creating the PopupWindow
            settingPopup = new PopupWindow(context);
            settingPopup.setContentView(layout);
            settingPopup.setWidth((int)popupWidth);
            settingPopup.setHeight((int)popupHeight);
            settingPopup.setFocusable(true);
            settingPopup.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss() {
                    hideTransparentImage();
                    if(player!=null){
                        player.getController().setSettingsBtnDrawable(false);
                        player.getController().setAutoHide(!getTouchExploreEnabled());
                    }
                }
            });

            // Clear the default translucent background
            settingPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

            // Displaying the popup at the specified location, + offsets.
            settingPopup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x-(int)popupWidth, p.y-(int)popupHeight);

            TextView tv_closedCaption = (TextView) layout.findViewById(R.id.tv_closedcaption);
            if ((langList != null) && (langList.size() > 0))
            {
                tv_closedCaption.setBackgroundResource(R.drawable.white_rounded_selector);
                tv_closedCaption.setOnClickListener(new View.OnClickListener(){
                    public void onClick(View paramAnonymousView) {
                        showCCFragmentPopup();
                    }
                });
            }else{
                tv_closedCaption.setBackgroundResource(R.drawable.grey_roundedbg);
                tv_closedCaption.setOnClickListener(null);
            }

            layout.findViewById(R.id.tv_video_speed).setOnClickListener(v -> showVideoSpeedFragmentPopup());
        }
    }catch(Exception e){
        logger.error(e);
    }
}
 
Example 19
private void init() {
    mSolidColor = 0;
    mSelectionDivider = new Paint();
    mSelectionDivider.setColor(Theme.getColor(Theme.key_dialogButton));

    mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics());
    mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics());

    mMinHeight = SIZE_UNSPECIFIED;

    mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics());
    if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) {
        throw new IllegalArgumentException("minHeight > maxHeight");
    }

    mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics());

    mMaxWidth = SIZE_UNSPECIFIED;
    if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) {
        throw new IllegalArgumentException("minWidth > maxWidth");
    }

    mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);

    mPressedStateHelper = new PressedStateHelper();

    setWillNotDraw(false);

    mInputText = new TextView(getContext());
    mInputText.setGravity(Gravity.CENTER);
    mInputText.setSingleLine(true);
    mInputText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    mInputText.setBackgroundResource(0);
    mInputText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    mInputText.setVisibility(INVISIBLE);
    addView(mInputText, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mTextSize = (int) mInputText.getTextSize();

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(mTextSize);
    paint.setTypeface(mInputText.getTypeface());
    ColorStateList colors = mInputText.getTextColors();
    int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE);
    paint.setColor(color);
    mSelectorWheelPaint = paint;

    mFlingScroller = new Scroller(getContext(), null, true);
    mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f));

    updateInputTextView();
}
 
Example 20
@Override
public void onConfigureActionBar(ActionBar actionBar) {
    super.onConfigureActionBar(actionBar);

    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);

    // Loading Toolbar header views
    ActorStyle style = ActorSDK.sharedActor().style;
    barView = LayoutInflater.from(getActivity()).inflate(R.layout.bar_conversation, null);
    actionBar.setCustomView(barView, new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT));
    Toolbar parent = (Toolbar) barView.getParent();
    parent.setContentInsetsAbsolute(0, 0);

    barView.findViewById(R.id.home).setOnClickListener(v -> {
        Activity activity = getActivity();
        if (activity != null) {
            activity.onBackPressed();
        }
    });

    counter = (TextView) barView.findViewById(R.id.counter);

    counter.setTextColor(style.getDialogsCounterTextColor());
    counter.setBackgroundResource(R.drawable.ic_counter_circle);
    counter.getBackground().setColorFilter(style.getDialogsCounterBackgroundColor(), PorterDuff.Mode.MULTIPLY);
    barTitle = (TextView) barView.findViewById(R.id.title);
    barSubtitleContainer = barView.findViewById(R.id.subtitleContainer);
    barTypingIcon = (ImageView) barView.findViewById(R.id.typingImage);
    barTypingIcon.setImageDrawable(new TypingDrawable());
    barTyping = (TextView) barView.findViewById(R.id.typing);
    barSubtitle = (TextView) barView.findViewById(R.id.subtitle);
    barTypingContainer = barView.findViewById(R.id.typingContainer);
    barTypingContainer.setVisibility(View.INVISIBLE);
    barAvatar = (AvatarView) barView.findViewById(R.id.avatarPreview);
    barAvatar.init(Screen.dp(32), 18);

    barView.findViewById(R.id.titleContainer).setOnClickListener(v -> {
        if (peer.getPeerType() == PeerType.PRIVATE) {
            ActorSDKLauncher.startProfileActivity(getActivity(), peer.getPeerId());
        } else if (peer.getPeerType() == PeerType.GROUP) {
            ActorSDK.sharedActor().startGroupInfoActivity(getActivity(), peer.getPeerId());
        } else {
            // Nothing to do
        }
    });
}