Android Open Source - Schowek My Utils






From Project

Back to project page Schowek.

License

The source code is released under:

MIT License

If you think the Android project Schowek listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.kkrolczyk.schowek;
//from   w w  w . j  av a  2s. c o  m
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * Created by kkrolczyk on 23.11.14.
 */
public class MyUtils {

    public enum db_copy_direction { STORE, LOAD };
    public static String[] convertToStrings(byte[][] byteStrings) {
        String[] data = new String[byteStrings.length];
        for (int i = 0; i < byteStrings.length; i++) {
            data[i] = new String(byteStrings[i], Charset.defaultCharset());

        }
        return data;
    }

    public static byte[][] convertToBytes(String[] strings) {
        byte[][] data = new byte[strings.length][];
        for (int i = 0; i < strings.length; i++) {
            String string = strings[i];
            data[i] = string.getBytes(Charset.defaultCharset()); // you can chose charset
        }
        return data;
    }


    public static String timestamp(){
        return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
    }
    public static String datenow(){
        return new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
    }
    public static String timenow(){
        return new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime());
    }



    public static Boolean Backup_DB(Enum direction, String dbname, boolean target_ext){

        try {
            File source = Environment.getDataDirectory();
            File target = target_ext ? new File("/mnt/extSdCard/") : Environment.getExternalStorageDirectory();

            //if (sd.canWrite()) {
            String currentDBPath = "//data//" + MyUtils.class.getPackage().getName() + "//databases//" + dbname;
            String backupDBPath = dbname;
            File currentDB, backupDB;
            if (direction == db_copy_direction.LOAD) { // TODO: swap dirs == swap(currentDB, backupDB);
                currentDB = new File(target, backupDBPath);
                backupDB = new File(source, currentDBPath);
            } else {
                currentDB = new File(source, currentDBPath);
                backupDB = new File(target, backupDBPath);
            }

            //if (currentDB.exists()) {
            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            //}
        } catch (Exception e) {
            Log.e("SCHOWEK", e.toString());
            return false;
        }
        return true;
    }

}




Java Source Code List

org.kkrolczyk.schowek.AbstractConfig.java
org.kkrolczyk.schowek.AbstractDBAdapter.java
org.kkrolczyk.schowek.ApplicationTest.java
org.kkrolczyk.schowek.BilansAdd.java
org.kkrolczyk.schowek.BilansConfig.java
org.kkrolczyk.schowek.BilansCustomArrayAdapter.java
org.kkrolczyk.schowek.BilansDBAdapter.java
org.kkrolczyk.schowek.BilansView.java
org.kkrolczyk.schowek.DBAdapter.java
org.kkrolczyk.schowek.MainActivity.java
org.kkrolczyk.schowek.MyUtils.java
org.kkrolczyk.schowek.NoteAdd.java
org.kkrolczyk.schowek.NoteConfig.java
org.kkrolczyk.schowek.NoteDBAdapter.java
org.kkrolczyk.schowek.NoteView.java