public static boolean isNetworkConnected(Context ctx) { boolean isNetworkConnected; ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); isNetworkConnected = ni != null; if (SHOW_LOGS) Logger.v(TAG, "isNetworkConnected, " + isNetworkConnected); return isNetworkConnected; }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (SHOW_LOGS) Logger.v( TAG, "onMeasure, mContentoWidth " + mContentWidth + ", mContentHeight " + mContentHeight); if (mContentWidth != null && mContentHeight != null) { updateTextureViewSize(); } }
public void updateTextureViewSize() { if (SHOW_LOGS) Logger.d(TAG, ">> updateTextureViewSize"); if (mContentWidth == null || mContentHeight == null) { throw new RuntimeException("null content size"); } float viewWidth = getMeasuredWidth(); float viewHeight = getMeasuredHeight(); float contentWidth = mContentWidth; float contentHeight = mContentHeight; if (SHOW_LOGS) { Logger.v( TAG, "updateTextureViewSize, mContentWidth " + mContentWidth + ", mContentHeight " + mContentHeight + ", mScaleType " + mScaleType); Logger.v(TAG, "updateTextureViewSize, viewWidth " + viewWidth + ", viewHeight " + viewHeight); } float scaleX = 1.0f; float scaleY = 1.0f; switch (mScaleType) { case FILL: if (viewWidth > viewHeight) { // device in landscape scaleX = (viewHeight * contentWidth) / (viewWidth * contentHeight); } else { scaleY = (viewWidth * contentHeight) / (viewHeight * contentWidth); } break; case BOTTOM: case CENTER_CROP: case TOP: if (contentWidth > viewWidth && contentHeight > viewHeight) { scaleX = contentWidth / viewWidth; scaleY = contentHeight / viewHeight; } else if (contentWidth < viewWidth && contentHeight < viewHeight) { scaleY = viewWidth / contentWidth; scaleX = viewHeight / contentHeight; } else if (viewWidth > contentWidth) { scaleY = (viewWidth / contentWidth) / (viewHeight / contentHeight); } else if (viewHeight > contentHeight) { scaleX = (viewHeight / contentHeight) / (viewWidth / contentWidth); } break; } if (SHOW_LOGS) { Logger.v(TAG, "updateTextureViewSize, scaleX " + scaleX + ", scaleY " + scaleY); } // Calculate pivot points, in our case crop from center float pivotPointX; float pivotPointY; switch (mScaleType) { case TOP: pivotPointX = 0; pivotPointY = 0; break; case BOTTOM: pivotPointX = viewWidth; pivotPointY = viewHeight; break; case CENTER_CROP: pivotPointX = viewWidth / 2; pivotPointY = viewHeight / 2; break; case FILL: pivotPointX = mPivotPointX; pivotPointY = mPivotPointY; break; default: throw new IllegalStateException( "pivotPointX, pivotPointY for ScaleType " + mScaleType + " are not defined"); } if (SHOW_LOGS) Logger.v( TAG, "updateTextureViewSize, pivotPointX " + pivotPointX + ", pivotPointY " + pivotPointY); float fitCoef = 1; switch (mScaleType) { case FILL: break; case BOTTOM: case CENTER_CROP: case TOP: if (mContentHeight > mContentWidth) { // Portrait video fitCoef = viewWidth / (viewWidth * scaleX); } else { // Landscape video fitCoef = viewHeight / (viewHeight * scaleY); } break; } mContentScaleX = fitCoef * scaleX; mContentScaleY = fitCoef * scaleY; mPivotPointX = pivotPointX; mPivotPointY = pivotPointY; updateMatrixScaleRotate(); if (SHOW_LOGS) Logger.d(TAG, "<< updateTextureViewSize"); }