master
伍洲行 2 years ago
parent 77e47bdbdf
commit dc6c5d2ffa

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<<<<<<< HEAD
<mapping directory="$PROJECT_DIR$" vcs="Git" />
=======
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
>>>>>>> dc8dfd73a8a58508fec99a79684ba5574328c7e7
</component>
</project>

@ -43,9 +43,18 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
<<<<<<< HEAD
implementation 'com.baidu.lbsyun:BaiduMapSDK_Map-AllNavi:7.4.0'
implementation files('libs/Msc.jar')
implementation files('libs\\android-support-v4.jar')
=======
implementation files('libs\\BaiduLBS_Android.jar')
implementation files('libs\\BaiduLBS_Android.jar')
implementation files('libs\\BaiduLBS_Android.jar')
implementation files('libs\\BaiduLBS_Android.jar')
implementation files('libs\\BaiduLBS_Android.jar')
implementation files('libs\\BaiduLBS_Android.jar')
>>>>>>> dc8dfd73a8a58508fec99a79684ba5574328c7e7
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
implementation 'androidx.work:work-runtime:2.7.1'

@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RenderSettings">
<option name="showDecorations" value="true" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
</GradleProjectSettings>
</option>
</component>
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>

@ -0,0 +1,56 @@
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.myapplication'
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 19
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
// SOso
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86","x86_64"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main{
jniLibs.srcDirs=['libs']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.baidu.lbsyun:BaiduMapSDK_Map-AllNavi:7.4.0'
//implementation files('libs\\BaiduLBS_Android.jar')
//implementation files('libs\\BaiduLBS_Android.jar')
//implementation files('libs\\BaiduLBS_Android.jar')
// implementation files('libs\\BaiduLBS_Android.jar')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

@ -0,0 +1,39 @@
# 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
#-dontoptimize
#-ignorewarnings
#-keeppackagenames com.baidu.**
#-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
#-dontwarn com.baidu.**
#-dontwarn com.baidu.navisdk.**
#-dontwarn com.baidu.navi.**
#-keep class com.baidu.** { *; }
#-keep interface com.baidu.** { *; }
#-keep class vi.com.gdi.** { *; }
#-dontwarn com.google.protobuf.**
#-keep class com.google.protobuf.** { *;}
#-keep interface com.google.protobuf.** { *;}

@ -1,98 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!--连接网络权限,用于执行云端语音能力 -->
<uses-permission android:name="android.permission.INTERNET"/>
<!--获取手机录音机使用权限,听写、识别、语义理解需要用到此权限 -->
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<!--读取网络信息状态 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--获取当前wifi状态 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<!-- 这个权限用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 这个权限用于访问系统接口提供的卫星定位信息 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 用于访问wifi网络信息wifi信息会用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 获取运营商信息,用于支持提供运营商信息相关的接口 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 这个权限用于获取wifi的获取权限wifi信息会用来进行网络定位 -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 访问网络,网络定位需要上网 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" /> <!-- 获取摄像头权限用于AR步行导航 -->
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".SpeechApplication"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".jiankang"
android:name=".WNaviGuideActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".yuyin"
android:name=".itemfound"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".zhaoxun"
android:name=".MapActivity1"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<service
android:name="com.baidu.location.f"
android:enabled="true"
android:process=":remote" />
<meta-data
android:name="com.baidu.lbsapi.API_KEY"
android:value="pFUGlHMArXB22vUlCvWuElgEDX6fhQU7" />
<activity
android:name=".yijiantong"
android:name=".jiankang"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".WNaviGuideActivity"
android:name=".yuyin"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".itemfound"
android:name=".zhaoxun"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".MapActivity1"
android:name=".yijiantong"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<service
android:name="com.baidu.location.f"
android:enabled="true"
android:process=":remote" />
<meta-data
android:name="com.baidu.lbsapi.API_KEY"
android:value="pFUGlHMArXB22vUlCvWuElgEDX6fhQU7" />
<activity
android:name=".MainActivity"
android:exported="true">
@ -106,10 +94,6 @@
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity android:name="com.example.myapplication.weather.MainActivity1"/>
<activity android:name="com.example.myapplication.weather.WeatherDetailActivity"/>
<activity android:name="com.example.myapplication.weather.SettingActivity"/>
<service android:name="com.example.myapplication.weather.NotificationService"/>
</application>
</manifest>

