GestureDialogManager.java
5.08 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.wd.player.gesture;
import android.app.Activity;
import android.view.View;
import com.wd.player.gesturedialog.BrightnessDialog;
import com.wd.player.gesturedialog.SeekDialog;
import com.wd.player.gesturedialog.VolumeDialog;
import com.wd.player.widget.AliyunScreenMode;
/**
* 手势对话框的管理器。
* 用于管理亮度 ,
* seek
* 音量
*/
public class GestureDialogManager {
// 用于构建手势用的dialog
private Activity mActivity;
// seek手势对话框
private SeekDialog mSeekDialog = null;
// 亮度对话框
private BrightnessDialog mBrightnessDialog = null;
// 音量对话框
private VolumeDialog mVolumeDialog = null;
// 当前屏幕默认为小屏
private AliyunScreenMode mCurrentScreenMode = AliyunScreenMode.Small;
public GestureDialogManager(Activity activity) {
mActivity = activity;
}
/**
* 显示seek对话框
*
* @param parent 显示在哪个view的中间
* @param targetPosition seek的位置
*/
public void showSeekDialog(View parent, int targetPosition) {
if (mSeekDialog == null) {
mSeekDialog = new SeekDialog(mActivity, targetPosition);
}
if (!mSeekDialog.isShowing()) {
mSeekDialog.show(parent);
mSeekDialog.updatePosition(targetPosition);
}
}
/**
* 更新seek进度。 在手势滑动的过程中调用。
*
* @param duration 时长
* @param currentPosition 当前位置
* @param deltaPosition 滑动位置
*/
public void updateSeekDialog(long duration, long currentPosition, long deltaPosition) {
int targetPosition = mSeekDialog.getTargetPosition(duration, currentPosition, deltaPosition);
mSeekDialog.updatePosition(targetPosition);
}
/**
* 隐藏seek对话框
*
* @return 最终的seek位置,用于实际的seek操作
*/
public int dismissSeekDialog() {
int seekPosition = -1;
if (mSeekDialog != null && mSeekDialog.isShowing()) {
seekPosition = mSeekDialog.getFinalPosition();
mSeekDialog.dismiss();
}
mSeekDialog = null;
// 返回最终的seek位置,用于实际的seek操作
return seekPosition;
}
/**
* 显示亮度对话框
*
* @param parent 显示在哪个view中间
*/
public void showBrightnessDialog(View parent, int currentBrightness) {
if (mBrightnessDialog == null) {
mBrightnessDialog = new BrightnessDialog(mActivity, currentBrightness);
}
if (!mBrightnessDialog.isShowing()) {
mBrightnessDialog.setScreenMode(mCurrentScreenMode);
mBrightnessDialog.show(parent);
mBrightnessDialog.updateBrightness(currentBrightness);
}
}
/**
* 更新亮度值
*
* @param changePercent 亮度变化百分比
* @return 最终的亮度百分比
*/
public int updateBrightnessDialog(int changePercent) {
int targetBrightnessPercent = mBrightnessDialog.getTargetBrightnessPercent(changePercent);
mBrightnessDialog.updateBrightness(targetBrightnessPercent);
return targetBrightnessPercent;
}
/**
* 隐藏亮度对话框
*/
public void dismissBrightnessDialog() {
if (mBrightnessDialog != null && mBrightnessDialog.isShowing()) {
mBrightnessDialog.dismiss();
}
mBrightnessDialog = null;
}
public void initDialog(Activity activity, float currentPercent) {
this.mActivity = activity;
if (mVolumeDialog == null) {
mVolumeDialog = new VolumeDialog(activity, currentPercent);
}
}
/**
* 显示音量对话框
*
* @param parent 显示在哪个view中间
* @param currentPercent 当前音量百分比
*/
public void showVolumeDialog(View parent, float currentPercent) {
if (mVolumeDialog == null) {
mVolumeDialog = new VolumeDialog(mActivity, currentPercent);
}
if (!mVolumeDialog.isShowing()) {
mVolumeDialog.setScreenMode(mCurrentScreenMode);
mVolumeDialog.show(parent);
mVolumeDialog.updateVolume(currentPercent);
}
}
public boolean isVolumeDialogIsShow() {
if (mVolumeDialog == null) {
return false;
}
return mVolumeDialog.isShowing();
}
/**
* 更新音量
*
* @param changePercent 变化的百分比
* @return 最终的音量百分比
*/
public float updateVolumeDialog(int changePercent) {
float targetVolume = mVolumeDialog.getTargetVolume(changePercent);
mVolumeDialog.updateVolume(targetVolume);
return targetVolume;
}
/**
* 关闭音量对话框
*/
public void dismissVolumeDialog() {
if (mVolumeDialog != null && mVolumeDialog.isShowing()) {
mVolumeDialog.dismiss();
}
mVolumeDialog = null;
}
public void setCurrentScreenMode(AliyunScreenMode currentScreenMode) {
this.mCurrentScreenMode = currentScreenMode;
}
}