Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加灾害预警功能 #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
apply plugin: 'com.android.application'
apply plugin: 'walle'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.heweather.owp"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

signingConfigs {
he {
keyAlias "heweather"
keyPassword "He123qwe."
storeFile rootProject.file("he.jks")
storePassword "He123qwe."
}
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.he
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.he
}
}
allprojects {
Expand All @@ -44,6 +54,23 @@ android {
release.setRoot('build-types/release')
}
}
buildscript {
repositories {
jcenter()
}
}
//生成渠道包 ./gradlew clean assembleReleaseChannels
//支持 productFlavors ./gradlew clean assembleMeituanReleaseChannels
//生成单个渠道包 ./gradlew clean assembleReleaseChannels -PchannelList=google
//生成多个渠道包 ./gradlew clean assembleReleaseChannels -PchannelList=google,dianping
walle {
// 指定渠道包的输出路径
apkOutputFolder = new File("${project.buildDir}/channels")
// 定制渠道包的APK的文件名称
apkFileNameFormat = '${appName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk'
// 渠道配置文件
channelFile = new File("${project.getProjectDir()}/channel")
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<!-- 设置key -->
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="高德的key" />
android:value="9656fca1e4cef43a19082b4f37b600bb" />

<service android:name="com.amap.api.location.APSService" />
<service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public void getAlarm(String location) {
@Override
public void onError(Throwable throwable) {
weatherInterface.getAlarm(null);
SpUtils.saveBean(context, "alarm", null);
Log.i("sky", "getAlarm onError: ");
Log.i("sky", "getAlarm onError: " + throwable);
}

@Override
Expand Down Expand Up @@ -140,7 +139,7 @@ public void onError(Throwable throwable) {
@Override
public void onSuccess(Search search) {
String parentCity = search.getBasic().get(0).getParent_city();
if (TextUtils.isEmpty(parentCity)){
if (TextUtils.isEmpty(parentCity)) {
parentCity = search.getBasic().get(0).getAdmin_area();
}
HeWeather.getAirNow(context, parentCity, lang, unit, new HeWeather.OnResultAirNowBeansListener() {
Expand All @@ -161,21 +160,21 @@ public void onSuccess(List<AirNow> list) {

@Override
public void getAirForecast(String location) {
HeWeather.getAirForecast(context, location, lang, unit, new HeWeather.OnResultAirForecastBeansListener() {
@Override
public void onError(Throwable throwable) {
Log.i(TAG, "getAirForecast onError: ");
AirForecast airForecast = SpUtils.getBean(context, "airForecast", AirForecast.class);
weatherInterface.getAirForecast(airForecast);
}

@Override
public void onSuccess(List<AirForecast> list) {
weatherInterface.getAirForecast(list.get(0));
SpUtils.saveBean(context, "airForecast", list.get(0));

}
});
// HeWeather.getAirForecast(context, location, lang, unit, new HeWeather.OnResultAirForecastBeansListener() {
// @Override
// public void onError(Throwable throwable) {
// Log.i(TAG, "getAirForecast onError: ");
// AirForecast airForecast = SpUtils.getBean(context, "airForecast", AirForecast.class);
// weatherInterface.getAirForecast(airForecast);
// }
//
// @Override
// public void onSuccess(List<AirForecast> list) {
// weatherInterface.getAirForecast(list.get(0));
// SpUtils.saveBean(context, "airForecast", list.get(0));
//
// }
// });
}


Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/heweather/owp/utils/ContentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
public class ContentUtil {

//用户id
public static final String APK_USERNAME = "和风天气获取的ID";
public static final String APK_USERNAME = "HE1903211415311839";
//用户key
public static final String APK_KEY = "和风天气获取的key";
public static final String APK_KEY = "a7b3fdf76a2b44fc91e36b2afe63d080";
//当前所在位置
public static Double NOW_LON = 116.40;
public static Double NOW_LAT = 39.9;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.heweather.owp.view.activity;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.heweather.owp.R;

Expand All @@ -17,5 +20,26 @@ public void onClick(View view) {
onBackPressed();
}
});

TextView tvVersion = findViewById(R.id.tv_version_num);
tvVersion.setText(getVersionName(this));
}

/**
* 获取versionName
*
* @param context 上下文
* @return 版本号
*/
private static String getVersionName(Context context) {
String versionName = "";
try {
versionName = context.getPackageManager().
getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "v" + versionName;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.heweather.owp.view.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -42,6 +44,7 @@
import interfaces.heweather.com.interfacesmodule.bean.air.now.AirNow;
import interfaces.heweather.com.interfacesmodule.bean.air.now.AirNowCity;
import interfaces.heweather.com.interfacesmodule.bean.alarm.Alarm;
import interfaces.heweather.com.interfacesmodule.bean.alarm.AlarmBase;
import interfaces.heweather.com.interfacesmodule.bean.weather.forecast.Forecast;
import interfaces.heweather.com.interfacesmodule.bean.weather.forecast.ForecastBase;
import interfaces.heweather.com.interfacesmodule.bean.weather.hourly.Hourly;
Expand Down Expand Up @@ -117,6 +120,7 @@ public class WeatherFragment extends Fragment implements WeatherInterface {
private GridLayout gridAir;
private SwipeRefreshLayout swipeRefreshLayout;
private TextView tvWeek1;
private TextView tvAlarm;

public static WeatherFragment newInstance(String cityId) {
WeatherFragment fragment = new WeatherFragment();
Expand Down Expand Up @@ -298,6 +302,16 @@ private void initView(View view) {
textViewList.add(tvLineMin);
tvLineMax = view.findViewById(R.id.tv_line_max_tmp);
textViewList.add(tvLineMax);
tvAlarm = view.findViewById(R.id.tv_today_alarm);
textViewList.add(tvAlarm);

TextView tvFrom = view.findViewById(R.id.tv_from);
tvFrom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startUri();
}
});

tvSunTitle = view.findViewById(R.id.tv_sun_title);
textViewList.add(tvSunTitle);
Expand Down Expand Up @@ -550,9 +564,51 @@ public void getWeatherForecast(Forecast bean) {
}
}

@SuppressLint("SetTextI18n")
@Override
public void getAlarm(Alarm bean) {

if (bean != null && bean.getAlarm().size() > 0 && bean.getAlarm().get(0) != null) {
tvAlarm.setVisibility(View.VISIBLE);
AlarmBase alarmBase = bean.getAlarm().get(0);
String level = alarmBase.getLevel();
String type = alarmBase.getType();
if (ContentUtil.SYS_LANG.equals("en")) {
tvAlarm.setText(type);
} else {
tvAlarm.setText(type + "预警");
}
if (!TextUtils.isEmpty(level)) {
switch (level) {
case "蓝色":
case "Blue":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_blue_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.white));
break;
case "黄色":
case "Yellow":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_yellow_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.white));
break;
case "橙色":
case "Orange":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_orange_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.white));
break;
case "红色":
case "Red":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_red_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.white));
break;
case "白色":
case "White":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_white_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.black));
break;
}
}
} else {
tvAlarm.setVisibility(View.GONE);
}
}

