Example usage for android.util TypedValue COMPLEX_UNIT_DIP

List of usage examples for android.util TypedValue COMPLEX_UNIT_DIP

Introduction

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

Prototype

int COMPLEX_UNIT_DIP

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

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is Device Independent Pixels.

Usage

From source file:com.daiv.android.twitter.ui.compose.Compose.java

public int toDP(int px) {
    try {/*from  w  ww  .jav  a 2s  .c o m*/
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, px,
                getResources().getDisplayMetrics());
    } catch (Exception e) {
        return px;
    }
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

public void initNaverMap() {
    naverFragment = new FragmentMapview();
    naverFragment.setArguments(new Bundle());

    final Button expandView = (Button) mainArView.findViewById(R.id.ar_mixview_naverview_expand);
    expandView.setOnClickListener(new View.OnClickListener() {
        boolean isFull = false;

        @Override/*from  www.ja va 2  s . c om*/
        public void onClick(View view) {
            RelativeLayout navermapWrapper = (RelativeLayout) mainArView
                    .findViewById(R.id.ar_mixview_naverview_wrapper);
            if (isFull) {
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, naver_map_width,
                                Resources.getSystem().getDisplayMetrics()),
                        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, naver_map_height,
                                Resources.getSystem().getDisplayMetrics()));
                int tenMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
                        Resources.getSystem().getDisplayMetrics());
                params.setMargins(0, tenMargin, tenMargin, 0);
                params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                navermapWrapper.setLayoutParams(params);
                expandView.setBackgroundResource(R.drawable.ic_minimap_zoom_in);
                isFull = false;
            } else {
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.MATCH_PARENT);
                params.setMargins(0, 0, 0, 0);
                navermapWrapper.setLayoutParams(params);
                expandView.setBackgroundResource(R.drawable.ic_minimap_zoom_out);
                isFull = true;
            }
        }
    });

    try {
        FragmentTransaction fragmentTransaction = ((FragmentActivity) context).getSupportFragmentManager()
                .beginTransaction();
        fragmentTransaction.add(R.id.ar_mixview_naverview, naverFragment);
        fragmentTransaction.commit();
    } catch (Exception e) {
        e.printStackTrace();
        Log.i(TAG, "Only FragmentActivity can use naver maps");
    }
}

From source file:com.android.mail.browse.ConversationItemView.java

private boolean isTouchInContactPhoto(float x, float y) {
    // Everything before the end edge of contact photo

    final boolean isRtl = ViewUtils.isViewRtl(this);
    final int threshold = (isRtl) ? mCoordinates.contactImagesX - sSenderImageTouchSlop
            : mCoordinates.contactImagesX + mCoordinates.contactImagesWidth + sSenderImageTouchSlop;

    // Allow touching a little right of the contact photo when we're already in selection mode
    final float extra;
    if (mCheckedConversationSet == null || mCheckedConversationSet.isEmpty()) {
        extra = 0;/*from  w ww  . ja  v a2s.  co m*/
    } else {
        extra = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
    }

    return mHeader.gadgetMode == ConversationItemViewCoordinates.GADGET_CONTACT_PHOTO
            && ((isRtl) ? x > (threshold - extra) : x < (threshold + extra));
}

From source file:com.if3games.chessonline.DroidFish.java

private final void updateButtons() {
    boolean largeButtons = settings.getBoolean("largeButtons", false);
    Resources r = getResources();
    int bWidth = (int) Math
            .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, r.getDisplayMetrics()));
    int bHeight = (int) Math
            .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, r.getDisplayMetrics()));
    if (largeButtons) {
        if (custom1ButtonActions.isEnabled() && custom2ButtonActions.isEnabled()
                && custom3ButtonActions.isEnabled()) {
            Configuration config = getResources().getConfiguration();
            if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                bWidth = bWidth * 6 / 5;
                bHeight = bHeight * 6 / 5;
            } else {
                bWidth = bWidth * 5 / 4;
                bHeight = bHeight * 5 / 4;
            }/*w  ww.j  ava2 s . com*/
        } else {
            bWidth = bWidth * 3 / 2;
            bHeight = bHeight * 3 / 2;
        }
    }
    SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.touch);
    setButtonData(custom1Button, bWidth, bHeight, custom1ButtonActions.getIcon(), svg);
    setButtonData(custom2Button, bWidth, bHeight, custom2ButtonActions.getIcon(), svg);
    setButtonData(custom3Button, bWidth, bHeight, custom3ButtonActions.getIcon(), svg);
    setButtonData(modeButton, bWidth, bHeight, R.raw.mode, svg);
    setButtonData(undoButton, bWidth, bHeight, R.raw.left, svg);
    setButtonData(redoButton, bWidth, bHeight, R.raw.right, svg);
}

