Skip to content

Commit

Permalink
publish 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wsj1024 committed Jul 22, 2021
1 parent df7799b commit 7761f5d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ class Forecast15dAdapter(val context: Context, val datas: List<Daily>) :
holder.tvWind.text = item.windDirDay
holder.tvWindScale.text = item.windScaleDay + ""

holder.tempChart.setData(mMin, mMax, item.tempMin.toInt(), item.tempMax.toInt())
holder.tempChart.setData(
mMin,
mMax,
if (position == 0) null else datas[position - 1],
item,
if (position == datas.size - 1) null else datas[position + 1]
)
}

val weeks = arrayOf("周日", "周一", "周二", "周三", "周四", "周五", "周六")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SplashActivity : AppCompatActivity() {
lifecycleScope.launch {
var citySize = 0

DensityUtil.setDensity(application, 418f)
// DensityUtil.setDensity(application, 418f)

withContext(Dispatchers.IO) {
val start = System.currentTimeMillis()
Expand Down
53 changes: 38 additions & 15 deletions app/src/main/java/me/wsj/fengyun/widget/TempChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Pair;
import android.view.View;

import androidx.annotation.Nullable;

import me.wsj.fengyun.R;
import me.wsj.fengyun.bean.Daily;
import per.wsj.commonlib.utils.DisplayUtil;

public class TempChart extends View {
Expand All @@ -20,7 +22,7 @@ public class TempChart extends View {

private int lowTemp, highTemp;

private int mWidth, mHeight;
private float mHalfWidth, mHeight;

private Paint mLowPaint, mHighPaint, mTextPaint;

Expand Down Expand Up @@ -58,22 +60,29 @@ private void init() {
mTextPaint.setColor(getResources().getColor(R.color.color_666));
textHeight = (int) (mTextPaint.getFontMetrics().bottom - mTextPaint.getFontMetrics().top);

int lineWidth = DisplayUtil.dip2px(getContext(), 2);
mLowPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mLowPaint.setStrokeWidth(10);
mLowPaint.setColor(Color.parseColor("#FF7200"));
mLowPaint.setStrokeWidth(lineWidth);
mLowPaint.setColor(Color.parseColor("#00A368"));

mHighPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHighPaint.setStrokeWidth(10);
mHighPaint.setColor(Color.parseColor("#00A368"));
mHighPaint.setStrokeWidth(lineWidth);
mHighPaint.setColor(Color.parseColor("#FF7200"));

pntRadius = DisplayUtil.dip2px(getContext(), 3);
}

public void setData(int minTemp, int maxTemp, int lowTemp, int highTemp) {
private Daily mPrev, mNext;


public void setData(int minTemp, int maxTemp, Daily prev, Daily current, Daily next) {
this.minTemp = minTemp;
this.maxTemp = maxTemp;
this.lowTemp = lowTemp;
this.highTemp = highTemp;
this.lowTemp = Integer.parseInt(current.getTempMin());
this.highTemp = Integer.parseInt(current.getTempMax());

mPrev = prev;
mNext = next;

lowText = lowTemp + "°C";
highText = highTemp + "°C";
Expand All @@ -88,29 +97,43 @@ public void setData(int minTemp, int maxTemp, int lowTemp, int highTemp) {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

mWidth = getMeasuredWidth();
mHalfWidth = getMeasuredWidth()/2f;
mHeight = getMeasuredHeight();

usableHeight = mHeight - topBottom * 2 - textHeight * 2;
usableHeight = (int) (mHeight - topBottom * 2 - textHeight * 2);

density = usableHeight / (float) tempDiff;
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.translate(mWidth / 2, 0);
canvas.translate(mHalfWidth, 0);

int topY = (int) ((maxTemp - highTemp) * density + topBottom + textHeight);
int bottomY = (int) ((maxTemp - lowTemp) * density + topBottom + textHeight);
canvas.drawCircle(0, topY, pntRadius, mLowPaint);
canvas.drawCircle(0, bottomY, pntRadius, mHighPaint);

canvas.drawCircle(0, topY, pntRadius, mHighPaint);
canvas.drawCircle(0, bottomY, pntRadius, mLowPaint);

canvas.drawText(highText, -lowTextWidth / 2, topY - mTextPaint.getFontMetrics().bottom * 2, mTextPaint);

canvas.drawText(lowText, -lowTextWidth / 2, bottomY + textHeight, mTextPaint);
}

if (mPrev != null) {
Pair<Integer, Integer> prev = getEnds(mPrev);
canvas.drawLine(-mHalfWidth, (prev.first + topY) / 2f, 0, topY, mHighPaint);
canvas.drawLine(-mHalfWidth, (prev.second + bottomY) / 2f, 0, bottomY, mLowPaint);
}
if (mNext != null) {
Pair<Integer, Integer> next = getEnds(mNext);
canvas.drawLine(0, topY, mHalfWidth, (next.first + topY) / 2f, mHighPaint);
canvas.drawLine(0, bottomY, mHalfWidth, (next.second + bottomY) / 2f, mLowPaint);
}
}

private Pair<Integer, Integer> getEnds(Daily daily) {
int topY = (int) ((maxTemp - Integer.parseInt(daily.getTempMax())) * density + topBottom + textHeight);
int bottomY = (int) ((maxTemp - Integer.parseInt(daily.getTempMin())) * density + topBottom + textHeight);
return new Pair<>(topY, bottomY);
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
- [x] 城市管理(定位添加)

## 下载体验
- 点击[![](https://img.shields.io/badge/Download-apk-green.svg)](https://www.pgyer.com/ENha)
- 点击[![](https://img.shields.io/badge/Download-apk-green.svg)](https://wangsj.oss-cn-shanghai.aliyuncs.com/fengyun/fengyun-weather-1.0.0.apk)
- 下方二维码下载(每日上限100次,如达到上限,还是 clone 源码吧!✧(≖ ◡ ≖✿)))<br/>
<img src="https://www.pgyer.com/app/qrcode/ENha"/>

Expand Down

0 comments on commit 7761f5d

Please sign in to comment.