Skip to content

Commit

Permalink
release v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
li-yu committed Dec 15, 2017
1 parent e07770d commit 814abdd
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 38 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
## 假装看天气 ##
![screenshot](screenshot.jpg)

>2017-12-15 更新:
时间过得很快,这个项目已经有一年了,因为是练手的项目,写完之后也没过多的维护,直到有一次在站酷上看到一个[天气设计原型](http://www.zcool.com.cn/work/ZMjE1MDgwMjQ=.html),然后我把天气模块给重写了。

更多细节可以查看最新博文[**《重构天气》**](http://liyuyu.cn/2017/12/15/Refactor-fake-weather/)

这个项目的前身原本只是为了实现公交查询而练手的 App,一次偶然的机会,看到了开源项目 [就看天气](https://github.com/xcc3641/SeeWeather),我被这单纯而简单的天气软件所吸引,所以增加了天气查询功能。工作这么多年我一直觉得,很多新的特性和技术很少在工作项目中应用到,所以有了利用空闲时间持续学习和开发的打算。后面增加了 [闲读](http://gank.io/xiandu) 和妹子图等模块,整个 App 变成了一个大杂烩,索性就叫『假装看天气』吧。

整个项目未完全遵循 Material Design 风格,同时在构架和编码方面可能也不尽如人意,但作为现阶段的学习和总结,我希望可以给大家带来帮助。
### 简介 ###
『假装看天气』─── 天气预报 & 公交查询 & 资讯阅读 & 妹纸福利 的 Android 客户端

- 天气,自动定位当前城市,获取天气信息,支持分享和 TTS 语音播报
- 天气,自动定位当前城市,11 种动态天气效果
- 公交,定位搜索附近线路和站台,支持手动查询和收藏(仅苏州)
- 闲读,阅读最新科技资讯,读那些值得读的
- 福利,大量妹子图,你懂的,还不赶紧上车
Expand All @@ -16,15 +23,13 @@

### 下载

[直接下载 v1.2.8_20170809](http://7xp1a1.com1.z0.glb.clouddn.com/FakeWeather/FakeWeather_v1.2.8_20170809.apk)
[直接下载 v1.3.0_20171215](http://7xp1a1.com1.z0.glb.clouddn.com/FakeWeather/FakeWeather_v1.3.0_20171215.apk)

![qcode](qcode.png)

### 截图 ###

![screenshot](screenshot.png)

### 特别感谢 ###
- [天气视觉探索-尝试方案](http://www.zcool.com.cn/work/ZMjE1MDgwMjQ=.html)
- [ZUI-Weather](http://www.zcool.com.cn/work/ZMjMwNDMxNDA=.html)
- [干货集中营](http://gank.io) 提供闲读和部分妹子数据
- [就看天气](https://github.com/xcc3641/SeeWeather) 提供学习灵感
- [妹纸&gank.io](https://github.com/drakeet/Meizhi) 提供学习参考
Expand All @@ -41,6 +46,7 @@
- [Retrofit](https://github.com/square/retrofit)
- [LitePal](https://github.com/LitePalFramework/LitePal)
- [EventBus](https://github.com/greenrobot/EventBus)
- [Lottie-android](https://github.com/airbnb/lottie-android)
- [RxAndroid](https://github.com/ReactiveX/RxAndroid)
- [SeeWeather](https://github.com/xcc3641/SeeWeather)
- [RxBinding](https://github.com/JakeWharton/RxBinding)
Expand All @@ -53,7 +59,7 @@
### 免责声明 ###

- 项目中部分图片素材来自网络,版权归属原作者,侵立删
- 项目中所使用的 api 均搜集于网络,仅供学习和交流使用
- 项目中所使用的 api 部分搜集于网络,仅供学习和交流使用

### License ###
[Apache License
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.liyu.fakeweather"
minSdkVersion 19
targetSdkVersion 25
versionCode 12
versionName "1.2.8"
versionCode 13
versionName "1.3.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public List<WeatherCity> call(BDLocation bdLocation) {
values.put("cityId", city.getCityId());
DataSupport.updateAll(WeatherCity.class, values, "cityName = ?", nowCity);
} else {
DataSupport.deleteAll(WeatherCity.class, "cityIndex = 0");
city.save();
savedCities.add(0, city);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.animation.AnimationUtils;

import com.liyu.fakeweather.model.IFakeWeather;
Expand All @@ -26,6 +27,7 @@ public class DynamicWeatherView extends SurfaceView implements SurfaceHolder.Cal
private int mViewHeight;
private IFakeWeather originWeather;
int fromColor;
private SurfaceHolder holder;

public DynamicWeatherView(Context context) {
this(context, null);
Expand All @@ -39,9 +41,9 @@ public DynamicWeatherView(Context context, AttributeSet attrs, int defStyleAttr)
super(context, attrs, defStyleAttr);
mContext = context;
weatherType = new DefaultType(context);
getHolder().setFormat(PixelFormat.RGBA_8888);
getHolder().addCallback(this);

holder = getHolder();
holder.addCallback(this);
holder.setFormat(PixelFormat.RGBA_8888);
}

public int getColor() {
Expand Down Expand Up @@ -132,7 +134,6 @@ public void onDestroy() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
mDrawThread = new DrawThread();
mDrawThread.mSurface = holder;
mDrawThread.setRunning(true);
mDrawThread.start();
weatherType.startAnimation(this, weatherType.getColor());
Expand All @@ -149,8 +150,6 @@ public void surfaceDestroyed(SurfaceHolder holder) {

private class DrawThread extends Thread {

private SurfaceHolder mSurface;

private boolean isRunning = false;

private boolean suspended = false;
Expand Down Expand Up @@ -183,17 +182,17 @@ public void run() {
e.printStackTrace();
}
}
// final long startTime = AnimationUtils.currentAnimationTimeMillis();
Canvas canvas = mSurface.lockCanvas();
final long startTime = AnimationUtils.currentAnimationTimeMillis();
Canvas canvas = holder.lockCanvas();
if (canvas != null) {
weatherType.onDrawElements(canvas);
mSurface.unlockCanvasAndPost(canvas);
// final long drawTime = AnimationUtils.currentAnimationTimeMillis() - startTime;
// final long needSleepTime = 16 - drawTime;
holder.unlockCanvasAndPost(canvas);
final long drawTime = AnimationUtils.currentAnimationTimeMillis() - startTime;
final long needSleepTime = 16 - drawTime;
System.out.print("fuck");
// if (needSleepTime > 0) {
// SystemClock.sleep(needSleepTime);
// }
if (needSleepTime > 0) {
SystemClock.sleep(needSleepTime);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class SunnyType extends BaseWeatherType {

private float φ;

private Shader shader;
private Shader shaderRear;
private Shader shaderFront;

private float boardSpeed;

Expand All @@ -65,13 +66,17 @@ public class SunnyType extends BaseWeatherType {

private static final int colorNight = 0xFF7F9EE9;

private static final int colorWaveStartNight = 0x337187DB;
private static final int colorWaveStartNight = 0x1A3A66CF;

private static final int colorWaveEndNight = 0xFF7187DB;
private static final int colorWaveEndNightRear = 0x803A66CF;

private static final int colorWaveStartDay = 0x33FFFFFF;
private static final int colorWaveEndNightFront = 0xE63A66CF;

private static final int colorWaveEndDay = 0xFFFFFFFF;
private static final int colorWaveStartDay = 0x1AFFFFFF;

private static final int colorWaveEndDayRear = 0x80FFFFFF;

private static final int colorWaveEndDayFront = 0xE6FFFFFF;

private float currentSunPosition;
private float currentMoonPosition;
Expand Down Expand Up @@ -134,8 +139,11 @@ public void onDrawElements(Canvas canvas) {
mPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur.SOLID));
canvas.drawCircle(sunPos[0], sunPos[1], 40, mPaint);
mPaint.setMaskFilter(null);
if (shader == null) {
shader = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartDay, colorWaveEndDay, Shader.TileMode.CLAMP);
if (shaderRear == null) {
shaderRear = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartDay, colorWaveEndDayRear, Shader.TileMode.CLAMP);
}
if (shaderFront == null) {
shaderFront = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartDay, colorWaveEndDayFront, Shader.TileMode.CLAMP);
}
} else if (currentMoonPosition >= 0 && currentMoonPosition <= 1) {
mPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur.SOLID));
Expand All @@ -144,18 +152,22 @@ public void onDrawElements(Canvas canvas) {
canvas.drawCircle(moonPos[0] + 20, moonPos[1] - 20, 40, mPaint);
mPaint.setColor(Color.WHITE);
mPaint.setMaskFilter(null);
if (shader == null) {
shader = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartNight, colorWaveEndNight, Shader.TileMode.CLAMP);
if (shaderRear == null) {
shaderRear = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartNight, colorWaveEndNightRear, Shader.TileMode.CLAMP);
}
if (shaderFront == null) {
shaderFront = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartNight, colorWaveEndNightFront, Shader.TileMode.CLAMP);
}
} else {
mPaint.setMaskFilter(null);
if (shader == null) {
shader = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartNight, colorWaveEndNight, Shader.TileMode.CLAMP);
if (shaderRear == null) {
shaderRear = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartNight, colorWaveEndNightRear, Shader.TileMode.CLAMP);
}
if (shaderFront == null) {
shaderFront = new LinearGradient(0, getHeight(), getWidth(), getHeight(), colorWaveStartNight, colorWaveEndNightFront, Shader.TileMode.CLAMP);
}
}

mPaint.setShader(shader);

φ -= 0.05f;

float y, y2;
Expand Down Expand Up @@ -183,7 +195,7 @@ public void onDrawElements(Canvas canvas) {
mPathFront.lineTo(getWidth() + boat.getWidth() * bitmapScale, getHeight());
mPathRear.lineTo(getWidth() + boat.getWidth() * bitmapScale, getHeight());

mPaint.setAlpha(60);
mPaint.setShader(shaderRear);
canvas.drawPath(mPathRear, mPaint);

measure.setPath(mPathFront, false);
Expand All @@ -195,7 +207,8 @@ public void onDrawElements(Canvas canvas) {
mMatrix.postTranslate(pos[0] - boat.getWidth() / 2 * bitmapScale, pos[1] - boat.getHeight() * bitmapScale + 4);
mPaint.setAlpha(255);
canvas.drawBitmap(boat, mMatrix, mPaint);
mPaint.setAlpha(100);

mPaint.setShader(shaderFront);
canvas.drawPath(mPathFront, mPaint);

if (!isCloud)
Expand Down
Binary file modified qcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshot.png
Binary file not shown.

0 comments on commit 814abdd

Please sign in to comment.