1. 程式人生 > >仿微信運動步數折線統計圖

仿微信運動步數折線統計圖

完整程式碼如下

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.RectF
; import android.graphics.Shader; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils
; import com.ast.smartlighter.R; import com.ast.smartlighter.utils.UIUtils; import java.util.ArrayList; import java.util.List; //仿微信運動步數折線分佈圖 public class WXSportStatistics extends View implements OnTouchListener { float mHigh = 0; float Width = 0; List<String> listValue = new ArrayList<String
>(); List<RectF> listRectF = new ArrayList<RectF>(); List<String> listDAY = new ArrayList<String>(); boolean isKcal = false; Float MaxValue = 0f; private Paint paintbg; private Paint paintCircle; private Paint paintLine; private Paint paint; private Paint paintText; private Paint paintText2; private Path path; Shader mShader; int color_w = Color.argb(200, 255, 255, 255); int CircleR = 5; //4fd4d0 int bottomH = 0;//距離底部高度,給文字顯示用的 int topH = 0;//距離頂部部高度,給選中後的文字顯示用的 Context context; public int select = -1; public int selectbottom = -1; public WXSportStatistics(Context context, AttributeSet attrs) { super(context, attrs); CircleR = UIUtils.dip2px(context, 3); bottomH = UIUtils.dip2px(context, 12); topH = UIUtils.dip2px(context, 16); this.context = context; initView(); } public WXSportStatistics(Context context) { super(context); CircleR = UIUtils.dip2px(context, 3); bottomH = UIUtils.dip2px(context, 12); topH = UIUtils.dip2px(context, 16); this.context = context; initView(); } private void initView() { setOnTouchListener(this); mHigh = getHeight(); Width = getWidth(); paint = new Paint(); paint.setAntiAlias(true); paint.setStrokeWidth(2); paint.setColor(Color.rgb(255, 255, 255)); paint.setStyle(Paint.Style.FILL); paintText = new Paint(); paintText.setAntiAlias(true); paintText.setStrokeWidth(4); paintText.setColor(getResources().getColor(R.color.white));//Color.rgb(255, 255, 255)); paintText.setStyle(Paint.Style.FILL); paintText.setTextSize(16); paintText2 = new Paint(); paintText2.setAntiAlias(true); paintText2.setStrokeWidth(4); paintText2.setColor(Color.WHITE);//.rgb(33, 35, 59)); paintText2.setStyle(Paint.Style.FILL); paintText2.setTextSize(20); paintLine = new Paint(); paintLine.setAntiAlias(true); paintLine.setStrokeWidth(1); paintLine.setColor(Color.rgb(255, 255, 255)); paintLine.setStyle(Paint.Style.STROKE); PathEffect effects = new DashPathEffect(new float[]{6, 4, 6, 4}, 1); paintLine.setPathEffect(effects); paintbg = new Paint(); paintbg.setAntiAlias(true); paintbg.setStrokeWidth(0); paintbg.setColor(Color.rgb(255, 255, 255)); paintbg.setStyle(Paint.Style.FILL); paintCircle = new Paint(); paintCircle.setAntiAlias(true); paintCircle.setStrokeWidth(2); paintCircle.setStyle(Paint.Style.FILL); paintCircle.setColor(getResources().getColor(R.color.white)); path = new Path(); mShader = new LinearGradient(0, 0, 0, getHeight(), new int[]{color_w, getResources().getColor(R.color.transparency)}, null, Shader.TileMode.CLAMP); paintbg.setShader(mShader); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); float High = mHigh - bottomH; if (listValue != null && listValue.size() != 0 && listDAY != null && listDAY.size() != 0) { for (int i = 0; i < listValue.size(); i++) { float h = High - High * Float.parseFloat(listValue.get(i)) / MaxValue; h = h + topH; float w = (float) (Width / listValue.size() * (i + 0.5)); if (High * Float.parseFloat(listValue.get(i)) / MaxValue < CircleR) { h = High - CircleR - 1; } if (h < CircleR) { h = CircleR + 1; } if (h > High - CircleR) { h = High - CircleR + 1; } if (MaxValue == 0) h = High - CircleR - 1; if (i == 0) { path.moveTo(w, h); } else if (i == listValue.size() - 1) { path.lineTo(w, h); path.lineTo(w, High); path.lineTo((float) (Width / listValue.size() * 0.5), High); path.lineTo((float) (Width / listValue.size() * 0.5), High - High * Float.parseFloat(listValue.get(0)) / MaxValue); path.close(); canvas.drawPath(path, paintbg); } else { path.lineTo(w, h); } if (i != listValue.size() - 1) { float stopY = High - High * Float.parseFloat(listValue.get(i + 1)) / MaxValue + topH; float stopX = (float) (Width / listValue.size() * (i + 1.5)); if (High * Float.parseFloat(listValue.get(i + 1)) / MaxValue < CircleR) { stopY = High - CircleR - 1; } if (stopY < CircleR) { stopY = CircleR + 1; } if (MaxValue == 0) stopY = High - CircleR - 1; if (stopY > High - CircleR) { stopY = High - CircleR + 1; } canvas.drawLine(w, h, stopX, stopY, paint); } } listRectF.clear(); for (int i = 0; i < listDAY.size(); i++) { float w = (float) (Width / listValue.size() * (i + 0.5)); String day = listDAY.get(i); if (listDAY.size() == 7) { paintText.setTextSize(UIUtils.dip2px(getContext(), 10)); paintText2.setTextSize(UIUtils.dip2px(getContext(), 10)); int width = getTextWidth(paintText, day); if (selectbottom == i) { canvas.drawText(day, w - width / 2, mHigh - 2, paintText2); selectbottom = -1; } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText); } } else if (listDAY.size() == 12) { paintText.setTextSize(UIUtils.dip2px(getContext(), 10)); paintText2.setTextSize(UIUtils.dip2px(getContext(), 10)); int width = getTextWidth(paintText, day); if (selectbottom == i) { canvas.drawText(day, w - width / 2, mHigh - 2, paintText2); selectbottom = -1; } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText); } } else if (listDAY.size() == 30) { paintText.setTextSize(UIUtils.dip2px(getContext(), 10)); paintText2.setTextSize(UIUtils.dip2px(getContext(), 10)); if (i == 0 || i == 7 || i == 15 || i == 22 || i == 29) { int width = getTextWidth(paintText, day); if (selectbottom == i) { if (i == 0) { canvas.drawText(day, w, mHigh - 2, paintText2); } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText2); } selectbottom = -1; } else { if (i == 0) { canvas.drawText(day, w, mHigh - 2, paintText); } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText); } } } } else if (listDAY.size() == 31) { paintText.setTextSize(UIUtils.dip2px(getContext(), 10)); paintText2.setTextSize(UIUtils.dip2px(getContext(), 10)); if (i == 0 || i == 7 || i == 15 || i == 22 || i == 30) { int width = getTextWidth(paintText, day); if (selectbottom == i) { if (i == 0) { canvas.drawText(day, w, mHigh - 2, paintText2); } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText2); } selectbottom = -1; } else { if (i == 0) { canvas.drawText(day, w, mHigh - 2, paintText); } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText); } } } } else if (listDAY.size() == 29) { paintText.setTextSize(UIUtils.dip2px(getContext(), 10)); paintText2.setTextSize(UIUtils.dip2px(getContext(), 10)); if (i == 0 || i == 7 || i == 15 || i == 22 || i == 28) { int width = getTextWidth(paintText, day); if (selectbottom == i) { if (i == 0) { canvas.drawText(day, w, mHigh - 2, paintText2); } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText2); } selectbottom = -1; } else { if (i == 0) { canvas.drawText(day, w, mHigh - 2, paintText); } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText); } } } } else if (listDAY.size() == 28) { paintText.setTextSize(UIUtils.dip2px(getContext(), 10)); paintText2.setTextSize(UIUtils.dip2px(getContext(), 10)); if (i == 0 || i == 7 || i == 15 || i == 22 || i == 27) { int width = getTextWidth(paintText, day); if (selectbottom == i) { if (i == 0) { canvas.drawText(day, w, mHigh - 2, paintText2); } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText2); } selectbottom = -1; } else { if (i == 0) { canvas.drawText(day, w, mHigh - 2, paintText); } else { canvas.drawText(day, w - width / 2, mHigh - 2, paintText); } } } } } for (int i = 0; i < listValue.size(); i++) { float h = High - High * Float.parseFloat(listValue.get(i)) / MaxValue + topH; float w = (float) (Width / listValue.size() * (i + 0.5)); if (High * Float.parseFloat(listValue.get(i)) / MaxValue < CircleR) { h = High - CircleR - 1; } if (h < CircleR) { h = CircleR + 1; } if (h > High - CircleR) { h = High - CircleR + 1; } if (MaxValue == 0) h = High - CircleR - 1; canvas.drawCircle(w, h, CircleR, paint); RectF f1 = new RectF(); float wrf = (float) (Width / listValue.size() / 2); f1.set(w - wrf, 0, w + wrf, getHeight()); if (select == i) { int width = getTextWidth(paintText2, Float.parseFloat(listValue.get(i)) + ""); int high = (int) getTextHigh(paintText2); if (w - width / 2 < 0) { canvas.drawText(Float.parseFloat(listValue.get(i)) + "", w, high, paintText2); } else if (w + width / 2 > Width) { canvas.drawText(Float.parseFloat(listValue.get(i)) + "", w - width, high, paintText2); } else { canvas.drawText(Float.parseFloat(listValue.get(i)) + "", w - width / 2, high, paintText2); } select = -1; } listRectF.add(f1); } } } Animation popup_enter_bottom; Animation popup_out_bottom; SelectItem mselectItem; int vid = 0; public void setValue(final List<String> listValue, final boolean cal, final boolean anim, final List<String> listDay, SelectItem mselectItem, int vid) { this.mselectItem = mselectItem; this.vid = vid; this.listDAY = new ArrayList<String>(); ; this.listDAY.addAll(listDay); this.isKcal = cal; if (this.listValue != null && this.listValue.size() != 0 && anim) { popup_out_bottom = AnimationUtils.loadAnimation(getContext(), R.anim.sacle_bottom_out); startAnimation(popup_out_bottom); popup_out_bottom.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation arg0) { setVisibility(View.INVISIBLE); play(listValue, cal, anim, 10); } }); } else { play(listValue, cal, anim, 600); } } private void play(final List<String> listValue, final boolean cal, boolean anim, int time) { this.listValue = new ArrayList<String>(); this.listValue.addAll(listValue); MaxValue = 0f; post(new Runnable() { @Override public void run() { for (String a : listValue) { if (Float.parseFloat(a) > MaxValue) MaxValue = Float.parseFloat(a); } initView(); invalidate(); } }); if (anim) { setVisibility(View.INVISIBLE); popup_enter_bottom = AnimationUtils.loadAnimation(getContext(), R.anim.sacle_bottom_in); popup_enter_bottom.setAnimationListener(new AnimationListener() {

