Example usage for android.util TypedValue COMPLEX_UNIT_PX

List of usage examples for android.util TypedValue COMPLEX_UNIT_PX

Introduction

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

Prototype

int COMPLEX_UNIT_PX

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

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is raw pixels.

Usage

From source file:com.agenthun.readingroutine.utils.TextSharedElementCallback.java

@Override
public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
        List<View> sharedElementSnapshots) {
    TextView initialView = getTextView(sharedElements);

    if (initialView == null) {
        Log.w(TAG, "onSharedElementEnd: No shared TextView, skipping");
        return;/*  www.jav  a  2 s.  c o  m*/
    }

    // Setup the TextView's end values.
    initialView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTargetViewTextSize);
    ViewUtils.setPaddingStart(initialView, mTargetViewPaddingStart);

    // Re-measure the TextView (since the text size has changed).
    int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    initialView.measure(widthSpec, heightSpec);
    initialView.requestLayout();
}

From source file:com.krg.ParallaxScrollView.sample.PagerViewBackgroundActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create ParallaxScrollView, which will eventually be the container for everything.
    ParallaxScrollView parallaxScrollView = new ParallaxScrollView(this);
    parallaxScrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // Create the Background View, a ViewPager.
    ViewPager backgroundViewPager = new ViewPager(this);
    backgroundViewPager.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 600));
    ImageAdapter adapter = new ImageAdapter(this);
    backgroundViewPager.setAdapter(adapter);

    // Create the Contents View.
    LinearLayout contentView = new LinearLayout(this);
    contentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    contentView.setBackgroundColor(0xffffffff);
    int padding = getResources().getDimensionPixelSize(R.dimen.content_padding);
    contentView.setPadding(padding, padding, padding, padding);
    TextView textView = new TextView(this);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setText(R.string.starry_night);
    float textSize = getResources().getDimension(R.dimen.content_text_size);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    contentView.addView(textView);//from w w w  . j  a va  2  s. co  m

    // Make the ParallaxScrollView aware of the Background, Content, and Header Views, and set the content of
    // this view to the ParallaxScrollView.
    parallaxScrollView.setBackgroundView(backgroundViewPager);
    parallaxScrollView.setContentView(contentView);
    setContentView(parallaxScrollView);
}

From source file:org.homelinux.tapiri.jei.essem.AutoFitTextView.java

private void refitTextOnChanged(String text, int textWidth, int textHeight) {
    if (textWidth > 0) {
        // Subtract a little extra space to account for line height
        int availableWidth = textWidth - this.getPaddingLeft() - this.getPaddingRight();
        int availableHeight = textHeight - this.getPaddingTop() - this.getPaddingBottom() - 20;
        String largestLine = getLargestLine(text);
        int currentChars = text.length();

        if (currentChars != previousChars) {
            float trySize = this.getTextSize();

            if (currentChars > previousChars) {
                while ((trySize > minTextSize) && ((this.getPaint().measureText(largestLine) > availableWidth)
                        || ((this.getLineHeight() * getOriginalLineCount()) > availableHeight))) {
                    trySize -= 1;/*from w ww  .j a  v a  2 s.c  om*/
                    if (trySize <= minTextSize) {
                        trySize = minTextSize;
                        this.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
                        break;
                    }
                    this.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
                }
            } else {
                while ((trySize < maxTextSize) && (this.getPaint().measureText(largestLine) < availableWidth)
                        && ((this.getLineHeight() * getOriginalLineCount()) < availableHeight)) {
                    trySize += 1;
                    if (trySize >= maxTextSize) {
                        trySize = maxTextSize;
                        this.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
                        break;
                    }
                    this.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
                }
                // It's possible that the size of the text is now bigger than the available space
                if ((this.getPaint().measureText(largestLine) > availableWidth)
                        || ((this.getLineHeight() * getOriginalLineCount()) > availableHeight)) {
                    trySize -= 1;
                    this.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
                }
            }
            previousChars = currentChars;
        } else {
            float trySize = maxTextSize;

            this.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
            while ((trySize > minTextSize) && ((this.getPaint().measureText(largestLine) > availableWidth)
                    || ((this.getLineHeight() * getOriginalLineCount()) > availableHeight))) {
                trySize -= 1;
                if (trySize <= minTextSize) {
                    trySize = minTextSize;
                    break;
                }
                this.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
            }
            this.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
        }
    }
}