@ -1,5 +1,8 @@
package com.example.myapplication;
<<<<<<< HEAD:src/MyApplication/app/src/main/java/com/example/myapplication/WNaviGuideActivity.java
import android.annotation.SuppressLint;
=======
>>>>>>> dc8dfd73a8a58508fec99a79684ba5574328c7e7:src/MyApplication/app/src/MyApplication/app/src/main/java/com/example/myapplication/WNaviGuideActivity.java
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
@ -49,7 +52,10 @@ public class WNaviGuideActivity extends Activity {
Handler handler = new Handler() {
<<<<<<< HEAD:src/MyApplication/app/src/main/java/com/example/myapplication/WNaviGuideActivity.java
@SuppressLint("HandlerLeak")
=======
>>>>>>> dc8dfd73a8a58508fec99a79684ba5574328c7e7:src/MyApplication/app/src/MyApplication/app/src/main/java/com/example/myapplication/WNaviGuideActivity.java
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);

@ -0,0 +1,224 @@
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.baidu.mapapi.bikenavi.BikeNavigateHelper;
import com.baidu.mapapi.walknavi.adapter.IWRoutePlanListener;
import com.baidu.mapapi.walknavi.model.WalkRoutePlanError;
import com.baidu.mapapi.walknavi.params.*;
import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.model.LatLng;
import java.util.ArrayList;
import java.util.List;
import android.widget.ImageButton;
import android.widget.TextView;
import android.annotation.SuppressLint;
import android.os.Bundle;
import com.baidu.baidunavis.BaiduNaviParams;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.walknavi.WalkNavigateHelper;
import com.baidu.mapapi.walknavi.adapter.IWEngineInitListener;
import com.baidu.mapapi.walknavi.params.WalkNaviLaunchParam;
public class itemfound extends AppCompatActivity {
private WalkNavigateHelper helper = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initPermissions(); // 初始化权限
setContentView(R.layout.activity_itemfound); // 填充视图
// 点击按钮开始导航
Button imageButton = findViewById(R.id.button_item_keys);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 初始化步行导航
startBikeNavi();
}
});
Button imageButtonwallet = findViewById(R.id.button_item_wallet);
imageButtonwallet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 初始化步行导航
startBikeNavi();
}
});
}
// 初始化权限
/*
private void initPermissions() {
if (Build.VERSION.SDK_INT >= 23) {
ArrayList<String> permissionsList = new ArrayList<>();
String[] permissions = {
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
};
for (String perm : permissions) {
if (PackageManager.PERMISSION_GRANTED != checkSelfPermission(perm)) {
permissionsList.add(perm);
// 进入到这里代表没有权限.
}
if (!permissionsList.isEmpty()) {
String[] strings = new String[permissionsList.size()];
requestPermissions(permissionsList.toArray(strings), 0);
}
}
}
}*/
private void startBikeNavi() {
//Log.d("=========", "startBikeNavi");
try {
helper = WalkNavigateHelper.getInstance();
helper.initNaviEngine(this, new IWEngineInitListener() {
@Override
public void engineInitSuccess() {
// Log.d("=========", "BikeNavi engineInitSuccess引擎初始化成功");
startWebNavi();
}
@Override
public void engineInitFail() {
// Log.d("=========", "BikeNavi engineInitFail");
BikeNavigateHelper.getInstance().unInitNaviEngine();
}
});
} catch (Exception e) {
// Log.d("=========", "startBikeNavi Exception");
e.printStackTrace();
}
}
private void startWebNavi() {
//起终点位置
LatLng walkStartNode = new LatLng(39.110132, 117.358512);
LatLng walkEndNode = new LatLng(39.111348, 117.358940);
WalkRouteNodeInfo startNode = new WalkRouteNodeInfo();
startNode.setLocation(walkStartNode);
WalkRouteNodeInfo endNode = new WalkRouteNodeInfo();
endNode.setLocation(walkEndNode);
// 官网
//构造WalkNaviLaunchParam
WalkNaviLaunchParam walkParam = new WalkNaviLaunchParam().startNodeInfo(startNode).endNodeInfo(endNode);
//获取WalkNavigateHelper实例 //发起算路
helper.routePlanWithRouteNode(walkParam, new IWRoutePlanListener() {
@Override
public void onRoutePlanStart() {
// Log.d("=======", "WalkNavi onRoutePlanStart开始步行导航");
}
@Override
public void onRoutePlanSuccess() {
// Log.d("========", "onRoutePlanSuccess算路成功");
Intent intent = new Intent(itemfound.this,WNaviGuideActivity.class);
// intent.setClass(getContext(), WNaviGuideActivity.class);
startActivity(intent);
}
@Override
public void onRoutePlanFail(WalkRoutePlanError error) {
// Log.d("Walk", "WalkNavi onRoutePlanFail");
}
});
}
/*
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_itemfound);
Button find_wallet=findViewById(R.id.button_item_wallet);
Button find_keys=findViewById(R.id.button_item_keys);
find_wallet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {//Intent
double locationX;
double locationy;
//BaiduMapNavigation
}
});
find_keys.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {//Intent
//NaviParaOption para=new Navi();
}
});
}*/ private void startBikeNavi1() {
//Log.d("=========", "startBikeNavi");
try {
helper = WalkNavigateHelper.getInstance();
helper.initNaviEngine(this, new IWEngineInitListener() {
@Override
public void engineInitSuccess() {
// Log.d("=========", "BikeNavi engineInitSuccess引擎初始化成功");
startWebNavi1();
}
@Override
public void engineInitFail() {
// Log.d("=========", "BikeNavi engineInitFail");
BikeNavigateHelper.getInstance().unInitNaviEngine();
}
});
} catch (Exception e) {
// Log.d("=========", "startBikeNavi Exception");
e.printStackTrace();
}
}
private void startWebNavi1() {
//起终点位置
LatLng walkStartNode = new LatLng(39.110132, 117.358512);
LatLng walkEndNode = new LatLng(39.112286, 117.359619);
WalkRouteNodeInfo startNode = new WalkRouteNodeInfo();
startNode.setLocation(walkStartNode);
WalkRouteNodeInfo endNode = new WalkRouteNodeInfo();
endNode.setLocation(walkEndNode);
// 官网
//构造WalkNaviLaunchParam
WalkNaviLaunchParam walkParam = new WalkNaviLaunchParam().startNodeInfo(startNode).endNodeInfo(endNode);
//获取WalkNavigateHelper实例 //发起算路
helper.routePlanWithRouteNode(walkParam, new IWRoutePlanListener() {
@Override
public void onRoutePlanStart() {
// Log.d("=======", "WalkNavi onRoutePlanStart开始步行导航");
}
@Override
public void onRoutePlanSuccess() {
// Log.d("========", "onRoutePlanSuccess算路成功");
Intent intent = new Intent(itemfound.this,WNaviGuideActivity.class);
// intent.setClass(getContext(), WNaviGuideActivity.class);
startActivity(intent);
}
@Override
public void onRoutePlanFail(WalkRoutePlanError error) {
// Log.d("Walk", "WalkNavi onRoutePlanFail");
}
});
}
}

