react-native-video-trim 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +168 -33
  2. package/android/src/main/AndroidManifest.xml +13 -0
  3. package/android/src/main/java/com/videotrim/VideoTrimModule.java +282 -75
  4. package/android/src/main/java/com/videotrim/enums/ErrorCode.java +10 -0
  5. package/android/src/main/java/com/videotrim/interfaces/VideoTrimListener.java +4 -1
  6. package/android/src/main/java/com/videotrim/utils/MediaMetadataUtil.java +75 -0
  7. package/android/src/main/java/com/videotrim/utils/StorageUtil.java +2 -2
  8. package/android/src/main/java/com/videotrim/utils/VideoTrimmerUtil.java +26 -16
  9. package/android/src/main/java/com/videotrim/widgets/VideoTrimmerView.java +310 -81
  10. package/android/src/main/res/drawable/airpodsmax.xml +19 -0
  11. package/android/src/main/res/drawable/exclamationmark_triangle_fill.xml +15 -0
  12. package/android/src/main/res/drawable/thumb_container_bg.xml +8 -0
  13. package/android/src/main/res/layout/video_trimmer_view.xml +71 -4
  14. package/android/src/main/res/xml/file_paths.xml +5 -0
  15. package/ios/AssetLoader.swift +99 -0
  16. package/ios/ErrorCode.swift +16 -0
  17. package/ios/ProgressAlertController.swift +100 -0
  18. package/ios/VideoTrim.mm +4 -2
  19. package/ios/VideoTrim.swift +472 -177
  20. package/ios/VideoTrimmer.swift +16 -10
  21. package/ios/VideoTrimmerViewController.swift +191 -22
  22. package/lib/commonjs/index.js +25 -55
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/module/index.js +24 -55
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/typescript/index.d.ts +215 -9
  27. package/lib/typescript/index.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/src/index.tsx +229 -66
  30. package/android/src/main/java/iknow/android/utils/BuildConfig.java +0 -18
  31. package/android/src/main/java/iknow/android/utils/DateUtil.java +0 -64