相關推薦

仿運動步數折線統計

完整程式碼如下 import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.DashPathE

爆料 | 別小看“運動步數,可以看出你的職業、生活狀態

在微信的“微信運動”,可以看到自己和好友的運動狀態,還能確切的看到微信運動步數。微信運動步數,雖然只是一個簡單的數字,但是卻可以從中解讀出很多有趣的個人資訊。一起來看下外媒對於“微信運動”步數的相關解讀低於50步,宅或心情不好 微信步數很多時候低於50步,活動範圍一般侷限在家

Android仿朋友圈高清檢視控制元件可縮放、雙擊、移動

該庫支援和包含的功能: 1.圖片支援手勢操作, 可縮放、雙擊、移動 2.圖片載入時的進度條, 支援自定義 該庫的效果圖如下: 本地相簿圖片效果圖: 點選預覽大圖的效果 本想直接新增gradle依賴庫,不巧的是,之前版本已作廢,待現在版本穩定後,

小程式獲取運動步數

第一步,獲取session_key,用來解密必須用到的 程式碼為: wx.login({ success: function (res) { var appid = "wx1b4e5e75***48af1"; var secret = "

t小程式開發-獲取運動步數

官方API步驟最近做一個微信小程式需用到微信運動資料,根據文件,我寫了一個demo;先總結一下步驟,流程簡單如下:1、呼叫小程式API:wx.login獲取code和sessionKey; 2、呼叫小程式API: wx.getWeRunData獲取微信運動資料(加密的); 3

基於Xposed修改運動步數

前言:Zygote 是 Android 的核心,每開啟一個 app,Zygote 就會 fork 一個虛擬機器例項來執行 app,基於Xposed我們可以使用Android hook技術對APK中的方法進行除錯、關鍵API攔截、外掛等。 這篇文章建立在Xposed模組開發

小程式開發-獲取運動步數

官方API 步驟 最近做一個微信小程式需用到微信運動資料,根據文件,我寫了一個demo;先總結一下步驟,流程簡單如下: 1、呼叫小程式API:wx.login獲取code和sessionKey; 2、呼叫小程式API: wx.getWe

運動沒有步數解決辦法

color save nbsp blog inf key logs term con 激活微信計步設備: //setkey<deviceinfoconfig><voip><sensor><stepCounterMaxStep5

【虛擬走路】運動刷步公眾號更新了再用什麽刷步數

tro 微信 每天 搜索 需求 HR strong ron jsb 大家都知道微信運動可以記錄我們每天的步行數據,但是我們想知道這個數據能否通過技術手段進行作弊呢? 之前我們知道有一個黑科技公眾號【虛擬走路】,可以對微信運動數據進行輕松修改。 但是後來因為種種原因這個公眾號

2018運動公眾號刷步數教程,刷98800步

ima 如果 alt 說明 多公司 寵物狗 高效 程序 在線 炎炎夏日,人們都願意躲在空調房中,誰都不敢踏入陽光下半步。但是有一群人卻對此無可奈何,那就是在外跑業務的業務員們,為了工作在外中暑了那可真是得不償失,所以很多怕熱的員工往往都會在空閑之余找棵大樹嬉戲乘涼。 萬惡的

步數新神器_運動一鍵刷步數_虛擬走路_愛刷步

AC gen margin 行數 是不是 CA 技術 訪問 p s 大家肯定都知道微信運動可以記錄我們每天的步行數據,但是我們想知道這個數據能否通過技術手段進行作弊呢? 之前我們知道有一個黑科技公眾號【虛擬走路】,可以對微信運動數據進行輕松修改。 現在為網友們推薦一個更簡單

Android 廣告(banner)圖片輪播、圖片瀏覽、仿檢視控制元件(支援視訊和gif圖片)、支援動態新增資料

    之前專案需要做個仿微信檢視大圖,需要新增圓形下載進度,支援視訊和圖片切換等一系列功能控制元件,自己抽空把開發的自定義控制元件的成果重新構造、整理處理封裝成庫(aar),提供出來,有需要朋友,歡迎使用,如果有什麼建議歡迎留言或者GitHub上提issues

android 仿選擇器(帶預覽、照相功能)

實現了單選、多選 、拍照 、預覽 等功能;先上圖:      程式碼結構  下面不如正題: 一、新增依賴、許可權 1)新增以下依賴 dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])

