package com.shuyu.gsyvideoplayer;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by shuyu on 2016/12/6.
 */

public class GSYImageCover extends ImageView {

    public GSYImageCover(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public GSYImageCover(Context context) {
        super(context);
    }

    public GSYImageCover(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int videoWidth = GSYVideoManager.instance().getCurrentVideoWidth();
        int videoHeight = GSYVideoManager.instance().getCurrentVideoHeight();

        int width = getDefaultSize(videoWidth, widthMeasureSpec);
        int height = getDefaultSize(videoHeight, heightMeasureSpec);

        int widthS = getDefaultSize(videoWidth, widthMeasureSpec);
        int heightS = getDefaultSize(videoHeight, heightMeasureSpec);


        if (videoWidth > 0 && videoHeight > 0) {

            int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
            int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
            int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);

            if (widthSpecMode == MeasureSpec.EXACTLY && heightSpecMode == MeasureSpec.EXACTLY) {
                width = widthSpecSize;
                height = heightSpecSize;

                if (videoWidth * height < width * videoHeight) {
                    width = height * videoWidth / videoHeight;
                } else if (videoWidth * height > width * videoHeight) {
                    height = width * videoHeight / videoWidth;
                }
            } else if (widthSpecMode == MeasureSpec.EXACTLY) {
                width = widthSpecSize;
                height = width * videoHeight / videoWidth;
                if (heightSpecMode == MeasureSpec.AT_MOST && height > heightSpecSize) {
                    height = heightSpecSize;
                }
            } else if (heightSpecMode == MeasureSpec.EXACTLY) {
                height = heightSpecSize;
                width = height * videoWidth / videoHeight;
                if (widthSpecMode == MeasureSpec.AT_MOST && width > widthSpecSize) {
                    width = widthSpecSize;
                }
            } else {
                width = videoWidth;
                height = videoHeight;
                if (heightSpecMode == MeasureSpec.AT_MOST && height > heightSpecSize) {
                    height = heightSpecSize;
                    width = height * videoWidth / videoHeight;
                }
                if (widthSpecMode == MeasureSpec.AT_MOST && width > widthSpecSize) {
                    width = widthSpecSize;
                    height = width * videoHeight / videoWidth;
                }
            }
        } else {
            // no size yet, just adopt the given spec sizes
        }

        if (getRotation() != 0 && getRotation() % 90 == 0) {
            if (widthS < heightS) {
                if (width > height) {
                    width = (int) (width * (float) widthS / height);
                    height = widthS;
                } else {
                    height = (int) (height * (float) width / widthS);
                    width = widthS;
                }
            } else {
                if (width > height) {
                    height = (int) (height * (float) width / widthS);
                    width = widthS;
                } else {
                    width = (int) (width * (float) widthS / height);
                    height = widthS;
                }
            }
        }
        setMeasuredDimension(width, height);
    }

}

@@ -3801,32 +3801,543 @@
  %7D%0A            %7D
+%0A%0A            //%E5%A6%82%E6%9E%9C%E6%97%8B%E8%BD%AC%E5%90%8E%E7%9A%84%E9%AB%98%E5%BA%A6%E5%A4%A7%E4%BA%8E%E5%AE%BD%E5%BA%A6%0A            if (width %3E height) %7B%0A                //%E5%A6%82%E6%9E%9C%E8%A7%86%E9%A2%91%E7%9A%84%E6%97%8B%E8%BD%AC%E5%90%8E%EF%BC%8Cwidth%EF%BC%88%E9%AB%98%E5%BA%A6%EF%BC%89%E5%A4%A7%E4%BA%8E%E6%8E%A7%E4%BB%B6%E9%AB%98%E5%BA%A6%EF%BC%8C%E9%9C%80%E8%A6%81%E5%8E%8B%E7%BC%A9%E4%B8%8B%E9%AB%98%E5%BA%A6%0A                if (width %3E heightS) %7B%0A                    width = heightS;%0A                    height = (int) (height * (float) (width / heightS));%0A                %7D%0A            %7D else %7B%0A                //%E5%A6%82%E6%9E%9C%E6%97%8B%E8%BD%AC%E5%90%8E%E7%9A%84%E5%AE%BD%E5%BA%A6%E5%A4%A7%E4%BA%8E%E9%AB%98%E5%BA%A6%0A                if (height %3E widthS) %7B%0A                    height = widthS;%0A                    width = (int) (width * (float) (height / widthS));%0A                %7D%0A            %7D
 %0A        %7D%0A     

修改了播放器全屏时的选择90度的时候，暂停的裁减了的问题(2017-04-12)