Skip to content

Commit

Permalink
modify->添加一个LoadView
Browse files Browse the repository at this point in the history
  • Loading branch information
gumingwei committed Jun 1, 2016
1 parent 3715ab0 commit 8a3bb6c
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.well.swipe"
minSdkVersion 14
targetSdkVersion 23
versionCode 7
versionName "1.0.8"
versionCode 8
versionName "1.0.9"

}
buildTypes {
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application
android:name=".SwipeApplication"
Expand Down Expand Up @@ -49,9 +50,13 @@
android:authorities="com.well.swipe.favorites"
android:exported="true" />

<receiver android:name=".BootReceiver">
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/well/swipe/BootReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.well.swipe.service.SwipeService;
import com.well.swipe.tools.SwipeSetting;
Expand All @@ -14,8 +15,11 @@
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {

if (SettingHelper.getInstance(context).getBoolean(SwipeSetting.SWIPE_TOGGLE, true)) {

context.startService(new Intent(context, SwipeService.class));
}
}
Expand Down
30 changes: 23 additions & 7 deletions app/src/main/java/com/well/swipe/view/AngleLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.animation.ValueAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.VelocityTracker;
Expand All @@ -23,7 +24,8 @@
* Created by mingwei on 2/26/16.
*/
public class AngleLayout extends FrameLayout implements AngleView.OnAngleChangeListener,
AngleIndicatorView.OnIndexChangedLitener, AngleView.OnEditModeChangeListener, CornerView.OnCornerClickListener {
AngleIndicatorView.OnIndexChangedLitener, AngleView.OnEditModeChangeListener, CornerView.OnCornerClickListener,
AngleView.OnBindListener {
/**
*
*/
Expand Down Expand Up @@ -55,6 +57,8 @@ public class AngleLayout extends FrameLayout implements AngleView.OnAngleChangeL

private CornerThemeView mCornerTheme;

private LoadingView mLoading;

private float mThemeScale;

private int mChildHalfSize;
Expand All @@ -72,6 +76,8 @@ public class AngleLayout extends FrameLayout implements AngleView.OnAngleChangeL
private int mAngleLogoSize;

private int mIndicatorSize;

private int mLoadingSize;
/**
* 主题的小用像素,然后根据Indocator再做大小变化
*/
Expand Down Expand Up @@ -217,6 +223,7 @@ public AngleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
*/
mIndicatorThemeSize = getResources().getDimensionPixelSize(R.dimen.angleindicator_theme_size);
mAngleLogoSize = getResources().getDimensionPixelSize(R.dimen.anglelogo_size);
mLoadingSize = getResources().getDimensionPixelSize(R.dimen.loadingview_size);

ViewConfiguration mConfig = ViewConfiguration.get(context);
mTouchSlop = mConfig.getScaledTouchSlop();
Expand Down Expand Up @@ -246,6 +253,9 @@ protected void onFinishInflate() {

mCornerTheme = (CornerThemeView) findViewById(R.id.corner_theme);

mLoading = (LoadingView) findViewById(R.id.recent_loading);
mAngleView.setOnBindListener(this);


/**
* 拖拽view
Expand Down Expand Up @@ -288,7 +298,8 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
mCornerTheme.layout(0, mHeight - mAngleLogoSize, mAngleLogoSize, mHeight);
mCornerTheme.setPivotX(0);
mCornerTheme.setPivotY(mAngleLogoSize);
//mTestView.layout(0, mHeight - mAngleLogoSize, mAngleLogoSize, mHeight);
mLoading.layout((mAngleSize - mLoadingSize) / 2, mHeight - (mAngleSize + mLoadingSize) / 2,
(mAngleSize + mLoadingSize) / 2, mHeight - (mAngleSize - mLoadingSize) / 2);
} else if (mAngleView.isRight()) {
mAngleView.layout(mWidth - mAngleSize, mHeight - mAngleSize, mWidth, mHeight);
mAngleViewTheme.layout(mWidth - mAngleSize, mHeight - mAngleSize, mWidth, mHeight);
Expand All @@ -302,7 +313,8 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
mCornerTheme.layout(mWidth - mAngleLogoSize, mHeight - mAngleLogoSize, mWidth, mHeight);
mCornerTheme.setPivotX(mAngleLogoSize);
mCornerTheme.setPivotY(mAngleLogoSize);
//mTestView.layout(mWidth - mAngleLogoSize, mHeight - mAngleLogoSize, mWidth, mHeight);
mLoading.layout(mWidth - mAngleSize + (mAngleSize - mLoadingSize) / 2, mHeight - (mAngleSize + mLoadingSize) / 2,
mWidth - mAngleSize + (mAngleSize + mLoadingSize) / 2, mHeight - (mAngleSize - mLoadingSize) / 2);
}
/**
* 根据Indicator来缩放IndicatorTheme保证Theme的质量
Expand All @@ -320,7 +332,6 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
//Log.i("Gmw", "AngleLayout_onInterceptTouchEvent");
if (getChildCount() <= 0) {
return super.onInterceptTouchEvent(ev);
}
Expand Down Expand Up @@ -354,9 +365,9 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
}

} else if (mEditState == STATE_EDIT) {
if ((Math.abs(diffX) > mTouchSlop || Math.abs(diffY) > mTouchSlop) && isAllowAngle) {
return true;
}
//if ((Math.abs(diffX) > mTouchSlop || Math.abs(diffY) > mTouchSlop) && isAllowAngle) {
return true;
//}
}

break;
Expand Down Expand Up @@ -822,6 +833,11 @@ public void CornerEvent() {
}
}

@Override
public void bindComplete() {
mLoading.stop();
}

/**
* 重要方法:反转AngleLayout
* 反转之后根据不同情况对子控件做反转
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/well/swipe/view/AngleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ public interface OnEditModeChangeListener {
void onCancelDrag();
}

public OnBindListener mOnBindListener;

interface OnBindListener {

/**
* 数据绑定完成
*/
void bindComplete();
}


/**
* 临时坐标信息
Expand Down Expand Up @@ -493,6 +503,11 @@ public void putRecentTask(List<ActivityManager.RecentTaskInfo> activityInfoList,
}
}
refresh();

/**
* 绑定万Recent之后调用
*/
mOnBindListener.bindComplete();
}

public boolean contains(List<ActivityManager.RecentTaskInfo> activityInfoList, ItemApplication app) {
Expand Down Expand Up @@ -1283,6 +1298,10 @@ public void setOnAngleLongClickListener(OnEditModeChangeListener listener) {
mOnEditModeChangeListener = listener;
}

public void setOnBindListener(OnBindListener listener) {
mOnBindListener = listener;
}

/**
* 手指按下时的初始角度
*/
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/well/swipe/view/AngleViewTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public AngleViewTheme(Context context, AttributeSet attrs) {

public AngleViewTheme(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

mInnerSize = getResources().getDimensionPixelSize(R.dimen.angleindicator_size);
mDistance = getResources().getDimensionPixelSize(R.dimen.angleview_indicatorview_distance);
mColor = getResources().getColor(R.color.angleview_arc_background);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(mColor);
}

@Override
Expand All @@ -59,15 +59,14 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setColor(mColor);
if (mPositionState == PositionState.POSITION_STATE_LEFT) {
if (isLeft()) {
canvas.drawCircle(0, mHeight, mHeight, mPaint);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));

canvas.drawCircle(0, mHeight, mInnerSize + mDistance, mPaint);
canvas.drawCircle(0, mHeight, mInnerSize, mPaint);
mPaint.setXfermode(null);
} else if (mPositionState == PositionState.POSITION_STATE_RIGHT) {
} else if (isRight()) {
canvas.drawCircle(mWidth, mHeight, mHeight, mPaint);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));

Expand Down
146 changes: 146 additions & 0 deletions app/src/main/java/com/well/swipe/view/LoadingView.java
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);
}

}
1 change: 0 additions & 1 deletion app/src/main/res/drawable/angle_item_bg.xml
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>
Loading

0 comments on commit 8a3bb6c

Please sign in to comment.