Example usage for android.util TypedValue COMPLEX_UNIT_SP

List of usage examples for android.util TypedValue COMPLEX_UNIT_SP

Introduction

In this page you can find the example usage for android.util TypedValue COMPLEX_UNIT_SP.

Prototype

int COMPLEX_UNIT_SP

To view the source code for android.util TypedValue COMPLEX_UNIT_SP.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is a scaled pixel.

Usage

From source file:com.anniu.shandiandaojia.view.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        v.setBackgroundResource(tabBackgroundResId);
        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            //TODO tab?   ????
            tab.setTextSize(TypedValue.COMPLEX_UNIT_SP, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            if (i == currentPosition) {
                tab.setTextColor(tabTextColorSelected);
            } else {
                tab.setTextColor(tabTextColor);
            }//from  w w w  .ja v  a  2  s  . c o m

            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }
}

From source file:net.oschina.app.ui.MainActivity.java

private void initTabs() {
    MainTab[] tabs = MainTab.values();/*from   www  .j  a v  a2 s  .com*/
    final int size = tabs.length;
    for (int i = 0; i < size; i++) {
        MainTab mainTab = tabs[i];
        TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName()));
        View indicator = LayoutInflater.from(getApplicationContext()).inflate(R.layout.tab_indicator, null);
        TextView title = (TextView) indicator.findViewById(R.id.tab_title);
        Drawable drawable = this.getResources().getDrawable(mainTab.getResIcon());
        title.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
        if (i == 2) {
            indicator.setVisibility(View.INVISIBLE);
            mTabHost.setNoTabChangedTag(getString(mainTab.getResName()));
        }
        title.setText(getString(mainTab.getResName()));
        tab.setIndicator(indicator);
        tab.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new View(MainActivity.this);
            }
        });
        mTabHost.addTab(tab, mainTab.getClz(), null);

        if (mainTab.equals(MainTab.ME)) {
            View cn = indicator.findViewById(R.id.tab_mes);
            mBvNotice = new BadgeView(MainActivity.this, cn);
            mBvNotice.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
            mBvNotice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
            mBvNotice.setBackgroundResource(R.drawable.notification_bg);
            mBvNotice.setGravity(Gravity.CENTER);
        }
        mTabHost.getTabWidget().getChildAt(i).setOnTouchListener(this);
    }
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

public DrawerForm(Context context, Context unstyledContext, Callback callback,
        WatcherService.Client watcherServiceClient) {
    this.context = context;
    this.unstyledContext = unstyledContext;
    this.callback = callback;
    this.watcherServiceClient = watcherServiceClient;
    float density = ResourceUtils.obtainDensity(context);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setLayoutParams(new SortableListView.LayoutParams(SortableListView.LayoutParams.MATCH_PARENT,
            SortableListView.LayoutParams.WRAP_CONTENT));
    LinearLayout editTextContainer = new LinearLayout(context);
    editTextContainer.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(editTextContainer);
    searchEdit = new SafePasteEditText(context);
    searchEdit.setOnKeyListener((v, keyCode, event) -> {
        if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
            v.clearFocus();/*from w  w w .ja  v  a  2 s .c om*/
        }
        return false;
    });
    searchEdit.setHint(context.getString(R.string.text_code_number_address));
    searchEdit.setOnEditorActionListener(this);
    searchEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    searchEdit.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    ImageView searchIcon = new ImageView(context, null, android.R.attr.buttonBarButtonStyle);
    searchIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonForward, 0));
    searchIcon.setScaleType(ImageView.ScaleType.CENTER);
    searchIcon.setOnClickListener(this);
    editTextContainer.addView(searchEdit,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    editTextContainer.addView(searchIcon, (int) (40f * density), (int) (40f * density));
    if (C.API_LOLLIPOP) {
        editTextContainer.setPadding((int) (12f * density), (int) (8f * density), (int) (8f * density), 0);
    } else {
        editTextContainer.setPadding(0, (int) (2f * density), (int) (4f * density), (int) (2f * density));
    }
    LinearLayout selectorContainer = new LinearLayout(context);
    selectorContainer.setBackgroundResource(
            ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0));
    selectorContainer.setOrientation(LinearLayout.HORIZONTAL);
    selectorContainer.setGravity(Gravity.CENTER_VERTICAL);
    selectorContainer.setOnClickListener(v -> {
        hideKeyboard();
        setChanSelectMode(!chanSelectMode);
    });
    linearLayout.addView(selectorContainer);
    selectorContainer.setMinimumHeight((int) (40f * density));
    if (C.API_LOLLIPOP) {
        selectorContainer.setPadding((int) (16f * density), 0, (int) (16f * density), 0);
        ((LinearLayout.LayoutParams) selectorContainer.getLayoutParams()).topMargin = (int) (4f * density);
    } else {
        selectorContainer.setPadding((int) (8f * density), 0, (int) (12f * density), 0);
    }
    chanNameView = new TextView(context, null, android.R.attr.textAppearanceListItem);
    chanNameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f);
    if (C.API_LOLLIPOP) {
        chanNameView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
    } else {
        chanNameView.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
    }
    selectorContainer.addView(chanNameView,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    chanSelectorIcon = new ImageView(context);
    chanSelectorIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonDropDownDrawer, 0));
    selectorContainer.addView(chanSelectorIcon, (int) (24f * density), (int) (24f * density));
    ((LinearLayout.LayoutParams) chanSelectorIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL
            | Gravity.END;
    headerView = linearLayout;
    inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    chans.add(new ListItem(ListItem.ITEM_DIVIDER, 0, 0, null));
    int color = ResourceUtils.getColor(context, R.attr.drawerIconColor);
    ChanManager manager = ChanManager.getInstance();
    Collection<String> availableChans = manager.getAvailableChanNames();
    for (String chanName : availableChans) {
        ChanConfiguration configuration = ChanConfiguration.get(chanName);
        if (configuration.getOption(ChanConfiguration.OPTION_READ_POSTS_COUNT)) {
            watcherSupportSet.add(chanName);
        }
        Drawable drawable = manager.getIcon(chanName, color);
        chanIcons.put(chanName, drawable);
        chans.add(
                new ListItem(ListItem.ITEM_CHAN, chanName, null, null, configuration.getTitle(), 0, drawable));
    }
    if (availableChans.size() == 1) {
        selectorContainer.setVisibility(View.GONE);
    }
}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ? // w  w  w.  j a  v  a 2 s  . c o m
 */
