├── .gitignore
├── .idea
├── .gitignore
├── compiler.xml
├── gradle.xml
├── jarRepositories.xml
└── misc.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── libs
│ ├── BaiduLBS_Android.jar
│ ├── arm64-v8a
│ │ ├── libindoor.so
│ │ └── liblocSDK8a.so
│ ├── armeabi-v7a
│ │ ├── libindoor.so
│ │ └── liblocSDK8a.so
│ ├── armeabi
│ │ ├── libindoor.so
│ │ └── liblocSDK8a.so
│ ├── x86
│ │ ├── libindoor.so
│ │ └── liblocSDK8a.so
│ └── x86_64
│ │ ├── libindoor.so
│ │ └── liblocSDK8a.so
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── myweather
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── city.db
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── myweather
│ │ │ ├── CheckNet.java
│ │ │ ├── City.java
│ │ │ ├── CityDb.java
│ │ │ ├── CityManagement.java
│ │ │ ├── CustomImage.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MainActivity2.java
│ │ │ ├── MyApplication.java
│ │ │ ├── RoundAngleImageView.java
│ │ │ ├── SearchCity.java
│ │ │ ├── TodayWeather.java
│ │ │ └── WeatherChartView.java
│ └── res
│ │ ├── anim
│ │ ├── in_from_left.xml
│ │ ├── in_from_right.xml
│ │ ├── out_to_left.xml
│ │ └── out_to_right.xml
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── button_shape.xml
│ │ ├── citybutton_shape.xml
│ │ ├── dayu.png
│ │ ├── dayuicon.png
│ │ ├── duoyun3.png
│ │ ├── duoyunicon.png
│ │ ├── edit_shape.xml
│ │ ├── ic_back.png
│ │ ├── ic_launcher_background.xml
│ │ ├── ic_plus.png
│ │ ├── leidian.png
│ │ ├── leidianicon.png
│ │ ├── pm25.png
│ │ ├── qingicon.png
│ │ ├── qingtian.png
│ │ ├── sandian.png
│ │ ├── seach_view.png
│ │ ├── search.png
│ │ ├── shidu.png
│ │ ├── testpng.png
│ │ ├── wu.png
│ │ ├── wuicon.png
│ │ ├── xiaoyu.png
│ │ ├── xiaoyuicon.png
│ │ ├── yinicon.png
│ │ ├── yintian3.png
│ │ ├── zhenyuicon.png
│ │ ├── zhongyu.png
│ │ └── zhongyuicon.png
│ │ ├── layout
│ │ ├── activity_city1.xml
│ │ ├── activity_main.xml
│ │ ├── activity_main2.xml
│ │ └── activity_search_city.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── navigation
│ │ └── nav_graph.xml
│ │ ├── values-night
│ │ └── themes.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── myweather
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── image
├── 1.txt
└── 20210114093921657.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Weather-Forecast-App
2 | 该java项目是在Android Studio的环境下实现的,主要是仿照了小米10手机上的天气预报App。
3 |
4 | 1.主界面:主要显示该城市的天气信息,包括城市名,温度,天气状况和相应图标,污染程度,湿度,近三天的最高温度和最低温度还有一个跳转2界面的按钮,背景图会通过天气状况显示对应的插图,天气状况图标也会根据天气显示相应图标。
5 |
6 | 2.该城市近五日天气界面:主要显示1界面城市中近五日天气状况,其中包括星期,日期,早晚的天气状况及图标,最低温度和最高温度的温度曲线,风向和风力等级。点击左上角三角符号返回1界面。
7 |
8 | 3.城市管理界面:将1界面的城市做成一张卡片,放在该界面,该界面显示当天天气信息,可以通过点击这张卡片返回1界面,搜索框可以搜索任意城市的天气。
9 |
10 | 4.热门城市和搜索界面:该界面用来搜索任意城市天气,下方热门城市可以点击常看的城市直接去往主界面,还可以点击定位按钮,定位到当前城市的天气预报。
11 |
12 | 5.搜索结果界面:该界面显示包含输入框字的城市名列表,通过点击列表中任意城市名回到该城市的1界面.
13 |
14 |
15 | 
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.3"
8 |
9 | defaultConfig {
10 | applicationId "com.example.myweather"
11 | minSdkVersion 16
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | sourceSets{
30 | main{
31 | jniLibs.srcDirs = ['libs']
32 | }
33 | }
34 | }
35 |
36 | dependencies {
37 |
38 | implementation 'androidx.appcompat:appcompat:1.2.0'
39 | implementation 'com.google.android.material:material:1.2.1'
40 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
41 | implementation 'androidx.navigation:navigation-fragment:2.3.2'
42 | implementation 'androidx.navigation:navigation-ui:2.3.2'
43 | implementation files('libs\\BaiduLBS_Android.jar')
44 | testImplementation 'junit:junit:4.+'
45 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
46 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
47 | implementation 'dom4j:dom4j:1.6.1'
48 | }
--------------------------------------------------------------------------------
/app/libs/BaiduLBS_Android.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/BaiduLBS_Android.jar
--------------------------------------------------------------------------------
/app/libs/arm64-v8a/libindoor.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/arm64-v8a/libindoor.so
--------------------------------------------------------------------------------
/app/libs/arm64-v8a/liblocSDK8a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/arm64-v8a/liblocSDK8a.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libindoor.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/armeabi-v7a/libindoor.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/liblocSDK8a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/armeabi-v7a/liblocSDK8a.so
--------------------------------------------------------------------------------
/app/libs/armeabi/libindoor.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/armeabi/libindoor.so
--------------------------------------------------------------------------------
/app/libs/armeabi/liblocSDK8a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/armeabi/liblocSDK8a.so
--------------------------------------------------------------------------------
/app/libs/x86/libindoor.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/x86/libindoor.so
--------------------------------------------------------------------------------
/app/libs/x86/liblocSDK8a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/x86/liblocSDK8a.so
--------------------------------------------------------------------------------
/app/libs/x86_64/libindoor.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/x86_64/libindoor.so
--------------------------------------------------------------------------------
/app/libs/x86_64/liblocSDK8a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/libs/x86_64/liblocSDK8a.so
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/myweather/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.example.myweather", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
63 |
64 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/app/src/main/assets/city.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/assets/city.db
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myweather/CheckNet.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.Network;
6 | import android.net.NetworkCapabilities;
7 | import android.net.NetworkInfo;
8 | import android.os.Build;
9 | import android.util.Log;
10 |
11 | public class CheckNet {
12 |
13 |
14 | public final static int NET_NONE = 0;
15 | public final static int NET_WIFI = 1;
16 | public final static int NET_MOBILE = 2;
17 |
18 |
19 | public int checkNetworkInfo(Context context) {
20 | ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
21 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
22 | if (connectivity != null) {
23 | Network networks = connectivity.getActiveNetwork();
24 |
25 | NetworkCapabilities networkCapabilities = connectivity.getNetworkCapabilities(networks);
26 | if (networkCapabilities != null) {
27 | if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
28 | return NET_WIFI;
29 | } else if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
30 | return NET_MOBILE;
31 | }
32 | else {
33 | return NET_NONE;
34 | }
35 | } else {
36 | return NET_NONE;
37 | }
38 | }
39 | }
40 | return NET_NONE;
41 |
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myweather/City.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | public class City {
4 |
5 |
6 | private String province;
7 | private String city;
8 | private String number;
9 | private String firstPY;
10 | private String allPY;
11 | private String allFirstPY;
12 |
13 |
14 | public String getProvince() {
15 | return province;
16 | }
17 |
18 | public void setProvince(String province) {
19 | this.province = province;
20 | }
21 |
22 | public String getCity() {
23 | return city;
24 | }
25 |
26 | public void setCity(String city) {
27 | this.city = city;
28 | }
29 |
30 | public String getNumber() {
31 | return number;
32 | }
33 |
34 | public void setNumber(String number) {
35 | this.number = number;
36 | }
37 |
38 | public String getFirstPY() {
39 | return firstPY;
40 | }
41 |
42 | public void setFirstPY(String firstPY) {
43 | this.firstPY = firstPY;
44 | }
45 |
46 | public String getAllPY() {
47 | return allPY;
48 | }
49 |
50 | public void setAllPY(String allPY) {
51 | this.allPY = allPY;
52 | }
53 |
54 | public String getAllFirstPY() {
55 | return allFirstPY;
56 | }
57 |
58 | public void setAllFirstPY(String allFirstPY) {
59 | this.allFirstPY = allFirstPY;
60 | }
61 |
62 | public City(String province, String city, String number, String firstPY, String allPY, String allFirstPY) {
63 | this.province = province;
64 | this.city = city;
65 | this.number = number;
66 | this.firstPY = firstPY;
67 | this.allPY = allPY;
68 | this.allFirstPY = allFirstPY;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myweather/CityDb.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.database.sqlite.SQLiteDatabase;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class CityDb {
11 |
12 | private SQLiteDatabase db;
13 | public static final String CITY_DB_NAME = "city.db";
14 | private static final String CITY_TABLE_NAME = "city";
15 |
16 | public CityDb(Context context, String path){
17 | db = context.openOrCreateDatabase(CITY_DB_NAME,Context.MODE_PRIVATE,null);
18 | }
19 |
20 |
21 |
22 |
23 |
24 | public List getCityList( )
25 | {
26 |
27 | //SQLiteDatabase db = SQLiteDatabase.openDatabase(sqlPath, null, SQLiteDatabase.OPEN_READONLY);
28 |
29 |
30 | List list = new ArrayList<>();
31 | Cursor cursor = db.rawQuery("SELECT * from "+CITY_TABLE_NAME,null);
32 | while(cursor.moveToNext())
33 | {
34 | String province = cursor.getString(cursor.getColumnIndex("province"));
35 | String city = cursor.getString(cursor.getColumnIndex("city"));
36 | String number = cursor.getString(cursor.getColumnIndex("number"));
37 | String allPY = cursor.getString(cursor.getColumnIndex("allpy"));
38 | String allFirstPY = cursor.getString(cursor.getColumnIndex("allfirstpy"));
39 | String firstPY = cursor.getString(cursor.getColumnIndex("firstpy"));
40 | City item = new City(province,city,number,allPY,allFirstPY,firstPY);
41 | list.add(item);
42 | }
43 | return list;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myweather/CityManagement.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.core.app.ActivityOptionsCompat;
5 |
6 | import android.app.ActivityOptions;
7 | import android.content.Intent;
8 | import android.os.Bundle;
9 | import android.text.InputType;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 | import android.widget.ImageButton;
14 | import android.widget.ImageView;
15 | import android.widget.TextView;
16 |
17 | public class CityManagement extends AppCompatActivity {
18 |
19 | private String cityType;
20 |
21 | private ImageView img;
22 | private String cityname,todaywendu,mlow1,mhigh1,zhishu,type;
23 | private TextView citynameT,todaywenduT,mlow1T,mhigh1T,zhishuT;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_city1);
29 |
30 |
31 | //去掉标题栏
32 | getSupportActionBar().hide();
33 |
34 | ImageButton btn2 = (ImageButton)findViewById(R.id.imageButton);
35 | btn2.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | finish();
39 |
40 | //设置切换动画,从左边进入,右边退出
41 | //overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
42 | }
43 | });
44 |
45 | //设置共享元素动画
46 | Button gv = (Button)findViewById(R.id.seach_view);
47 | gv.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | Intent intent = new Intent(CityManagement.this,SearchCity.class);
51 | //startActivity(intent);
52 | startActivity(intent, ActivityOptionsCompat.makeSceneTransitionAnimation(CityManagement.this,gv,"myimageview").toBundle());
53 | }
54 | });
55 |
56 | //设置共享元素动画
57 | ImageView gv2 = (ImageView)findViewById(R.id.img);
58 | gv2.setOnClickListener(new View.OnClickListener() {
59 | @Override
60 | public void onClick(View v) {
61 | Intent intent = new Intent(CityManagement.this,MainActivity.class);
62 | //startActivity(intent);
63 | startActivity(intent, ActivityOptionsCompat.makeSceneTransitionAnimation(CityManagement.this,gv2,"testImg").toBundle());
64 | }
65 | });
66 |
67 | cityname = getIntent().getStringExtra("cityname");
68 | todaywendu = getIntent().getStringExtra("todaywendu");
69 | String []slow = getIntent().getStringExtra("mlow1").substring(3).split("℃");
70 | String []shigh = getIntent().getStringExtra("mhigh1").substring(3).split("℃");
71 | zhishu = getIntent().getStringExtra("zhishu");
72 | type = getIntent().getStringExtra("type");
73 | mlow1 = slow[0];
74 | mhigh1 = shigh[0];
75 |
76 | initCityMange();
77 | updateData();
78 |
79 |
80 | }
81 |
82 | public void initCityMange(){
83 |
84 | citynameT = (TextView)findViewById(R.id.city);
85 | citynameT.setText("N/A");
86 |
87 | todaywenduT = (TextView)findViewById(R.id.wendu);
88 | todaywenduT.setText("N/A");
89 |
90 | zhishuT = (TextView)findViewById(R.id.wuran);
91 | zhishuT.setText("N/A");
92 |
93 | citynameT = (TextView)findViewById(R.id.city);
94 | citynameT.setText("N/A");
95 |
96 | mlow1T = (TextView)findViewById(R.id.high);
97 | mlow1T.setText("N/A");
98 |
99 | mhigh1T = (TextView)findViewById(R.id.low);
100 | mhigh1T.setText("N/A");
101 |
102 | img = (ImageView)findViewById(R.id.img);
103 |
104 | }
105 | public void updateData(){
106 |
107 | citynameT.setText(cityname);
108 | todaywenduT.setText(todaywendu+"°");
109 | mlow1T.setText(mlow1+"°");
110 | mhigh1T.setText(mhigh1+"°");
111 | zhishuT.setText(zhishu);
112 |
113 | switch (type){
114 | case "晴":
115 | img.setImageResource(R.drawable.qingtian);
116 | break;
117 | case "阴":
118 | img.setImageResource(R.drawable.yintian3);
119 | break;
120 | case "雾":
121 | img.setImageResource(R.drawable.wu);
122 | break;
123 | case "多云":
124 | img.setImageResource(R.drawable.duoyun3);
125 | break;
126 | case "小雨":
127 | img.setImageResource(R.drawable.xiaoyu);
128 | break;
129 | case "中雨":
130 | img.setImageResource(R.drawable.zhongyu);
131 | break;
132 | case "大雨":
133 | img.setImageResource(R.drawable.dayu);
134 | break;
135 | case "阵雨":
136 | img.setImageResource(R.drawable.dayu);
137 | break;
138 | case "雷电":
139 | img.setImageResource(R.drawable.leidian);
140 | break;
141 | default:
142 | break;
143 | }
144 |
145 | }
146 |
147 |
148 |
149 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myweather/CustomImage.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import androidx.appcompat.widget.AppCompatImageView;
7 |
8 | public class CustomImage extends AppCompatImageView {
9 | private int mResId;
10 |
11 | public CustomImage(Context context) {
12 | this(context, null, 0);
13 | }
14 |
15 | public CustomImage(Context context, AttributeSet attrs) {
16 | this(context, attrs, 0);
17 | }
18 |
19 | public CustomImage(Context context, AttributeSet attrs, int defStyleAttr) {
20 | super(context, attrs, defStyleAttr);
21 | if (attrs != null) {
22 | String namespace = "http://schemas.android.com/apk/res/android";
23 | String attribute = "src";
24 | mResId = attrs.getAttributeResourceValue(namespace, attribute, 0);
25 | }
26 | }
27 |
28 | public int getImageId() {
29 | return mResId;
30 | }
31 |
32 | @Override
33 | public void setImageResource(int resId) {
34 | super.setImageResource(resId);
35 | mResId = resId;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myweather/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.content.SharedPreferences;
8 | import android.os.Bundle;
9 | import android.os.Handler;
10 | import android.os.Message;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import android.widget.ImageButton;
15 | import android.widget.ImageView;
16 | import android.widget.TextView;
17 | import org.dom4j.Document;
18 | import org.dom4j.DocumentException;
19 | import org.dom4j.Element;
20 | import org.dom4j.io.SAXReader;
21 | import org.xmlpull.v1.XmlPullParser;
22 | import org.xmlpull.v1.XmlPullParserFactory;
23 | import java.io.BufferedReader;
24 | import java.io.ByteArrayInputStream;
25 | import java.io.File;
26 | import java.io.FileOutputStream;
27 | import java.io.IOException;
28 | import java.io.InputStream;
29 | import java.io.InputStreamReader;
30 | import java.io.OutputStream;
31 | import java.io.StringReader;
32 | import java.net.HttpURLConnection;
33 | import java.net.URL;
34 | import java.util.List;
35 |
36 |
37 | public class MainActivity extends AppCompatActivity {
38 |
39 | private TextView cityNameT,temperatureT,typeT,shiduT,type1T,low1T,high1T,wuranzhishuT,type2T,low2T,high2T,type3T,low3T,high3T,week3T,timeT;
40 | private ImageView backgroundImg,typeIcon1,typeIcon2,typeIcon3;
41 | private String UpdateCityCode,cityname,todaywendu,zhishu,type;
42 | private String mdate0,mdate1,mdate2,mdate3,mdate4;
43 | private String mtype0_d,mtype0_n,mtype1_d,mtype1_n,mtype2_d,mtype2_n,mtype3_d,mtype3_n,mtype4_d,mtype4_n;
44 | private String mlow0,mhigh0,mlow1,mhigh1,mlow2,mhigh2,mlow3,mhigh3,mlow4,mhigh4;
45 | private String mfx0,mfx1,mfx2,mfx3,mfx4,mfl0,mfl1,mfl2,mfl3,mfl4;
46 |
47 | //实时更新主界面数据
48 | final Handler mhandler = new Handler(){
49 | public void handleMessage(Message msg){
50 | switch (msg.what){
51 | case 1:
52 | updateTodayWeather((TodayWeather)msg.obj);
53 | break;
54 | default:
55 | break;
56 | }
57 | }
58 | };
59 |
60 |
61 | TodayWeather todayWeather = null;
62 |
63 |
64 | @Override
65 | protected void onCreate(Bundle savedInstanceState) {
66 | super.onCreate(savedInstanceState);
67 | setContentView(R.layout.activity_main);
68 |
69 | //去掉标题栏
70 | getSupportActionBar().hide();
71 |
72 |
73 | Button weather = (Button) findViewById(R.id.viewweather);
74 | weather.getBackground().setAlpha(100);
75 | weather.setOnClickListener(new View.OnClickListener() {
76 | @Override
77 | public void onClick(View v) {
78 | Intent intent = new Intent(MainActivity.this, MainActivity2.class);
79 | intent.putExtra("date0",mdate0);
80 | intent.putExtra("date1",mdate1);
81 | intent.putExtra("date2",mdate2);
82 | intent.putExtra("date3",mdate3);
83 | intent.putExtra("date4",mdate4);
84 |
85 | intent.putExtra("mtype0_d",mtype0_d);
86 | intent.putExtra("mtype0_n",mtype0_n);
87 | intent.putExtra("mtype1_d",mtype1_d);
88 | intent.putExtra("mtype1_n",mtype1_n);
89 | intent.putExtra("mtype2_d",mtype2_d);
90 | intent.putExtra("mtype2_n",mtype2_n);
91 | intent.putExtra("mtype3_d",mtype3_d);
92 | intent.putExtra("mtype3_n",mtype3_n);
93 | intent.putExtra("mtype4_d",mtype4_d);
94 | intent.putExtra("mtype4_n",mtype4_n);
95 |
96 | intent.putExtra("mlow0",mlow0);
97 | intent.putExtra("mhigh0",mhigh0);
98 | intent.putExtra("mlow1",mlow1);
99 | intent.putExtra("mhigh1",mhigh1);
100 | intent.putExtra("mlow2",mlow2);
101 | intent.putExtra("mhigh2",mhigh2);
102 | intent.putExtra("mlow3",mlow3);
103 | intent.putExtra("mhigh3",mhigh3);
104 | intent.putExtra("mlow4",mlow4);
105 | intent.putExtra("mhigh4",mhigh4);
106 |
107 |
108 | intent.putExtra("mfx0",mfx0);
109 | intent.putExtra("mfx1",mfx1);
110 | intent.putExtra("mfx2",mfx2);
111 | intent.putExtra("mfx3",mfx3);
112 | intent.putExtra("mfx4",mfx4);
113 | intent.putExtra("mfl0",mfl0);
114 | intent.putExtra("mfl1",mfl1);
115 | intent.putExtra("mfl2",mfl2);
116 | intent.putExtra("mfl3",mfl3);
117 | intent.putExtra("mfl4",mfl4);
118 | startActivity(intent);
119 |
120 | //设置切换动画,从右边进入,左边退出
121 | overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
122 | }
123 | });
124 |
125 |
126 | ImageButton btn2 = (ImageButton) findViewById(R.id.imageButton3);
127 | btn2.setOnClickListener(new View.OnClickListener() {
128 | @Override
129 | public void onClick(View v) {
130 | Intent intent = new Intent(MainActivity.this, CityManagement.class);
131 |
132 | intent.putExtra("cityname",cityname);
133 | intent.putExtra("todaywendu",todaywendu);
134 | intent.putExtra("mlow1",mlow1);
135 | intent.putExtra("mhigh1",mhigh1);
136 | intent.putExtra("zhishu",zhishu);
137 | intent.putExtra("type",type);
138 |
139 | startActivity(intent);
140 |
141 | //设置切换动画,从右边进入,左边退出
142 | //overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
143 | }
144 | });
145 |
146 | if (new CheckNet().checkNetworkInfo(this) == CheckNet.NET_NONE) {
147 | System.out.println("connect failed!");
148 | } else {
149 | System.out.println("connect successed!");
150 |
151 | //从SharePreference文件中获取数据
152 | SharedPreferences mySharePre = getSharedPreferences("citycodePreferences", Activity.MODE_PRIVATE);
153 | String sharecode = mySharePre.getString("citycode", "");
154 | if (!sharecode.equals("")) {
155 | getWeatherDatafromNet(sharecode);
156 | } else {
157 | getWeatherDatafromNet("101040100");
158 | }
159 | }
160 |
161 | initView();
162 |
163 | //获取点击城市的citycode
164 | UpdateCityCode = getIntent().getStringExtra("citycode");
165 | if (UpdateCityCode!="-1"){
166 | getWeatherDatafromNet(UpdateCityCode);
167 | }
168 |
169 |
170 | }
171 |
172 | public void CheckWeather(View view) {
173 | }
174 |
175 | //初始化主页面数据
176 | public void initView(){
177 | cityNameT = (TextView)findViewById(R.id.detailaddress);
178 | cityNameT.setText("N/A");
179 |
180 | temperatureT = (TextView)findViewById(R.id.temperature);
181 | temperatureT.setText("N/A");
182 |
183 | type1T = (TextView)findViewById(R.id.weather_forcast1);
184 | type1T.setText("N/A");
185 |
186 | typeT = (TextView)findViewById(R.id.weathercondition);
187 | typeT.setText("N/A");
188 |
189 | shiduT = (TextView)findViewById(R.id.shidu);
190 | shiduT.setText("N/A");
191 |
192 | high1T = (TextView)findViewById(R.id.high1);
193 | high1T.setText("N/A");
194 |
195 | low1T = (TextView)findViewById(R.id.low1);
196 | low1T.setText("N/A");
197 |
198 | type2T = (TextView)findViewById(R.id.weather_forcast2);
199 | type2T.setText("N/A");
200 |
201 | high2T = (TextView)findViewById(R.id.high2);
202 | high2T.setText("N/A");
203 |
204 | low2T = (TextView)findViewById(R.id.low2);
205 | low2T.setText("N/A");
206 |
207 | type3T = (TextView)findViewById(R.id.weather_forcast3);
208 | type3T.setText("N/A");
209 |
210 | high3T = (TextView)findViewById(R.id.high3);
211 | high3T.setText("N/A");
212 |
213 | low3T = (TextView)findViewById(R.id.low3);
214 | low3T.setText("N/A");
215 |
216 | week3T = (TextView)findViewById(R.id.date3);
217 | week3T.setText("N/A");
218 |
219 | wuranzhishuT = (TextView)findViewById(R.id.pollutionlevel);
220 | wuranzhishuT.setText("N/A");
221 |
222 | timeT = (TextView)findViewById(R.id.blankshang);
223 | timeT.setText("N/A");
224 |
225 | backgroundImg = (ImageView)findViewById(R.id.main_background);
226 |
227 | typeIcon1 = (ImageView)findViewById(R.id.weather_icon1);
228 | typeIcon2 = (ImageView)findViewById(R.id.weather_icon2);
229 | typeIcon3 = (ImageView)findViewById(R.id.weather_icon3);
230 |
231 | }
232 |
233 |
234 | //通过城市码(citycode)连接网络,获取天气状况的xml数据
235 | private void getWeatherDatafromNet(String cityCode) {
236 | final String address = "http://wthrcdn.etouch.cn/WeatherApi?citykey=" + cityCode;
237 |
238 | new Thread(new Runnable() {
239 | @Override
240 | public void run() {
241 | HttpURLConnection urlConnection = null;
242 | try {
243 | URL url = new URL(address);
244 | urlConnection = (HttpURLConnection) url.openConnection();
245 | urlConnection.setRequestMethod("GET");
246 | urlConnection.setConnectTimeout(8000);
247 | urlConnection.setReadTimeout(8000);
248 | InputStream in = urlConnection.getInputStream();
249 |
250 | // BufferedReader reader = new BufferedReader(new InputStreamReader(in));
251 | // StringBuffer sb = new StringBuffer();
252 | // String str;
253 | // while ((str = reader.readLine()) != null) {
254 | // sb.append(str);
255 | // }
256 | // String response = sb.toString();
257 | // InputStream inputStream = new ByteArrayInputStream(response.getBytes());
258 | //
259 | // if(response != null && response.startsWith("\ufeff"))
260 | // {
261 | // response = response.substring(1);
262 | // }
263 |
264 | // todayWeather = parseXML(response);
265 | // if (todayWeather!=null){
266 | // Message message = new Message( );
267 | // message.what = 1;
268 | // message.obj=todayWeather;
269 | // mhandler.sendMessage(message);
270 | // }
271 | todayWeather = requestXML2(in);
272 |
273 |
274 | if (todayWeather!=null){
275 | Message message = new Message( );
276 | message.what = 1;
277 | message.obj=todayWeather;
278 | mhandler.sendMessage(message);
279 | }
280 |
281 |
282 | } catch (Exception e) {
283 | e.printStackTrace();
284 | }
285 | }
286 | }).start();
287 |
288 | }
289 |
290 |
291 |
292 | //解析天气数据
293 | public TodayWeather requestXML2(InputStream inputStream) throws DocumentException {
294 |
295 | TodayWeather todayWeather = new TodayWeather();
296 |
297 |
298 | SAXReader reader = new SAXReader();
299 | Document document =reader.read(inputStream);
300 | //3.获取根节点
301 | Element root = document.getRootElement();
302 | //root.elementText("city");
303 | todayWeather.setCity(root.elementText("city"));
304 |
305 | //root.elementText("updatetime");
306 | todayWeather.setTime(root.elementText("updatetime"));
307 | //root.elementText("wendu");
308 | todayWeather.setTemperature(root.elementText("wendu"));
309 | root.elementText("fengli");
310 | //root.elementText("shidu");
311 | todayWeather.setShidu(root.elementText("shidu"));
312 | root.elementText("fengxiang");
313 | root.elementText("yesterday");
314 |
315 | Element yesterday = root.element("yesterday");
316 | //yesterday.elementText("date_1");
317 | todayWeather.setDate0(yesterday.elementText("date_1"));
318 |
319 | //mainActivity2.setMdate(yesterday.elementText("date_1"));
320 | yesterday.element("date_1").getText();
321 | //yesterday.elementText("high_1");
322 | todayWeather.setHigh0(yesterday.elementText("high_1"));
323 | //yesterday.elementText("low_1");
324 | todayWeather.setLow0(yesterday.elementText("low_1"));
325 | if (yesterday.element("day_1") != null) {
326 | Element day_1_ele = yesterday.element("day_1");
327 | //day_1_ele.elementText("type_1");
328 | todayWeather.setType0_d(day_1_ele.elementText("type_1"));
329 | //day_1_ele.elementText("fx_1");
330 | todayWeather.setFx0(day_1_ele.elementText("fx_1"));
331 | //day_1_ele.elementText("fl_1");
332 | todayWeather.setFl0(day_1_ele.elementText("fl_1"));
333 | }
334 | if (yesterday.element("night_1") != null) {
335 | Element day_1_elen = yesterday.element("night_1");
336 | //day_1_ele.elementText("type_1");
337 | todayWeather.setType0_n(day_1_elen.elementText("type_1"));
338 | day_1_elen.elementText("fx_1");
339 | day_1_elen.elementText("fl_1");
340 | }
341 |
342 | Element zhishus = root.element("zhishus");
343 | List list2 = zhishus.elements();
344 | for (int i = 0;i list = forecast.elements();
357 | //for (Element ele : list) {
358 | for (int i = 0;i cityList;
16 | CityDb cityDb;
17 |
18 |
19 | @Override
20 | public void onCreate() {
21 | super.onCreate();
22 |
23 | Log.d("zhqMyApplication","OnCreate");
24 | cityDb = copyFileFromAssets("city.db");
25 | initCityList();
26 |
27 |
28 | }
29 |
30 | private boolean prepareCityList()
31 | {
32 |
33 | cityList = cityDb.getCityList();
34 | setCityList(cityList);
35 |
36 | for(City city:cityList)
37 | {
38 | String cityName = city.getCity();
39 | Log.d("CityDB",cityName);
40 | }
41 | return true;
42 | }
43 |
44 |
45 | public void initCityList()
46 | {
47 |
48 | new Thread(new Runnable() {
49 | @Override
50 | public void run() {
51 | prepareCityList();
52 | }
53 | }).start();
54 | }
55 |
56 | public List getCityList()
57 | {
58 | return cityList;
59 | }
60 |
61 | public void setCityList(List cityLists){
62 |
63 | cityList = cityLists;
64 |
65 | }
66 |
67 |
68 |
69 | /**
70 | * 将assets目录下的文件拷贝到sd上
71 | *
72 | * @return 存储数据库的地址
73 | */
74 | public CityDb copyFileFromAssets(String SqliteFileName) {
75 |
76 | // 第一次运行应用程序时,加载数据库到data/data/当前包的名称/database/
77 | String path = "data/data/" + getPackageName() + "/databases";
78 | File dir = new File(path);
79 |
80 | //判断如果文件夹不存在,或者不是一个目录,那么就创建一个文件夹
81 | if (!dir.exists() || !dir.isDirectory()) {
82 | dir.mkdir();
83 | }
84 |
85 | //获取file对象
86 | File file = new File(dir, SqliteFileName);
87 | InputStream inputStream = null;
88 | OutputStream outputStream = null;
89 |
90 | //通过IO流的方式,将assets目录下的数据库文件,写入到SD卡中。
91 | if (!file.exists()) {
92 | try {
93 | file.createNewFile();
94 |
95 | inputStream = getClass().getClassLoader().getResourceAsStream("assets/" + SqliteFileName);
96 | outputStream = new FileOutputStream(file);
97 |
98 | byte[] buffer = new byte[1024];
99 | int len;
100 |
101 | while ((len = inputStream.read(buffer)) != -1) {
102 | outputStream.write(buffer, 0, len);
103 | }
104 | } catch (IOException e) {
105 | e.printStackTrace();
106 | } finally {
107 | if (outputStream != null) {
108 | try {
109 | outputStream.flush();
110 | outputStream.close();
111 | } catch (IOException e) {
112 | e.printStackTrace();
113 | }
114 | }
115 | if (inputStream != null) {
116 | try {
117 | inputStream.close();
118 | } catch (IOException e) {
119 | e.printStackTrace();
120 | }
121 | }
122 | }
123 | }
124 |
125 | return new CityDb(this,path);
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myweather/RoundAngleImageView.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.graphics.PorterDuff;
11 | import android.graphics.PorterDuffXfermode;
12 | import android.graphics.RectF;
13 | import android.util.AttributeSet;
14 | import android.widget.ImageView;
15 |
16 | public class RoundAngleImageView extends androidx.appcompat.widget.AppCompatImageView {
17 |
18 | private Paint paint;
19 | /**
20 | * 个人理解是
21 | *
22 | * 这两个都是画圆的半径
23 | */
24 | private int roundWidth = 20;
25 | private int roundHeight = 20;
26 | private Paint paint2;
27 |
28 | public RoundAngleImageView(Context context, AttributeSet attrs, int defStyle) {
29 | super(context, attrs, defStyle);
30 | init(context, attrs);
31 | }
32 |
33 | public RoundAngleImageView(Context context, AttributeSet attrs) {
34 | super(context, attrs);
35 | init(context, attrs);
36 | }
37 |
38 | public RoundAngleImageView(Context context) {
39 | super(context);
40 | init(context, null);
41 | }
42 |
43 | private void init(Context context, AttributeSet attrs) {
44 |
45 | if (attrs != null) {
46 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundAngleImageView);
47 | roundWidth = a.getDimensionPixelSize(R.styleable.RoundAngleImageView_roundWidth, roundWidth);
48 | roundHeight = a.getDimensionPixelSize(R.styleable.RoundAngleImageView_roundHeight, roundHeight);
49 | } else {
50 | float density = context.getResources().getDisplayMetrics().density;
51 | roundWidth = (int) (roundWidth * density);
52 | roundHeight = (int) (roundHeight * density);
53 | }
54 |
55 | paint = new Paint();
56 | paint.setColor(Color.WHITE);
57 | paint.setAntiAlias(true);
58 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
59 |
60 | paint2 = new Paint();
61 | paint2.setXfermode(null);
62 | }
63 |
64 | @Override
65 | public void draw(Canvas canvas) {
66 | Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
67 | Canvas canvas2 = new Canvas(bitmap);
68 | super.draw(canvas2);
69 | drawLiftUp(canvas2);
70 | drawLiftDown(canvas2);
71 | drawRightUp(canvas2);
72 | drawRightDown(canvas2);
73 | canvas.drawBitmap(bitmap, 0, 0, paint2);
74 | bitmap.recycle();
75 | }
76 |
77 | private void drawLiftUp(Canvas canvas) {
78 | Path path = new Path();
79 | path.moveTo(0, roundHeight);
80 | path.lineTo(0, 0);
81 | path.lineTo(roundWidth, 0);
82 | path.arcTo(new RectF(0, 0, roundWidth * 2, roundHeight * 2), -90, -90);
83 | path.close();
84 | canvas.drawPath(path, paint);
85 | }
86 |
87 | private void drawLiftDown(Canvas canvas) {
88 | Path path = new Path();
89 | path.moveTo(0, getHeight() - roundHeight);
90 | path.lineTo(0, getHeight());
91 | path.lineTo(roundWidth, getHeight());
92 | path.arcTo(new RectF(0, getHeight() - roundHeight * 2, roundWidth * 2, getHeight()), 90, 90);
93 | path.close();
94 | canvas.drawPath(path, paint);
95 | }
96 |
97 | private void drawRightDown(Canvas canvas) {
98 | Path path = new Path();
99 | path.moveTo(getWidth() - roundWidth, getHeight());
100 | path.lineTo(getWidth(), getHeight());
101 | path.lineTo(getWidth(), getHeight() - roundHeight);
102 | path.arcTo(new RectF(getWidth() - roundWidth * 2, getHeight() - roundHeight * 2, getWidth(), getHeight()), -0, 90);
103 | path.close();
104 | canvas.drawPath(path, paint);
105 | }
106 |
107 | private void drawRightUp(Canvas canvas) {
108 | Path path = new Path();
109 | path.moveTo(getWidth(), roundHeight);
110 | path.lineTo(getWidth(), 0);
111 | path.lineTo(getWidth() - roundWidth, 0);
112 | path.arcTo(new RectF(getWidth() - roundWidth * 2, 0, getWidth(), 0 + roundHeight * 2), -90, 90);
113 | path.close();
114 | canvas.drawPath(path, paint);
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myweather/SearchCity.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.content.SharedPreferences;
7 | import android.os.Bundle;
8 | import android.provider.FontRequest;
9 | import android.util.Log;
10 | import android.view.View;
11 | import android.widget.AdapterView;
12 | import android.widget.ArrayAdapter;
13 | import android.widget.AutoCompleteTextView;
14 | import android.widget.Button;
15 | import android.widget.TextView;
16 | import com.baidu.location.BDAbstractLocationListener;
17 | import com.baidu.location.BDLocation;
18 | import com.baidu.location.BDLocationListener;
19 | import com.baidu.location.LocationClient;
20 | import com.baidu.location.LocationClientOption;
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | public class SearchCity extends AppCompatActivity {
25 |
26 | private MyApplication myApplication;
27 | private List mCityList;
28 | private ArrayList mArrayList;
29 | private List allCitys;
30 | private String UpdateCityCode = "-1";
31 | private String loccitycode,locacitycode;
32 | private Button btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8;
33 | //Button chcityBtn;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_search_city);
39 |
40 | //去掉标题栏
41 | getSupportActionBar().hide();
42 |
43 | TextView textView = (TextView)findViewById(R.id.cancel);
44 | textView.setOnClickListener(new View.OnClickListener() {
45 | @Override
46 | public void onClick(View v) {
47 | finish();
48 |
49 | //设置切换动画,从左边进入,右边退出
50 | //overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
51 |
52 | }
53 | });
54 |
55 |
56 | initLocation();
57 |
58 | //获取mCityList数据
59 | myApplication = (MyApplication)getApplication();
60 | mCityList = myApplication.getCityList();
61 |
62 | mArrayList = new ArrayList();
63 | allCitys = new ArrayList();
64 |
65 | //将数据存储到allCitys
66 | for (int i = 0; i adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, allCitys);
77 | autoCompleteTextView.setAdapter(adapter);
78 | //通过点击城市item项获取citycode
79 | autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
80 | @Override
81 | public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {
82 |
83 | String itemData = arg0.getItemAtPosition(arg2).toString();
84 | String cityStr = itemData.substring(0,itemData.indexOf("-"));
85 |
86 | for (int i = 0; i maxTempDay) {
201 | maxTempDay = item;
202 | }
203 | }
204 |
205 | // 存放夜间最低温度
206 | int minTempNight = mTempNight[0];
207 | // 存放夜间最高温度
208 | int maxTempNight = mTempNight[0];
209 | for (int item : mTempNight) {
210 | if (item < minTempNight) {
211 | minTempNight = item;
212 | }
213 | if (item > maxTempNight) {
214 | maxTempNight = item;
215 | }
216 | }
217 |
218 | // 白天,夜间中的最低温度
219 | int minTemp = minTempNight < minTempDay ? minTempNight : minTempDay;
220 | // 白天,夜间中的最高温度
221 | int maxTemp = maxTempDay > maxTempNight ? maxTempDay : maxTempNight;
222 |
223 | // 份数(白天,夜间综合温差)
224 | float parts = maxTemp - minTemp;
225 | // y轴一端到控件一端的距离
226 | float length = mSpace + mTextSize + mTextSpace + mRadius;
227 | // y轴高度
228 | float yAxisHeight = mHeight - length * 2;
229 |
230 | // 当温度都相同时(被除数不能为0)
231 | if (parts == 0) {
232 | for (int i = 0; i < LENGTH; i++) {
233 | mYAxisDay[i] = yAxisHeight / 2 + length;
234 | mYAxisNight[i] = yAxisHeight / 2 + length;
235 | }
236 | } else {
237 | float partValue = yAxisHeight / parts;
238 | for (int i = 0; i < LENGTH; i++) {
239 | mYAxisDay[i] = mHeight - partValue * (mTempDay[i] - minTemp) - length;
240 | mYAxisNight[i] = mHeight - partValue * (mTempNight[i] - minTemp) - length;
241 | }
242 | }
243 | }
244 |
245 | /**
246 | * 画折线图
247 | *
248 | * @param canvas 画布
249 | * @param color 画图颜色
250 | * @param temp 温度集合
251 | * @param yAxis y轴集合
252 | * @param type 折线种类:0,白天;1,夜间
253 | */
254 | private void drawChart(Canvas canvas, int color, int temp[], float[] yAxis, int type) {
255 | mLinePaint.setColor(color);
256 | mPointPaint.setColor(color);
257 |
258 | int alpha1 = 102;
259 | int alpha2 = 255;
260 | for (int i = 0; i < LENGTH; i++) {
261 | // 画线
262 | if (i < LENGTH - 1) {
263 | // 昨天
264 | if (i == 0) {
265 | mLinePaint.setAlpha(alpha1);
266 | // 设置虚线效果
267 | mLinePaint.setPathEffect(new DashPathEffect(new float[]{2 * mDensity, 2 * mDensity}, 0));
268 | // 路径
269 | Path path = new Path();
270 | // 路径起点
271 | path.moveTo(mXAxis[i], yAxis[i]);
272 | // 路径连接到
273 | path.lineTo(mXAxis[i + 1], yAxis[i + 1]);
274 | canvas.drawPath(path, mLinePaint);
275 | } else {
276 | mLinePaint.setAlpha(alpha2);
277 | mLinePaint.setPathEffect(null);
278 | canvas.drawLine(mXAxis[i], yAxis[i], mXAxis[i + 1], yAxis[i + 1], mLinePaint);
279 | }
280 | }
281 |
282 | // 画点
283 | if (i != 1) {
284 | // 昨天
285 | if (i == 0) {
286 | mPointPaint.setAlpha(alpha1);
287 | canvas.drawCircle(mXAxis[i], yAxis[i], mRadius, mPointPaint);
288 | } else {
289 | mPointPaint.setAlpha(alpha2);
290 | canvas.drawCircle(mXAxis[i], yAxis[i], mRadius, mPointPaint);
291 | }
292 | // 今天
293 | } else {
294 | mPointPaint.setAlpha(alpha2);
295 | canvas.drawCircle(mXAxis[i], yAxis[i], mRadiusToday, mPointPaint);
296 | }
297 |
298 | // 画字
299 | // 昨天
300 | if (i == 0) {
301 | mTextPaint.setAlpha(alpha1);
302 | drawText(canvas, mTextPaint, i, temp, yAxis, type);
303 | } else {
304 | mTextPaint.setAlpha(alpha2);
305 | drawText(canvas, mTextPaint, i, temp, yAxis, type);
306 | }
307 | }
308 | }
309 |
310 | /**
311 | * 绘制文字
312 | *
313 | * @param canvas 画布
314 | * @param textPaint 画笔
315 | * @param i 索引
316 | * @param temp 温度集合
317 | * @param yAxis y轴集合
318 | * @param type 折线种类:0,白天;1,夜间
319 | */
320 | private void drawText(Canvas canvas, Paint textPaint, int i, int[] temp, float[] yAxis, int type) {
321 | switch (type) {
322 | case 0:
323 | // 显示白天气温
324 | canvas.drawText(temp[i] + "°", mXAxis[i], yAxis[i] - mRadius - mTextSpace, textPaint);
325 | break;
326 | case 1:
327 | // 显示夜间气温
328 | canvas.drawText(temp[i] + "°", mXAxis[i], yAxis[i] + mTextSpace + mTextSize, textPaint);
329 | break;
330 | }
331 | }
332 |
333 | /**
334 | * 设置高度,x轴集合
335 | */
336 | private void setHeightAndXAxis() {
337 | mHeight = getHeight();
338 | // 控件宽
339 | int width = getWidth();
340 | // 每一份宽
341 | float w = width / 10;
342 | mXAxis[0] = w;
343 | mXAxis[1] = w * 3;
344 | mXAxis[2] = w * 5;
345 | mXAxis[3] = w * 7;
346 | mXAxis[4] = w * 9;
347 | //mXAxis[5] = w * 11;
348 | }
349 |
350 | /**
351 | * 设置白天温度
352 | *
353 | * @param tempDay 温度数组集合
354 | */
355 | public void setTempDay(int[] tempDay) {
356 | mTempDay = tempDay;
357 | }
358 |
359 | /**
360 | * 设置夜间温度
361 | *
362 | * @param tempNight 温度数组集合
363 | */
364 | public void setTempNight(int[] tempNight) {
365 | mTempNight = tempNight;
366 | }
367 | }
368 |
369 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/in_from_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/in_from_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/out_to_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/out_to_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/citybutton_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dayu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/dayu.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dayuicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/dayuicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/duoyun3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/duoyun3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/duoyunicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/duoyunicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/edit_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/ic_back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/ic_plus.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/leidian.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/leidian.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/leidianicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/leidianicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/pm25.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/pm25.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/qingicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/qingicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/qingtian.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/qingtian.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sandian.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/sandian.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/seach_view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/seach_view.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shidu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/shidu.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/testpng.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/testpng.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/wu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/wu.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/wuicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/wuicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/xiaoyu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/xiaoyu.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/xiaoyuicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/xiaoyuicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/yinicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/yinicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/yintian3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/yintian3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/zhenyuicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/zhenyuicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/zhongyu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/zhongyu.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/zhongyuicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/drawable/zhongyuicon.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_city1.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
14 |
18 |
21 |
22 |
23 |
24 |
29 |
32 |
40 |
41 |
50 |
51 |
52 |
53 |
58 |
61 |
62 |
63 |
64 |
69 |
72 |
84 |
85 |
86 |
87 |
92 |
95 |
96 |
97 |
98 |
99 |
104 |
107 |
108 |
119 |
120 |
131 |
142 |
153 |
164 |
175 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
26 |
27 |
28 |
29 |
32 |
33 |
40 |
41 |
45 |
46 |
49 |
50 |
51 |
52 |
57 |
58 |
61 |
62 |
71 |
72 |
80 |
81 |
88 |
89 |
90 |
91 |
92 |
93 |
98 |
99 |
103 |
111 |
119 |
126 |
127 |
128 |
129 |
130 |
131 |
136 |
139 |
148 |
149 |
157 |
158 |
159 |
168 |
169 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
188 |
189 |
194 |
201 |
202 |
203 |
204 |
205 |
206 |
211 |
214 |
223 |
224 |
234 |
235 |
243 |
244 |
252 |
263 |
264 |
273 |
274 |
283 |
284 |
285 |
286 |
287 |
288 |
293 |
296 |
297 |
306 |
307 |
308 |
318 |
319 |
327 |
328 |
336 |
347 |
348 |
357 |
358 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
378 |
381 |
390 |
391 |
401 |
402 |
410 |
411 |
419 |
430 |
431 |
440 |
441 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
14 |
15 |
19 |
22 |
23 |
31 |
32 |
42 |
43 |
44 |
45 |
46 |
47 |
52 |
55 |
63 |
64 |
72 |
73 |
74 |
82 |
83 |
91 |
92 |
100 |
101 |
102 |
103 |
104 |
109 |
112 |
119 |
120 |
127 |
128 |
135 |
136 |
143 |
144 |
151 |
152 |
153 |
154 |
155 |
160 |
163 |
172 |
173 |
182 |
183 |
192 |
193 |
202 |
203 |
212 |
213 |
214 |
215 |
216 |
221 |
224 |
231 |
232 |
239 |
240 |
247 |
248 |
255 |
256 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
274 |
277 |
286 |
287 |
288 |
289 |
290 |
295 |
298 |
307 |
308 |
317 |
318 |
327 |
328 |
337 |
338 |
347 |
348 |
349 |
350 |
351 |
356 |
359 |
366 |
367 |
374 |
375 |
382 |
383 |
390 |
391 |
398 |
399 |
400 |
401 |
402 |
407 |
410 |
417 |
418 |
425 |
426 |
433 |
434 |
441 |
442 |
449 |
450 |
451 |
452 |
453 |
458 |
461 |
468 |
469 |
476 |
477 |
484 |
485 |
492 |
493 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_search_city.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
17 |
20 |
21 |
22 |
23 |
28 |
31 |
43 |
44 |
53 |
54 |
55 |
56 |
57 |
58 |
63 |
66 |
80 |
81 |
82 |
83 |
84 |
89 |
92 |
93 |
94 |
95 |
100 |
103 |
111 |
112 |
113 |
114 |
119 |
122 |
123 |
134 |
144 |
154 |
155 |
156 |
157 |
158 |
159 |
164 |
167 |
168 |
169 |
170 |
171 |
176 |
179 |
180 |
190 |
200 |
210 |
211 |
212 |
213 |
218 |
221 |
222 |
223 |
224 |
229 |
232 |
233 |
243 |
253 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
17 |
18 |
23 |
24 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 | #8C00FFFF
11 | #303F9F
12 | #CCFFAA00
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MyWeather
3 | MainActivity
4 |
5 | First Fragment
6 | Second Fragment
7 | Next
8 | Previous
9 |
10 | Hello first fragment
11 | Hello second fragment. Arg: %1$s
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/myweather/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.myweather;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath "com.android.tools.build:gradle:4.1.1"
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | google()
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Dec 29 13:59:10 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/image/1.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/image/20210114093921657.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yunkex/Weather-Forecast-App/d354aa80e22c242776e20aa4e9c23442f6b74101/image/20210114093921657.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name = "MyWeather"
--------------------------------------------------------------------------------