PlayerUtils.java 1.74 KB
package com.cnlive.gundam.video.utils;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.view.WindowManager;

import java.util.Locale;

/**
 * Created by gujun on 2017/4/27.
 */

public class PlayerUtils {

    /**
     * 播放时间格式化
     *
     * @param second
     * @return
     */
    public static String stringForTime(long second) {
        int totalSeconds = (int) second;

        int seconds = totalSeconds % 60;
        int minutes = (totalSeconds / 60) % 60;
        int hours = totalSeconds / 3600;

        if (hours > 0) {
            return String.format(Locale.getDefault(), "%d:%02d:%02d", hours, minutes, seconds);
        } else {
            return String.format(Locale.getDefault(), "%02d:%02d", minutes, seconds);
        }
    }

    public static int checkSize(int curValue, int minValue, int maxValue) {
        if (curValue < minValue)
            curValue = minValue;
        else if (curValue > maxValue)
            curValue = maxValue;
        return curValue;
    }

    /**
     * 设置状态栏显示与隐藏
     *
     * @param show
     */
    public static void setStatusBarVisibility(Context context, boolean show) {
        if (context != null) {
            if (show) {
                ((Activity)context).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            } else {
                ((Activity)context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
        }
    }

    /**
     * 获取当前屏幕方向
     * @return
     */
    public static boolean isPortrait(Context context) {
        return ((Activity) context).getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    }
}