PlayerUtils.java
1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
}
}