@@ -1,22 +1,225 @@
1
+ import { type ColorValue } from 'react-native';
1
2
  export interface EditorConfig {
3
+ /**
4
+ * Enable haptic feedback
5
+ * @default true
6
+ */
7
+ enableHapticFeedback?: boolean;
8
+ /**
9
+ * Save the output file to Photos Library. Only video is supported. Note that you have to make sure you have permission to save to Photos Library.
10
+ * @default false
11
+ */
2
12
  saveToPhoto?: boolean;
3
- removeAfterSavedToPhoto?: boolean;
4
13
  maxDuration?: number;
14
+ /**
15
+ * Minimum duration for trimmer
16
+ * @default 1000
17
+ */
5
18
  minDuration?: number;
19
+ /**
20
+ * Cancel button text
21
+ * @default "Cancel"
22
+ */
6
23
  cancelButtonText?: string;
24
+ /**
25
+ * Save button text
26
+ * @default "Save"
27
+ */
7
28
  saveButtonText?: string;
29
+ /**
30
+ * Enable cancel dialog
31
+ * @default true
32
+ */
8
33
  enableCancelDialog?: boolean;
34
+ /**
35
+ * Cancel dialog title
36
+ * @default "Warning!"
37
+ */
9
38
  cancelDialogTitle?: string;
39
+ /**
40
+ * Cancel dialog message
41
+ * @default "Are you sure want to cancel?"
42
+ */
10
43
  cancelDialogMessage?: string;
44
+ /**
45
+ * Cancel dialog cancel text
46
+ * @default "Close"
47
+ */
11
48
  cancelDialogCancelText?: string;
49
+ /**
50
+ * Cancel dialog confirm text
51
+ * @default "Proceed"
52
+ */
12
53
  cancelDialogConfirmText?: string;
54
+ /**
55
+ * Enable save dialog
56
+ * @default true
57
+ */
13
58
  enableSaveDialog?: boolean;
59
+ /**
60
+ * Save dialog title
61
+ * @default "Confirmation!"
62
+ */
14
63
  saveDialogTitle?: string;
64
+ /**
65
+ * Save dialog message
66
+ * @default "Are you sure want to save?"
67
+ */
15
68
  saveDialogMessage?: string;
69
+ /**
70
+ * Save dialog cancel text
71
+ * @default "Close"
72
+ */
16
73
  saveDialogCancelText?: string;
74
+ /**
75
+ * Save dialog confirm text
76
+ * @default "Proceed"
77
+ */
17
78
  saveDialogConfirmText?: string;
79
+ /**
80
+ * Trimming text
81
+ * @default "Trimming video..."
82
+ */
18
83
  trimmingText?: string;
84
+ /**
85
+ * By default, on iOS the editor will be presented as a modal. If you want to present it as a full screen modal, set this to `true`.
86
+ * @default false
87
+ */
19
88
  fullScreenModalIOS?: boolean;
89
+ /**
90
+ * Type of the file to edit. If video file, recommend to use `video`. If audio file, recommend to use `audio`.
91
+ * @default "video"
92
+ */
93
+ type?: 'video' | 'audio';
94
+ /**
95
+ * Output file extension. If video file, recommend to use `mp4` or `mov`. If audio file, recommend to use `wav` or `m4a`.
96
+ * @default "mp4"
97
+ * @example "mp4", "mov", "wav", "m4a", "3gp", "avi", "mkv", "flv", "wmv", "webm"
98
+ */
99
+ outputExt?: string;
100
+ /**
101
+ * Whether to open Documents app after finish editing
102
+ * @default false
103
+ */
104
+ openDocumentsOnFinish?: boolean;
105
+ /**
106
+ * Whether to open Share Sheet after finish editing
107
+ * @default false
108
+ */
109
+ openShareSheetOnFinish?: boolean;
110
+ /**
111
+ * Remove the file after saved to Photos Library
112
+ * @default false
113
+ */
114
+ removeAfterSavedToPhoto?: boolean;
115
+ /**
116
+ * Remove the file after failed to save to Photos Library
117
+ * @default false
118
+ */
119
+ removeAfterFailedToSavePhoto?: boolean;
120
+ /**
121
+ * Remove the file after saved to Documents app
122
+ * @default false
123
+ */
124
+ removeAfterSavedToDocuments?: boolean;
125
+ /**
126
+ * Remove the file after failed to save to Documents app
127
+ * @default false
128
+ */
129
+ removeAfterFailedToSaveDocuments?: boolean;
130
+ /**
131
+ * Remove the file after shared to other apps. Currently only support iOS, on Android there's no way to detect if the file is shared or not.
132
+ * @default false
133
+ */
134
+ removeAfterShared?: boolean;
135
+ /**
136
+ * Remove the file after failed to share to other apps. Currently only support iOS, on Android there's no way to detect if the file is shared or not.
137
+ * @default false
138
+ */
139
+ removeAfterFailedToShare?: boolean;
140
+ /**
141
+ * Whether to enable autoplay on load
142
+ */
143
+ autoplay?: boolean;
144
+ /**
145
+ * Jump to position on load in milliseconds
146
+ * @default `undefined` (beginning of the video)
147
+ */
148
+ jumpToPositionOnLoad?: number;
149
+ /**
150
+ * Whether to close the editor when finish editing
151
+ * @default true
152
+ */
153
+ closeWhenFinish?: boolean;
154
+ /**
155
+ * Enable cancel trimming
156
+ * @default true
157
+ */
158
+ enableCancelTrimming?: boolean;
159
+ /**
160
+ * Cancel trimming button text
161
+ * @default "Cancel"
162
+ */
163
+ cancelTrimmingButtonText?: string;
164
+ /**
165
+ * Enable cancel trimming dialog
166
+ * @default true
167
+ */
168
+ enableCancelTrimmingDialog?: boolean;
169
+ /**
170
+ * Cancel trimming dialog title
171
+ * @default "Warning!"
172
+ */
173
+ cancelTrimmingDialogTitle?: string;
174
+ /**
175
+ * Cancel trimming dialog message
176
+ * @default "Are you sure want to cancel trimming?"
177
+ */
178
+ cancelTrimmingDialogMessage?: string;
179
+ /**
180
+ * Cancel trimming dialog cancel text
181
+ * @default "Close"
182
+ */
183
+ cancelTrimmingDialogCancelText?: string;
184
+ /**
185
+ * Cancel trimming dialog confirm text
186
+ * @default "Proceed"
187
+ */
188
+ cancelTrimmingDialogConfirmText?: string;
189
+ /**
190
+ * Header text
191
+ */
192
+ headerText?: string;
193
+ /**
194
+ * Header text size
195
+ * @default 16
196
+ */
197
+ headerTextSize?: number;
198
+ /**
199
+ * Header text color
200
+ * @default white
201
+ */
202
+ headerTextColor?: ColorValue;
203
+ /**
204
+ * Alert on fail to load media
205
+ * @default true
206
+ */
207
+ alertOnFailToLoad?: boolean;
208
+ /**
209
+ * Alert on fail to load media title
210
+ * @default "Error"
211
+ */
212
+ alertOnFailTitle?: string;
213
+ /**
214
+ * Alert on fail to load media message
215
+ * @default "Fail to load media. Possibly invalid file or no network connection"
216
+ */
217
+ alertOnFailMessage?: string;
218
+ /**
219
+ * Alert on fail to load media close text
220
+ * @default "Close"
221
+ */
222
+ alertOnFailCloseText?: string;
20
223
  }