From source file:edu.mit.viral.shen.DroidFish.java

private final void updateButtons() {
    boolean largeButtons = settings.getBoolean("largeButtons", true);
    Resources r = getResources();
    int bWidth = (int) Math
            .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, r.getDisplayMetrics()));
    int bHeight = (int) Math
            .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, r.getDisplayMetrics()));
    if (largeButtons) {
        if (custom1ButtonActions.isEnabled() && custom2ButtonActions.isEnabled()
                && custom3ButtonActions.isEnabled()) {
            Configuration config = getResources().getConfiguration();
            if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                bWidth = bWidth * 7 / 6;
                bHeight = bHeight * 7 / 6;
            } else {
                bWidth = bWidth * 6 / 5;
                bHeight = bHeight * 6 / 5;
            }//from   w w w .j  ava  2  s . com
        } else {
            bWidth = bWidth * 3 / 2;
            bHeight = bHeight * 3 / 2;
        }
    }
    SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.touch);
    setButtonData(custom1Button, bWidth, bHeight, custom1ButtonActions.getIcon(), svg);
    setButtonData(custom2Button, bWidth, bHeight, custom2ButtonActions.getIcon(), svg);
    setButtonData(custom3Button, bWidth, bHeight, custom3ButtonActions.getIcon(), svg);
    setButtonData(commentButton, bWidth, bHeight, R.raw.comment, svg);
    setButtonData(undoButton, bWidth, bHeight, R.raw.left, svg);
    setButtonData(redoButton, bWidth, bHeight, R.raw.right, svg);
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

private void setInterface() {
    if (mCurrentCard == null) {
        return;//  ww w. j av a 2 s . c o  m
    }
    if (mSimpleInterface) {
        Note note = mCurrentCard.note();
        mCurrentSimpleInterface = true;
        for (String s : mSimpleInterfaceExcludeTags) {
            if (note.hasTag(s)) {
                mCurrentSimpleInterface = false;
                break;
            }
        }
    }
    if (mCurrentSimpleInterface) {
        if (mSimpleCard == null) {
            mSimpleCard = new ScrollTextView(this);
            Themes.setRegularFont(mSimpleCard);
            mSimpleCard.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
                    getResources().getDisplayMetrics()) * mDisplayFontSize / 100);
            mSimpleCard.setGravity(Gravity.CENTER);
            try {
                mSetTextIsSelectable = TextView.class.getMethod("setTextIsSelectable", boolean.class);
            } catch (Throwable e) {
                // Log.i(AnkiDroidApp.TAG, "mSetTextIsSelectable could not be found due to a too low Android version (< 3.0)");
                mSetTextIsSelectable = null;
            }
            if (mSetTextIsSelectable != null) {
                try {
                    mSetTextIsSelectable.invoke(mSimpleCard, true);
                } catch (Exception e) {
                    Log.e(AnkiDroidApp.TAG, e.toString());
                }
            }
            mSimpleCard.setClickable(true);
            mCardFrame.addView(mSimpleCard);

            mSimpleCard.setBackgroundColor(mCurrentBackgroundColor);
            mSimpleCard.setTextColor(mForegroundColor);
        }
        if (mSimpleCard.getVisibility() != View.VISIBLE
                || (mCard != null && mCard.getVisibility() == View.VISIBLE)) {
            mSimpleCard.setVisibility(View.VISIBLE);
            mCard.setVisibility(View.GONE);
        }
    } else {
        if (mCard == null) {
            mCard = createWebView();
            mCardFrame.addView(mCard);
            if (!mUseQuickUpdate) {
                mNextCard = createWebView();
                mNextCard.setVisibility(View.GONE);
                mCardFrame.addView(mNextCard, 0);
                mCard.setBackgroundColor(mCurrentBackgroundColor);

                mCustomFontStyle = getCustomFontsStyle() + getDefaultFontStyle();
            }
        }
        if (mCard.getVisibility() != View.VISIBLE
                || (mSimpleCard != null && mSimpleCard.getVisibility() == View.VISIBLE)) {
            mSimpleCard.setVisibility(View.GONE);
            mCard.setVisibility(View.VISIBLE);
        }
    }
}

