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.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter.java

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.search_suggestion_item, viewGroup,
            false);//from  w  ww.  ja  v  a 2s  .c  o m
    SearchSuggestionViewHolder viewHolder = new SearchSuggestionViewHolder(view,
            new SearchSuggestionViewHolder.Listener() {

                @Override
                public void onItemClicked(int adapterPosition) {

                    if (mListener != null) {
                        mListener.onItemSelected(mSearchSuggestions.get(adapterPosition));
                    }
                }

                @Override
                public void onMoveItemToSearchClicked(int adapterPosition) {

                    if (mListener != null) {
                        mListener.onMoveItemToSearchClicked(mSearchSuggestions.get(adapterPosition));
                    }
                }

            });

    viewHolder.rightIcon.setImageDrawable(mRightIconDrawable);
    viewHolder.body.setTextSize(TypedValue.COMPLEX_UNIT_PX, mBodyTextSizePx);

    return viewHolder;
}

From source file:com.guerinet.formgenerator.TextViewFormItem.java

/**
 * Sets the {@link TextView} text size//from  w  ww .  j  a va2s  .co m
 *
 * @param size The text size from the dimensions file
  *             (use getResources().getDimension())
 * @return The {@link TextViewFormItem} instance
 */
public TextViewFormItem textSize(float size) {
    // If it's -1, don't do anything
    if (size != -1) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    }
    return this;
}

From source file:io.imoji.sdk.grid.ui.ResultView.java

public ResultView(Context context, @ResultViewSize int viewSize) {
    super(context);
    this.context = context;

    this.viewSize = viewSize;

    int resultWidth = getDimension(0);
    int resultHeight = getDimension(1);
    setLayoutParams(new StaggeredGridLayoutManager.LayoutParams(resultWidth, resultHeight));

    placeholder = new ImageView(context);
    int placeholderSide = getDimension(4);
    RelativeLayout.LayoutParams placeholderParams = new LayoutParams(placeholderSide, placeholderSide);
    placeholderParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    placeholder.setLayoutParams(placeholderParams);
    addView(placeholder);//from ww  w . j a va2  s  .c  om

    container = new RelativeLayout(context);
    addView(container, new LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT));

    final Animation pressedAnimation = AnimationUtils.loadAnimation(context, R.anim.search_result_pressed);
    final Animation releasedAnimation = AnimationUtils.loadAnimation(context, R.anim.search_result_released);
    imageView = new GifImageView(context) {

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (searchResult != null && !searchResult.isCategory()) {
                    imageView.startAnimation(pressedAnimation);
                }
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                if (searchResult != null && !searchResult.isCategory()) {
                    imageView.startAnimation(releasedAnimation);
                }
                break;
            }
            return super.onTouchEvent(event);
        }
    };

    RelativeLayout.LayoutParams imageParams = new LayoutParams(resultWidth, resultWidth);
    imageParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    imageView.setLayoutParams(imageParams);
    container.addView(imageView);

    textView = new TextView(context);
    int titleHeight = getDimension(2);
    RelativeLayout.LayoutParams titleParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            titleHeight);
    titleParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    textView.setLayoutParams(titleParams);
    textView.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Montserrat-Light.otf"));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getDimension(3));
    //TODO // FIXME: 5/2/16
    textView.setTextColor(getResources().getColor(R.color.search_result_category_title));
    textView.setGravity(Gravity.CENTER);
    container.addView(textView);

    imageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            listener.onTap(searchResult);
        }
    });

}

From source file:nccp.app.ui.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);/*ww  w . ja va2  s .  c  o m*/
    textView.setBackgroundResource(R.drawable.view_pager_tab_background);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    textView.setOnLongClickListener(new OnTabLongClickListener(position));

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    //        textView.setAllCaps(mTextAllCaps);
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.waz.zclient.pages.main.conversation.views.row.message.views.TextMessageLinkTextView.java

private void resizeIfEmoji(Message message) {
    if (message.getMessageType() == Message.Type.TEXT_EMOJI_ONLY) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizeEmoji);
    } else {/*from  w ww. j a  v a  2s . co  m*/
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizeRegular);
    }
}

From source file:com.cyanogenmod.eleven.widgets.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);/*ww  w .  j ava 2  s.c o m*/
    textView.setBackgroundResource(R.drawable.view_pager_tab_background);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    textView.setOnLongClickListener(new OnTabLongClickListener(position));

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:aws.apps.underthehood.Main.java

