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.edible.ocr.CaptureActivity.java

/**
   * Displays information relating to the results of a successful real-time OCR request.
   * //from   ww  w. ja  v a  2s  . c o  m
   * @param ocrResult Object representing successful OCR results
   */
void handleOcrContinuousDecode(OcrResult ocrResult) {

    lastResult = ocrResult;

    // Send an OcrResultText object to the ViewfinderView for text rendering
    viewfinderView.addResultText(new OcrResultText(ocrResult.getText(), ocrResult.getWordConfidences(),
            ocrResult.getMeanConfidence(), ocrResult.getBitmapDimensions(), ocrResult.getRegionBoundingBoxes(),
            ocrResult.getTextlineBoundingBoxes(), ocrResult.getStripBoundingBoxes(),
            ocrResult.getWordBoundingBoxes(), ocrResult.getCharacterBoundingBoxes()));

    Integer meanConfidence = ocrResult.getMeanConfidence();

    if (CONTINUOUS_DISPLAY_RECOGNIZED_TEXT) {
        // Display the recognized text on the screen
        statusViewTop.setText(ocrResult.getText());
        int scaledSize = Math.max(22, 32 - ocrResult.getText().length() / 4);
        statusViewTop.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);
        statusViewTop.setTextColor(Color.BLACK);
        statusViewTop.setBackgroundResource(R.color.status_top_text_background);

        statusViewTop.getBackground().setAlpha(meanConfidence * (255 / 100));
    }

    if (CONTINUOUS_DISPLAY_METADATA) {
        // Display recognition-related metadata at the bottom of the screen
        long recognitionTimeRequired = ocrResult.getRecognitionTimeRequired();
        statusViewBottom.setTextSize(14);
        statusViewBottom.setText("OCR: " + sourceLanguageReadable + " - Mean confidence: "
                + meanConfidence.toString() + " - Time required: " + recognitionTimeRequired + " ms");
    }
}

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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showThemeDialog() {
    final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme());
    Resources resources = getResources();
    float density = ResourceUtils.obtainDensity(resources);
    ScrollView scrollView = new ScrollView(this);
    LinearLayout outer = new LinearLayout(this);
    outer.setOrientation(LinearLayout.VERTICAL);
    int outerPadding = (int) (16f * density);
    outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding);
    scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme)
            .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create();
    View.OnClickListener listener = v -> {
        int index = (int) v.getTag();
        if (index != checkedItem) {
            Preferences.setTheme(Preferences.VALUES_THEME[index]);
            recreate();/*from   w  w  w .  ja va  2 s  .  c om*/
        }
        dialog.dismiss();
    };
    int circleSize = (int) (56f * density);
    int itemPadding = (int) (12f * density);
    LinearLayout inner = null;
    for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) {
        if (i % 3 == 0) {
            inner = new LinearLayout(this);
            inner.setOrientation(LinearLayout.HORIZONTAL);
            outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
        }
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setGravity(Gravity.CENTER);
        layout.setBackgroundResource(
                ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0));
        layout.setPadding(0, itemPadding, 0, itemPadding);
        layout.setOnClickListener(listener);
        layout.setTag(i);
        inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
        View view = new View(this);
        int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0];
        int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1];
        int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2];
        Resources.Theme theme = getResources().newTheme();
        theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true);
        TypedArray typedArray = theme
                .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr });
        view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0),
                typedArray.getColor(2, 0)));
        typedArray.recycle();
        if (C.API_LOLLIPOP) {
            view.setElevation(6f * density);
        }
        layout.addView(view, circleSize, circleSize);
        TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem);
        textView.setSingleLine(true);
        textView.setEllipsize(TextUtils.TruncateAt.END);
        textView.setText(Preferences.ENTRIES_THEME[i]);
        if (C.API_LOLLIPOP) {
            textView.setAllCaps(true);
            textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f);
        } else {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f);
        }
        textView.setGravity(Gravity.CENTER_HORIZONTAL);
        textView.setPadding(0, (int) (8f * density), 0, 0);
        layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) {
            if (Preferences.ENTRIES_THEME.length % 3 == 1) {
                inner.addView(new View(this), 0,
                        new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
            }
            inner.addView(new View(this),
                    new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
        }
    }
    dialog.show();
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    if (actionBarTitleView != null) {
        actionBarTitleView.setTypeface(lobsterTwo);
        actionBarTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28f);
        actionBarTitleView.setTextColor(getResources().getColor(R.color.blue));
    }/*w  w w .  java  2  s .  c o  m*/
}

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

private TextView makeCommonTextView(boolean header) {
    TextView textView = new TextView(context, null,
            C.API_LOLLIPOP ? android.R.attr.textAppearanceListItem : android.R.attr.textAppearance);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f);
    textView.setGravity(Gravity.CENTER_VERTICAL);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setSingleLine(true);/*w  w w .  ja v a2 s  .  c om*/
    if (C.API_LOLLIPOP) {
        textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
        int color = textView.getTextColors().getDefaultColor();
        if (header) {
            color &= 0x5effffff;
        } else {
            color &= 0xddffffff;
        }
        textView.setTextColor(color);
    }
    return textView;
}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

private Toast createToastShort(String text) {
    Toast toast = new Toast(this);
    TextView tv = new TextView(this);
    tv.setText(text);//w w  w .  ja v  a  2 s  .  co m
    tv.setTextColor(ContextCompat.getColor(this, R.color.colorAccent));
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, TOAST_TEXT_SIZE);
    //        int pixel = (int)mWindowDensity * 56;
    int toastMargin = getResources().getDimensionPixelSize(R.dimen.toast_margin_top_bottom);
    tv.setPadding(0, toastMargin, 0, toastMargin);
    toast.setView(tv);
    toast.setGravity(mToastPosition, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);

    return toast;
}

From source file:com.android.launcher3.Utilities.java

public static int pxFromSp(float size, DisplayMetrics metrics) {
    return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, size, metrics));
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public int translatePixelForDPI(int pixel) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, pixel,
            getContext().getResources().getDisplayMetrics());
}

From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Same as {@link #setDiscreteIndicatorTextSize(int, float)} in {@link TypedValue#COMPLEX_UNIT_SP}
 * and the specified <var>size</var>.
 *
 * @see #getDiscreteIndicatorTextSize()/*w w  w .j a  va 2 s.  c  o m*/
 */
public void setDiscreteIndicatorTextSize(float size) {
    setDiscreteIndicatorTextSize(TypedValue.COMPLEX_UNIT_SP, size);
}