運動刷步教程 QQ健康刷步數(一)之安卓版本

New微信QQ最新刷方法 公眾號版:kejidd STEP1:下載樂動力APP(自行上應用市場搜尋) 請先完成下載後使用微信登入 APP。 STEP2:開打樂動力APP>&

Android仿新增照片並且隨意限制照片數量並顯示縮介面

前段時間做專案時產品加入一個新功能,拍照並顯示縮圖,之前我們公司的都是隻顯示拍了幾張照片 然後點選之後跳到另外一個介面顯示這幾張照片,自我感覺這種方式很是不方便,就趁次機會做了一個實用並且通用的拍照顯示工具,先看效果 這是拍照過程中,如果沒有達到設定的拍照數量那麼拍照按鈕就

Android GridView擴充套件仿博發動態新增刪除圖片

在平時的開發中,我們會看到不管是微信發朋友圈照片還是微博釋出新鮮事,新增圖片的時候都是選完後面還有個+號再去選擇圖片,這樣的話比較方便使用者去新增圖片,有的右上角還有個-號方便使用者去刪除圖片,而一般使用者選擇的圖片多少都是不定的,我們只限制最大張

運動作弊 竟然可以刷步數,一起看下怎麼刷步數,探祕刷步的原理

最近一直有人問我微信是怎麼刷步的?對於這種問題我就無言以對了。 但還是抱著好奇心的態度瞭解了一下具體是怎麼搞的。 首先是有人專門寫了一套刷步的程式碼,利用微信運動原有的漏洞有人還專門寫了一套介面,就是直接向微信運動傳送假的 post 請求,從而更新你的步數。 微信運動怎麼

Android實現仿朋友圈釋出動態(拍照、相簿選擇、照片壓縮、顯示、儲存、縮、點選縮刪除對應檔案等)附原始碼

         原創作品,轉載請註明出處:http://blog.csdn.net/zhang3776813/article/details/52092591 最近專案需求中要用到類似微信朋友圈釋出動態選擇圖片的UI效果,研究了一下,特來分享成果,多的不說來看程式碼。

小程式微運動步數處理

微信小程式的微信運動每日步數獲取 第一步,獲取session_key,用來解密必須用到的 ①這裡,獲取session_key就不敘述了,跟獲取openid的步驟是一樣的,詳見: 注意:這裡要注意的是,在體驗版中,使用體驗版的appid和secret,

分享一個仿多選cordova外掛(相簿內帶相機功能)

上面的外掛有些問題: 1,android沒有相簿目錄,而且如果相簿圖片過多的使用者開啟相簿需要載入很長時間。 2,ios上選圖介面不自適應。 3,相簿內沒有相機拍照入口。 以上問題並不能滿足我的需求,所以自己打算寫一個外掛敬上。 仿微信多選圖cordov