From source file:com.google.samples.apps.topeka.widget.TextResizeTransition.java

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }/*w w w .ja  v  a 2  s.c o  m*/

    float initialTextSize = (float) startValues.values.get(PROPERTY_NAME_TEXT_RESIZE);
    float targetTextSize = (float) endValues.values.get(PROPERTY_NAME_TEXT_RESIZE);
    TextView targetView = (TextView) endValues.view;
    targetView.setTextSize(TypedValue.COMPLEX_UNIT_PX, initialTextSize);

    int initialPaddingStart = (int) startValues.values.get(PROPERTY_NAME_PADDING_RESIZE);
    int targetPaddingStart = (int) endValues.values.get(PROPERTY_NAME_PADDING_RESIZE);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(targetView, ViewUtils.PROPERTY_TEXT_SIZE, initialTextSize, targetTextSize),
            ObjectAnimator.ofInt(targetView, ViewUtils.PROPERTY_TEXT_PADDING_START, initialPaddingStart,
                    targetPaddingStart));
    return animatorSet;
}

From source file:com.esminis.server.library.dialog.about.AboutViewImpl.java

@Override
public void setupOnShow() {
    final Button button = getButton(DialogInterface.BUTTON_NEGATIVE);
    final ViewGroup.LayoutParams params = button.getLayoutParams();
    button.setTextColor(Color.BLACK);
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            getContext().getResources().getDimensionPixelSize(R.dimen.dialog_button_font_size));
    button.setGravity(Gravity.CENTER);/*w w w  .j  a v a  2s .com*/
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    button.setLayoutParams(params);
}

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.instructions.InstructionDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_instruction_detail, container, false);

    Drawable instructionDrawable = AssetsManager.getImage(getActivity(),
            getArguments().getString(ARG_ITEM_IMAGE));
    if (instructionDrawable != null) {
        ((ImageView) rootView.findViewById(R.id.image_illustration)).setImageDrawable(instructionDrawable);
    }//  w  w  w .j ava2s. co m

    ArrayList<String> instructionText = getArguments().getStringArrayList(ARG_ITEM_TEXT);
    if (instructionText != null) {

        LinearLayout linearLayout = (LinearLayout) rootView.findViewById(R.id.layout_instructions);
        for (String instruction : instructionText) {
            TextView textView = new TextView(getActivity());
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                    getResources().getDimension(R.dimen.mediumTextSize));

            textView.setPadding(0, 0, 0, (int) getResources().getDimension(R.dimen.activity_vertical_margin));

            textView.setLineSpacing(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5.0f,
                    getResources().getDisplayMetrics()), 1.0f);

            String text = instruction;
            if (instruction.contains("<!>")) {
                text = instruction.replaceAll("<!>", "");
                textView.setTextColor(Color.RED);
            } else {
                textView.setTextColor(Color.DKGRAY);
            }

            if (instruction.contains("<b>")) {
                text = text.replaceAll("<b>", "").replaceAll("</b>", "");
                textView.setTypeface(null, Typeface.BOLD);
            } else {
                textView.setTextColor(Color.DKGRAY);
            }

            Spanned spanned = StringUtil.getStringResourceByName(getContext(), text);
            if (!text.isEmpty()) {
                textView.append(spanned);
                linearLayout.addView(textView);
            }
        }
    }

    return rootView;
}

From source file:info.guardianproject.notepadbot.NoteEdit.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.note_edit);//from w  w  w . j  a  v  a  2s.  c o  m

    // Find all the views now to save time searching later multiple times
    mImageView = (ImageView) findViewById(R.id.odata);
    mBodyText = (LinedEditText) findViewById(R.id.body);
    mTitleText = (EditText) findViewById(R.id.title);

    // Show the Up button in the action bar.
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    if (savedInstanceState != null) {
        mRowId = savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID);
        mTextSize = savedInstanceState.getFloat(TEXT_SIZE, 0);
    }

    if (mTextSize == 0)
        mTextSize = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getFloat(TEXT_SIZE, 0);

    if (mTextSize != 0)
        mBodyText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);

    mCacheWord = new CacheWordActivityHandler(this, ((App) getApplication()).getCWSettings());

}

From source file:com.stfalcon.chatkit.messages.MessageInput.java

