Example usage for android.graphics.drawable Drawable getIntrinsicHeight

List of usage examples for android.graphics.drawable Drawable getIntrinsicHeight

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable getIntrinsicHeight.

Prototype

public int getIntrinsicHeight() 

Source Link

Document

Returns the drawable's intrinsic height.

Usage

From source file:com.guodong.sun.guodong.widget.ZoomImageView.java

/**
 * ?ImageView?//  ww w .  jav a  2  s  .  c o  m
 */
@Override
public void onGlobalLayout() {

    if (mOnce) {

        // ?
        Drawable d = getDrawable();
        if (d == null) {
            return;
        }

        // 
        int width = getWidth();
        int height = getHeight();

        int dWidth = d.getIntrinsicWidth();
        int dHeight = d.getIntrinsicHeight();

        float scale = 1.0f;

        // ??
        if (dWidth > width && dHeight <= height) {
            scale = width * 1.0f / dWidth;
        }

        // ??
        if (dHeight > height && dWidth <= width) {
            scale = height * 1.0f / dHeight;
        }

        // ?
        // ??
        if ((dWidth > width && dHeight > height) || (dWidth < width && dHeight < height)) {

            scale = Math.min(width * 1.0f / dWidth, height * 1.0f / dHeight);
        }

        // ?
        mMinScale = scale;
        mMidScale = mMinScale * 2f;
        mMaxScale = mMinScale * 4f;

        // ?X?Y?
        int dX = (width - dWidth) / 2;
        int dY = (height - dHeight) / 2;
        // 
        mScaleMatrix.postTranslate(dX, dY);
        mScaleMatrix.postScale(mMinScale, mMinScale, width / 2, height / 2);
        setImageMatrix(mScaleMatrix);

        mOnce = false;
    }
}

From source file:com.shizhefei.view.largeimage.LargeImageView.java

private void updateDrawable(Drawable d) {
    if (mDrawable != null) {
        mDrawable.setCallback(null);/*  ww  w . j  a v a 2s .co m*/
        unscheduleDrawable(mDrawable);
    }
    mDrawable = d;
    if (d != null) {
        d.setCallback(this);
        DrawableCompat.setLayoutDirection(d, DrawableCompat.getLayoutDirection(d));
        if (d.isStateful()) {
            d.setState(getDrawableState());
        }
        d.setVisible(getVisibility() == VISIBLE, true);
        d.setLevel(mLevel);
        mDrawableWidth = d.getIntrinsicWidth();
        mDrawableHeight = d.getIntrinsicHeight();
    } else {
        mDrawableWidth = mDrawableHeight = -1;
    }
}

From source file:com.cssweb.android.trade.stock.StockTrading.java