private void changeFontSize(TableLayout t, float fontSize) {
    for (int i = 0; i <= t.getChildCount() - 1; i++) {
        TableRow row = (TableRow) t.getChildAt(i);

        for (int j = 0; j <= row.getChildCount() - 1; j++) {
            View v = row.getChildAt(j);

            try {
                if (v.getClass() == Class.forName("android.widget.TextView")) {
                    TextView tv = (TextView) v;
                    if (i % 2 == 0) {
                    } else {
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
                    }/*from w w w .j  a v  a 2 s  .  c  o m*/
                }
            } catch (Exception e) {
                Log.e(TAG, "^ changeFontSize: ");
            }
        }
    }
}

From source file:com.fastbootmobile.encore.utils.Utils.java

/**
 * Calculates the optimal size of the text based on the text view width
 *
 * @param textView     The text view in which the text should fit
 * @param desiredWidth The desired final text width, or -1 for the TextView's getMeasuredWidth
 *//*ww  w.  j  a v  a2s .co  m*/
public static void adjustTextSize(TextView textView, int desiredWidth) {
    if (desiredWidth <= 0) {
        desiredWidth = textView.getMeasuredWidth();

        if (desiredWidth <= 0) {
            // Invalid width, don't do anything
            Log.w("Utils", "adjustTextSize: Not doing anything (measured width invalid)");
            return;
        }
    }

    // Add some margin to width
    desiredWidth *= 0.8f;

    Paint paint = new Paint();
    Rect bounds = new Rect();

    paint.setTypeface(textView.getTypeface());
    float textSize = textView.getTextSize() * 2.0f;
    paint.setTextSize(textSize);
    String text = textView.getText().toString();
    paint.getTextBounds(text, 0, text.length(), bounds);

    while (bounds.width() > desiredWidth) {
        textSize--;
        paint.setTextSize(textSize);
        paint.getTextBounds(text, 0, text.length(), bounds);
    }

    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}

From source file:com.pavelsikun.seekbarpreference.SeekBarPreference.java

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);

    /* HACK: v7 Preference seems to keep references to the recycled view's object somehow */
    holder.setIsRecyclable(false);// w  ww.ja va  2  s  . c o m

    final int currentValue = getPersistedInt(mDefaultValue);

    final DiscreteSeekBar seekBar = (DiscreteSeekBar) holder.findViewById(R.id.seekbar);
    final EditText seekBarValue = (EditText) holder.findViewById(R.id.seekbar_value);
    final TextView measurementUnitView = (TextView) holder.findViewById(R.id.measurement_unit);

    seekBar.setMin(mMinValue);
    seekBar.setMax(mMaxValue);
    seekBar.setProgress(currentValue);
    seekBar.setEnabled(isEnabled());
    seekBar.setOnProgressChangeListener(new DiscreteSeekBar.OnProgressChangeListener() {
        @Override
        public void onProgressChanged(DiscreteSeekBar seekBar, int value, boolean fromUser) {
            setError(getContext(), seekBarValue, null);
            persistInt(value);
            seekBarValue.setText(String.valueOf(value));
        }

        @Override
        public void onStartTrackingTouch(DiscreteSeekBar seekBar) {
            // Do nothing
        }

        @Override
        public void onStopTrackingTouch(DiscreteSeekBar seekBar) {
            // Do nothing
        }
    });

    seekBarValue.setText(String.valueOf(currentValue));
    seekBarValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, mValueTextSize);
    seekBarValue.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
            Math.max(String.valueOf(mMaxValue).length(), String.valueOf(mMinValue).length())), });
    seekBarValue.setEnabled(false);

    measurementUnitView.setText(mMeasurementUnit);
}

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.camera.InstructionFragment.java

private void showInstruction(@NonNull LinearLayout linearLayout, @NonNull String instruction, int style) {
    TextView textView = new TextView(getActivity());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.mediumTextSize));

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

    String text = instruction;/*from w w w .  j  a  va  2  s  .c o m*/
    if (instruction.contains("<!>")) {
        text = instruction.replaceAll("<!>", "");
        textView.setTextColor(Color.RED);
    } else {
        textView.setTextColor(Color.DKGRAY);
    }

    if (instruction.contains("<b>") || style == BOLD) {
        text = text.replaceAll("<b>", "").replaceAll("</b>", "");
        textView.setTypeface(null, Typeface.BOLD);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.titleTextSize));
    } else {
        textView.setTextColor(Color.DKGRAY);
    }

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

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