From source file:com.bookkos.bircle.CaptureActivity.java

private void setScanUnregisterBookView() {

    int registSelectShelfRelativeLayout_width = displayWidth;
    int registSelectShelfRelativeLayout_height = displayHeight / 3;
    int registSelectShelfRelativeLayout_x = 0;
    int registSelectShelfRelativeLayout_y = displayHeight;
    registSelectShelfRelativeLayout.setTranslationX(registSelectShelfRelativeLayout_x);
    registSelectShelfRelativeLayout.setTranslationY(registSelectShelfRelativeLayout_y);
    registSelectShelfRelativeLayout.setLayoutParams(new FrameLayout.LayoutParams(
            registSelectShelfRelativeLayout_width, registSelectShelfRelativeLayout_height));
    //registSelectShelfRelativeLayout.setVisibility(View.GONE);

    int textViewLinearLayout_width = displayWidth;
    int textViewLinearLayout_height = registSelectShelfRelativeLayout_height / 4;
    textViewLinearLayout.setLayoutParams(
            new RelativeLayout.LayoutParams(textViewLinearLayout_width, textViewLinearLayout_height));
    RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) textViewLinearLayout.getLayoutParams();
    //      params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    textViewLinearLayout.setLayoutParams(params1);

    String tempText = "<font color=#3498db>?????!</font><br />?????????QR???, ?????\"\"????";
    tempTextView.setText(Html.fromHtml(tempText));
    tempTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize - displayInch * 1.5f);

    int buttonLinearLayout_width = displayWidth;
    int buttonLinearLayout_height = registSelectShelfRelativeLayout_height / 4;
    int buttonLinearLayout_x = 0;
    int buttonLinearLayout_y = displayHeight;
    //      buttonLinearLayout.setTranslationX(buttonLinearLayout_x);
    //      buttonLinearLayout.setTranslationY(buttonLinearLayout_y);
    buttonLinearLayout.setLayoutParams(//from w  w  w .  j ava  2 s  .c  o  m
            new RelativeLayout.LayoutParams(buttonLinearLayout_width, buttonLinearLayout_height));
    RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) buttonLinearLayout.getLayoutParams();
    params2.addRule(RelativeLayout.BELOW, R.id.text_view_linear_layout);
    buttonLinearLayout.setLayoutParams(params2);

    int listViewLinearLayout_width = displayWidth;
    int listViewLinearLayout_height = registSelectShelfRelativeLayout_height / 2;
    int listViewLinearLayout_x = 0;
    int listViewLinearLayout_y = displayHeight;
    //      listViewLinearLayout.setTranslationX(listViewLinearLayout_x);
    //      listViewLinearLayout.setTranslationY(listViewLinearLayout_y);
    listViewLinearLayout.setLayoutParams(
            new RelativeLayout.LayoutParams(listViewLinearLayout_width, listViewLinearLayout_height));
    RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) listViewLinearLayout.getLayoutParams();
    params3.addRule(RelativeLayout.BELOW, R.id.button_linear_layout);
    listViewLinearLayout.setLayoutParams(params3);
    //      listViewLinearLayout.setVisibility(View.GONE);

    int decisionButton_width = displayWidth / 5 * 2;
    //      int decisionButton_height = displayHeight / 10;
    int decisionButton_height = registSelectShelfRelativeLayout_height / 4;
    int decisionButton_x = ((displayWidth / 2) - decisionButton_width) / 2;
    int decisionButton_y = displayHeight - (titleBarHeight * 4);
    decisionButton.setTranslationX(decisionButton_x);
    //      decisionButton.setTranslationY(decisionButton_y);
    decisionButton.setLayoutParams(new LinearLayout.LayoutParams(decisionButton_width, decisionButton_height));
    decisionButton.setBackgroundColor(Color.argb(255, 230, 126, 34));
    decisionButton.setTextColor(Color.WHITE);
    decisionButton.setText("");
    decisionButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            doDecideClick(registSelectShelfIsbn, registSelectShelfId, registSelectShelfName);
            registButton.setEnabled(true);
            borrowReturnButton.setEnabled(true);
        }
    });

    int cancelButton_width = displayWidth / 5 * 2;
    //      int cancelButton_height = displayHeight / 10;
    int cancelButton_height = registSelectShelfRelativeLayout_height / 4;
    int cancelButton_x = ((displayWidth / 2) + decisionButton_x) - decisionButton_width;
    int cancelButton_y = displayHeight - (titleBarHeight * 4);
    cancelButton.setTranslationX(cancelButton_x);
    //      cancelButton.setTranslationY(cancelButton_y);
    cancelButton.setLayoutParams(new LinearLayout.LayoutParams(cancelButton_width, cancelButton_height));
    cancelButton.setBackgroundColor(Color.argb(255, 127, 140, 141));
    cancelButton.setText("");
    cancelButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            resetRegistSelectShelfData();
            animateTranslationY(registSelectShelfRelativeLayout,
                    displayHeight - displayHeight / 3 - titleBarHeight, displayHeight);
            registFlag = 0;
            registButton.setEnabled(true);
            borrowReturnButton.setEnabled(true);
        }
    });

}