@Override
Expand Down Expand Up @@ -826,4 +882,10 @@ public void setUserVisibleHint(boolean isVisibleToUser) {
hasAni = true;
}
}

private void startUri() {
Uri uri = Uri.parse("https://www.heweather.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_blue_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/blue_alarm" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_orange_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/orange_alarm" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_red_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/red_alarm" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_white_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_yellow_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/yellow_alarm" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
18 changes: 17 additions & 1 deletion app/src/main/res/layout/fragment_weather.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:tools="http:https://schemas.android.com/tools"
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:background="@color/back_white"
android:layout_height="match_parent"
android:background="@color/back_white"
tools:context=".view.fragment.WeatherFragment">

<android.support.v4.widget.NestedScrollView
Expand Down Expand Up @@ -66,6 +66,22 @@
android:textColor="@color/white80"
android:textSize="16sp" />

<TextView
android:id="@+id/tv_today_alarm"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_below="@+id/tv_today_cond"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:background="@drawable/shape_blue_alarm"
android:gravity="center"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:text="暴雨预警"
android:textColor="@color/white80"
android:textSize="12sp"
android:visibility="gone" />

</RelativeLayout>

<LinearLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/layout_today_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@
</LinearLayout>

<TextView
android:id="@+id/tv_from"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/back_white"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@
<string name="Cape_Town">Cape Town</string>
<string name="Bangkok">Bangkok</string>
<string name="Madrid">Madrid</string>
<string name="powered">Powered By heweather.com</string>

</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<color name="aqi_color_light">#B9C0CA</color>
<color name="color_8E8E93">#8E8E93</color>

<color name="red_alarm">#c01b09</color>
<color name="blue_alarm">#318bf8</color>
<color name="yellow_alarm">#d1ca13</color>
<color name="orange_alarm">#d76801</color>

<color name="dark_line">#1D2834</color>
<color name="set_line">#2E3A48</color>
<color name="light_line">#EDEEF0</color>
Expand Down
Binary file added he.jks
Binary file not shown.