21
224
  /**
22
225
  * Delete a file
@@ -25,14 +228,7 @@ export interface EditorConfig {
25
228
  * @param {EditorConfig} config: editor configuration
26
229
  * @returns {void} A **Promise** which resolves `void`
27
230
  */
28
- export declare function showEditor(filePath: string, config?: EditorConfig): Promise<void>;
29
- /**
30
- * Delete a file
31
- *
32
- * @param {string} filePath: absolute non-empty file path to check if editable
33
- * @returns {Promise} A **Promise** which resolves `true` if editable
34
- */
35
- export declare function isValidVideo(filePath: string): Promise<boolean>;
231
+ export declare function showEditor(filePath: string, config?: EditorConfig): void;
36
232
  /**
37
233
  * Clean output files generated at all time
38
234
  *
@@ -52,4 +248,14 @@ export declare function cleanFiles(): Promise<number>;
52
248
  * @returns {Promise} A **Promise** which resolves `true` if successful
53
249
  */
54
250
  export declare function deleteFile(filePath: string): Promise<boolean>;
251
+ /**
252
+ * Close editor
253
+ */
254
+ export declare function closeEditor(): void;
255
+ /**
256
+ * Check if a file is valid audio or video file
257
+ *
258
+ * @returns {Promise} A **Promise** which resolves file info if successful
259
+ */
260
+ export declare function isValidFile(url: string): Promise<boolean>;
55
261
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3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0",
4
4
  "description": "Video trimmer for your React Native app",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.tsx CHANGED
@@ -1,4 +1,9 @@
1
- import { NativeModules, PermissionsAndroid, Platform } from 'react-native';
1
+ import {
2
+ NativeModules,
3
+ Platform,
4
+ processColor,
5
+ type ColorValue,
6
+ } from 'react-native';
2
7
 
3
8
  const LINKING_ERROR =
4
9
  `The package 'react-native-video-trim' doesn't seem to be linked. Make sure: \n\n` +
@@ -18,24 +23,226 @@ const VideoTrim = NativeModules.VideoTrim
18
23
  );
19
24
 
