change TimeUtil to kotlin

pull/166/head
xufuji456 4 years ago
parent 4d740446a1
commit b78bd398ea
  1. 82
      app/src/main/java/com/frank/ffmpeg/util/TimeUtil.java
  2. 82
      app/src/main/java/com/frank/ffmpeg/util/TimeUtil.kt
  3. 4
      app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java

@ -1,82 +0,0 @@
package com.frank.ffmpeg.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
* the tool of time transforming
* Created by frank on 2018/11/12.
*/
public class TimeUtil {
private static final String YMDHMS = "yyyy-MM-dd HH:mm:ss";
/**
* convert timestramp into String
*
* @param time time
* @return yyyy/MM/dd HH:mm:ss
*/
public static String getDetailTime(long time) {
SimpleDateFormat format = new SimpleDateFormat(YMDHMS, Locale.getDefault());
Date date = new Date(time);
return format.format(date);
}
/**
* convert normal time into timestamp
*
* @param time time
* @return timestamp
*/
public static long getLongTime(String time, Locale locale) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YMDHMS, locale);
try {
Date dt = simpleDateFormat.parse(time);
return dt.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}
private static String addZero(int time) {
if (time >= 0 && time < 10) {
return "0" + time;
} else if (time >= 10) {
return "" + time;
} else {
return "";
}
}
/**
* convert timestamp into video time
*
* @param time time
* @return video time
*/
public static String getVideoTime(long time) {
if (time <= 0)
return null;
time = time / 1000;
int second, minute = 0, hour = 0;
second = (int) time % 60;
time = time / 60;
if (time > 0) {
minute = (int) time % 60;
hour = (int) time / 60;
}
if (hour > 0) {
return addZero(hour) + ":" + addZero(minute) + ":" + addZero(second);
} else if (minute > 0) {
return addZero(minute) + ":" + addZero(second);
} else {
return "00:" + addZero(second);
}
}
}

@ -0,0 +1,82 @@
package com.frank.ffmpeg.util
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
/**
* the tool of time transforming
* Created by frank on 2018/11/12.
*/
object TimeUtil {
private const val YMDHMS = "yyyy-MM-dd HH:mm:ss"
/**
* convert timestramp into String
*
* @param time time
* @return yyyy/MM/dd HH:mm:ss
*/
fun getDetailTime(time: Long): String {
val format = SimpleDateFormat(YMDHMS, Locale.getDefault())
val date = Date(time)
return format.format(date)
}
/**
* convert normal time into timestamp
*
* @param time time
* @return timestamp
*/
fun getLongTime(time: String, locale: Locale): Long {
val simpleDateFormat = SimpleDateFormat(YMDHMS, locale)
try {
val dt = simpleDateFormat.parse(time)
return dt.time
} catch (e: ParseException) {
e.printStackTrace()
}
return 0
}
private fun addZero(time: Int): String {
return when {
time in 0..9 -> "0$time"
time >= 10 -> "" + time
else -> ""
}
}
/**
* convert timestamp into video time
*
* @param t time
* @return video time
*/
fun getVideoTime(t: Long): String? {
var time = t
if (time <= 0)
return null
time /= 1000
val second: Int
var minute = 0
var hour = 0
second = time.toInt() % 60
time /= 60
if (time > 0) {
minute = time.toInt() % 60
hour = time.toInt() / 60
}
return when {
hour > 0 -> addZero(hour) + ":" + addZero(minute) + ":" + addZero(second)
minute > 0 -> addZero(minute) + ":" + addZero(second)
else -> "00:" + addZero(second)
}
}
}

@ -169,7 +169,7 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On
@Override
public void run() {
previewBar.setMax(durationMs);
txtVideoDuration.setText(TimeUtil.getVideoTime(durationMs));
txtVideoDuration.setText(TimeUtil.INSTANCE.getVideoTime(durationMs));
texturePreView.setVisibility(GONE);
}
});
@ -198,7 +198,7 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On
public void updateProgress(int progress) {
if (progress >= 0 && progress <= duration) {
txtVideoProgress.setText(TimeUtil.getVideoTime(progress));
txtVideoProgress.setText(TimeUtil.INSTANCE.getVideoTime(progress));
previewBar.setProgress(progress);
}
}

Loading…
Cancel
Save