Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
GcsSloop committed Jun 17, 2016
1 parent 1d4befa commit f4a87ac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
21 changes: 21 additions & 0 deletions Sample/src/main/java/com/gcssloop/rockertest/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

Expand All @@ -14,5 +15,25 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

RockerView rocker = (RockerView) findViewById(R.id.rocker);
if (null != rocker){
rocker.setListener(new RockerView.RockerListener() {
@Override
public void callback(int eventType, int currentAngle) {
switch (eventType) {
case RockerView.EVENT_ACTION:
// 触摸事件回调
Log.e("EVENT_ACTION-------->", "angle="+currentAngle);
break;
case RockerView.EVENT_CLOCK:
// 定时回调
Log.e("EVENT_CLOCK", "angle="+currentAngle);
break;
}
}
});
}


}
}
2 changes: 1 addition & 1 deletion Sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
tools:context="com.gcssloop.rockertest.MainActivity">

<com.gcssloop.widget.RockerView
android:id="@+id/rocker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
rocker:area_background="@drawable/area_bg"
rocker:area_radius="80dp"
rocker:refresh_cycle="50"
rocker:rocker_background="@drawable/rocker_bg"
rocker:rocker_radius="30dp"/>

Expand Down
10 changes: 5 additions & 5 deletions library/src/main/java/com/gcssloop/widget/RockerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
Expand Down Expand Up @@ -74,8 +75,8 @@ public class RockerView extends SurfaceView implements Runnable, SurfaceHolder.C


private RockerListener mListener;
private static final int EVENT_ACTION = 1;
private static final int EVENT_CLOCK = 2;
public static final int EVENT_ACTION = 1;
public static final int EVENT_CLOCK = 2;


private int mRefreshCycle = 30;
Expand Down Expand Up @@ -247,7 +248,6 @@ public boolean onTouchEvent(MotionEvent event) {

if (event.getAction() == MotionEvent.ACTION_DOWN) {
//如果屏幕接触点不在摇杆挥动范围内,则不处理
// Log.e("Rocker", "len:"+len);
if (len > mAreaRadius) {
return true;
}
Expand Down Expand Up @@ -357,7 +357,7 @@ private void listenerCallback() {
mListener.callback(EVENT_CLOCK, -1);
} else {
float radian = MathUtils.getRadian(mAreaPosition, new Point(mRockerPosition.x, mRockerPosition.y));
mListener.callback(EVENT_ACTION, RockerView.this.getAngleConvert(radian));
mListener.callback(EVENT_CLOCK, RockerView.this.getAngleConvert(radian));
}
}
}
Expand Down Expand Up @@ -442,7 +442,7 @@ public void setRockerColor(int rockerColor) {
mRockerBitmap = null;
}

public void setListener(RockerListener listener) {
public void setListener(@NonNull RockerListener listener) {
mListener = listener;
}

Expand Down

0 comments on commit f4a87ac

Please sign in to comment.