20
25
  export interface EditorConfig {
26
+ /**
27
+ * Enable haptic feedback
28
+ * @default true
29
+ */
30
+ enableHapticFeedback?: boolean;
31
+ /**
32
+ * Save the output file to Photos Library. Only video is supported. Note that you have to make sure you have permission to save to Photos Library.
33
+ * @default false
34
+ */
21
35
  saveToPhoto?: boolean;
22
- removeAfterSavedToPhoto?: boolean;
23
36
  maxDuration?: number;
37
+ /**
38
+ * Minimum duration for trimmer
39
+ * @default 1000
40
+ */
24
41
  minDuration?: number;
42
+ /**
43
+ * Cancel button text
44
+ * @default "Cancel"
45
+ */
25
46
  cancelButtonText?: string;
47
+ /**
48
+ * Save button text
49
+ * @default "Save"
50
+ */
26
51
  saveButtonText?: string;
52
+ /**
53
+ * Enable cancel dialog
54
+ * @default true
55
+ */
27
56
  enableCancelDialog?: boolean;
57
+ /**
58
+ * Cancel dialog title
59
+ * @default "Warning!"
60
+ */
28
61
  cancelDialogTitle?: string;
62
+ /**
63
+ * Cancel dialog message
64
+ * @default "Are you sure want to cancel?"
65
+ */
29
66
  cancelDialogMessage?: string;
67
+ /**
68
+ * Cancel dialog cancel text
69
+ * @default "Close"
70
+ */
30
71
  cancelDialogCancelText?: string;
72
+ /**
73
+ * Cancel dialog confirm text
74
+ * @default "Proceed"
75
+ */
31
76
  cancelDialogConfirmText?: string;
77
+ /**
78
+ * Enable save dialog
79
+ * @default true
80
+ */
32
81
  enableSaveDialog?: boolean;
82
+ /**
83
+ * Save dialog title
84
+ * @default "Confirmation!"
85
+ */
33
86
  saveDialogTitle?: string;
87
+ /**
88
+ * Save dialog message
89
+ * @default "Are you sure want to save?"
90
+ */
34
91
  saveDialogMessage?: string;
92
+ /**
93
+ * Save dialog cancel text
94
+ * @default "Close"
95
+ */
35
96
  saveDialogCancelText?: string;
97
+ /**
98
+ * Save dialog confirm text
99
+ * @default "Proceed"
100
+ */
36
101
  saveDialogConfirmText?: string;
102
+ /**
103
+ * Trimming text
104
+ * @default "Trimming video..."
105
+ */
37
106
  trimmingText?: string;
107
+ /**
108
+ * By default, on iOS the editor will be presented as a modal. If you want to present it as a full screen modal, set this to `true`.
109
+ * @default false
110
+ */
38
111
  fullScreenModalIOS?: boolean;
112
+ /**
113
+ * Type of the file to edit. If video file, recommend to use `video`. If audio file, recommend to use `audio`.
114
+ * @default "video"
115
+ */
116
+ type?: 'video' | 'audio';
117
+ /**
118
+ * Output file extension. If video file, recommend to use `mp4` or `mov`. If audio file, recommend to use `wav` or `m4a`.
119
+ * @default "mp4"
120
+ * @example "mp4", "mov", "wav", "m4a", "3gp", "avi", "mkv", "flv", "wmv", "webm"
121
+ */
122
+ outputExt?: string;
123
+ /**
124
+ * Whether to open Documents app after finish editing
125
+ * @default false
126
+ */
127
+ openDocumentsOnFinish?: boolean;
128
+ /**
129
+ * Whether to open Share Sheet after finish editing
130
+ * @default false
131
+ */
132
+ openShareSheetOnFinish?: boolean;
133
+ /**
134
+ * Remove the file after saved to Photos Library
135
+ * @default false
136
+ */
137
+ removeAfterSavedToPhoto?: boolean;
138
+ /**
139
+ * Remove the file after failed to save to Photos Library
140
+ * @default false
141
+ */
142
+ removeAfterFailedToSavePhoto?: boolean;
143
+ /**
144
+ * Remove the file after saved to Documents app
145
+ * @default false
146
+ */
147
+ removeAfterSavedToDocuments?: boolean;
148
+ /**
149
+ * Remove the file after failed to save to Documents app
150
+ * @default false
151
+ */
152
+ removeAfterFailedToSaveDocuments?: boolean;
153
+ /**
154
+ * Remove the file after shared to other apps. Currently only support iOS, on Android there's no way to detect if the file is shared or not.
155
+ * @default false
156
+ */
157
+ removeAfterShared?: boolean;
158
+ /**
159
+ * Remove the file after failed to share to other apps. Currently only support iOS, on Android there's no way to detect if the file is shared or not.
160
+ * @default false
161
+ */
162
+ removeAfterFailedToShare?: boolean;
163
+ /**
164
+ * Whether to enable autoplay on load
165
+ */
166
+ autoplay?: boolean;
167
+ /**
168
+ * Jump to position on load in milliseconds
169
+ * @default `undefined` (beginning of the video)
170
+ */
171
+ jumpToPositionOnLoad?: number;
172
+ /**
173
+ * Whether to close the editor when finish editing
174
+ * @default true
175
+ */
176
+ closeWhenFinish?: boolean;
177
+ /**
178
+ * Enable cancel trimming
179
+ * @default true
180
+ */
181
+ enableCancelTrimming?: boolean;
182
+ /**
183
+ * Cancel trimming button text
184
+ * @default "Cancel"
185
+ */
186
+ cancelTrimmingButtonText?: string;
187
+ /**
188
+ * Enable cancel trimming dialog
189
+ * @default true
190
+ */
191
+ enableCancelTrimmingDialog?: boolean;
192
+ /**
193
+ * Cancel trimming dialog title
194
+ * @default "Warning!"
195
+ */
196
+ cancelTrimmingDialogTitle?: string;
197
+ /**
198
+ * Cancel trimming dialog message
199
+ * @default "Are you sure want to cancel trimming?"
200
+ */
201
+ cancelTrimmingDialogMessage?: string;
202
+ /**
203
+ * Cancel trimming dialog cancel text
204
+ * @default "Close"
205
+ */
206
+ cancelTrimmingDialogCancelText?: string;
207
+ /**
208
+ * Cancel trimming dialog confirm text
209
+ * @default "Proceed"
210
+ */
211
+ cancelTrimmingDialogConfirmText?: string;
212
+ /**
213
+ * Header text
214
+ */
215
+ headerText?: string;
216
+ /**
217
+ * Header text size
218
+ * @default 16
219
+ */
220
+ headerTextSize?: number;
221
+ /**
222
+ * Header text color
223
+ * @default white
224
+ */
225
+ headerTextColor?: ColorValue;
226
+ /**
227
+ * Alert on fail to load media
228
+ * @default true
229
+ */
230
+ alertOnFailToLoad?: boolean;
231
+ /**
232
+ * Alert on fail to load media title
233
+ * @default "Error"
234
+ */
235
+ alertOnFailTitle?: string;
236
+ /**
237
+ * Alert on fail to load media message
238
+ * @default "Fail to load media. Possibly invalid file or no network connection"
239
+ */
240
+ alertOnFailMessage?: string;
241
+ /**
242
+ * Alert on fail to load media close text
243
+ * @default "Close"
244
+ */
245
+ alertOnFailCloseText?: string;
39
246
  }
