Browse Source

复制到新数据库目录

授权码生成工具
liup 3 months ago
parent
commit
dbfcbb1aa3
8 changed files with 161 additions and 37 deletions
  1. +2
    -1
      app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
  2. +128
    -11
      app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java
  3. +20
    -0
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java
  4. +5
    -5
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java
  5. +1
    -1
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java
  6. +0
    -16
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_message.java
  7. +3
    -2
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/jingdutiao1.java
  8. +2
    -1
      app/src/main/res/layout/activity_bunkersetup.xml

+ 2
- 1
app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java View File

@@ -36,7 +36,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class ConfigName {
public static boolean isTEST = false;
public boolean is800WithFeeding = false;//是否是800带投料版 有5个投料位
public boolean isPhoneVersion = true;//是否适配手机
public boolean isPhoneVersion = false;//是否适配手机
public boolean isHighVersion = false;//是否适配高版本
public double scale = 1;

//region 单例模式


+ 128
- 11
app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java View File

@@ -5,12 +5,15 @@ import android.content.Context;
import android.os.Environment;
import android.util.Log;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.file.DBHelper;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
@@ -46,13 +49,7 @@ public class SdCart {
* 初始化数据库到SD卡
*/
public void initSD() {
// File sdDir = null;
// boolean sdCardExist = Environment.getExternalStorageState().equals(
// Environment.MEDIA_MOUNTED);
// if (sdCardExist) {
// sdDir = Environment.getExternalStorageDirectory();
// ConfigName.getInstance().sdCardPath = sdDir.toString();
// }

ConfigName.getInstance().sdCardPath = ConfigName.getFileRoot(MainApplication.getContext());

ConfigName.getInstance().appResRoot = ConfigName.getInstance().sdCardPath +ConfigName.dataPath;
@@ -68,10 +65,28 @@ public class SdCart {
if(!file.exists())//文件不存在那么创建数据库
{
Log.i("日志","初始化数据库:文件不存在准备新建!");
//1.复制本地文件到SD卡
copyFilesFassets(ConfigName.getInstance().dishesCon, ConfigName.getInstance().dbPath);
//2.创建数据库结构
DBHelper.getInstance(ConfigName.getInstance().dishesCon).CreateTables();

//复制文件
if(!ConfigName.getInstance().isHighVersion){

File sdDir = null;
String dbPath = "";
boolean sdCardExist = Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED);
if (sdCardExist) {
sdDir = Environment.getExternalStorageDirectory();
dbPath = sdDir.toString()+ConfigName.dataPath;
}
File file2 = new File(dbPath);
if(file2.exists()){
copyDirectory(dbPath,ConfigName.getInstance().appResRoot);
}
}else {
//1.复制本地文件到SD卡
copyFilesFassets(ConfigName.getInstance().dishesCon, ConfigName.getInstance().dbPath);
//2.创建数据库结构
DBHelper.getInstance(ConfigName.getInstance().dishesCon).CreateTables();
}
}

ConfigName.getInstance(). AuthorizeCodePath=ConfigName.getInstance().appResRoot + "/AuthorizeCode.aes";
@@ -108,7 +123,109 @@ public class SdCart {

} catch (Exception e) {
e.printStackTrace();
LogUtils.d("copyFilesFassets Exception");
}
}




/**
* 复制目录及其子目录中的所有文件到另一个目录
*
* @param srcDir 源目录路径
* @param destDir 目标目录路径
* @return 复制是否成功
*/
public static boolean copyDirectory(String srcDir, String destDir) {
LogUtils.d("copyDirectory srcDir="+srcDir+";destDir="+destDir);
File srcFile = new File(srcDir);
File destFile = new File(destDir);

// 如果源目录不存在,则返回false
if (!srcFile.exists()) {
LogUtils.d("copyDirectory 如果源目录不存在");
return false;
}

// 如果目标目录不存在,则创建它
if (!destFile.exists()) {
destFile.mkdirs();
}
LogUtils.d("copyDirectory ==");
// 列出源目录下的所有文件和文件夹
File[] files = srcFile.listFiles();

if (files != null) {
for (File file : files) {
// 构造源和目标文件路径
String srcFilePath = file.getAbsolutePath();
String destFilePath = destDir + File.separator + file.getName();

// 如果是文件,则直接复制
if (file.isFile()) {
copyFile(srcFilePath, destFilePath);
}
// 如果是目录,则递归复制
else if (file.isDirectory()) {
copyDirectory(srcFilePath, destFilePath);
}
}
}
LogUtils.d("copyDirectory true");
return true;
}

/**
* 复制单个文件
*
* @param sourceFile 源文件路径
* @param destFile 目标文件路径
* @return 复制是否成功
*/
private static boolean copyFile(String sourceFile, String destFile) {
File sourceFileObj = new File(sourceFile);
File destFileObj = new File(destFile);

if (!sourceFileObj.isFile()) {
// 如果源文件不存在,则复制失败
LogUtils.d("copyFile 如果源文件不存在");

return false;
}

// 确保目标文件所在的目录存在
File destFileParentDir = destFileObj.getParentFile();
if (!destFileParentDir.exists()) {
destFileParentDir.mkdirs();
}

FileInputStream fis = null;
FileOutputStream fos = null;

try {
fis = new FileInputStream(sourceFileObj);
fos = new FileOutputStream(destFileObj);

byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}

return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
LogUtils.d("copyFile true");
// 关闭流
try {
if (fis != null) fis.close();
if (fos != null) fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

+ 20
- 0
app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java View File

@@ -250,6 +250,26 @@ public class HomeFragmentSBKZ extends BaseFragment {
tv5.setVisibility(ConfigName.getInstance().is800WithFeeding?View.VISIBLE:View.GONE);
}

@Override
public void onResume() {
super.onResume();
ArrayList<BPA_SILOS> silosArrayList = QueryDB.GetSilosALL();
List<String> nameList = new ArrayList<>();
if(!silosArrayList.isEmpty()) {
for (BPA_SILOS silos : silosArrayList) {
List<BPA_MATERIAL> materials = QueryDB.GetMaterialBySilosID(silos.id);
if (!materials.isEmpty()) {
nameList.add(silos.num + "料仓:" + materials.get(0).name);
} else {
nameList.add(silos.num + "料仓:未设置");
}
}
ArrayAdapter<String> adapter_kk = new ArrayAdapter<>(getContext(), R.layout.spinner_text_item20, nameList);
adapter_kk.setDropDownViewResource(R.layout.spinner_dropdown_item20);
spinner_silos.setAdapter(adapter_kk);
}
}

@Override
public void onDestroy() {
super.onDestroy();


+ 5
- 5
app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java View File

@@ -142,11 +142,11 @@ public class BunkerSetupActivity extends BaseActivity {
DataBus.getInstance().GetLc();
if(ConfigName.getInstance().silosAuto){
binding.llSilosAuto.removeAllViews();
// for (lcMode item : DataBus.getInstance().lcModes) {
// jingdutiao1 view = new jingdutiao1(this);
// view.SetValue(item,myClickListener);
// binding.llSilosAuto.addView(view);
// }
for (lcMode item : DataBus.getInstance().lcModes) {
jingdutiao1 view = new jingdutiao1(this);
view.SetValue(item,myClickListener);
binding.llSilosAuto.addView(view);
}
}else {
for (lcMode item : DataBus.getInstance().lcModes) {
if (item.num == 1) {


+ 1
- 1
app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java View File

@@ -316,7 +316,7 @@ public class SystemSystemsetFragment extends BaseFragment {
if(size>newSize){
for(int i=size-1;i>=newSize;i--){
QueryDB.DeleteSilos(silosArrayList.get(i));
QueryDB.DeleteSilosAndMaterial(silosandmaterials.get(i));
QueryDB.DeleteSilosAndMaterial(silosArrayList.get(i).id);
}
}else if(size<newSize ){
for(int i=size;i<newSize;i++){


+ 0
- 16
app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_message.java View File

@@ -99,22 +99,6 @@ public class add_silos_message extends LinearLayout {
}
}
});

/**
* 单仓清洗
*/
/* click_dcqx.mListener=new MyClickListener() {
@Override
public void clickListener(View v, Object data) {
boolean status = (boolean) data;
ExecuteTheRecipe.WritePLC("料仓" + mode.num + "手动开关", status, null);
}

@Override
public void clickListenerNew(View v, int k, Object data) {

}
};*/
}

/**


+ 3
- 2
app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/jingdutiao1.java View File

@@ -43,8 +43,9 @@ public class jingdutiao1 extends LinearLayout {
private View root;

public jingdutiao1(Context context) {
this(context, null);

super(context, null);
root= LayoutInflater.from(context).inflate(R.layout.item_jingdutiao1, this);
ButterKnife.bind(this, root);
}

public jingdutiao1(Context context, @Nullable AttributeSet attrs) {


+ 2
- 1
app/src/main/res/layout/activity_bunkersetup.xml View File

@@ -162,13 +162,14 @@
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_marginTop="100dp"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll_silos_auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="100dp"
android:paddingBottom="200dp"
>

</LinearLayout>


Loading…
Cancel
Save