BaseGestureDialog.java
2.44 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
package com.wd.player.gesturedialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.aliyun.svideo.wd.player.R;
import com.wd.player.widget.AliyunScreenMode;
/*
* Copyright (C) 2010-2018 Alibaba Group Holding Limited.
*/
/**
* 手势滑动的手势提示框。
* 其子类有:{@link BrightnessDialog} , {@link SeekDialog} , {@link VolumeDialog}
*/
public class BaseGestureDialog extends PopupWindow {
// 手势文字
TextView mTextView;
// 手势图片
ImageView mImageView;
// 对话框的宽高
private int mDialogWidthAndHeight;
// 当前屏幕模式
private AliyunScreenMode mCurrentScreenMode = AliyunScreenMode.Small;
public BaseGestureDialog(Context context) {
// 使用同一个布局
LayoutInflater mInflater =
(LayoutInflater) context.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = mInflater.inflate(R.layout.alivc_dialog_gesture, null);
view.measure(0, 0);
setContentView(view);
// 找出view
mTextView = (TextView) view.findViewById(R.id.gesture_text);
mImageView = (ImageView) view.findViewById(R.id.gesture_image);
// 设置对话框宽高
mDialogWidthAndHeight = context.getResources().getDimensionPixelSize(R.dimen.rmrb_dp155);
setWidth(mDialogWidthAndHeight);
setHeight(mDialogWidthAndHeight);
}
/**
* 居中显示对话框
*
* @param parent 所属的父界面
*/
public void show(View parent) {
int[] location = new int[2];
parent.getLocationOnScreen(location);
// 保证显示居中
int x = location[0] + (parent.getRight() - parent.getLeft() - mDialogWidthAndHeight) / 2;
int y = location[1] + (parent.getBottom() - parent.getTop() - mDialogWidthAndHeight) / 2;
if (mCurrentScreenMode == AliyunScreenMode.Small) {
showAtLocation(parent, Gravity.TOP | Gravity.LEFT, x, y);
} else {
// 当全屏模式下,用CENTER,解决在分屏模式下,部分手机展示不居中问题
showAtLocation(parent, Gravity.CENTER, 0, 0);
}
}
public void setScreenMode(AliyunScreenMode currentScreenMode) {
this.mCurrentScreenMode = currentScreenMode;
}
}