From source file:com.bookkos.bircle.CaptureActivity.java

private void setBookRegistView() {
    int bookRegistRelativeLayout_width = displayWidth;
    int bookRegistRelativeLayout_height = displayHeight / 4;
    int bookRegistRelativeLayout_x = 0;
    int bookRegistRelativeLayout_y = displayHeight;
    bookRegistRelativeLayout.setTranslationX(bookRegistRelativeLayout_x);
    bookRegistRelativeLayout.setTranslationY(bookRegistRelativeLayout_y);
    bookRegistRelativeLayout.setLayoutParams(
            new FrameLayout.LayoutParams(bookRegistRelativeLayout_width, bookRegistRelativeLayout_height));

    int bookRegistLinearLayout_width = displayWidth;
    int bookRegistLinearLayout_height = bookRegistRelativeLayout_height / 3;
    bookRegistLinearLayout.setLayoutParams(
            new RelativeLayout.LayoutParams(bookRegistLinearLayout_width, bookRegistLinearLayout_height));
    RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) bookRegistLinearLayout
            .getLayoutParams();//from  w w  w  . j a  v  a2s .c  o m
    params1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    bookRegistLinearLayout.setLayoutParams(params1);

    int bookRegistListViewLinearLayout_width = displayWidth;
    int bookRegistListViewLinearLayout_height = bookRegistRelativeLayout_height * 2 / 3;
    bookRegistListViewLinearLayout.setLayoutParams(new RelativeLayout.LayoutParams(
            bookRegistListViewLinearLayout_width, bookRegistListViewLinearLayout_height));
    RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) bookRegistListViewLinearLayout
            .getLayoutParams();
    params2.addRule(RelativeLayout.BELOW, R.id.book_regist_linear_layout);
    bookRegistListViewLinearLayout.setLayoutParams(params2);

    int bookRegistListView_width = bookRegistListViewLinearLayout_width;
    int bookRegistListView_height = bookRegistListViewLinearLayout_height;
    bookRegistListView.setLayoutParams(
            new LinearLayout.LayoutParams(bookRegistListView_width, bookRegistListView_height));
    bookRegistListView.setAdapter(bookListViewAdapter);

    int bookRegistTextView_width = displayWidth * 4 / 5;
    int bookRegistTextView_height = bookRegistLinearLayout_height;
    int bookRegistTextView_x = 0;
    int bookRegistTextView_y = displayHeight;
    bookRegistTextView.setLayoutParams(
            new LinearLayout.LayoutParams(bookRegistTextView_width, bookRegistTextView_height, Gravity.LEFT));
    bookRegistTextView.setText("??");
    bookRegistTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize - displayInch * 1.5f);

    int bookRegistCancelButton_width = displayWidth / 5;
    int bookRegistCancelButton_height = bookRegistLinearLayout_height;
    int bookRegistCancelButton_x = 0;
    int bookRegistCancelButton_y = displayHeight;
    bookRegistCancelButton.setLayoutParams(new LinearLayout.LayoutParams(bookRegistCancelButton_width,
            bookRegistCancelButton_height, Gravity.RIGHT));
    bookRegistCancelButton.setText("");
    bookRegistCancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize - displayInch * 1.5f);
    bookRegistCancelButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            animateTranslationY(bookRegistRelativeLayout, displayHeight - displayHeight / 4 - titleBarHeight,
                    displayHeight);
            arrayList.clear();
            bookListViewAdapter.clear();
            registButton.setEnabled(true);
            borrowReturnButton.setEnabled(true);
            registButton.setTextColor(Color.WHITE);
        }
    });
}