@Override
public void onCreate(Bundle paramBundle) {
    super.onCreate(paramBundle);
    sc = new ServiceControl(this);//??
    ///* w  ww . ja  va 2s . c  o m*/
    HandlerThread mHandlerThread = new HandlerThread("CSSWEB_THREAD");
    mHandlerThread.start();
    priceHandler = new PriceDataHandler(mHandlerThread.getLooper());

    setContentView(com.cssweb.android.main.R.layout.zr_trade_stock_trade);
    Bundle bundle = getIntent().getExtras();
    type = bundle.getInt("type");
    bsname = bundle.getString("bsname");
    String stockCode = bundle.getString("stkcode");

    initTitle(R.drawable.njzq_title_left_back, 0, bsname);

    LinearLayout localLinearLayout = (LinearLayout) findViewById(R.id.zrtradelayout);
    localLinearLayout.setOnFocusChangeListener(setOnEditFocusListener);
    this.m_vklayout = localLinearLayout;
    View localView1 = this.m_vklayout;
    localView1.setOnFocusChangeListener(setOnEditFocusListener);
    View localView2 = this.m_vklayout;
    localView2.setOnClickListener(setOnEditClickListener);

    viewFlipper = (ViewFlipper) this.findViewById(R.id.ViewFlipper01);
    preView = (ImageView) findViewById(R.id.previous_screen);

    leftIn = AnimationUtils.loadAnimation(this, R.anim.push_left_in_layout);
    leftOut = AnimationUtils.loadAnimation(this, R.anim.push_left_out_layout);
    rightIn = AnimationUtils.loadAnimation(this, R.anim.push_right_in_layout);
    rightOut = AnimationUtils.loadAnimation(this, R.anim.push_right_out_layout);

    priceView = (PriceMini) findViewById(R.id.zrviewprice);
    trendView = (TrendView) findViewById(R.id.zrviewtrend);
    trendView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }
    });
    klineView = (KlineMini) findViewById(R.id.zrviewkline);
    klineView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }
    });
    financeView = (FinanceMini) findViewById(R.id.zrviewfinance);

    stockHolder = (Spinner) findViewById(R.id.zrtxtaccount);
    queryMethod = (Spinner) findViewById(R.id.zrtxtbsflag);
    //      availableNum = (SeekBar) findViewById(R.id.zrcanbs);
    //      lblMaxNumber = (TextView)findViewById(R.id.txtMaxNumber);
    stkcode = (EditText) findViewById(R.id.zredtstockcode);
    stkname = (TextView) findViewById(R.id.zrtxtstockname);
    price = (EditText) findViewById(R.id.zredtprice);
    number = (EditText) findViewById(R.id.zredtcount);
    lblNumberUnit = (TextView) findViewById(R.id.lblNumberUnit);
    btn0 = (ShadowButton) findViewById(R.id.zr_surebutton);
    btn0.setOnClickListener(myShowProgreeBar);

    layoutprice0 = (LinearLayout) findViewById(R.id.LinearLayout03);
    layoutprice = (LinearLayout) findViewById(R.id.LinearLayout11);
    //layoutAvaiNumber = (LinearLayout)findViewById(R.id.LinearLayout04);
    //layoutAvaiAsset = (LinearLayout)findViewById(R.id.LinearLayout06);
    lblAvaiAsset = (TextView) findViewById(R.id.lblAvaiAsset);
    AvaiAsset = (TextView) findViewById(R.id.AvaiAsset);
    lblPrice = (TextView) findViewById(R.id.lblPrice);
    lblPrice1 = (TextView) findViewById(R.id.lblPrice1);
    lblNumber = (TextView) findViewById(R.id.lblNumber);
    avaiAsset = (TextView) findViewById(R.id.AvaiAsset);
    lblNumberUnit = (TextView) findViewById(R.id.lblNumberUnit);

    setDynamic();

    adjustDownPrice = (ImageView) findViewById(R.id.AdjustDownPrice);
    adjustDownPrice.setTag(0);
    adjustDownPrice.setOnClickListener(adjustIconListener);

    adjustUpPrice = (ImageView) findViewById(R.id.AdjustUpPrice);
    adjustUpPrice.setTag(1);
    adjustUpPrice.setOnClickListener(adjustIconListener);

    adjustDownNumber = (ImageView) findViewById(R.id.AdjustDownNumber);
    adjustDownNumber.setTag(2);
    adjustDownNumber.setOnClickListener(adjustIconListener);

    adjustUpNumber = (ImageView) findViewById(R.id.AdjustUpNumber);
    adjustUpNumber.setTag(3);
    adjustUpNumber.setOnClickListener(adjustIconListener);

    stkcode.setText(stockCode);
    if (stkcode.getText().length() == 6) {
        showProgress();
    }

    stkcode.setInputType(InputType.TYPE_NULL);
    stkcode.setFocusable(true);
    stkcode.setTag("STOCK");
    stkcode.setOnClickListener(setOnEditClickListener);
    stkcode.setOnFocusChangeListener(setOnEditFocusListener);

    price.setInputType(InputType.TYPE_NULL);
    price.setFocusable(true);
    price.setTag("NUMDOT");
    price.setOnClickListener(setOnEditClickListener);
    price.setOnFocusChangeListener(setOnEditFocusListener);

    number.setInputType(InputType.TYPE_NULL);
    number.setFocusable(true);
    number.setTag("");
    number.setOnClickListener(setOnEditClickListener);
    number.setOnFocusChangeListener(setOnEditFocusListener);

    stkcode.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable arg0) {
            //queryStock(queryCode.getText());
            OnTextChanged(arg0);
        }

        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

    });

    holder = TradeUser.getInstance().getHolder();

    stockHolderAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            (String[]) holder.toArray(new String[holder.size()]));
    stockHolderAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    stockHolder.setAdapter(stockHolderAdapter);

    String[] arrayOfString = getResources().getStringArray(R.array.other_market_bs_methods);
    for (int i = 0; i < arrayOfString.length; i++) {
        Log.e("arrayOfString", arrayOfString[i]);
    }

    queryMethodAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arrayOfString);
    queryMethodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    queryMethod.setAdapter(queryMethodAdapter);
    queryMethod.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position != 0) {
                layoutprice0.setVisibility(View.GONE);
                layoutprice.setVisibility(View.VISIBLE);
            } else {
                layoutprice0.setVisibility(View.VISIBLE);
                layoutprice.setVisibility(View.GONE);
            }
        }

        public void onNothingSelected(AdapterView<?> arg0) {

        }
    });

    int h = R.drawable.forminput;
    Resources localResources = getResources();
    Drawable localDrawable = null;
    localDrawable = localResources.getDrawable(h);
    int spinnerheight = localDrawable.getIntrinsicHeight() - 4;
    //      Log.e("<<<<<<<<<<<<<<<<<<<eeeeeeeeeeeeeeeeeeeeeeeeeee>>>>>>>>>>>>>>", String.valueOf(spinnerheight));
    LinearLayout.LayoutParams linearParams1 = (LinearLayout.LayoutParams) stockHolder.getLayoutParams();//?stockHolder?
    linearParams1.height = spinnerheight;//??
    stockHolder.setLayoutParams(linearParams1);

    LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) queryMethod.getLayoutParams();//?queryMethod?
    linearParams.height = spinnerheight;//??
    queryMethod.setLayoutParams(linearParams);
}

