Skip to content

Commit

Permalink
🎉 Release.2.2.441,2.2版本,OKHttp3库更新,新增保存传感器数据
Browse files Browse the repository at this point in the history
  • Loading branch information
Hny0305Lin committed Aug 28, 2022
1 parent 2a911b9 commit 67fd958
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 23 deletions.
3 changes: 2 additions & 1 deletion HaohanyhHAMOSProjectY Android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions HaohanyhHAMOSProjectY Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
}

dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
Expand Down
9 changes: 3 additions & 6 deletions HaohanyhHAMOSProjectY Android/app/huawei/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
targetSdk 33
versionCode 1

versionName "1.4"
versionName "1.3.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -29,10 +29,7 @@ android {
}

dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
//华为函数目前简化到仅两个
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.haohanyh.hamos.projecty"
android:versionName="@string/app_version">
<!--MainActivity和HAMOSActivity需求权限-->
<!--MainActivity和HAMOSActivity需求权限 && 和风天气所需网络权限-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Expand All @@ -13,7 +13,7 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--MainActivity 2.2储存权限 多设备使用-->
<!--MainActivity 2.2储存权限 多设备使用 && 和风天气所需存储权限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean ReadFile() {
Log.v(TAG,"第二份结束");
return true;
} catch (IOException e) {
e.printStackTrace();
Log.v(TAG,"失败,说明您没有保存,您需要正常启动成功后,手动保存好信息!");
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SaveHuaweiData {
private String werobfker = null;//第三个

public SaveHuaweiData() {};
public static SaveHuaweiData GetSaveData() { return SaveHuaweiData.savedata.thing; }
public static SaveHuaweiData NeedSaveData() { return SaveHuaweiData.savedata.thing; }
protected static class savedata { private static final SaveHuaweiData thing = new SaveHuaweiData(); }

public String ProcessDataToWriteFile() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.haohanyh.hamos.managedata;

import android.annotation.SuppressLint;
import android.util.Log;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;

public class SaveSensorData {
//浩瀚银河此类保存用户如下信息:
/* 5. 使用者的护花使者的传感器信息、电机开关情况、传感器信息时间、华为云提交次数
* (内容为附近温度、空气湿度和土壤湿度)
*/
private static final String TAG = "浩瀚银河保存传感器文件:";
int count = 0;
private String Dir = null;
public void setDir(String dir) { Dir = dir; }
private String temp = null;//附近温度
private String humi = null;//空气湿度
private String soil = null;//土壤湿度
private String time = null;//信息时间
private String num = null;//提交次数

public SaveSensorData() {};
public static SaveSensorData NeedSaveData() { return SaveSensorData.savedata.thing; }
protected static class savedata { private static final SaveSensorData thing = new SaveSensorData(); }
//HAMOSActivity写入值,用于保存
public void setTemp(String temp) { this.temp = temp; }
public void setHumi(String humi) { this.humi = humi; }
public void setSoil(String soil) { this.soil = soil; }
public void setTime(String time) { this.time = time; }
public void setNum(String num) { this.num = num; }

/* 通过华为云API该页面:https://apiexplorer.developer.huaweicloud.com/apiexplorer/doc?product=IoTDA&api=ShowDeviceShadow
* 我们可以得知:properties为设备影子的属性数据,event_time为事件操作时间。
* 华为云对event_time有格式规定:yyyyMMdd'T'HHmmss'Z',如20151212T121212Z。
* 那么我们可以举例:20220828T180036Z,为2022年8月28号18时00分36秒。
* 那么,String Stime,就能说明这里注释的一切~
*/
public String ProcessDataToWriteFile() {
String Snum = "华为云IoTDA数据记录次数:" + num;
String Stemp = "附近温度:" + temp;
String Shumi = "空气湿度:" + humi;
String Ssoil = "土壤湿度:" + soil;
String Stime = "信息时间:" + time.substring(0,4) + "年" + time.substring(4,6) + "月" + time.substring(6,8) + "日" + time.substring(9,11) + "时" + time.substring(11,13) + "分" + time.substring(13,15) + "秒";
return Snum + "\t" + Stemp + "\t" + Shumi + "\t" + Ssoil + "\t" + Stime + "\n";
}

/**
* WriteFile(),保存文件到我们的一亩三分地里~不乱存
*/
@SuppressLint("SdCardPath")
public void WriteFile() {
Log.v(TAG,"开始");
try {
File file = new File(Dir + "/HAMOSData");
if(!file.exists()) { file.mkdir(); }//判断目录是否存在,不存在就得创建
File file2 = new File(Dir + "/HAMOSData/Sensor");
if(!file2.exists()) { file2.mkdir(); }//判断目录是否存在,不存在就得创建
File newFile = new File(file2 + "/Sensor.txt");
if(!newFile.exists()) { newFile.createNewFile(); }//判断文件是否存在,不存在就得创建
//经过多次版本测试,我们终于得到了确切目录树: /storage/emulated/0/HAMOSData/Sensor/Sensor.txt
String Path = Dir + "/HAMOSData/Sensor/Sensor.txt";
File targetFile = new File(Path);
RandomAccessFile randomAccessFile = new RandomAccessFile(targetFile,"rw");
long fileLength = randomAccessFile.length();//神来之笔,我要知道这个JSON里面,存了多少字节了,就靠long fileLength!
randomAccessFile.seek(fileLength);
randomAccessFile.write(ProcessDataToWriteFile().getBytes(StandardCharsets.UTF_8));//写入我们保存的用户信息
randomAccessFile.close();
} catch (IOException e) {
e.printStackTrace();
}
count++;
Log.v(TAG,"保存"+count+"次,数据于华为云IoTDA版本为" + num +",感谢您使用浩瀚银河2.2灰度测试功能!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SaveWLANData {
private String weruygker = null;private String werrgfjer = null;//第四个

public SaveWLANData() {};
public static SaveWLANData GetSaveData() { return SaveWLANData.savedata.thing; }
public static SaveWLANData NeedSaveData() { return SaveWLANData.savedata.thing; }
protected static class savedata { private static final SaveWLANData thing = new SaveWLANData(); }

public String ProcessDataToWriteFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ public void run() {
}
});
}
for(int i = 0;i < jsonArray.length(); i++){
//第一层,reported,取version明白已上报次数
JSONObject obj = jsonArray.getJSONObject(i);
Object reported = obj.get("reported");
String VersionResult = obj.getString("version");
//第二层,properties,里面就有我们要的数据的同时,可以取时间值
JSONObject Two = new JSONObject(String.valueOf(reported));
String TimeResult = Two.getString("event_time");
String properties = Two.getString("properties");
//最后一层,我们取里面,传感器上报到华为云的数据,这一些代码才是精华
JSONObject Last = new JSONObject(properties);
String TemperatureResult = Last.getString("Temperature");
String HumidityResult = Last.getString("Humidity");
String SoilResult = Last.getString("Soil_Moisture");
//设置值,开始写入文件
com.haohanyh.hamos.managedata.SaveSensorData.NeedSaveData().setTemp(TemperatureResult);
com.haohanyh.hamos.managedata.SaveSensorData.NeedSaveData().setHumi(HumidityResult);
com.haohanyh.hamos.managedata.SaveSensorData.NeedSaveData().setSoil(SoilResult);
com.haohanyh.hamos.managedata.SaveSensorData.NeedSaveData().setTime(TimeResult);
com.haohanyh.hamos.managedata.SaveSensorData.NeedSaveData().setNum(VersionResult);
com.haohanyh.hamos.managedata.SaveSensorData.NeedSaveData().WriteFile();
}
} catch (JSONException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -222,7 +244,7 @@ public void run() {
@Override
public void onClick(View view) {
//存IAM
boolean aBoolean = SaveHuaweiData.GetSaveData().WriteFile();
boolean aBoolean = SaveHuaweiData.NeedSaveData().WriteFile();
if(aBoolean) {
Toast.makeText(HAMOSActivity.this,getApplicationContext().getFilesDir().getAbsolutePath() + "/HAMOSData/User.json",Toast.LENGTH_SHORT).show();
}
Expand All @@ -232,7 +254,7 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
//存WLAN
boolean bBoolean = SaveWLANData.GetSaveData().WriteFile();
boolean bBoolean = SaveWLANData.NeedSaveData().WriteFile();
if(bBoolean) {
Toast.makeText(HAMOSActivity.this,getApplicationContext().getFilesDir().getAbsolutePath() + "/HAMOSData/Wlan.json",Toast.LENGTH_SHORT).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.haohanyh.hamos.dataI.Data;
import com.haohanyh.hamos.managedata.ReadHuaweiAndWlanData;
import com.haohanyh.hamos.managedata.SaveHuaweiData;
import com.haohanyh.hamos.managedata.SaveSensorData;
import com.haohanyh.hamos.managedata.SaveWLANData;
import com.haohanyh.hamos.projecty.HAMOSGetSomePermission.Permission.Location;
import com.haohanyh.hamos.projecty.HAMOSGetSomePermission.Permission.Storage;
Expand Down Expand Up @@ -165,9 +166,12 @@ private void Init() {
//输出些开发者信息,并且供给SaveXXXXData类使用,如果后续想修改成SD卡内保存,可以这里修改写入值
Log.i("浩瀚银河:","该用户SD卡地址:" + Environment.getExternalStorageDirectory());
Log.v("浩瀚银河:","该程序存储文件路径:" + getApplicationContext().getFilesDir().getAbsolutePath());
//设置保存路径,让保存类
String FirstLink = getApplicationContext().getFilesDir().getAbsolutePath();
SaveHuaweiData.GetSaveData().setDir(FirstLink);
SaveWLANData.GetSaveData().setDir(FirstLink);
String SecondLink = String.valueOf(Environment.getExternalStorageDirectory());
SaveHuaweiData.NeedSaveData().setDir(FirstLink);
SaveWLANData.NeedSaveData().setDir(FirstLink);
SaveSensorData.NeedSaveData().setDir(SecondLink);
ReadHuaweiAndWlanData.GetReadData().setDir(FirstLink);
//2.2.301版本,初始化新增获取权限,获取完了就不会弹出了
permissions = HAMOSGetSomePermission
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions HaohanyhHAMOSProjectY Android/app/src/main/res/layout/debugapi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fuzhou2"
android:orientation="vertical">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/Pink_is_fancy"
android:gravity="bottom|left"
android:text="@string/haohanyh_hamos_lights_project"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="italic"
tools:ignore="TextContrastCheck" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/Pink_is_fancy"
android:gravity="left|center"
android:orientation="horizontal"
tools:ignore="RtlHardcoded">

<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:text="@string/haohanyh_hamos_lights_project_manymain3"
android:textColor="@color/black"
android:textSize="18sp" />

</LinearLayout>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />

</ScrollView>

</LinearLayout>
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<resources>
<string name="app_name">HAMOS Project:Y</string>
<string name="app_version">Release.2.2.419.2022.0826.Haohanyh.Comet</string>
<string name="app_version">Release.2.2.441.2022.0829.Haohanyh.Comet</string>
<string name="haohanyh_hamos_lights_project">Haohanyh HAMOS:LiGHTs Project</string>
<string name="haohanyh_hamos_lights_project_manymain1">护花使者 Android版</string>
<string name="haohanyh_hamos_lights_project_manymain2">护花使者 NFC页面</string>
<string name="haohanyh_hamos_lights_project_manymain3">护花使者 调试API</string>
<string name="haohanyh_hamos_lights_project_jiaohua">点我浇花</string>
<string name="haohanyh_hamos_lights_project_CtrlS">保存Huawei账号信息</string>
<string name="haohanyh_hamos_lights_project_CtrlS2">保存WIAN信息</string>
Expand Down
4 changes: 3 additions & 1 deletion HaohanyhHAMOSProjectY Android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.enableJetifier=true

android.suppressUnsupportedCompileSdk=32
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 67fd958

Please sign in to comment.