@ -0,0 +1,24 @@
package com.example.myapplication.weather;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int VERSION = 1;
private static final String NAME = "weather";
public DatabaseHelper(Context context){
super(context,NAME,null,VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table weather (_id INTEGER PRIMARY KEY AUTOINCREMENT,date text,max_temp text,min_temp text,text text,humidity text,pressure text,wind text,icon text)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}

@ -0,0 +1,103 @@
package com.example.myapplication.weather;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
//获取数据的二进制数组/字符串形式
//获取JSON数组
//解析JSON数组变成WeatherItem的数组形式
public class FlickrFetcher {
public static final String TAG = "FlickrFetcher";
public byte[] getUrlBytes(String urlSpec) throws Exception{
URL url = new URL(urlSpec);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// connection.setInstanceFollowRedirects(false); //跟踪重定向
// String redirect = connection.getHeaderField("Location");
// if (redirect != null){
// connection = (HttpURLConnection)new URL(redirect).openConnection();
// }
try{
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = connection.getInputStream();
if(connection.getResponseCode() != HttpURLConnection.HTTP_OK){
throw new IOException(connection.getResponseMessage() + " :with "+urlSpec);
}
int bytesRead = 0;
byte[] buffer = new byte[1024];
while((bytesRead = in.read(buffer)) > 0){
out.write(buffer,0,bytesRead);
}
out.close();
return out.toByteArray();
}finally {
connection.disconnect();
}
}
public String getUrlString(String urlSpec)throws Exception{
return new String(getUrlBytes(urlSpec));
}
public List<WeatherItem> fetchItems(String urlSpec){
List<WeatherItem> items = new ArrayList<>();
try{
String jsonString = getUrlString(urlSpec);
Log.i(TAG,"result: "+jsonString);
JSONObject jsonBody = new JSONObject(jsonString);
parseItems(items,jsonBody);
}catch (Exception e){
Log.i(TAG,"Failed!"+e);
}
return items;
}
public JSONObject fetchCity(String urlSpec){
String locationID = "";
JSONObject jsonObject = null;
try{
String jsonString = getUrlString(urlSpec);
Log.i(TAG,"result: "+jsonString);
JSONObject jsonBody = new JSONObject(jsonString);
JSONArray locationJsonArray = jsonBody.getJSONArray("location");
jsonObject = locationJsonArray.getJSONObject(0);
// locationID = locationJsonArray.getJSONObject(0).getString("id");
// String lat = locationJsonArray.getJSONObject(0).getString("lat");
// String lon = locationJsonArray.getJSONObject(0).getString("lon");
}catch (Exception e){
Log.i(TAG,"Failed!"+e);
}
return jsonObject;
}
private void parseItems(List<WeatherItem> items,JSONObject jsonBody) throws Exception{ //将从url获得的json转换成MarsItem
JSONArray weatherJsonArray = jsonBody.getJSONArray("daily");
for(int i=0;i<weatherJsonArray.length();i++){
JSONObject weatherJsonObject = weatherJsonArray.getJSONObject(i);
WeatherItem item = new WeatherItem();
item.setData(weatherJsonObject.getString("fxDate"));
item.setMax_temp(weatherJsonObject.getString("tempMax"));
item.setMin_temp(weatherJsonObject.getString("tempMin"));
item.setText(weatherJsonObject.getString("textDay"));
item.setHumidity(weatherJsonObject.getString("humidity"));
item.setPressure(weatherJsonObject.getString("pressure"));
item.setWind(weatherJsonObject.getString("windSpeedDay"));
item.setIcon(weatherJsonObject.getString("iconDay"));
items.add(item);
}
}
}

@ -0,0 +1,38 @@
package com.example.myapplication.weather;
import androidx.fragment.app.Fragment;
import android.content.Intent;
import com.example.myapplication.R;
import com.example.myapplication.weather.SingleFragmentActivity;
import com.example.myapplication.weather.WeatherFragment;
public class MainActivity1 extends SingleFragmentActivity implements WeatherFragment.Callbacks{
@Override
protected Fragment createFragment() {
return WeatherFragment.newInstance();
}
@Override
protected int getLayoutId() {
return R.layout.activity_masterdetail;
}
@Override
protected int getFragmentId() {
return R.id.fragment_container;
}
public void onWeatherSelected(WeatherItem weatherItem){ //平板中选中天气
if(findViewById(R.id.detail_container)==null){
Intent intent = WeatherDetailActivity.newIntent(this,weatherItem);
startActivity(intent);
}else{
Fragment newDetail = WeatherDetailFragment.newInstance(weatherItem);
getSupportFragmentManager().beginTransaction()
.replace(R.id.detail_container,newDetail)
.commit();
}
}
}

@ -0,0 +1,95 @@
package com.example.myapplication.weather;
import android.app.AlarmManager;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.SystemClock;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import com.example.myapplication.R;
import com.example.myapplication.weather.WeatherFragment;
public class NotificationService extends IntentService {
private static final String TAG = "NotificationService";
private static final int NOTIFICATION_INTERVAL = 1000*60;
public static Intent newIntent(Context context){
return new Intent(context,NotificationService.class);
}
public NotificationService(){
super(TAG);
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
Log.i(TAG,"Intent there");
Intent i = WeatherFragment.newIntent(this);
PendingIntent pi = PendingIntent.getService(this,0,i,0);
Notification notification = null;
SharedPreferences pref = this.getSharedPreferences("setting",Context.MODE_PRIVATE);
String unit = pref.getString("unit","摄氏度");
String unit_text = "°";
if (unit == "华氏度"){
unit_text = "℉";
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setTicker("ticker")
.setSmallIcon(R.drawable.a100)
.setContentTitle("今日天气")
.setContentText(pref.getString("city","北京")+
" 天气:"+pref.getString("text","")+
", 最高温度:"+pref.getString("max_temp","")+unit_text+
", 最低温度:"+pref.getString("min_temp","")+unit_text)
.setContentIntent(pi)
.setAutoCancel(true);
NotificationManager notificationManager =(NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
//一定要设置channel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("to-do"
, "待办消息",
NotificationManager.IMPORTANCE_HIGH);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{500});
notificationManager.createNotificationChannel(channel);
builder.setChannelId("to-do");
notification = builder.build();
} else {
notification = builder.build();
}
notificationManager.notify(0,notification);
System.out.println(notification);
}
public static void setServiceAlarm(Context context,boolean isOn){
Intent i = NotificationService.newIntent(context);
PendingIntent pi = PendingIntent.getService(context,0,i,0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if(isOn){
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),
NOTIFICATION_INTERVAL,pi);
}else{
alarmManager.cancel(pi);
pi.cancel();
}
}
}

