Skip to content

Commit

Permalink
更新到 v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GcsSloop committed Dec 18, 2016
1 parent 9805a3b commit 87df91d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ captures/

# Keystore files
*.jks

Sample/src/androidTest/java/com/gcssloop/rocker/ApplicationTest.java

Sample/src/test/java/com/gcssloop/rocker/ExampleUnitTest.java
45 changes: 26 additions & 19 deletions Sample/src/main/java/com/gcssloop/rockertest/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.gcssloop.rockertest;

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

import com.gcssloop.widget.RockerView;

Expand All @@ -15,25 +13,34 @@ 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;
try{
RockerView rocker = (RockerView) findViewById(R.id.rocker);
if (null != rocker){
rocker.setListener(new RockerView.RockerListener() {
@Override
public void callback(int eventType, int currentAngle) {
}
}
});

@Override
public void callback(int eventType, int currentAngle, float currentDistance) {
switch (eventType) {
case RockerView.EVENT_ACTION:
// 触摸事件回调
Log.e("EVENT_ACTION-------->", "angle="+currentAngle+" - distance"+currentDistance);
break;
case RockerView.EVENT_CLOCK:
// 定时回调
Log.e("EVENT_CLOCK", "angle="+currentAngle+" - distance"+currentDistance);
break;
}
}
});
}
}catch (Exception e){
e.printStackTrace();
}



}
}
1 change: 1 addition & 0 deletions Sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:layout_height="wrap_content"
rocker:area_background="@drawable/area_bg"
rocker:area_radius="80dp"
rocker:callback_cycle="300"
rocker:rocker_background="@drawable/rocker_bg"
rocker:rocker_radius="30dp"/>

Expand Down
25 changes: 23 additions & 2 deletions library/src/main/java/com/gcssloop/widget/RockerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,18 @@ public boolean onTouchEvent(MotionEvent event) {
}
if (mListener != null) {
float radian = MathUtils.getRadian(mAreaPosition, new Point((int) event.getX(), (int) event.getY()));
mListener.callback(EVENT_ACTION, getAngleConvert(radian));
int angle = RockerView.this.getAngleConvert(radian);
float distance = MathUtils.getDistance(mAreaPosition.x, mAreaPosition.y, event.getX(), event.getY());
mListener.callback(EVENT_ACTION, angle);
mListener.callback(EVENT_ACTION, angle, distance);
}
}
//如果手指离开屏幕,则摇杆返回初始位置
if (event.getAction() == MotionEvent.ACTION_UP) {
mRockerPosition = new Point(mAreaPosition);
if (mListener != null) {
mListener.callback(EVENT_ACTION, -1);
mListener.callback(EVENT_ACTION, -1, 0);
}
}
} catch (Exception e) {
Expand Down Expand Up @@ -373,9 +377,13 @@ private void listenerCallback() {
if (mListener != null) {
if (mRockerPosition.x == mAreaPosition.x && mRockerPosition.y == mAreaPosition.y) {
mListener.callback(EVENT_CLOCK, -1);
mListener.callback(EVENT_CLOCK, -1, 0);
} else {
float radian = MathUtils.getRadian(mAreaPosition, new Point(mRockerPosition.x, mRockerPosition.y));
mListener.callback(EVENT_CLOCK, RockerView.this.getAngleConvert(radian));
int angle = RockerView.this.getAngleConvert(radian);
float distance = MathUtils.getDistance(mAreaPosition.x, mAreaPosition.y, mRockerPosition.x, mRockerPosition.y);
mListener.callback(EVENT_CLOCK, angle);
mListener.callback(EVENT_CLOCK, angle, distance);
}
}
}
Expand Down Expand Up @@ -474,6 +482,9 @@ public void setListener(@NonNull RockerListener listener) {

/*Rocker Listener******************************************************************************/

/**
* rocker listener
*/
public interface RockerListener {
/**
* you can get some event from this method
Expand All @@ -482,5 +493,15 @@ public interface RockerListener {
* @param currentAngle The current angle
*/
void callback(int eventType, int currentAngle);

/**
* you can get some event from this method
*
* @param eventType The event type, EVENT_ACTION or EVENT_CLOCK
* @param currentAngle The current angle
* @param currentDistance The current distance (px)
*/
void callback(int eventType, int currentAngle, float currentDistance);
}

}

0 comments on commit 87df91d

Please sign in to comment.