private void showAddPop() {
    final EditText editText = new EditText(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    editText.setLayoutParams(layoutParams);
    //        editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint("?~");
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));
    editText.setBackgroundColor(getResources().getColor(android.R.color.black));
    final PopupWindow popupWindow = new PopupWindow(editText, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                ProgressDialogUtils.showProgressDialog();
                UnFinishItem item = new UnFinishItem();
                Date date = new Date();
                item.createDay = date;
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                dataList.add(item);
                refreshData(true);
                presenter.addItem(item);
            }
        }
    });
}

From source file:com.icoder.couldnewsclient.widget.PagerSlidingTabStrip.java

public void setTabTextSize(int textSize) {
    float size = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSize,
            getResources().getDisplayMetrics());
    this.tabTextSize = (int) size;
    updateTabStyles();//from   w w  w  .j ava 2 s . c om
}

From source file:com.ape.cloudfile.widget.vpi.TabPageIndicator.java

@Override
public void setCurrentItem(int item) {
    if (mViewPager == null) {
        throw new IllegalStateException("ViewPager has not been bound.");
    }/*from   ww w  . ja v a2 s  . com*/
    mSelectedTabIndex = item;
    mViewPager.setCurrentItem(item);

    final int tabCount = mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        final View child = mTabLayout.getChildAt(i);
        final boolean isSelected = (i == item);
        child.setSelected(isSelected);
        if (isSelected) {
            animateToTab(item);
            if (child instanceof TabView) {
                ((TabView) child).setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
            }
        } else {
            if (child instanceof TabView) {
                ((TabView) child).setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
            }
        }
    }
}

From source file:com.bitants.wally.fragments.MaterialDialogFragment.java

protected void setupViews(Context context) {

    if (titleResourceId != 0) {
        textViewTitle.setText(titleResourceId);
    } else if (titleString != null) {
        textViewTitle.setText(titleString);
    }/*from ww  w  .ja  v a  2 s .c  o  m*/

    if (primaryColor != 0) {
        buttonPositive.setTextColor(primaryColor);
    }

    if (positiveButtonTextResourceId != 0) {
        buttonPositive.setText(positiveButtonTextResourceId);
    }

    if (negativeButtonTextResourceId != 0) {
        buttonNegative.setText(negativeButtonTextResourceId);
    }

    buttonNegative.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (negativeButtonOnClickListener != null) {
                negativeButtonOnClickListener.onClick(null, 1);
            }
            dismiss();
        }
    });
    buttonPositive.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (positiveButtonOnClickListener != null) {
                positiveButtonOnClickListener.onClick(null, 0);
            }
            dismiss();
        }
    });

    if (layoutResourceId != 0) {
        viewStub.setLayoutResource(layoutResourceId);
        viewStub.inflate();
    } else if (message != null || messageResourceId != 0) {
        TextView textView = new TextView(context);
        if (messageResourceId != 0) {
            textView.setText(messageResourceId);
        } else {
            textView.setText(message);
        }
        textView.setTextColor(getResources().getColor(R.color.Black_Light));
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        textView.setLineSpacing(1f, 1.2f);
        scrollView.removeAllViews();
        scrollView.addView(textView);
    }
}

From source file:cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper.java

/**
 * id??? sp//from  ww w.j a v a  2  s  .c  o  m
 *
 * @param viewId
 * @param size   ??? sp
 * @return
 */
public BGAViewHolderHelper setTextSizeSp(@IdRes int viewId, float size) {
    getTextView(viewId).setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
    return this;
}

From source file:com.ferid.app.notetake.MainActivity.java

/**
 * Set font size
 */
private void setFontSize() {
    notePad.setTextSize(TypedValue.COMPLEX_UNIT_SP, PrefsUtil.getFontSize(context));
}

From source file:com.hao.common.adapter.BaseViewHolderHelper.java

/**
 * id??? sp//from w w w. j av a2s.c o  m
 *
 * @param viewId
 * @param size   ??? sp
 * @return
 */
public BaseViewHolderHelper setTextSizeSp(@IdRes int viewId, float size) {
    getTextView(viewId).setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
    return this;
}