private void init(Context context, AttributeSet attrs) {
    init(context);//w ww  .  j  a v a  2 s .  c  o m
    MessageInputStyle style = MessageInputStyle.parse(context, attrs);

    this.messageInput.setMaxLines(style.getInputMaxLines());
    this.messageInput.setHint(style.getInputHint());
    this.messageInput.setText(style.getInputText());
    this.messageInput.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getInputTextSize());
    this.messageInput.setTextColor(style.getInputTextColor());
    this.messageInput.setHintTextColor(style.getInputHintColor());
    this.messageInput.setBackground(style.getInputBackground());
    setCursor(style.getInputCursorDrawable());

    this.messageSendButton.setBackground(style.getInputButtonBackground());
    this.messageSendButton.setImageDrawable(style.getInputButtonIcon());
    this.messageSendButton.getLayoutParams().width = style.getInputButtonWidth();
    this.messageSendButton.getLayoutParams().height = style.getInputButtonHeight();
    this.buttonSpace.getLayoutParams().width = style.getInputButtonMargin();

    if (getPaddingLeft() == 0 && getPaddingRight() == 0 && getPaddingTop() == 0 && getPaddingBottom() == 0) {
        setPadding(style.getInputDefaultPaddingLeft(), style.getInputDefaultPaddingTop(),
                style.getInputDefaultPaddingRight(), style.getInputDefaultPaddingBottom());
    }
}

From source file:cn.qbcbyb.library.view.PagerSlidingTabStrip.java

public void setCurrentItem(int currentItem) {
    if (this.currentItem > -1 && this.currentItem < tabsContainer.getChildCount()) {
        View view = tabsContainer.getChildAt(this.currentItem);
        view.setSelected(false);/*from   w  w w  .  j  a v a2 s  .c  o m*/
        if (view instanceof TextView) {
            TextView tab = ((TextView) view);
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
        }
    }
    this.currentItem = currentItem;
    if (this.currentItem > -1 && this.currentItem < tabsContainer.getChildCount()) {
        View view = tabsContainer.getChildAt(this.currentItem);
        view.setSelected(true);
        if (view instanceof TextView) {
            TextView tab = ((TextView) view);
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabSelectedTextSize);
        }
    }
}

From source file:com.ubergeek42.WeechatAndroid.CutePagerTitleStrip.java

public CutePagerTitleStrip(Context context, AttributeSet attrs) {
    super(context, attrs);

    addView(mPrevText = new TextView(context));
    addView(mCurrText = new TextView(context));
    addView(mNextText = new TextView(context));

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    final int textAppearance = a.getResourceId(0, 0);
    if (textAppearance != 0) {
        mPrevText.setTextAppearance(context, textAppearance);
        mCurrText.setTextAppearance(context, textAppearance);
        mNextText.setTextAppearance(context, textAppearance);
    }//  ww w. jav  a  2 s . com
    //noinspection ResourceType
    final int textSize = a.getDimensionPixelSize(1, 0);
    if (textSize != 0) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
    //noinspection ResourceType
    if (a.hasValue(2)) {
        //noinspection ResourceType
        final int textColor = a.getColor(2, 0);
        mPrevText.setTextColor(textColor);
        mCurrText.setTextColor(textColor);
        mNextText.setTextColor(textColor);
    }
    //noinspection ResourceType
    mGravity = a.getInteger(3, Gravity.BOTTOM);
    a.recycle();

    mTextColor = mCurrText.getTextColors().getDefaultColor();
    setNonPrimaryAlpha(SIDE_ALPHA);

    mPrevText.setEllipsize(TruncateAt.END);
    mCurrText.setEllipsize(TruncateAt.END);
    mNextText.setEllipsize(TruncateAt.END);

    boolean allCaps = false;
    if (textAppearance != 0) {
        final TypedArray ta = context.obtainStyledAttributes(textAppearance, TEXT_ATTRS);
        allCaps = ta.getBoolean(0, false);
        ta.recycle();
    }

    if (allCaps) {
        setSingleLineAllCaps(mPrevText);
        setSingleLineAllCaps(mCurrText);
        setSingleLineAllCaps(mNextText);
    } else {
        mPrevText.setSingleLine();
        mCurrText.setSingleLine();
        mNextText.setSingleLine();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    mScaledTextSpacing = (int) (TEXT_SPACING * density);
}