@ -0,0 +1,132 @@
package com.example.myapplication.weather;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.R;
public class SettingActivity extends AppCompatActivity {
private EditText location;
private TextView unit_text;
private TextView send_text;
private LinearLayout page;
private LinearLayout unit;
private LinearLayout send;
private String city;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
location = (EditText) findViewById(R.id.location);
unit = (LinearLayout)findViewById(R.id.unit);
page = (LinearLayout)findViewById(R.id.page);
unit_text = (TextView)findViewById(R.id.unit_text);
send = (LinearLayout)findViewById(R.id.send);
send_text = (TextView)findViewById(R.id.send_text);
SharedPreferences pref = getSharedPreferences("setting",MODE_PRIVATE);
location.setText(pref.getString("city","北京"));
unit_text.setText(pref.getString("unit","摄氏度"));
send_text.setText(pref.getString("send","是"));
page.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
location.clearFocus();
}
});
location.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
city = s.toString();
SharedPreferences.Editor editor = getSharedPreferences("setting",MODE_PRIVATE).edit();
editor.putString("city",city);
editor.commit();
}
@Override
public void afterTextChanged(Editable s) {
}
});
unit.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
click();
}
});
send.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
click2();
}
});
}
//点击按钮弹出一个单选对话框
public void click() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请选择温度单位");
final String items[] = {"摄氏度","华氏度"};
//-1代表没有条目被选中
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//1.把选中的条目取出来
String item = items[which];
Toast.makeText(getApplicationContext(),item.toString(),Toast.LENGTH_LONG).show();
unit_text.setText(item.toString());
SharedPreferences.Editor editor = getSharedPreferences("setting",MODE_PRIVATE).edit();
editor.putString("unit",item.toString());
editor.commit();
//2.然后把对话框关闭
dialog.dismiss();
}
});
//一样要show
builder.show();
}
public void click2() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请选择是否开启通知");
final String items[] = {"是","否"};
//-1代表没有条目被选中
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//1.把选中的条目取出来
String item = items[which];
Toast.makeText(getApplicationContext(),item.toString(),Toast.LENGTH_LONG).show();
send_text.setText(item.toString());
SharedPreferences.Editor editor = getSharedPreferences("setting",MODE_PRIVATE).edit();
editor.putString("send",item.toString());
editor.commit();
//2.然后把对话框关闭
dialog.dismiss();
}
});
//一样要show
builder.show();
}
}

@ -0,0 +1,30 @@
package com.example.myapplication.weather;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
public abstract class SingleFragmentActivity extends AppCompatActivity {
protected abstract Fragment createFragment();
protected abstract int getLayoutId();
protected abstract int getFragmentId();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutId());
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(getFragmentId());
if(fragment == null){
fragment = createFragment();
fm.beginTransaction().
add(getFragmentId(),fragment)
.commit();
}
}
}

@ -0,0 +1,34 @@
package com.example.myapplication.weather;
import android.content.Context;
import android.content.Intent;
import androidx.fragment.app.Fragment;
import com.example.myapplication.R;
public class WeatherDetailActivity extends SingleFragmentActivity{
public static final String EXTRA_WEATHER_ITEM = "com.example.weather.weatherItem";
@Override
protected Fragment createFragment() {
WeatherItem weatherItem = (WeatherItem)getIntent().getSerializableExtra(EXTRA_WEATHER_ITEM);
return WeatherDetailFragment.newInstance(weatherItem);
}
@Override
protected int getLayoutId() {
return R.layout.activity_detail;
}
@Override
protected int getFragmentId() {
return R.id.detail_container;
}
public static Intent newIntent(Context packageContext, WeatherItem weatherItem){
Intent intent = new Intent(packageContext,WeatherDetailActivity.class);
intent.putExtra(EXTRA_WEATHER_ITEM,weatherItem);
return intent;
}
}