From source file:com.tpos.widget.pagertab.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;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            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 w  w w. j ava2s  . c  o  m
            }
        }

        // steven add
        if (pager.getAdapter() instanceof IconTextTabProvider) {
            if (v instanceof TextView) {
                Drawable tDrawable = null;
                try {
                    tDrawable = getResources()
                            .getDrawable(((IconTextTabProvider) pager.getAdapter()).getPageIconResId(i));
                } catch (NotFoundException e) {
                    e.printStackTrace();
                    tDrawable = null;
                }
                if (tDrawable != null) {
                    tDrawable.setBounds(0, 0, (int) (tDrawable.getIntrinsicWidth() * 0.5),
                            (int) (tDrawable.getIntrinsicHeight() * 0.5));
                    ((TextView) v).setCompoundDrawables(null, tDrawable, null, null);
                }
            }
        }
    }

}

From source file:it.configure.imageloader.zoom.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER//from   w w w. j av a 2  s .c  om
 * 
 * @param d - Drawable being displayed
 */
private void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    final float viewWidth = imageView.getWidth();
    final float viewHeight = imageView.getHeight();
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        switch (mScaleType) {
        case FIT_CENTER:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle/*  w  ww.j a va  2 s .  c om*/
 */
private RectF getDisplayRect(Matrix matrix) {
    ImageView imageView = getImageView();

    if (null != imageView) {
        Drawable d = imageView.getDrawable();
        if (null != d) {
            mDisplayRect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
            matrix.mapRect(mDisplayRect);
            return mDisplayRect;
        }
    }
    return null;
}

From source file:radialdemo.RadialMenuWidget.java

private void determineWedges() {

    int entriesQty = menuEntries.size();
    if (entriesQty > 0) {
        wedgeQty = entriesQty;/*from  w w  w. j a v a  2s  . co m*/

        float degSlice = 360 / wedgeQty;
        float start_degSlice = 270 - (degSlice / 2);
        // calculates where to put the images
        double rSlice = (2 * Math.PI) / wedgeQty;
        double rStart = (2 * Math.PI) * (0.75) - (rSlice / 2);

        this.Wedges = new RadialMenuWedge[wedgeQty];
        this.iconRect = new Rect[wedgeQty];

        for (int i = 0; i < Wedges.length; i++) {
            this.Wedges[i] = new RadialMenuWedge(xPosition, yPosition, MinSize, MaxSize,
                    (i * degSlice) + start_degSlice, degSlice);
            float xCenter = (float) (Math.cos(((rSlice * i) + (rSlice * 0.5)) + rStart) * (MaxSize + MinSize)
                    / 2) + xPosition;
            float yCenter = (float) (Math.sin(((rSlice * i) + (rSlice * 0.5)) + rStart) * (MaxSize + MinSize)
                    / 2) + yPosition;

            int h = MaxIconSize;
            int w = MaxIconSize;
            if (menuEntries.get(i).getIcon() != 0) {
                Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon());
                h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize);
                w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize);
            }

            this.iconRect[i] = new Rect((int) xCenter - w / 2, (int) yCenter - h / 2, (int) xCenter + w / 2,
                    (int) yCenter + h / 2);
        }

        invalidate(); // re-draws the picture
    }
}

