From 11d492c8fad9d398395d8394dce4286c6d31ebdb Mon Sep 17 00:00:00 2001 From: seven332 Date: Sat, 27 Feb 2016 17:35:50 +0800 Subject: [PATCH] Improve download item UI --- .../java/com/hippo/ehviewer/CardBgTest.java | 164 ++++++++++++++++++ .../res/drawable-hdpi/card_grey_2dp.9.png | Bin 0 -> 375 bytes .../res/drawable-mdpi/card_grey_2dp.9.png | Bin 0 -> 250 bytes .../res/drawable-xhdpi/card_grey_2dp.9.png | Bin 0 -> 342 bytes .../res/drawable-xxhdpi/card_grey_2dp.9.png | Bin 0 -> 643 bytes app/src/main/res/drawable/card_background.xml | 2 +- app/src/main/res/layout/scene_download.xml | 16 +- app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 app/src/androidTest/java/com/hippo/ehviewer/CardBgTest.java create mode 100644 app/src/main/res/drawable-hdpi/card_grey_2dp.9.png create mode 100644 app/src/main/res/drawable-mdpi/card_grey_2dp.9.png create mode 100644 app/src/main/res/drawable-xhdpi/card_grey_2dp.9.png create mode 100644 app/src/main/res/drawable-xxhdpi/card_grey_2dp.9.png diff --git a/app/src/androidTest/java/com/hippo/ehviewer/CardBgTest.java b/app/src/androidTest/java/com/hippo/ehviewer/CardBgTest.java new file mode 100644 index 000000000..f48cf5b35 --- /dev/null +++ b/app/src/androidTest/java/com/hippo/ehviewer/CardBgTest.java @@ -0,0 +1,164 @@ +/* + * Copyright 2016 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.RectF; +import android.os.Environment; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; + +public class CardBgTest extends TestCase { + + private static final float[] TOP_ALPHA = { + 0f, // Dump + 0.12f, + 0.16f, + 0.19f, + 0.25f, + 0.30f, + }; + + private static final float[] TOP_OFFSET = { + 0f, // Dump + 1f, + 3f, + 10f, + 14f, + 19f, + }; + + private static final float[] TOP_BLUR = { + 0f, // Dump + 1.5f, + 3f, + 10f, + 14f, + 19f, + }; + + private static final float[] BOTTOM_ALPHA = { + 0f, // Dump + 0.24f, + 0.23f, + 0.23f, + 0.22f, + 0.22f, + }; + + private static final float[] BOTTOM_OFFSET = { + 0f, // Dump + 1f, + 3f, + 6f, + 10f, + 15f, + }; + + private static final float[] BOTTOM_BLUR = { + 0f, // Dump + 1f, + 3f, + 3f, + 5f, + 6f, + }; + + private static final int MAX_SIZE = 200; + + + public void testGen() throws FileNotFoundException { + genCardBg(Color.WHITE, 2, 2); + } + + private Path getPath(float radius, float base) { + RectF rectF = new RectF(); + Path path = new Path(); + path.moveTo(base / 2, -base / 2 - radius); + rectF.set(base / 2 - radius, -base / 2 - radius, base / 2 + radius, -base / 2 + radius); + path.arcTo(rectF, -90, 90); + path.lineTo(base / 2 + radius, base / 2); + rectF.set(base / 2 - radius, base / 2 - radius, base / 2 + radius, base / 2 + radius); + path.arcTo(rectF, 0, 90); + path.lineTo(-base / 2, base / 2 + radius); + rectF.set(-base / 2 - radius, base / 2 - radius, -base / 2 + radius, base / 2 + radius); + path.arcTo(rectF, 90, 90); + path.lineTo(-base / 2 - radius, -base / 2); + rectF.set(-base / 2 - radius, -base / 2 - radius, -base / 2 + radius, -base / 2 + radius); + path.arcTo(rectF, 180, 90); + path.close(); + return path; + } + + private void genCardBg(int color, float radius, int elevation) throws FileNotFoundException { + + float base = 4; + float topAlpha = TOP_ALPHA[elevation]; + float topOffset = TOP_OFFSET[elevation]; + float topBlur = TOP_BLUR[elevation]; + float bottomAlpha = BOTTOM_ALPHA[elevation]; + float bottomOffset = BOTTOM_OFFSET[elevation]; + float bottomBlur = BOTTOM_BLUR[elevation]; + + + float ratio = 3; + + + doGenCardBg(new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "test.png")), + color, radius * ratio, base * ratio, + topAlpha, topOffset * ratio, topBlur * ratio, + bottomAlpha, bottomOffset * ratio, bottomBlur * ratio); + + + } + + private int getColor(float alpha) { + return Color.argb((int) (alpha * 0xff), 0, 0, 0); + } + + private void doGenCardBg(OutputStream os, int color, float radius, float base, + float topAlpha, float topOffset, float topBlur, + float bottomAlpha, float bottomOffset, float bottomBlur) throws FileNotFoundException { + + Path path = getPath(radius, base); + path.offset(MAX_SIZE / 2, MAX_SIZE / 2); + + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); + paint.setColor(color); + Bitmap bitmap = Bitmap.createBitmap(MAX_SIZE, MAX_SIZE, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + + // Draw bottom + paint.setShadowLayer(bottomBlur, 0, bottomOffset, getColor(bottomAlpha)); + canvas.drawPath(path, paint); + + // Draw top + paint.setShadowLayer(topBlur, 0, topOffset, getColor(topAlpha)); + canvas.drawPath(path, paint); + + bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); + } +} diff --git a/app/src/main/res/drawable-hdpi/card_grey_2dp.9.png b/app/src/main/res/drawable-hdpi/card_grey_2dp.9.png new file mode 100644 index 0000000000000000000000000000000000000000..dbb819aa3a32e048a948435b29ece571f79b483c GIT binary patch literal 375 zcmV--0f_#IP)lngpBOWTeqtuGW&5}L?2#(NsEJWf z!ZZlAVRVc@blEC6N`(nAv4?RMBU?;4h42s+XyKA3OOAXXIkKd2u>=RH+^C7yJ^%IQ ze?Kn2-gM9LFy+Pvu6#SMPu3%+GQ8BQ|aFhroui9j=F;J&e5$cfRbUEde z9F9eLnsF;f0qP~wFOHR`j}sPICG3yuQi zA8a}fIOm2tN<7R`;*J~6IS4dexYbEh;E*Fu0y*N40_nI`-(i5+X;|BCFpXxtO#`Y7 V8XX;UD5U@Z002ovPDHLkV1gc7rThQ@ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/card_grey_2dp.9.png b/app/src/main/res/drawable-mdpi/card_grey_2dp.9.png new file mode 100644 index 0000000000000000000000000000000000000000..14dbd13b1cd6869809a0c528968333ff49baa637 GIT binary patch literal 250 zcmVVe1RZ?R-VUqF*jrM3oITWjG0hcIq#?$|>>)lG)ua0KSL@(rCFK4FCWD07*qoM6N<$g4Xn5 AOaK4? literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/card_grey_2dp.9.png b/app/src/main/res/drawable-xhdpi/card_grey_2dp.9.png new file mode 100644 index 0000000000000000000000000000000000000000..48fcc74262c1b6865b08f5e80eca2ff7f5441030 GIT binary patch literal 342 zcmV-c0jd6pP)wKTYgFOa#16mG(HPN_*sW3W^nP$B7kh zd$EX5knjtS literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/card_grey_2dp.9.png b/app/src/main/res/drawable-xxhdpi/card_grey_2dp.9.png new file mode 100644 index 0000000000000000000000000000000000000000..71173615cc30de41b01cfdf398659a07b084bf05 GIT binary patch literal 643 zcmV-}0(||6P)kq+5Nhv!%Zkar9!Lm7Y>o)aEC z*kjC=qG?tYg(~sw-<5mYR(=WtS_xg zyQk~)n~^vsFHc-oFTpfGK2BM}2)^7~x|m|s@8bj4nnCr>bjbx+_~|ttU*u!#(VtQP zJ@V8$Rt518fGUt#NQJcx6uY{2kzk5QqG^EH76M7ApwkQ%0xYVnO#pVMe*ja>U`7u* zpbBIbOYlPiu$Kh?;s_-xxt0fQ<$)*!SX}!q0oaHB0!%3nN0vdd)gxr^Z33__gX$4V z(jqCgQ!o#f)V@go_M<=1z!EA>2>z9%7L?UeU=B`c3q1I39?XMe_&j}lU{}WDvfq1- z(tn3*WjzlmVi^jN;8W=bd&*q3XE_wD-xD*AsZ=l@NcuY8SK$^e>v^%;)}0@42J zo0}QVsGtW*)6BF4Xl_W6n8Qn%R5_&J_R|BRZ%A99$8UMCX*3!(895_S^dH=#|L`SA dQwNkQ0svT5cp*gl5={UA002ovPDHLkV1k(!9oPT> literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable/card_background.xml b/app/src/main/res/drawable/card_background.xml index 3bf952060..5537b2d90 100644 --- a/app/src/main/res/drawable/card_background.xml +++ b/app/src/main/res/drawable/card_background.xml @@ -18,7 +18,7 @@ - + diff --git a/app/src/main/res/layout/scene_download.xml b/app/src/main/res/layout/scene_download.xml index 52cb7822c..e154ee98f 100644 --- a/app/src/main/res/layout/scene_download.xml +++ b/app/src/main/res/layout/scene_download.xml @@ -54,6 +54,7 @@ + android:src="@drawable/ic_check_all_dark_x24" + app:backgroundTint="?attr/colorPrimary"/> + android:src="@drawable/ic_play_dark_x24" + app:backgroundTint="?attr/colorPrimary"/> + android:src="@drawable/ic_pause_dark_x24" + app:backgroundTint="?attr/colorPrimary"/> + android:src="@drawable/ic_close_dark_x24" + app:backgroundTint="?attr/colorPrimary"/> + android:src="@drawable/ic_folder_move_dark_x24" + app:backgroundTint="?attr/colorPrimary"/> %1$d 项下载成功,%2$d 项下载失败 下载成功:%s 下载失败:%s - 移除画廊 + 移除下载项 从下载列表移除 %s ? 删除图片文件 全部停止 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 119ebbd87..c23681aa6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -230,7 +230,7 @@ %1$d succeeded, %2$d failed Succeeded: %s Failed: %s - Remove Gallery + Remove Download Item Remove %s from download list ? Delete image files Stop All