@ -0,0 +1,133 @@
package com.example.myapplication.weather;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.myapplication.R;
public class WeatherDetailFragment extends Fragment {
private WeatherItem mWeatherItem; //用来设置UI
private TextView mDeatilDate;
private TextView mDetailMaxTemp;
private TextView mDetailMinTemp;
private ImageView mDetialIcon;
private TextView mDetailDesc;
private TextView mDetailHumidity;
private TextView mDetailPressure;
private TextView mDetailWind;
private static final String TAG = "WeatherDetailFragment";
private static final String ARG_ITEM = "args_item";
private String unit_text = "°";
public static WeatherDetailFragment newInstance(WeatherItem weatherItem) {
Bundle args = new Bundle();
args.putSerializable(ARG_ITEM,weatherItem);
WeatherDetailFragment fragment = new WeatherDetailFragment();
fragment.setArguments(args);
return fragment;
}
//获取drawable图标资源的id
public int getIconId(Context mContext, String icon){
int i= getResources().getIdentifier(icon, "drawable", mContext.getPackageName()) ;
if(i>0){
Log.i(TAG,"Success to get drawable resoure");
}else{
Log.i(TAG,"Fail to get drawable resoure");
}
return i;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
mWeatherItem = (WeatherItem) getArguments().getSerializable(ARG_ITEM);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_weather_detail,container,false);
if(getActivity().getSharedPreferences("setting",Context.MODE_PRIVATE).getString("unit","摄氏度")=="华氏度"){
unit_text = "℉";
}
mDeatilDate = (TextView) v.findViewById(R.id.detail_date);
mDetailMaxTemp = (TextView) v.findViewById(R.id.detail_max_temp);
mDetailMinTemp = (TextView) v.findViewById(R.id.detail_min_temp);
mDetialIcon = (ImageView) v.findViewById(R.id.detail_icon);
mDetailHumidity = (TextView) v.findViewById(R.id.detail_humidity);
mDetailPressure = (TextView) v.findViewById(R.id.detail_pressure);
mDetailWind = (TextView) v.findViewById(R.id.detail_wind);
mDetailDesc = (TextView) v.findViewById(R.id.detail_desc);
mDeatilDate.setText(mWeatherItem.getData());
mDetailMaxTemp.setText(mWeatherItem.getMax_temp()+unit_text);
mDetailMinTemp.setText(mWeatherItem.getMin_temp()+unit_text);
String icon = "a"+mWeatherItem.getIcon();
int id = getIconId(getContext(),icon);
Drawable drawable = getResources().getDrawable(id);
mDetialIcon.setImageDrawable(drawable);
mDetailHumidity.setText("Humidity: "+mWeatherItem.getHumidity()+" %");
mDetailPressure.setText("Pressure: "+mWeatherItem.getPressure()+" hPa");
mDetailWind.setText("Wind: "+mWeatherItem.getWind()+" km/h SE");
mDetailDesc.setText(mWeatherItem.getText());
return v;
}
public String createMessage(){
String message = "";
message += "今天的天气状况为:"+mWeatherItem.getText();
message += " 今天的最高温度是: "+mWeatherItem.getMax_temp();
message += " 今天的最低温度是: "+mWeatherItem.getMin_temp();
message += " 今天的湿度为: "+mWeatherItem.getHumidity();
message += " 今天的风速为:"+mWeatherItem.getWind();
message += " 今天的气压为:"+mWeatherItem.getPressure();
message += " 希望您拥有美好的一天!";
return message;
}
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if(getActivity().findViewById(R.id.fragment_container)==null){ //是手机模式
inflater.inflate(R.menu.fragment_detail,menu);
}
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.menu_setting:
Intent intent = new Intent(getActivity(),SettingActivity.class);
startActivity(intent);
return true;
case R.id.menu_share:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT,createMessage());
startActivity(i);
return true;
}
return super.onOptionsItemSelected(item);
}
}

