編輯:關於Android編程
本文實例講述了Android編程簡單實現雷達掃描效果。分享給大家供大家參考,具體如下:
在eoe看到有一篇關於雷達掃描的文章,然後看了下,很簡單,但是覺得還有很多可以優化的地方,下面貼出來
package com.example.wave; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.Shader; import android.graphics.SweepGradient; import android.util.AttributeSet; import android.widget.FrameLayout; public class RadarView extends FrameLayout { private int viewSize = 500; private Paint mPaintLine; private Paint mPaintSector; private boolean isStart = false; private ScanThread mThread; private int start = 0; private final int paintWidth = 10; public RadarView(Context context) { super(context); init(); } public RadarView(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { initPaint(); mThread = new ScanThread(); setBackgroundColor(Color.TRANSPARENT); } private void initPaint() { mPaintLine = new Paint(); mPaintLine.setStrokeWidth(paintWidth); mPaintLine.setAntiAlias(true); mPaintLine.setStyle(Style.STROKE); mPaintLine.setColor(0xffff0000); mPaintSector = new Paint(); mPaintSector.setColor(0x9D00ff00); mPaintSector.setAntiAlias(true); } public void setViewSize(int size) { this.viewSize = size; mShader = new SweepGradient(viewSize >> 1, viewSize >> 1, Color.TRANSPARENT, Color.GREEN); setMeasuredDimension(viewSize, viewSize); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(viewSize, viewSize); } public void start() { mThread.start(); isStart = true; } public void stop() { if (isStart) { Thread.interrupted(); isStart = false; } } private Shader mShader = new SweepGradient(viewSize >> 1, viewSize >> 1, Color.TRANSPARENT, Color.GREEN); private Matrix matrix = new Matrix(); @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int halfRadaSize = viewSize >> 1; canvas.drawCircle(halfRadaSize, halfRadaSize, halfRadaSize >> 1, mPaintLine); canvas.drawCircle(halfRadaSize, halfRadaSize, halfRadaSize - (paintWidth >> 1), mPaintLine); canvas.drawLine(halfRadaSize, 0, halfRadaSize, viewSize, mPaintLine); canvas.drawLine(0, halfRadaSize, viewSize, halfRadaSize, mPaintLine); mPaintSector.setShader(mShader); canvas.concat(matrix); canvas.drawCircle(halfRadaSize, halfRadaSize, halfRadaSize - paintWidth, mPaintSector); } protected class ScanThread extends Thread { int halfRadaSize = viewSize >> 1; @Override public void run() { while (isStart) { start = start + 2; matrix.reset(); matrix.postRotate(start, halfRadaSize, halfRadaSize); postInvalidate(); try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } } } }
希望本文所述對大家Android程序設計有所幫助。
1,需要權限 2,下載 RootTools.jar包。3,兩個關鍵方法。主要是獲取shell,並執行命令行。方法如下: private
安裝cygwin:由於NDK編譯代碼時必須要用到make和gcc,所以你必須先搭建一個linux環境, cygwin是一個在windows平台上運行的unix模擬環境,它
0x00閱讀本文前,建議讀者首先閱讀Android加殼原理,參考文章Android中的Apk的加固(加殼)原理解析和實現。如果沒有看過這篇文章,本文理解起來比較困難。0x
策略模式(Strategy)策略模式是對象的行為模式。它的用意是針對一組算法,將每一個算法封裝到具有共同接口的獨立類中,從而使得它們可以相互替換。策略模式使得算法可以在不