Skip to content

Commit

Permalink
✅ 🎨 🚑 1.1.32,Huawei函数进Library、新增浇花功能。
Browse files Browse the repository at this point in the history
  • Loading branch information
Hny0305Lin committed Jul 20, 2022
1 parent e79e343 commit cf64fb6
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 39 deletions.
1 change: 1 addition & 0 deletions HaohanyhHAMOSProjectY Android/.idea/gradle.xml

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

2 changes: 2 additions & 0 deletions HaohanyhHAMOSProjectY Android/.idea/misc.xml

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

6 changes: 3 additions & 3 deletions HaohanyhHAMOSProjectY Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
minSdk 26
targetSdk 32
versionCode 1
//1.0.18,1.0版本第18次测试
versionName "1.0.18.2022.0719.Haohanyh.Aurora"
//1.1.32,1.1版本第32次测试
versionName "1.1.32.2022.0720.Haohanyh.Aurora"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -31,10 +31,10 @@ android {
dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'

implementation 'com.google.code.gson:gson:2.8.9'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(path: ':app:huawei')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
1 change: 1 addition & 0 deletions HaohanyhHAMOSProjectY Android/app/huawei/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions HaohanyhHAMOSProjectY Android/app/huawei/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
plugins {
id 'com.android.library'
}

android {
compileSdk 32

defaultConfig {
minSdk 26
targetSdk 32
versionCode 1

versionName "1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'

implementation 'androidx.appcompat:appcompat:1.4.2'
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'
}
Empty file.
21 changes: 21 additions & 0 deletions HaohanyhHAMOSProjectY Android/app/huawei/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.haohanyh.hamos.huawei;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.haohanyh.hamos.huawei.test", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.haohanyh.hamos.huawei">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* 受Haohanyh Computer Software Products Open Source LICENSE保护 https://git.haohanyh.top:3001/Haohanyh/LICENSE */
package com.haohanyh.hamos.projecty;

import android.util.Log;
package com.haohanyh.hamos.huawei;

import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -27,18 +25,17 @@ public class Huawei {
//获取得到的HUAWEI华为云Token,不许填写!!!
protected String HUAWEITOKEN = "";
//需要添加的IAM账号名、账号密码。想要获取IAM信息?点它即可→https://support.huaweicloud.com/api-iam/iam_17_0002.html
protected String JsonDomainName = "";
protected String JsonName = "";
protected String JsonPassword = "";
protected final String JsonDomainName = "";
protected final String JsonName = "";
protected final String JsonPassword = "";
//下面老三样,不要动!!!
protected Huawei() { }
protected static Huawei getHuawei() { return huawei.network; }
public static Huawei GetHuawei() { return huawei.network; }
protected static class huawei { private static final Huawei network = new Huawei(); }

/*
* 灰度测试,创建JSON转String,方便post函数进行使用和理解。
* 创建JSON转String,方便post函数进行使用和理解。
*/
protected String CreateJsonToPost() {
public String CreateJsonToPost() {
JSONObject First = new JSONObject();
try {
JSONObject Auth = new JSONObject();
Expand Down Expand Up @@ -68,11 +65,59 @@ protected String CreateJsonToPost() {
return String.valueOf(First);
}

/*
* 创建JSON转String,方便ControlSenderneedPost函数进行使用和理解。
*/
public void CreateJsonToControlSenderneedPost(String project_id,String device_id,String service_id,String command_name,String command_param,String command_value) {
String jsonParas = "";
JSONObject object = new JSONObject();
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("service_id", service_id);
jsonObject.put("command_name", command_name);
object.put(command_param, command_value);
jsonObject.put("paras", object);
jsonParas = jsonObject.toString();
ControlSenderneedpost(jsonParas,project_id,device_id);
} catch (JSONException e) {
e.printStackTrace();
}
}

/*
* CreateCommand 下发设备命令
* 华为云API调试地址:https://apiexplorer.developer.huaweicloud.com/apiexplorer/doc?product=IoTDA&api=CreateCommand
* 护花使者:采用E53-IA1,MotorStatus
* 小熊派:(E53-IA1 MotorStatus、LightStatus)(E53-ST1 BeepStatus)(E53_SC1 LightStatus)
*/
public void ControlSenderneedpost(String json,String project_id,String device_id) {
RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), json);
Request request = new Request.Builder()
.url("https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/" + project_id + "/devices/" + device_id + "/commands")
.addHeader("X-Auth-Token",HUAWEITOKEN)
.post(body)
.build();

OkHttpClient mOkHttpClient = new OkHttpClient();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
System.out.println(e.getLocalizedMessage() + ",失败");
}

@Override
public void onResponse(Call call, Response response) throws IOException {
System.out.println("函数链接: " + response.body().string());
}
});
}

/*
* ShowDeviceShadow 查询设备影子数据
* 华为云API调试地址:https://apiexplorer.developer.huaweicloud.com/apiexplorer/doc?product=IoTDA&api=ShowDeviceShadow
*/
protected String get(String url) {

public String Get(String url) {
String content = "";
URLConnection urlConnection = null;
try {
Expand All @@ -92,7 +137,7 @@ protected String get(String url) {
}
content = bs.toString();
} else if (responseCode == 401) {
System.out.println("浩瀚银河Get函数灰度测试:failed");
System.out.println("Get函数:failed");
}
return content;
} catch (IOException e) {
Expand All @@ -105,9 +150,10 @@ protected String get(String url) {
* KeystoneCreateUserTokenByPassword 获取IAM用户Token(使用密码)
* 华为云API调试地址:https://apiexplorer.developer.huaweicloud.com/apiexplorer/doc?product=IAM&api=KeystoneCreateUserTokenByPassword
*/
protected void post() {

public void Post() {

String jsonwenben = CreateJsonToPost();
Log.w("浩瀚银河灰度测试创建JSON操作",CreateJsonToPost());
RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), jsonwenben);
Request request = new Request.Builder()
.url("https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens")
Expand All @@ -117,15 +163,16 @@ protected void post() {
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
System.out.println("浩瀚银河post函数情况: " + e.getLocalizedMessage() + ",链接失败");
System.out.println(e.getLocalizedMessage() + ",失败");
}

@Override
public void onResponse(Call call, Response response) throws IOException {
System.out.println("浩瀚银河post函数链接: " + response.body().string());
System.out.println("浩瀚银河post函数头部读取: " + response.header("x-subject-token"));
HUAWEITOKEN = response.header("x-subject-token");
}
});
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.haohanyh.hamos.huawei;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:roundIcon="@drawable/a1"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/Theme.MyApplication"
android:theme="@style/Theme.HAMOS"
tools:targetApi="n">
<activity
android:name=".MainActivity"
Expand Down
Loading

0 comments on commit cf64fb6

Please sign in to comment.