40
247
 
41
248
  /**
@@ -45,70 +252,10 @@ export interface EditorConfig {
45
252
  * @param {EditorConfig} config: editor configuration
46
253
  * @returns {void} A **Promise** which resolves `void`
47
254
  */
48
- export async function showEditor(
49
- filePath: string,
50
- config: EditorConfig = {}
51
- ): Promise<void> {
52
- if (!filePath?.trim().length) {
53
- throw new Error('File path cannot be empty!');
54
- }
55
-
56
- const { saveToPhoto = true } = config;
57
- const outputPath = await VideoTrim.showEditor(filePath, config);
58
-
59
- if (Platform.OS === 'android') {
60
- if (saveToPhoto) {
61
- try {
62
- if (Platform.Version >= 33) {
63
- // since android 13 it's not needed to request permission for write storage: https://github.com/facebook/react-native/issues/36714#issuecomment-1491338276
64
- await VideoTrim.saveVideo(outputPath);
65
-
66
- if (config.removeAfterSavedToPhoto) {
67
- deleteFile(outputPath);
68
- }
69
- } else {
70
- const granted = await PermissionsAndroid.request(
71
- PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE!,
72
- {
73
- title: 'Video Trimmer Photos Access Required',
74
- message: 'Grant access to your Photos to write output Video',
75
- buttonNeutral: 'Ask Me Later',
76
- buttonNegative: 'Cancel',
77
- buttonPositive: 'OK',
78
- }
79
- );
80
- if (granted === PermissionsAndroid.RESULTS.GRANTED) {
81
- await VideoTrim.saveVideo(outputPath);
82
-
83
- if (config.removeAfterSavedToPhoto) {
84
- deleteFile(outputPath);
85
- }
86
- } else {
87
- throw new Error('Photos Library permission denied');
88
- }
89
- }
90
- } catch (err) {
91
- throw err;
92
- } finally {
93
- VideoTrim.hideDialog();
94
- }
95
- } else {
96
- VideoTrim.hideDialog();
97
- }
98
- }
99
- }
100
-
101
- /**
102
- * Delete a file
103
- *
104
- * @param {string} filePath: absolute non-empty file path to check if editable
105
- * @returns {Promise} A **Promise** which resolves `true` if editable
106
- */
107
- export function isValidVideo(filePath: string): Promise<boolean> {
108
- if (!filePath?.trim().length) {
109
- throw new Error('File path cannot be empty!');
110
- }
111
- return VideoTrim.isValidVideo(filePath);
255
+ export function showEditor(filePath: string, config: EditorConfig = {}): void {
256
+ const { headerTextColor } = config;
257
+ const color = processColor(headerTextColor);
258
+ VideoTrim.showEditor(filePath, { ...config, headerTextColor: color });
112
259
  }
113
260
 
114
261
  /**
@@ -141,3 +288,19 @@ export function deleteFile(filePath: string): Promise<boolean> {
141
288
  }
142
289
  return VideoTrim.deleteFile(filePath);
143
290
  }
291
+
292
+ /**
293
+ * Close editor
294
+ */
295
+ export function closeEditor(): void {
296
+ return VideoTrim.closeEditor();
297
+ }
298
+
299
+ /**
300
+ * Check if a file is valid audio or video file
301
+ *
302
+ * @returns {Promise} A **Promise** which resolves file info if successful
303
+ */
304
+ export function isValidFile(url: string): Promise<boolean> {
305
+ return VideoTrim.isValidFile(url);
306
+ }
@@ -1,18 +0,0 @@
1
- //
2
- // Source code recreated from a .class file by IntelliJ IDEA
3
- // (powered by FernFlower decompiler)
4
- //
5
-
6
- package iknow.android.utils;
7
-
8
- public final class BuildConfig {
9
- public static final boolean DEBUG = false;
10
- public static final String APPLICATION_ID = "iknow.android.utils";
11
- public static final String BUILD_TYPE = "release";
12
- public static final String FLAVOR = "";
13
- public static final int VERSION_CODE = 1;
14
- public static final String VERSION_NAME = "1.0";
15
-
16
- public BuildConfig() {
17
- }
18
- }
@@ -1,64 +0,0 @@
1
- package iknow.android.utils;
2
-
3
- import android.text.TextUtils;
4
-
5
- import java.text.SimpleDateFormat;
6
- import java.util.Date;
7
- import java.util.Locale;
8
-
9
- /**
10
- * Author:J.Chou
11
- * Date: 2016.07.21 11:43.
12
- * Email: who_know_me@163.com
13
- * Describe:
14
- */
15
- public final class DateUtil {
16
-
17
- /**
18
- * second to HH:MM:ss
19
- * @param seconds
20
- * @return
21
- */
22
- public static String convertSecondsToTime(long seconds) {
23
- String timeStr = null;
24
- int hour = 0;
25
- int minute = 0;
26
- int second = 0;
27
- if (seconds <= 0)
28
- return "00:00";
29
- else {
30
- minute = (int)seconds / 60;
31
- if (minute < 60) {
32
- second = (int)seconds % 60;
33
- timeStr = unitFormat(minute) + ":" + unitFormat(second);
34
- } else {
35
- hour = minute / 60;
36
- if (hour > 99)
37
- return "99:59:59";
38
- minute = minute % 60;
39
- second = (int)(seconds - hour * 3600 - minute * 60);
40
- timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
41
- }
42
- }
43
- return timeStr;
44
- }
45
-
46
- public static String convertSecondsToFormat(long seconds,String format){
47
-
48
- if(TextUtils.isEmpty(format))
49
- return "";
50
-
51
- Date date = new Date(seconds);
52
- SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
53
- return sdf.format(date);
54
- }
55
-
56
- private static String unitFormat(int i) {
57
- String retStr = null;
58
- if (i >= 0 && i < 10)
59
- retStr = "0" + Integer.toString(i);
60
- else
61
- retStr = "" + i;
62
- return retStr;
63
- }
64
- }