今天是周一课不少,所以冲刺的少一点,今天在android上封装好了时间函数和log函数,代码量300行,因为对媒体播放的要求,今天学习了MediaPlayer的使用,但是只是一些小的test并没有和项目结合起来,重复代码行数200行
Framework.java
package com.example.framework; import android.widget.FrameLayout; public class Framework { private volatile static Framework mFramework; private Framework() { } public static Framework getmFramework() { if(mFramework==null) { synchronized (Framework.class) { if(mFramework==null) { mFramework=new Framework(); } } } return mFramework; } }
LogUtils.java
package com.example.framework.utils; import android.text.TextUtils; import android.util.Log; import com.example.framework.BuildConfig; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.Date; public class LogUtils { private static SimpleDateFormat mSimpleDateFormat=new SimpleDateFormat("YYYY-YMM-DD HH:mm:ss"); //LogUtils.i("") public static void i(String text) { if(BuildConfig.LOG_DEBUG) { if (!TextUtils.isEmpty(text)) { Log.i(BuildConfig.LOG_TAG, text); writeToFile(text); } } } public static void e(String text) { if(BuildConfig.LOG_DEBUG) { if (!TextUtils.isEmpty(text)) { Log.e(BuildConfig.LOG_TAG, text); writeToFile(text); } } } private static void writeToFile(String text) { //文件路径 String fileName="/sdcard/Meet/Meet.log"; //时间 内容 String log=mSimpleDateFormat.format(new Date()) +" "+text + " "; //检查路径 File fileGroup =new File("/sdcard/Meet/"); if(!fileGroup.exists()) { fileGroup.mkdirs(); } //开始写入 FileOutputStream fileOutputStream=null; BufferedWriter bufferedWriter=null; try { fileOutputStream=new FileOutputStream(fileName,true); //GBK才能正确存入中文 bufferedWriter=new BufferedWriter( new OutputStreamWriter(fileOutputStream, Charset.forName("gbk")) ); try { bufferedWriter.write(log); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); }finally { if(bufferedWriter!=null) { try { bufferedWriter.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
TimeUtils.java
package com.example.framework.utils; public class TimeUtils { //时间转换类 public static String formatDuring(long ms) { long hours =(ms % (1000 * 60 * 60 * 24)) / (1000*60*60); long minutes=(ms % (1000 * 60 * 60)) / (1000*60); long seconds=(ms % (1000 * 60)) / (1000); String h=hours+""; if(hours<10) { h="0"+h; } String m=minutes+""; if(minutes<10) { m="0"+m; } String s=seconds+""; if(seconds<10) { s="0"+s; } return h + ":" + m + ":" + s; } }