2024-12-17 完善程序功能,SDK 接口调试完毕 #1

Merged
JRNitre merged 1 commits from main into master 2024-12-17 19:33:58 +08:00
13 changed files with 410 additions and 6 deletions

View File

@ -13,9 +13,11 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
@ -40,6 +42,7 @@ import com.example.weather.data.MyCity;
import com.example.weather.data.RainData;
import com.example.weather.util.QuoteUtil;
import com.example.weather.util.SpfUtil;
import com.example.weather.view.moreInfo;
import com.facebook.stetho.Stetho;
import com.google.gson.Gson;
import com.qweather.sdk.bean.base.Code;
@ -76,6 +79,10 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
private boolean state = false;//分钟级降水数据收缩 false 收缩 true 展开
private int wallpaper;
private String imagePath;
private List<MyCity> saveCityList; // 获取保存的城市信息
private PopupWindow infoPopupWindow; // 新增用于显示更多信息的 PopupWindow
public static final String KEY_WALLPAPER = "wallpaper_id";
public static final String KEY_IMAGEPATH = "image_path";
@ -96,7 +103,6 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat();
String formattedTime = sdf.format(date).substring(11);
Log.v("test", formattedTime);
// 地图接口
MapsInitializer.updatePrivacyShow(this, true, true);
@ -110,9 +116,14 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
hoursWeather = findViewById(R.id.hoursWeather);
daysWeather = findViewById(R.id.daysWeather);
// 上一次更新天气的时间
// TODO 这里的时间显示格式有问题
tv_lastTime.setText(tv_lastTime.getText() + formattedTime);
// 初始化数据库
cityDbOpenHelper = new CityDbOpenHelper(this);
// 设置状态栏为透明
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
);
@ -134,6 +145,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
findViewById(R.id.tv_precMore).setOnClickListener(this);
findViewById(R.id.tv_moreDays).setOnClickListener(this);
findViewById(R.id.iv_add).setOnClickListener(this);
//和风sdk key
HeConfig.init("CFB4NCKPV7", "c9762ba50c6249878a12aff7f1d8356f");
@ -142,6 +154,16 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
// HeConfig.switchToBizService();
// 免费订阅
HeConfig.switchToDevService();
// 初始化完毕调用 SDK 获取天气信息
saveCityList = new ArrayList<>();
saveCityList = cityDbOpenHelper.queryAllFromDb();
// 调取保存的城市列表中的第一个城市进行显示
String city = saveCityList.get(0).getCity_name();
tv_City.setText(city);
getCityId(city);
}
@Override
@ -161,13 +183,11 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
Intent intent = new Intent(this, MapActivity.class);
startActivity(intent);
} else if (view.getId() == R.id.tv_precMore) {
Log.d("hhz", "onClick: " + state);
if (state) {//收缩
fore_rain.setVisibility(View.GONE);
state = false;
tvPrecMore.setText("查看详情");
} else {//展开
// AnimationUtil.collapse(fore_rain, findViewById(R.id.tv_precMore));
fore_rain.setVisibility(View.VISIBLE);
state = true;
tvPrecMore.setText("收起详情");
@ -196,6 +216,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
mPopupWindow.showAsDropDown(view, -100, 0);
TextView changeCity = mPopupWindow.getContentView().findViewById(R.id.tv_change_city);//切换城市
TextView wallpaper = mPopupWindow.getContentView().findViewById(R.id.tv_wallpaper);//壁纸管理
TextView more = mPopupWindow.getContentView().findViewById(R.id.tv_more);//更多
changeCity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -216,6 +237,93 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
mPopupWindow.dismiss();
}
});
more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mPopupWindow == null) {
View contentView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.mpopupwindow, null, false);
mPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
// 设置属性
mPopupWindow.setBackgroundDrawable(new ColorDrawable(0x0000)); // 设置pop透明效果
mPopupWindow.setAnimationStyle(R.anim.cp_push_bottom_in);
mPopupWindow.setFocusable(true); // 设置pop获取焦点
mPopupWindow.setTouchable(true); // 设置pop可点击
mPopupWindow.setOutsideTouchable(true); // 设置点击pop外侧消失
// 设置点击监听器
TextView changeCity = contentView.findViewById(R.id.tv_change_city); // 切换城市
TextView wallpaper = contentView.findViewById(R.id.tv_wallpaper); // 壁纸管理
TextView more = contentView.findViewById(R.id.tv_more); // 更多
changeCity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, WeatherCardActivity.class);
intent.putExtra("id", LocationID);
intent.putExtra("city", locateCity);
intent.putExtra("province", locateProvince);
startActivity(intent);
mPopupWindow.dismiss();
}
});
wallpaper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, ChangeWallpaper.class); // 调用活动ChangeWallpaper
startActivity(intent);
mPopupWindow.dismiss();
}
});
more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 如果 infoPopupWindow 尚未初始化则进行初始化
if (infoPopupWindow == null) {
View popupView = LayoutInflater.from(MainActivity.this).inflate(R.layout.popup_info, null);
TextView infoText = popupView.findViewById(R.id.tv_info_text);
Button closeButton = popupView.findViewById(R.id.btn_close_popup);
// 设置信息文本可以根据需要动态设置
// infoText.setText("这里是更多详细信息");
// 关闭按钮的点击监听器
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (infoPopupWindow != null && infoPopupWindow.isShowing()) {
infoPopupWindow.dismiss();
}
}
});
// 初始化 infoPopupWindow
infoPopupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
infoPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
infoPopupWindow.setOutsideTouchable(true);
infoPopupWindow.setFocusable(true);
}
// 显示 infoPopupWindow
if (!infoPopupWindow.isShowing()) {
infoPopupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.CENTER, 0, 0);
}
// 避免同时显示两个 PopupWindow
if (mPopupWindow != null && mPopupWindow.isShowing()) {
mPopupWindow.dismiss();
}
}
});
}
// 显示主 PopupWindow
mPopupWindow.showAsDropDown(findViewById(android.R.id.content).getRootView(), -100, 0);
}
});
}
private void initLocation() {
@ -269,7 +377,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
MyCity myCity1 = new MyCity(locateCity, LocationID);
cityDbOpenHelper.insertData(myCity1);
Log.i(TAG, LocationID);
getNowTemp("101020100");
getNowTemp(LocationID);
getRain(lon, lat);
getTodayTemp(LocationID);
getHoursTemp(LocationID);
@ -489,6 +597,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
}
});
} else {
// 如果没有可用警告信息则调取一个名言显示
QuoteUtil.getQuote(new QuoteUtil.QuoteCallback() {
@Override
public void onSuccess(String quote) {

View File

@ -116,6 +116,7 @@ public class WeatherCardActivity extends AppCompatActivity implements View.OnCli
@Override
public void onLocate() {
// TODO 需要实现系统定位功能
//定位接口需要APP自身实现这里模拟一下定位
new Handler().postDelayed(new Runnable() {
@Override

View File

@ -0,0 +1,62 @@
package com.example.weather.view;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.weather.R;
public class moreInfo extends AppCompatActivity implements View.OnClickListener{
TextView bgTv,cacheTv,versionTv,shareTv;
ImageView backIv;
private SharedPreferences pref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
}
private void setRGListener() {
}
private String getVersionName() {
/* 获取应用的版本名称*/
PackageManager manager = getPackageManager();
String versionName = null;
try {
PackageInfo info = manager.getPackageInfo(getPackageName(), 0);
versionName = info.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionName;
}
@Override
public void onClick(View v) {
}
private void shareSoftwareMsg(String s) {
/* 分享软件文本的函数*/
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT,s);
startActivity(Intent.createChooser(intent,"知我天气"));
}
private void clearCache() {
}
}

View File

@ -0,0 +1,15 @@
<!-- res/drawable/rounded_background.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 设置背景颜色 -->
<solid android:color="@color/blue" />
<!-- 设置圆角 -->
<corners android:radius="16dp" /> <!-- 可以根据需要调整圆角半径 -->
<!-- 设置内边距Padding用于控制内容与边框之间的距离 -->
<padding
android:left="16dp"
android:top="16dp"
android:right="16dp"
android:bottom="16dp" />
</shape>

View File

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#F5F5F5"
android:id="@+id/more_top_layout">
<ImageView
android:id="@+id/more_iv_back"
android:layout_width="wrap_content"
android:src="@mipmap/icon_back"
android:layout_marginLeft="10dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/more_tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="更多设置"
android:textStyle="bold"
android:textSize="18sp"
android:layout_centerInParent="true"/>
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/more_top_layout"
android:background="#dcdcdc"
android:id="@+id/more_line1"/>
<TextView
android:id="@+id/more_tv_exchangebg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/more_line1"
android:drawableLeft="@mipmap/more_bg"
android:drawablePadding="20dp"
android:padding="10dp"
android:text="改变壁纸"
android:textSize="18sp" />
<ImageView
android:id="@+id/more_line2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/more_tv_exchangebg"
android:background="#DCDCDC"/>
<RadioGroup
android:id="@+id/more_rg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/more_line2"
android:visibility="gone"
android:orientation="horizontal">
<RadioButton
android:id="@+id/more_rb_green"
android:layout_width="0dp"
android:layout_height="40dp"
android:background="#C5EDD1"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:text="青瓦白墙"
android:textStyle="bold"/>
<RadioButton
android:id="@+id/more_rb_pink"
android:layout_width="0dp"
android:layout_height="40dp"
android:background="#FCAFAE"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:text="粉状玉砌"
android:textStyle="bold"/>
<RadioButton
android:id="@+id/more_rb_blue"
android:layout_width="0dp"
android:layout_height="40dp"
android:background="#87CEEB"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:text="蓝色梦想"
android:textStyle="bold"/>
</RadioGroup>
<TextView
android:id="@+id/more_tv_version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="当前版本"
android:textSize="18sp"
android:drawableLeft="@mipmap/more_version"
android:layout_below="@id/more_rg"
android:drawablePadding="20dp"
android:padding="10dp"/>
<ImageView
android:id="@+id/more_line3"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/more_tv_version"
android:background="#DCDCDC"/>
<TextView
android:id="@+id/more_tv_cache"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="清除缓存"
android:textSize="18sp"
android:drawableLeft="@mipmap/more_cache"
android:layout_below="@id/more_line3"
android:drawablePadding="20dp"
android:padding="10dp"/>
<ImageView
android:id="@+id/more_line4"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/more_tv_cache"
android:background="#DCDCDC"/>
<TextView
android:id="@+id/more_tv_share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="分享软件"
android:textSize="18sp"
android:drawableLeft="@mipmap/more_share"
android:layout_below="@id/more_line4"
android:drawablePadding="20dp"
android:padding="10dp"/>
</RelativeLayout>

View File

@ -40,7 +40,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="城市"
android:text="test"
android:textColor="@color/white"
android:textSize="25sp" />
@ -267,7 +267,9 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/hoursWeather"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:background="@drawable/rounded_background"
/>
<!--用于显示天气预报数据-->

View File

@ -35,6 +35,16 @@
android:textColor="@color/black"
android:textSize="16sp"/>
<TextView
android:id="@+id/tv_more"
android:gravity="center"
android:layout_width="140dp"
android:layout_height="48dp"
android:text="更多"
android:foreground="@drawable/bg_white"
android:textColor="@color/black"
android:textSize="16sp"/>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="@android:color/white">
<TextView
android:id="@+id/tv_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="天气查询系统 V0.1"
android:textSize="16sp"
android:padding="16dp"/>
<TextView
android:id="@+id/tv_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="罗梓源 - 2022810618"
android:textSize="13sp"
android:padding="10dp"/>
<TextView
android:id="@+id/tv_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="秦水源 - 2022810623"
android:textSize="13sp"
android:padding="10dp"/>
<TextView
android:id="@+id/tv_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="杜智暄 - 2022810602"
android:textSize="13sp"
android:padding="16dp"/>
<TextView
android:id="@+id/tv_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="闫 烽 - 2022810635"
android:textSize="13sp"
android:padding="10dp"/>
<TextView
android:id="@+id/tv_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="袁梦豪 - 2022810638"
android:textSize="13sp"
android:padding="10dp"/>
<TextView
android:id="@+id/tv_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Copy by JRNitre"
android:textSize="8sp"
android:padding="10dp"/>
<Button
android:id="@+id/btn_close_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="关闭"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"/>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB