20211020真机可运行
2
MyApplication2/entry/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/build
|
||||
/node_modules
|
55
MyApplication2/entry/build.gradle
Normal file
@@ -0,0 +1,55 @@
|
||||
apply plugin: 'com.huawei.ohos.hap'
|
||||
apply plugin: 'com.huawei.ohos.decctest'
|
||||
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
|
||||
ohos {
|
||||
compileSdkVersion 6
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 6
|
||||
}
|
||||
showInServiceCenter true
|
||||
buildTypes {
|
||||
release {
|
||||
proguardOpt {
|
||||
proguardEnabled false
|
||||
rulesFiles 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.devio.hi.json:hijson:1.0.0'
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.200'
|
||||
}
|
||||
decc {
|
||||
supportType = ['html','xml']
|
||||
}
|
||||
buildscript {
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://mirrors.huaweicloud.com/repository/maven/'
|
||||
}
|
||||
maven {
|
||||
url 'https://developer.huawei.com/repo/'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.huawei.ohos:hap:3.0.3.2'
|
||||
classpath 'com.huawei.ohos:decctest:1.2.6.0'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://mirrors.huaweicloud.com/repository/maven/'
|
||||
}
|
||||
maven {
|
||||
url 'https://developer.huawei.com/repo/'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
}
|
1
MyApplication2/entry/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1 @@
|
||||
# config module specific ProGuard rules here.
|
77
MyApplication2/entry/src/main/config.json
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.example.test.weather",
|
||||
"vendor": "example",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.example.weather",
|
||||
"name": ".MyApplication",
|
||||
"mainAbility": "com.example.weather.MainAbility",
|
||||
"deviceType": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"wearable"
|
||||
],
|
||||
"reqPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.INTERNET"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_NETWORK_INFO"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.SET_NETWORK_INFO"
|
||||
}
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry",
|
||||
"installationFree": false
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"orientation": "unspecified",
|
||||
"visible": true,
|
||||
"name": "com.example.weather.MainAbility",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:mainability_description",
|
||||
"formsEnabled": true,
|
||||
"label": "$string:entry_MainAbility",
|
||||
"type": "page",
|
||||
"forms": [
|
||||
{
|
||||
"isDefault": true,
|
||||
"scheduledUpdateTime": "10:30",
|
||||
"defaultDimension": "2*2",
|
||||
"name": "widget",
|
||||
"description": "This is a service widget",
|
||||
"colorMode": "auto",
|
||||
"type": "JS",
|
||||
"supportDimensions": [
|
||||
"2*2"
|
||||
],
|
||||
"updateEnabled": true,
|
||||
"updateDuration": 1
|
||||
}
|
||||
],
|
||||
"launchType": "standard"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.example.weather;
|
||||
|
||||
import com.example.weather.slice.MainAbilitySlice;
|
||||
import ohos.aafwk.ability.Ability;
|
||||
import ohos.aafwk.content.Intent;
|
||||
|
||||
public class MainAbility extends Ability {
|
||||
@Override
|
||||
public void onStart(Intent intent) {
|
||||
super.onStart(intent);
|
||||
super.setMainRoute(MainAbilitySlice.class.getName());
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package com.example.weather;
|
||||
|
||||
import ohos.aafwk.ability.AbilityPackage;
|
||||
|
||||
public class MyApplication extends AbilityPackage {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
super.onInitialize();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.example.weather.data;
|
||||
|
||||
public class CityMo {
|
||||
public String cityName;
|
||||
public String cityCode;
|
||||
|
||||
public CityMo(String cityName, String cityCode) {
|
||||
this.cityName = cityName;
|
||||
this.cityCode = cityCode;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.example.weather.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DataMo {
|
||||
public ArrayList<CityMo> cityMos;
|
||||
|
||||
public DataMo(ArrayList<CityMo> cityMos){
|
||||
this.cityMos = cityMos;
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
package com.example.weather.data;
|
||||
|
||||
import ohos.aafwk.ability.AbilitySlice;
|
||||
import ohos.agp.components.*;
|
||||
import com.example.weather.ResourceTable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ListItemProvider extends RecycleItemProvider {
|
||||
private AbilitySlice mSlice;
|
||||
private OnItemClickListener listener;
|
||||
private ArrayList<DataMo> dataMos = new ArrayList<>();
|
||||
|
||||
public ListItemProvider(AbilitySlice abilitySlice, OnItemClickListener listener){
|
||||
this.mSlice = abilitySlice;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setData(ArrayList<CityMo> cityMos){
|
||||
this.dataMos.clear();
|
||||
int i = 0;
|
||||
ArrayList<CityMo> tempList = new ArrayList<>();
|
||||
for (CityMo mo:cityMos){
|
||||
if (i == 3){
|
||||
i = 0;
|
||||
dataMos.add(new DataMo(tempList));
|
||||
tempList = new ArrayList<>();
|
||||
}
|
||||
tempList.add(mo);
|
||||
i++;
|
||||
}
|
||||
dataMos.add(new DataMo(tempList));
|
||||
this.notifyDataChanged();
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
return dataMos.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
return dataMos.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
|
||||
Component component_item = LayoutScatter.getInstance(mSlice).parse(ResourceTable.Layout_list_item, null, false);
|
||||
if ( !(component_item instanceof ComponentContainer)){
|
||||
return null;
|
||||
}
|
||||
ComponentContainer rootLayout = (ComponentContainer)component_item;
|
||||
DataMo dataMo = dataMos.get(i);
|
||||
for (CityMo mo:dataMo.cityMos){
|
||||
Text titleItem = (Text) LayoutScatter.getInstance(mSlice).parse(ResourceTable.Layout_item_title, null, false);
|
||||
titleItem.setText(mo.cityName);
|
||||
rootLayout.addComponent(titleItem);
|
||||
titleItem.setClickedListener(new Component.ClickedListener() {
|
||||
@Override
|
||||
public void onClick(Component component) {
|
||||
listener.OnItemClick(mo, i);
|
||||
}
|
||||
});
|
||||
}
|
||||
return component_item;
|
||||
}
|
||||
|
||||
public interface OnItemClickListener{
|
||||
void OnItemClick(CityMo cityMo, int position);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,92 @@
|
||||
package com.example.weather.net;
|
||||
|
||||
import ohos.hiviewdfx.HiLog;
|
||||
import ohos.hiviewdfx.HiLogLabel;
|
||||
import ohos.net.NetHandle;
|
||||
import ohos.net.NetManager;
|
||||
import org.devio.hi.json.HiJson;
|
||||
import org.devio.hi.json.JSONException;
|
||||
import org.devio.hi.json.JSONObject;
|
||||
import com.example.weather.util.HiExecutor;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Map;
|
||||
|
||||
public class HiNet implements IHiNet{
|
||||
private NetManager netManager;
|
||||
private HiLogLabel logLabel = new HiLogLabel(0,0, HiNet.class.getSimpleName());
|
||||
|
||||
public HiNet(){
|
||||
netManager = NetManager.getInstance(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void get(String url, Map<String, String> params, NetListener listener) {
|
||||
String finalUrl = HiNetUtil.buildParams(url, params);
|
||||
HiLog.debug(logLabel, "finalUrl:" + finalUrl);
|
||||
HiExecutor.runBG(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doGet(finalUrl, listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doGet(String finalUrl, NetListener listener) {
|
||||
NetHandle netHandle = netManager.getDefaultNet();
|
||||
HttpURLConnection connection = null;
|
||||
InputStream inputStream = null;
|
||||
ByteArrayOutputStream baos = null;
|
||||
try {
|
||||
URL url = new URL(finalUrl);
|
||||
URLConnection urlConnection = netHandle.openConnection(url, Proxy.NO_PROXY);
|
||||
if (urlConnection instanceof HttpURLConnection){
|
||||
connection = (HttpURLConnection)urlConnection;
|
||||
}
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
HiLog.debug(logLabel, "connect...");
|
||||
if (connection.getResponseCode() == 200){
|
||||
inputStream = connection.getInputStream();
|
||||
baos = new ByteArrayOutputStream();
|
||||
int readLen;
|
||||
byte[] bytes = new byte[1024];
|
||||
while((readLen = inputStream.read(bytes)) != -1){
|
||||
baos.write(bytes, 0, readLen);
|
||||
}
|
||||
String result = baos.toString();
|
||||
HiExecutor.runUI(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
HiJson res = new HiJson(new JSONObject(result));
|
||||
listener.onSuccess(res);
|
||||
HiLog.debug(logLabel, "success.");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
listener.onFail("data parse error, msg" + e.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
HiLog.debug(logLabel, "Request fail, code:" + connection.getResponseCode());
|
||||
listener.onFail("Request fail, code:" + connection.getResponseCode());
|
||||
}
|
||||
} catch (Exception e){
|
||||
HiLog.debug(logLabel, "Request fail, msg:" + e.toString());
|
||||
listener.onFail("Request fail, msg:" + e.toString());
|
||||
} finally {
|
||||
if (connection != null){
|
||||
connection.disconnect();
|
||||
}
|
||||
HiNetUtil.close(inputStream);
|
||||
HiNetUtil.close(baos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.example.weather.net;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class HiNetUtil {
|
||||
|
||||
public static String buildParams(String url, Map<String, String> params){
|
||||
if (params == null) return null;
|
||||
StringBuilder builder = new StringBuilder(url);
|
||||
boolean isFirst = true;
|
||||
for (String key : params.keySet()){
|
||||
String value = params.get(key);
|
||||
if (key != null && value != null){
|
||||
if (isFirst){
|
||||
isFirst = false;
|
||||
builder.append("?");
|
||||
} else {
|
||||
builder.append("&");
|
||||
}
|
||||
builder.append(key)
|
||||
.append("=")
|
||||
.append(value);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static void close(Closeable closeable){
|
||||
if (closeable != null){
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.example.weather.net;
|
||||
|
||||
import org.devio.hi.json.HiJson;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IHiNet {
|
||||
void get(String url, Map<String, String> params, NetListener listener);
|
||||
|
||||
interface NetListener{
|
||||
void onSuccess(HiJson res);
|
||||
void onFail(String message);
|
||||
}
|
||||
}
|
@@ -0,0 +1,176 @@
|
||||
package com.example.weather.slice;
|
||||
|
||||
import ohos.agp.components.DirectionalLayout;
|
||||
import ohos.agp.components.Image;
|
||||
import ohos.agp.components.ListContainer;
|
||||
import ohos.agp.components.Text;
|
||||
import ohos.hiviewdfx.HiLog;
|
||||
import ohos.hiviewdfx.HiLogLabel;
|
||||
import org.devio.hi.json.HiJson;
|
||||
import com.example.weather.ResourceTable;
|
||||
import ohos.aafwk.ability.AbilitySlice;
|
||||
import ohos.aafwk.content.Intent;
|
||||
import com.example.weather.data.CityMo;
|
||||
import com.example.weather.data.ListItemProvider;
|
||||
import com.example.weather.net.HiNet;
|
||||
import com.example.weather.net.IHiNet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MainAbilitySlice extends AbilitySlice implements ListItemProvider.OnItemClickListener{
|
||||
private DirectionalLayout mLayout = new DirectionalLayout(this);
|
||||
private ListContainer listContainer;
|
||||
private ListItemProvider listItemProvider;
|
||||
private ArrayList<CityMo> cities = new ArrayList<>();
|
||||
private HiNet hiNet;
|
||||
private Text temperatureText,weatherText,tipsText,temperature_1Text,weather_1Text,tips_1Text;
|
||||
private Image weatherImage,weatherImage_1;
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent) {
|
||||
super.onStart(intent);
|
||||
super.setUIContent(ResourceTable.Layout_ability_main);
|
||||
hiNet = new HiNet();
|
||||
initLayout();
|
||||
initLayout1();
|
||||
intCity();
|
||||
loadData(new CityMo("深圳", "114.03,22.32"));/*此处的地址应由API根据经纬度解的,而经纬度应有设备自身获取*/
|
||||
loadData1(new CityMo("太原", "112.45,38.02"));
|
||||
}
|
||||
|
||||
private void initLayout1() {
|
||||
listContainer = (ListContainer)findComponentById(ResourceTable.Id_list);
|
||||
listItemProvider = new ListItemProvider(this, this);
|
||||
listContainer.setItemProvider(listItemProvider);
|
||||
temperatureText = (Text)findComponentById(ResourceTable.Id_temperature_1);
|
||||
weatherText = (Text)findComponentById(ResourceTable.Id_weather_1);
|
||||
tipsText = (Text)findComponentById(ResourceTable.Id_tips_1);
|
||||
weatherImage = (Image) findComponentById(ResourceTable.Id_weather_icon_1);
|
||||
}
|
||||
|
||||
private void intCity() {
|
||||
listItemProvider.setData(cities);
|
||||
}
|
||||
|
||||
|
||||
private void initLayout(){
|
||||
listContainer = (ListContainer)findComponentById(ResourceTable.Id_list);
|
||||
listItemProvider = new ListItemProvider(this, this);
|
||||
listContainer.setItemProvider(listItemProvider);
|
||||
temperature_1Text = (Text)findComponentById(ResourceTable.Id_temperature);
|
||||
weather_1Text = (Text)findComponentById(ResourceTable.Id_weather);
|
||||
tips_1Text = (Text)findComponentById(ResourceTable.Id_tips);
|
||||
weatherImage_1 = (Image) findComponentById(ResourceTable.Id_weather_icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActive() {
|
||||
super.onActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForeground(Intent intent) {
|
||||
super.onForeground(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnItemClick(CityMo cityMo, int position) {
|
||||
|
||||
loadData(cityMo);
|
||||
}
|
||||
private void loadData(CityMo mo){
|
||||
//https://devapi.qweather.com/v7/weather/now?location=114.03,22.32&key=<用户key:18418bf60e874597abf85b7906d03e48>
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("location", mo.cityCode);
|
||||
params.put("key", "18418bf60e874597abf85b7906d03e48");
|
||||
hiNet.get("https://devapi.qweather.com/v7/weather/now", params, new IHiNet.NetListener() {
|
||||
@Override
|
||||
public void onSuccess(HiJson res) {
|
||||
HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0x00201, "WeatherApp"), "Get success:" + res.toString());
|
||||
//System.out.println("WeatherApp onSuccess:"+ res);
|
||||
bindData(res, mo);
|
||||
}
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0x00201, "WeatherApp"), "Get fail:" + message);
|
||||
//System.out.println("WeatherApp onSuccess:"+ message);
|
||||
}
|
||||
});
|
||||
}
|
||||
private void loadData1(CityMo mo){
|
||||
//https://devapi.qweather.com/v7/weather/now?location=114.03,22.32&key=<用户key:18418bf60e874597abf85b7906d03e48>
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("location", mo.cityCode);
|
||||
params.put("key", "18418bf60e874597abf85b7906d03e48");
|
||||
hiNet.get("https://devapi.qweather.com/v7/weather/now", params, new IHiNet.NetListener() {
|
||||
@Override
|
||||
public void onSuccess(HiJson res) {
|
||||
HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0x00201, "WeatherApp"), "Get success:" + res.toString());
|
||||
//System.out.println("WeatherApp onSuccess:"+ res);
|
||||
bindData1(res, mo);
|
||||
}
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0x00201, "WeatherApp"), "Get fail:" + message);
|
||||
//System.out.println("WeatherApp onSuccess:"+ message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void bindData(HiJson res, CityMo mo) {
|
||||
HiJson hiJson = res.get("now");
|
||||
String temperature = hiJson.value("temp");
|
||||
String weather = hiJson.value("text");
|
||||
String winddirection = hiJson.value("windDir");
|
||||
String windpower = hiJson.value("windScale");
|
||||
String humidity = hiJson.value("humidity");
|
||||
/*
|
||||
*上方为对于获取到的JSON数据的读取处理,可加异常抛出
|
||||
*/
|
||||
temperatureText.setText(temperature + "℃");
|
||||
weatherText.setText(weather);
|
||||
tipsText.setText(mo.cityName + ":" + winddirection +" 最大风力:"+ windpower + "级" + " 空气湿度" + humidity + "%");
|
||||
int id = ResourceTable.Media_sunshine;
|
||||
if (weather.contains("阴")){
|
||||
id = ResourceTable.Media_overcast;
|
||||
} else if (weather.contains("雨")){
|
||||
id = ResourceTable.Media_rain;
|
||||
} else if (weather.contains("雪")){
|
||||
id = ResourceTable.Media_snow;
|
||||
} else if (weather.contains("雷电")){
|
||||
id = ResourceTable.Media_thunder;
|
||||
} else if (weather.contains("多云")){
|
||||
id = ResourceTable.Media_cloudy;
|
||||
}/*此处的天气详情待完善*/
|
||||
weatherImage.setImageAndDecodeBounds(id);
|
||||
}
|
||||
private void bindData1(HiJson res, CityMo mo) {
|
||||
HiJson hiJson = res.get("now");
|
||||
String temperature = hiJson.value("temp");
|
||||
String weather = hiJson.value("text");
|
||||
String winddirection = hiJson.value("windDir");
|
||||
String windpower = hiJson.value("windScale");
|
||||
String humidity = hiJson.value("humidity");
|
||||
/*
|
||||
*上方为对于获取到的JSON数据的读取处理,可加异常抛出
|
||||
*/
|
||||
temperature_1Text.setText(temperature + "℃");
|
||||
weather_1Text.setText(weather);
|
||||
tips_1Text.setText(mo.cityName + ":" + winddirection +" 最大风力:"+ windpower + "级" + " 空气湿度" + humidity + "%");
|
||||
int id = ResourceTable.Media_sunshine;
|
||||
if (weather.contains("阴")){
|
||||
id = ResourceTable.Media_overcast;
|
||||
} else if (weather.contains("雨")){
|
||||
id = ResourceTable.Media_rain;
|
||||
} else if (weather.contains("雪")){
|
||||
id = ResourceTable.Media_snow;
|
||||
} else if (weather.contains("雷电")){
|
||||
id = ResourceTable.Media_thunder;
|
||||
} else if (weather.contains("多云")){
|
||||
id = ResourceTable.Media_cloudy;
|
||||
}/*此处的天气详情待完善*/
|
||||
weatherImage_1.setImageAndDecodeBounds(id);
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.example.weather.util;
|
||||
|
||||
import ohos.eventhandler.EventHandler;
|
||||
import ohos.eventhandler.EventRunner;
|
||||
|
||||
public class HiExecutor {
|
||||
/*
|
||||
* 切换任务到主线程执行
|
||||
* @param runnable
|
||||
* */
|
||||
public static void runUI(Runnable runnable){
|
||||
// 切换到主线程
|
||||
EventRunner runner = EventRunner.getMainEventRunner();
|
||||
EventHandler eventHandler = new EventHandler(runner);
|
||||
//切换任务
|
||||
eventHandler.postSyncTask(runnable);
|
||||
}
|
||||
|
||||
/*
|
||||
* 在子线程执行任务
|
||||
* @param runnable
|
||||
* */
|
||||
public static void runBG(Runnable runnable){
|
||||
//开启一个线程
|
||||
EventRunner runner = EventRunner.create(true);
|
||||
EventHandler eventHandler = new EventHandler(runner);
|
||||
// 执行任务
|
||||
eventHandler.postTask(runnable, 0, EventHandler.Priority.IMMEDIATE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_MainAbility",
|
||||
"value": "entry_MainAbility"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "Java_Empty Ability"
|
||||
},
|
||||
{
|
||||
"name": "mainability_HelloWorld",
|
||||
"value": "Hello World"
|
||||
},
|
||||
{
|
||||
"name": "widget_ability_description",
|
||||
"value": "This is a WidgetAbility"
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
|
||||
ohos:shape="rectangle">
|
||||
<solid
|
||||
ohos:color="#FFFFFF"/>
|
||||
</shape>
|
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<DirectionalLayout
|
||||
xmlns:ohos="http://schemas.huawei.com/res/ohos"
|
||||
ohos:height="match_parent"
|
||||
ohos:width="match_parent"
|
||||
ohos:id="$+id:root"
|
||||
ohos:alignment="horizontal_center"
|
||||
ohos:padding="32"
|
||||
ohos:orientation="vertical">
|
||||
|
||||
<DirectionalLayout
|
||||
ohos:orientation="horizontal"
|
||||
ohos:width="match_parent"
|
||||
ohos:height="match_content"
|
||||
ohos:alignment="horizontal_center">
|
||||
<Image
|
||||
ohos:id="$+id:weather_icon"
|
||||
ohos:height="60vp"
|
||||
ohos:width="60vp"
|
||||
ohos:scale_mode="inside"
|
||||
ohos:padding="5vp"
|
||||
ohos:image_src="$media:sunshine"
|
||||
/>
|
||||
<Text
|
||||
ohos:id="$+id:weather"
|
||||
ohos:height="match_content"
|
||||
ohos:width="match_content"
|
||||
ohos:text="1保留"
|
||||
ohos:text_color="#FF000000"
|
||||
ohos:right_margin="10vp"
|
||||
ohos:text_size="12fp"
|
||||
/>
|
||||
<Text
|
||||
ohos:id="$+id:temperature"
|
||||
ohos:height="match_content"
|
||||
ohos:width="match_content"
|
||||
ohos:text="1保留"
|
||||
ohos:top_padding="8vp"
|
||||
ohos:text_color="#FF000000"
|
||||
ohos:text_size="20fp"
|
||||
/>
|
||||
</DirectionalLayout>
|
||||
<Text
|
||||
ohos:id="$+id:tips"
|
||||
ohos:width="match_content"
|
||||
ohos:height="match_content"
|
||||
ohos:layout_alignment="horizontal_center"
|
||||
ohos:text="1保留"
|
||||
ohos:text_color="#FF3A6B53"
|
||||
ohos:left_margin="10vp"
|
||||
ohos:right_margin="10vp"
|
||||
ohos:text_size="12vp"
|
||||
/>
|
||||
|
||||
<DirectionalLayout
|
||||
ohos:orientation="horizontal"
|
||||
ohos:width="match_parent"
|
||||
ohos:height="match_content"
|
||||
ohos:alignment="horizontal_center">
|
||||
<Image
|
||||
ohos:id="$+id:weather_icon_1"
|
||||
ohos:height="60vp"
|
||||
ohos:width="60vp"
|
||||
ohos:scale_mode="inside"
|
||||
ohos:padding="5vp"
|
||||
ohos:image_src="$media:sunshine"
|
||||
/>
|
||||
<Text
|
||||
ohos:id="$+id:weather_1"
|
||||
ohos:height="match_content"
|
||||
ohos:width="match_content"
|
||||
ohos:text="2保留"
|
||||
ohos:text_color="#FF000000"
|
||||
ohos:right_margin="10vp"
|
||||
ohos:text_size="12fp"
|
||||
/>
|
||||
<Text
|
||||
ohos:id="$+id:temperature_1"
|
||||
ohos:height="match_content"
|
||||
ohos:width="match_content"
|
||||
ohos:text="2保留"
|
||||
ohos:top_padding="8vp"
|
||||
ohos:text_color="#FF000000"
|
||||
ohos:text_size="20fp"
|
||||
/>
|
||||
</DirectionalLayout>
|
||||
<Text
|
||||
ohos:id="$+id:tips_1"
|
||||
ohos:width="match_content"
|
||||
ohos:height="match_content"
|
||||
ohos:layout_alignment="horizontal_center"
|
||||
ohos:text="2保留"
|
||||
ohos:text_color="#FF3A6B53"
|
||||
ohos:left_margin="10vp"
|
||||
ohos:right_margin="10vp"
|
||||
ohos:text_size="12vp"
|
||||
/>
|
||||
|
||||
<ListContainer
|
||||
ohos:id="$+id:list"
|
||||
ohos:height="match_parent"
|
||||
ohos:width="match_parent"
|
||||
ohos:top_margin="20vp"
|
||||
/>
|
||||
|
||||
</DirectionalLayout>
|
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Text xmlns:ohos="http://schemas.huawei.com/res/ohos"
|
||||
ohos:id="$+id:city_item"
|
||||
ohos:height="match_content"
|
||||
ohos:width="match_content"
|
||||
ohos:text_size="12vp"
|
||||
ohos:text_color="#3fffff"
|
||||
ohos:padding="6vp"
|
||||
ohos:margin="2vp"
|
||||
ohos:background_element="#70000000"/>
|
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<DirectionalLayout
|
||||
xmlns:ohos="http://schemas.huawei.com/res/ohos"
|
||||
ohos:height="match_content"
|
||||
ohos:width="match_parent"
|
||||
ohos:orientation="horizontal"
|
||||
ohos:alignment="horizontal_center"/>
|
BIN
MyApplication2/entry/src/main/resources/base/media/bg1.png
Normal file
After Width: | Height: | Size: 368 KiB |
BIN
MyApplication2/entry/src/main/resources/base/media/cloudy.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
MyApplication2/entry/src/main/resources/base/media/icon.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
MyApplication2/entry/src/main/resources/base/media/overcast.png
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
MyApplication2/entry/src/main/resources/base/media/rain.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
MyApplication2/entry/src/main/resources/base/media/snow.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
MyApplication2/entry/src/main/resources/base/media/sunshine.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
MyApplication2/entry/src/main/resources/base/media/thunder.png
Normal file
After Width: | Height: | Size: 30 KiB |
@@ -0,0 +1,14 @@
|
||||
package com.example.myapplication;
|
||||
|
||||
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ExampleOhosTest {
|
||||
@Test
|
||||
public void testBundleName() {
|
||||
final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
|
||||
assertEquals("com.example.myapplication", actualBundleName);
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package com.example.myapplication;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExampleTest {
|
||||
@Test
|
||||
public void onStart() {
|
||||
}
|
||||
}
|