forked from gumingwei/WellSwipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package com.well.swipe.view; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.RectF; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
import com.well.swipe.R; | ||
|
||
/** | ||
* Created by mingwei on 5/31/16. | ||
*/ | ||
public class LoadingView extends View { | ||
|
||
private final String TAG = "LoadingView"; | ||
private Paint mTestPaint; | ||
private Paint mOuterPaint; | ||
private RectF mOuterRectF; | ||
private Paint mInnerPaint; | ||
private RectF mInnerRectF; | ||
/** | ||
* mStart 起始值 弧度 mSweep 终点值 弧度 | ||
*/ | ||
int mStart = 0; | ||
int mSweep = 90; | ||
|
||
int mWidth, mHeight; | ||
int mArcLenght = 60; | ||
/** | ||
* outer width | ||
*/ | ||
int mOuterWidth; | ||
/** | ||
* inner width | ||
*/ | ||
int mInnerWidth; | ||
/** | ||
* outer color | ||
*/ | ||
int mOuterColor; | ||
/** | ||
* inner color | ||
*/ | ||
int mInnerColor; | ||
/** | ||
* inner rotating speed | ||
*/ | ||
int mInnerRotatingSpeed = 1; | ||
/** | ||
* Circle degree | ||
*/ | ||
int mCircle = 0; | ||
/** | ||
* Circle speed,only mode==circle | ||
*/ | ||
int mCircleSpeed = 1; | ||
/** | ||
* custom degree,only mode==custom | ||
*/ | ||
int mCustomDegree = 0; | ||
|
||
private boolean isStop; | ||
|
||
public LoadingView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public LoadingView(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public LoadingView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
initAttr(context, attrs); | ||
|
||
} | ||
|
||
private void setBounds() { | ||
mOuterRectF = new RectF(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() | ||
- getPaddingBottom()); | ||
mInnerRectF = new RectF(mOuterRectF); | ||
} | ||
|
||
@Override | ||
protected void onSizeChanged(int w, int h, int oldw, int oldh) { | ||
super.onSizeChanged(w, h, oldw, oldh); | ||
setBounds(); | ||
initPaint(); | ||
} | ||
|
||
private void initPaint() { | ||
mOuterPaint = new Paint(); | ||
mOuterPaint.setAntiAlias(true); | ||
mOuterPaint.setColor(mOuterColor); | ||
mOuterPaint.setStyle(Paint.Style.STROKE); | ||
mOuterPaint.setStrokeWidth(mOuterWidth); | ||
// | ||
mInnerPaint = new Paint(); | ||
mInnerPaint.setAntiAlias(true); | ||
mInnerPaint.setColor(mInnerColor); | ||
mInnerPaint.setStyle(Paint.Style.STROKE); | ||
mInnerPaint.setStrokeWidth(mInnerWidth); | ||
// | ||
mTestPaint = new Paint(); | ||
mTestPaint.setAntiAlias(true); | ||
mTestPaint.setColor(Color.BLACK); | ||
mTestPaint.setStyle(Paint.Style.STROKE); | ||
} | ||
|
||
private void initAttr(Context context, AttributeSet attrs) { | ||
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.Loading); | ||
mOuterWidth = array.getDimensionPixelOffset(R.styleable.Loading_outer_width, 0); | ||
mOuterColor = array.getColor(R.styleable.Loading_outer_color, Color.GRAY); | ||
mInnerWidth = array.getDimensionPixelOffset(R.styleable.Loading_inner_width, R.styleable.Loading_inner_width); | ||
mInnerColor = array.getColor(R.styleable.Loading_inner_color, Color.BLACK); | ||
mInnerRotatingSpeed = array.getInt(R.styleable.Loading_inner_rotating_speed, 1); | ||
array.recycle(); | ||
} | ||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
super.onDraw(canvas); | ||
// canvas.drawRect(mOuterRectF, mTestPaint); | ||
canvas.drawArc(mOuterRectF, 360, 360, false, mOuterPaint); | ||
canvas.drawArc(mInnerRectF, mStart, mSweep + 2, false, mInnerPaint); | ||
// int d = mRandom.nextInt(8); | ||
mStart += mInnerRotatingSpeed; | ||
if (mStart > 360) { | ||
mStart -= 360; | ||
} | ||
if (!isStop) { | ||
invalidate(); | ||
} | ||
|
||
} | ||
|
||
public void stop() { | ||
isStop = true; | ||
setVisibility(GONE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="oval"> | ||
|
||
<solid android:color="@color/indicator_color" /> | ||
</shape> |
Oops, something went wrong.