@ -0,0 +1,372 @@
package com.example.myapplication.weather;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.myapplication.R;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class WeatherFragment extends Fragment {
private static final String TAG="WeatherFragment";
private RecyclerView mWeatherRecyclerView;
//今日天气板块
private TextView mTodayTime;
private TextView mTodayMaxTemp;
private TextView mTodayMinTemp;
private ImageView mTodayIcon;
private TextView mTodayIconDesc;
private String location = "北京"; //记录当前的城市ID如果有变化需要刷新你页面
private String temp_unit = "摄氏度";
private String unit_text = "°";
private List<WeatherItem> mItems = new ArrayList<>(); //七天的天气详情对象
private Callbacks mCallbacks;
private SQLiteDatabase mDatabase;
public static WeatherFragment newInstance(){
return new WeatherFragment();
}
/*回调函数fragment调用activity的函数这样点击列表后方便出发事件不应该用fragment执行其他fragment的细节*/
public interface Callbacks{
void onWeatherSelected(WeatherItem weatherItem);
}
public static Intent newIntent(Context context){
Intent i = new Intent(context, MainActivity1.class);
return i;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mCallbacks = (Callbacks)activity;
}
@Override
public void onDetach() {
super.onDetach();
mCallbacks = null;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences.Editor editor = getActivity().getSharedPreferences("setting",Context.MODE_PRIVATE).edit();
setRetainInstance(true);
//设置其他选项让manager知道fragment替activity进行处理
setHasOptionsMenu(true);
//创建数据库
mDatabase = new DatabaseHelper(getActivity()).getWritableDatabase();
new FetchItemsTask().execute(); //异步执行获取网站上的json内容
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_weather,container,false);
mWeatherRecyclerView = (RecyclerView) v.findViewById(R.id.fragment_weather_recycler_view);
mWeatherRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//绑定今日天气模块
mTodayTime = (TextView)v.findViewById(R.id.today_time);
mTodayMaxTemp = (TextView)v.findViewById(R.id.today_max_temp);
mTodayMinTemp = (TextView)v.findViewById(R.id.today_min_temp);
mTodayIcon = (ImageView)v.findViewById(R.id.today_icon);
mTodayIconDesc = (TextView)v.findViewById(R.id.today_icon_desc);
return v;
}
@Override
public void onResume() {
super.onResume();
SharedPreferences pref = getActivity().getSharedPreferences("setting",Context.MODE_PRIVATE);
String city = pref.getString("city","北京");
String unit = pref.getString("unit","摄氏度");
String send = pref.getString("send","是");
if(city!=location){ //在重新启动页面的时候,如果地址改变了,需要刷新
location = city;
new FetchItemsTask().execute(); //异步执行获取网站上的json内容
return;
}
if(unit!=temp_unit){ //在重新启动页面的时候,如果地址改变了,需要刷新
temp_unit = unit;
new FetchItemsTask().execute(); //异步执行获取网站上的json内容
return;
}
if (send=="是"){
//开启后台服务,启动定时器,发送通知消息
NotificationService.setServiceAlarm(getActivity(),true);
}else{
NotificationService.setServiceAlarm(getActivity(),false);
}
}
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_weather,menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
SharedPreferences pref = getActivity().getSharedPreferences("setting",Context.MODE_PRIVATE);
switch (item.getItemId()){
case R.id.menu_setting:
Intent intent = new Intent(getActivity(),SettingActivity.class);
startActivity(intent);
return true;
case R.id.menu_map:
//调用腾讯地图
Intent intent_txmap = new Intent();
System.out.println("lat is :"+pref.getString("lat","39.90498"));
System.out.println("lon is :"+pref.getString("lon","116.40528"));
intent_txmap.setData(Uri.parse("qqmap://map/geocoder?coord="+
pref.getString("lat","39.90498")+
"," +pref.getString("lon","116.40528")+
"&referer=BJWBZ-EXJ3U-IUGV4-4A74J-754OJ-KXFVX"));
startActivity(intent_txmap);
}
return super.onOptionsItemSelected(item);
}
//获取drawable图标资源的id
public int getIconId(Context mContext, String icon){
int i= getResources().getIdentifier(icon, "drawable", mContext.getPackageName()) ;
if(i>0){
//Log.i(TAG,"Success to get drawable resoure");
}else{
Log.i(TAG,"Fail to get drawable resoure");
}
return i;
}
// 异步从URL获取天气对象
private class FetchItemsTask extends AsyncTask<Void,Void, List<WeatherItem>> {
SharedPreferences.Editor editor = getActivity().getSharedPreferences("setting",Context.MODE_PRIVATE).edit();
SharedPreferences pref = getActivity().getSharedPreferences("setting",Context.MODE_PRIVATE);
String city = pref.getString("city","北京");
String unit = pref.getString("unit","摄氏度");
String city_url = "https://geoapi.qweather.com/v2/city/lookup?location="+city+"&key=6b01a87a7f3347a19c7b6b84f2ba35e3";
@Override
protected List<WeatherItem> doInBackground(Void... voids) {
List<WeatherItem> weatherItems = new ArrayList<>();
unit_text = "°";
if(unit=="华氏度"){
unit_text = "℉";
}
System.out.println("network is :"+isNetworkConnected(getActivity().getApplicationContext()));
//如果没有网络连接,从数据库获取信息
if(!isNetworkConnected(getActivity().getApplicationContext())){
Cursor cursor = mDatabase.query ("weather",null,null,null,null,null,null);
cursor.moveToFirst();
for(int i=0;i<cursor.getCount();i++){
WeatherItem item = new WeatherItem();
item.setData(cursor.getString(cursor.getColumnIndex("date")));
item.setMax_temp(cursor.getString(cursor.getColumnIndex("max_temp")));
item.setMin_temp(cursor.getString(cursor.getColumnIndex("min_temp")));
item.setText(cursor.getString(cursor.getColumnIndex("text")));
item.setHumidity(cursor.getString(cursor.getColumnIndex("humidity")));
item.setPressure(cursor.getString(cursor.getColumnIndex("pressure")));
item.setWind(cursor.getString(cursor.getColumnIndex("wind")));
item.setIcon(cursor.getString(cursor.getColumnIndex("icon")));
weatherItems.add(item);
cursor.moveToNext();
}
return weatherItems;
}
//有网络
//String locationID = new FlickrFetcher().fetchCity(city_url);
JSONObject jsonObject = new FlickrFetcher().fetchCity(city_url);
String locationID = "";
try{
locationID = jsonObject.getString("id");
editor.putString("lat",jsonObject.getString("lat"));
System.out.println("input lat is: "+jsonObject.getString("lat"));
editor.putString("lon",jsonObject.getString("lon"));
editor.commit();
}catch (Exception e){}
String url = "https://devapi.qweather.com/v7/weather/7d?location="+locationID+"&key=6b01a87a7f3347a19c7b6b84f2ba35e3";
if(unit=="华氏度"){
url = "https://devapi.qweather.com/v7/weather/7d?location="+locationID+"&key=6b01a87a7f3347a19c7b6b84f2ba35e3&unit=i";
}
weatherItems = new FlickrFetcher().fetchItems(url);
//删除原来的数据库,将获取的数据放入数据库
mDatabase.execSQL("drop table weather");
mDatabase.execSQL("create table weather (_id INTEGER PRIMARY KEY AUTOINCREMENT,date text,max_temp text,min_temp text,text text,humidity text,pressure text,wind text,icon text)");
for(int i=0;i<weatherItems.size();i++){
WeatherItem item = weatherItems.get(i);
ContentValues values = new ContentValues();
values.put("date",item.getData());
values.put("max_temp",item.getMax_temp());
values.put("min_temp",item.getMin_temp());
values.put("text",item.getText());
values.put("humidity",item.getHumidity());
values.put("pressure",item.getPressure());
values.put("wind",item.getWind());
values.put("icon",item.getIcon());
mDatabase.insert("weather",null,values);
}
return weatherItems;
}
@Override
protected void onPostExecute(List<WeatherItem> weatherItems) {
mItems = weatherItems;
SharedPreferences.Editor editor = getActivity().getSharedPreferences("setting", Context.MODE_PRIVATE).edit();
//实现今天天气部分的UI
WeatherItem item = mItems.get(0);
mTodayTime.setText("Today,"+location);
mTodayMaxTemp.setText(item.getMax_temp()+unit_text);
editor.putString("max_temp",item.getMax_temp());
mTodayMinTemp.setText(item.getMin_temp()+unit_text);
editor.putString("min_temp",item.getMin_temp());
mTodayIconDesc.setText(item.getText());
editor.putString("text",item.getText());
String icon = "a"+item.getIcon();
int id = getIconId(getContext(),icon);
Drawable drawable = getResources().getDrawable(id);
mTodayIcon.setImageDrawable(drawable);
editor.commit();
//实现recyclerview部分的UI
setupAdapter();
//如果是ipad就手动更新详情页面
if(getActivity().findViewById(R.id.detail_container)!=null){
mCallbacks.onWeatherSelected(item);
}
}
}
public class WeatherHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private WeatherItem mWeatherItem;
private TextView mItemMaxWeather;
private TextView mItemMinWeather;
private ImageView mItemIcon;
private TextView mItemDate;
private TextView mItemDesc;
public void setDay(String day){
mItemDate.setText(day);
}
public WeatherHolder(View itemView){
super(itemView);
itemView.setOnClickListener(this);
mItemMaxWeather = (TextView) itemView.findViewById(R.id.item_max_weather);
mItemMinWeather = (TextView) itemView.findViewById(R.id.item_min_weather);
mItemIcon = (ImageView) itemView.findViewById(R.id.item_icon);
mItemDate = (TextView) itemView.findViewById(R.id.item_date);
mItemDesc = (TextView) itemView.findViewById(R.id.item_desc);
}
public void bindWeatherItem(WeatherItem weatherItem){
mWeatherItem = weatherItem;
mItemMaxWeather.setText(weatherItem.getMax_temp()+unit_text);
mItemMinWeather.setText(weatherItem.getMin_temp()+unit_text);
String icon = "a"+weatherItem.getIcon();
int id = getIconId(getContext(),icon);
Drawable drawable = getResources().getDrawable(id);
mItemIcon.setImageDrawable(drawable);
mItemDate.setText(weatherItem.getData());
mItemDesc.setText(weatherItem.getText());
}
//点击列表,跳转到详情页面
@Override
public void onClick(View v) {
Log.i(TAG,"click");
mCallbacks.onWeatherSelected(mWeatherItem);
}
}
private class WeatherAdaper extends RecyclerView.Adapter<WeatherHolder>{
private List<WeatherItem> mWeatherList = new ArrayList<>();
public WeatherAdaper(List<WeatherItem> items){
mWeatherList = items;
}
@Override
public int getItemCount() {
return mWeatherList.size();
}
@Override
public WeatherHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//实例化mars_item布局
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = inflater.inflate(R.layout.weather_item,parent,false);
return new WeatherHolder(view);
}
@Override
public void onBindViewHolder(@NonNull WeatherHolder holder, int position) {
WeatherItem weatherItem = mWeatherList.get(position);
holder.bindWeatherItem(weatherItem);
if(position==0){
holder.setDay("Today");
}
if(position==1){
holder.setDay("Tomorrow");
}
}
}
private void setupAdapter(){
if(isAdded()){
mWeatherRecyclerView.setAdapter(new WeatherAdaper(mItems));
}
}
//判断网络是否连接
public boolean isNetworkConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isNetworkAvailable = cm.getActiveNetwork() != null;
boolean isNetworkConnected = isNetworkAvailable && cm.getActiveNetworkInfo().isConnected();
return isNetworkConnected;
}
}

