src/com/todddavies/components/progressbar/ProgressWheel.java
/*
     * When this is called, make the view square.
     * From: http://www.jayway.com/2012/12/12/creating-custom-android-views-part-4-measuring-and-how-to-force-a-view-to-be-square/
     * 
     */
When this is called, make the view square.
When this is called make the view square .
@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    	super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int size = 0;
        int width = getMeasuredWidth();
        int height = getMeasuredHeight();
        int widthWithoutPadding = width - getPaddingLeft() - getPaddingRight();
        int heightWithoutPadding = height - getPaddingTop() - getPaddingBottom();
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        if (heightMode != MeasureSpec.UNSPECIFIED && widthMode != MeasureSpec.UNSPECIFIED) {
            if (widthWithoutPadding > heightWithoutPadding) {
                size = heightWithoutPadding;
            } else {
                size = widthWithoutPadding;
            }
        } else {
            size = Math.max(heightWithoutPadding, widthWithoutPadding);
        }
        setMeasuredDimension(
                size + getPaddingLeft() + getPaddingRight(),
                size + getPaddingTop() + getPaddingBottom());
    }
@ Override protected void onMeasure ( int widthMeasureSpec , int heightMeasureSpec ) { super . onMeasure ( widthMeasureSpec , heightMeasureSpec ) ; int size = 0 ; int width = getMeasuredWidth ( ) ; int height = getMeasuredHeight ( ) ; int widthWithoutPadding = width - getPaddingLeft ( ) - getPaddingRight ( ) ; int heightWithoutPadding = height - getPaddingTop ( ) - getPaddingBottom ( ) ; int heightMode = MeasureSpec . getMode ( heightMeasureSpec ) ; int widthMode = MeasureSpec . getMode ( widthMeasureSpec ) ; if ( heightMode != MeasureSpec . UNSPECIFIED && widthMode != MeasureSpec . UNSPECIFIED ) { if ( widthWithoutPadding > heightWithoutPadding ) { size = heightWithoutPadding ; } else { size = widthWithoutPadding ; } } else { size = Math . max ( heightWithoutPadding , widthWithoutPadding ) ; } setMeasuredDimension ( size + getPaddingLeft ( ) + getPaddingRight ( ) , size + getPaddingTop ( ) + getPaddingBottom ( ) ) ; }
When this is called, make the view square.
When this is called make the view square .
// The first thing that happen is that we call the superclass 
 // implementation of onMeasure. The reason for that is that measuring 
 // can be quite a complex process and calling the super method is a 
 // convenient way to get most of this complexity handled.
 // We can’t use getWidth() or getHight() here. During the measuring 
 // pass the view has not gotten its final size yet (this happens first 
 // at the start of the layout pass) so we have to use getMeasuredWidth() 
 // and getMeasuredHeight().
 // Finally we have some simple logic that calculates the size of the view 
 // and calls setMeasuredDimension() to set that size.
 // Before we compare the width and height of the view, we remove the padding, 
 // and when we set the dimension we add it back again. Now the actual content 
 // of the view will be square, but, depending on the padding, the total dimensions 
 // of the view might not be.
 // If you override onMeasure() you have to call setMeasuredDimension(). 
 // This is how you report back the measured size.  If you don’t call
 // setMeasuredDimension() the parent will throw an exception and your 
 // application will crash.        
 // We are calling the onMeasure() method of the superclass so we don’t 
 // actually need to call setMeasuredDimension() since that takes care 
 // of that. However, the purpose with overriding onMeasure() was to 
 // change the default behaviour and to do that we need to call 
 // setMeasuredDimension() with our own values.
