VideoUI.java
3.87 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
package com.sw.laryngoscope.camera;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.sw.laryngoscope.R;
import com.sw.laryngoscope.activity.fragment.HomeFragment;
import com.sw.laryngoscope.manager.SpManager;
import com.sw.laryngoscope.utils.Logger;
import com.sw.laryngoscope.utils.TimeUtil;
public class VideoUI {
private final HomeFragment fragment;
private final View mRootView;
TextView txt_video_time;
//TextView txt_video_total_time;
ImageView img_record_shortcut;
ImageView img_record_flag;
private boolean mRecordingStarted = false;
public VideoUI(HomeFragment fragment, View parent) {
this.fragment = fragment;
mRootView = parent;
txt_video_time = (TextView) fragment.getView().findViewById(R.id.txt_video_time);
//txt_video_total_time = (TextView) fragment.getView().findViewById(R.id.txt_video_total_time);
img_record_shortcut = (ImageView) fragment.getView().findViewById(R.id.img_record_shortcut);
img_record_flag = (ImageView) fragment.getView().findViewById(R.id.img_record_flag);
}
public void setRecordingTime(String text, String total) {
txt_video_time.setText(text);
//txt_video_total_time.setText(total);
Logger.d("========text=========" + text);
if ( img_record_flag.getVisibility() == View.VISIBLE ) {
img_record_flag.setVisibility(View.GONE);
} else if ( !text.isEmpty() ) {
img_record_flag.setVisibility(View.VISIBLE);
}
}
public void showRecordingUIBack(boolean recording) {
mRecordingStarted = recording;
if (recording) {
txt_video_time.setText("");
txt_video_time.setVisibility(View.VISIBLE);
img_record_shortcut.setSelected(true);
//txt_video_total_time.setText("");
//txt_video_total_time.setVisibility(View.VISIBLE);
} else {
txt_video_time.setText("");
//txt_video_record.setVisibility(View.GONE);
txt_video_time.setVisibility(View.GONE);
img_record_flag.setVisibility(View.GONE);
img_record_shortcut.setSelected(false);
//txt_video_total_time.setText("");
}
}
public SpannableString valueAndIcon(Context context, String str, int resId) {
boolean isLeft = context.getResources().getConfiguration().locale.getLanguage().endsWith("ir");
String res;
if (isLeft) {
res = " " + str;
} else {
res = str + " ";
}
SpannableString sp = new SpannableString(res);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId);
Bitmap newBitmap = alterSizeBitmap(bitmap, 60, 60);
if (newBitmap != null) {
ImageSpan imageSpan = new ImageSpan(context, newBitmap);
if (!isLeft) {
sp.setSpan(imageSpan, res.length() - 1, res.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} else {
sp.setSpan(imageSpan, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
return sp;
}
public Bitmap alterSizeBitmap(Bitmap bitmap, int newWidth, int newHeight) {
float scaleWidth = ((float) newWidth) / bitmap.getWidth();
float scaleHeight = ((float) newHeight) / bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
}