@ -0,0 +1,78 @@
package com.example.myapplication.weather;
import java.io.Serializable;
public class WeatherItem implements Serializable {
private String data; //天气日期
private String max_temp; //最高温度
private String min_temp; //最低温度
private String text; //天气描述
private String humidity; //适度
private String pressure; //气压
private String wind; //风力
private String icon; //图标
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getMax_temp() {
return max_temp;
}
public void setMax_temp(String max_temp) {
this.max_temp = max_temp;
}
public String getMin_temp() {
return min_temp;
}
public void setMin_temp(String min_temp) {
this.min_temp = min_temp;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getHumidity() {
return humidity;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
public String getPressure() {
return pressure;
}
public void setPressure(String pressure) {
this.pressure = pressure;
}
public String getWind() {
return wind;
}
public void setWind(String wind) {
this.wind = wind;
}
}

@ -2,7 +2,6 @@ package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@ -16,7 +15,7 @@ public class zhaoxun extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zhaoxun);
Button buttonitem=findViewById(R.id.myitem);
Button buttonitem=findViewById(R.id.myitem);
Button buttonmap=findViewById(R.id.map);
buttonitem.setOnClickListener(new View.OnClickListener() {
@Override

@ -5,7 +5,7 @@
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#008577"
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/detail_container"
xmlns:android="http://schemas.android.com/apk/res/android" />

@ -19,7 +19,11 @@
android:layout_height="100dp"
android:gravity="left"
android:text="钱包"
<<<<<<< HEAD:src/MyApplication/app/src/main/res/layout/activity_itemfound.xml
android:textSize="30sp" />
=======
android:textSize="30sp"></Button>
>>>>>>> dc8dfd73a8a58508fec99a79684ba5574328c7e7:src/MyApplication/app/src/MyApplication/app/src/main/res/layout/activity_itemfound.xml
<Button
android:id="@+id/button_item_keys"
@ -27,7 +31,11 @@
android:layout_height="100dp"
android:text="钥匙"
android:textSize="30sp"
<<<<<<< HEAD:src/MyApplication/app/src/main/res/layout/activity_itemfound.xml
android:gravity="left" />
=======
android:gravity="left"></Button>
>>>>>>> dc8dfd73a8a58508fec99a79684ba5574328c7e7:src/MyApplication/app/src/MyApplication/app/src/main/res/layout/activity_itemfound.xml
</LinearLayout>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"
xmlns:android="http://schemas.android.com/apk/res/android" />

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/page">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location"
android:textSize="16dp"
android:textColor="#333"/>
<EditText
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="请输入地理位置"
android:textSize="13dp"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0.8dp"
android:background="#aaa"/>
<LinearLayout
android:id="@+id/unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unit"
android:textSize="16dp"
android:textColor="#333"/>
<TextView
android:id="@+id/unit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="摄氏度"
android:textSize="12dp"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0.8dp"
android:background="#aaa"/>
<LinearLayout
android:id="@+id/send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开启通知"
android:textSize="16dp"
android:textColor="#333"/>
<TextView
android:id="@+id/send_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="是"
android:textSize="12dp"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0.8dp"
android:background="#aaa"/>
</LinearLayout>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/fragment_container"/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:id="@+id/detail_container"/>
</LinearLayout>

@ -11,8 +11,12 @@
android:text="选择要找寻物品的编号"
android:textSize="30sp"
android:onClick="jump"
<<<<<<< HEAD:src/MyApplication/app/src/main/res/layout/activity_zhaoxun.xml
android:gravity="left" />
=======
android:gravity="left"></Button>
>>>>>>> dc8dfd73a8a58508fec99a79684ba5574328c7e7:src/MyApplication/app/src/MyApplication/app/src/main/res/layout/activity_zhaoxun.xml
<Button
android:id="@+id/map"
android:layout_width="380dp"
@ -20,5 +24,9 @@
android:text="查看自己所在的定位"
android:onClick="jump"
android:textSize="30sp"
<<<<<<< HEAD:src/MyApplication/app/src/main/res/layout/activity_zhaoxun.xml
android:gravity="left" />
=======
android:gravity="left"></Button>
>>>>>>> dc8dfd73a8a58508fec99a79684ba5574328c7e7:src/MyApplication/app/src/MyApplication/app/src/main/res/layout/activity_zhaoxun.xml
</LinearLayout>

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/blue">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:gravity="top|center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/today_time"
android:text="Today,May 17"
android:textColor="#fff"
android:textSize="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/today_max_temp"
android:text="26°"
android:textColor="#fff"
android:textSize="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/today_min_temp"
android:text="14°"
android:textColor="#fff"
android:textSize="30dp"
android:layout_marginTop="-5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="top|center"
android:orientation="vertical"
android:layout_marginTop="10dp">
<ImageView
android:id="@+id/today_icon"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/a100"
android:padding="20dp"/>
<TextView
android:id="@+id/today_icon_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="25dp"
android:text="Sun"
android:layout_marginTop="-20dp"/>
</LinearLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_weather_recycler_view"/>
</LinearLayout>

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detail_date"
android:text="Tomorrow"
android:textColor="#000"
android:textSize="20dp"
android:layout_margin="30dp"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="25dp"
android:gravity="top|center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detail_max_temp"
android:text="26℉"
android:textSize="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detail_min_temp"
android:text="14°"
android:textSize="40dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="top|center"
android:orientation="vertical">
<ImageView
android:id="@+id/detail_icon"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/a100"
/>
<TextView
android:id="@+id/detail_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="Sun"
android:layout_marginTop="-10dp"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detail_humidity"
android:text="Humidity: 78 %"
android:textColor="#000"
android:textSize="20dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detail_pressure"
android:text="Pressure: 1018 hPa"
android:textColor="#000"
android:textSize="20dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detail_wind"
android:text="Wind: 3 km/h SE"
android:textColor="#000"
android:textSize="20dp"
android:layout_marginLeft="15dp"/>
</LinearLayout>

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/weather_item"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:gravity="top|center"
android:padding="10dp">
<TextView
android:id="@+id/item_max_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="27°"
android:textSize="20dp"/>
<TextView
android:id="@+id/item_min_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="16°"/>
</LinearLayout>
<ImageView
android:id="@+id/item_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/a100"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/item_icon"
android:padding="10dp">
<TextView
android:id="@+id/item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tomorrow"
android:textSize="20dp"/>
<TextView
android:id="@+id/item_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sun"
android:textSize="18dp"/>
</LinearLayout>
</RelativeLayout>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save