From source file:radialdemo.RadialMenuWidget.java

private void determineOuterWedges(RadialMenuItem entry) {

    int entriesQty = entry.getChildren().size();
    wedgeQty2 = entriesQty;/*from  www. j ava  2s.c o  m*/

    // Wedge 2
    float degSlice2 = 360 / wedgeQty2;
    float start_degSlice2 = 270 - (degSlice2 / 2);
    // calculates where to put the images
    double rSlice2 = (2 * Math.PI) / wedgeQty2;
    double rStart2 = (2 * Math.PI) * (0.75) - (rSlice2 / 2);

    this.Wedges2 = new RadialMenuWedge[wedgeQty2];
    this.iconRect2 = new Rect[wedgeQty2];

    for (int i = 0; i < Wedges2.length; i++) {
        this.Wedges2[i] = new RadialMenuWedge(xPosition, yPosition, r2MinSize, r2MaxSize,
                (i * degSlice2) + start_degSlice2, degSlice2);
        float xCenter = (float) (Math.cos(((rSlice2 * i) + (rSlice2 * 0.5)) + rStart2) * (r2MaxSize + r2MinSize)
                / 2) + xPosition;
        float yCenter = (float) (Math.sin(((rSlice2 * i) + (rSlice2 * 0.5)) + rStart2) * (r2MaxSize + r2MinSize)
                / 2) + yPosition;

        int h = MaxIconSize;
        int w = MaxIconSize;
        if (entry.getChildren().get(i).getIcon() != 0) {
            Drawable drawable = getResources().getDrawable(entry.getChildren().get(i).getIcon());
            h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize);
            w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize);
        }
        this.iconRect2[i] = new Rect((int) xCenter - w / 2, (int) yCenter - h / 2, (int) xCenter + w / 2,
                (int) yCenter + h / 2);
    }
    this.wedge2Data = entry;
    invalidate(); // re-draws the picture
}

From source file:com.keylesspalace.tusky.activity.ComposeActivity.java

private void setStatusVisibility(String visibility) {
    statusVisibility = visibility;//ww  w  . ja v a 2  s. c om
    switch (visibility) {
    case "public": {
        floatingBtn.setText(R.string.action_send_public);
        floatingBtn.setCompoundDrawables(null, null, null, null);
        break;
    }
    case "private": {
        floatingBtn.setText(R.string.action_send);
        Drawable lock = AppCompatResources.getDrawable(this, R.drawable.send_private);
        if (lock != null) {
            lock.setBounds(0, 0, lock.getIntrinsicWidth(), lock.getIntrinsicHeight());
            floatingBtn.setCompoundDrawables(null, null, lock, null);
        }
        break;
    }
    default: {
        floatingBtn.setText(R.string.action_send);
        floatingBtn.setCompoundDrawables(null, null, null, null);
        break;
    }
    }
}

From source file:github.madmarty.madsonic.util.ImageLoader.java

@SuppressWarnings("deprecation")
private void setImage(View view, Drawable drawable, boolean crossfade) {
    if (view instanceof TextView) {
        // Cross-fading is not implemented for TextView since it's not in use.  It would be easy to add it, though.
        TextView textView = (TextView) view;
        textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
    } else if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;
        if (crossfade) {

            Drawable existingDrawable = imageView.getDrawable();
            if (existingDrawable == null) {
                Bitmap emptyImage;/*from w  ww. j a  va2 s . c o  m*/
                if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
                    emptyImage = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
                } else {
                    emptyImage = Bitmap.createBitmap(imageSizeDefault, imageSizeDefault,
                            Bitmap.Config.ARGB_8888);
                }
                existingDrawable = new BitmapDrawable(emptyImage);
            } else {
                // Try to get rid of old transitions
                try {
                    TransitionDrawable tmp = (TransitionDrawable) existingDrawable;
                    int layers = tmp.getNumberOfLayers();
                    existingDrawable = tmp.getDrawable(layers - 1);
                } catch (Exception e) {
                    // Do nothing, just means that the drawable is a flat image
                }
            }

            Drawable[] layers = new Drawable[] { existingDrawable, drawable };

            TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
            imageView.setImageDrawable(transitionDrawable);
            transitionDrawable.startTransition(250);
        } else {
            imageView.setImageDrawable(drawable);
        }
    }
}