-sleep ist jetzt nur in der main erlaubt, nicht mehr im worker -ui wurde an vielen stellen angepasst #5 -effekte beim bildschirm klicken
This commit is contained in:
@@ -41,5 +41,5 @@ dependencies {
|
|||||||
implementation 'com.android.support:recyclerview-v7:26.1.0'
|
implementation 'com.android.support:recyclerview-v7:26.1.0'
|
||||||
implementation 'com.android.support:wear:26.1.0'
|
implementation 'com.android.support:wear:26.1.0'
|
||||||
compileOnly 'com.google.android.wearable:wearable:2.1.0'
|
compileOnly 'com.google.android.wearable:wearable:2.1.0'
|
||||||
compile 'com.sdsmdg.harjot:croller:1.0.7'
|
//compile 'com.sdsmdg.harjot:croller:1.0.7'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
package de.tonifetzer.conductorswatch;
|
package de.tonifetzer.conductorswatch;
|
||||||
|
|
||||||
import android.app.Fragment;
|
|
||||||
import android.app.FragmentManager;
|
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.gesture.Gesture;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.graphics.Point;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.view.GestureDetectorCompat;
|
import android.os.Handler;
|
||||||
|
import android.os.Vibrator;
|
||||||
import android.support.wearable.activity.WearableActivity;
|
import android.support.wearable.activity.WearableActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.sdsmdg.harjot.crollerTest.Croller;
|
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import de.tonifetzer.conductorswatch.utilities.Utils;
|
||||||
|
|
||||||
public class MainActivity extends WearableActivity implements WorkerFragment.OnFragmentInteractionListener{
|
public class MainActivity extends WearableActivity implements WorkerFragment.OnFragmentInteractionListener{
|
||||||
|
|
||||||
// member
|
// member
|
||||||
@@ -27,11 +25,122 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
|||||||
private GestureDetector mDetector;
|
private GestureDetector mDetector;
|
||||||
private boolean mModeRecord;
|
private boolean mModeRecord;
|
||||||
|
|
||||||
|
// display center
|
||||||
|
private int mDisplayWidth;
|
||||||
|
private int mDisplayHeight;
|
||||||
|
|
||||||
|
//parameter for long press to start the worker
|
||||||
|
private Point mPreviousMovePoint;
|
||||||
|
private int mDistanceJitteringLongPress = 50; // in pixel
|
||||||
|
private int mLongPressDelay = 1200; // in Milliseconds
|
||||||
|
private boolean mLongPressHandlerActivated = false;
|
||||||
|
private final Handler mHandler = new Handler();
|
||||||
|
private Runnable mLongPressed = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
vibrator.vibrate(100);
|
||||||
|
|
||||||
|
mLongPressHandlerActivated = true;
|
||||||
|
|
||||||
|
mModeRecord = !mModeRecord;
|
||||||
|
|
||||||
|
if(mModeRecord){
|
||||||
|
WorkerFragment worker = new WorkerFragment();
|
||||||
|
|
||||||
|
//provide the fragment with the bpm set
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt("bpm", mCroller.getProgress());
|
||||||
|
worker.setArguments(args);
|
||||||
|
|
||||||
|
//create fragment instance
|
||||||
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||||
|
transaction.replace(R.id.layout, worker);
|
||||||
|
transaction.addToBackStack(null);
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
getFragmentManager().popBackStack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private boolean onColorChanging(MotionEvent ev){
|
||||||
|
Point currentPoint = new Point((int)ev.getX(), (int)ev.getY());
|
||||||
|
|
||||||
|
//only works within the maincircle of the scroller
|
||||||
|
float distancePointToMiddle = Utils.getDistance(currentPoint.x, currentPoint.y, (float) (mDisplayWidth / 2.0f), (float) (mDisplayHeight / 2.0f));
|
||||||
|
if ((distancePointToMiddle > mCroller.getMainCircleRadius())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ev.getAction() == MotionEvent.ACTION_DOWN){
|
||||||
|
//push down effect
|
||||||
|
mCroller.setBackCircleColorAnimated(Color.parseColor("#cccccc"), Color.parseColor("#158b69"),150);
|
||||||
|
|
||||||
|
//make color of backgroundcircle brighter the longer we press
|
||||||
|
mCroller.setMainCircleColorAnimated(Color.parseColor("#ffffff"), Color.parseColor("#158b69"),1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ev.getAction() == MotionEvent.ACTION_UP){
|
||||||
|
//push_up effect
|
||||||
|
mCroller.setBackCircleColorAnimated(Color.parseColor("#158b69"), Color.parseColor("#cccccc"),150);
|
||||||
|
mCroller.stopMainCircleColorAnimated();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean onLongPressCustomized(MotionEvent ev){
|
||||||
|
|
||||||
|
Point currentPoint = new Point((int)ev.getX(), (int)ev.getY());
|
||||||
|
|
||||||
|
//make sure the longPress only works within the maincircle of the scroller
|
||||||
|
float distancePointToMiddle = Utils.getDistance(currentPoint.x, currentPoint.y, (float) (mDisplayWidth / 2.0f), (float) (mDisplayHeight / 2.0f));
|
||||||
|
if ((distancePointToMiddle > mCroller.getMainCircleRadius())){
|
||||||
|
//do nothing
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ev.getAction() == MotionEvent.ACTION_DOWN){
|
||||||
|
mHandler.postDelayed(mLongPressed, mLongPressDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((ev.getAction() == MotionEvent.ACTION_MOVE) || (ev.getAction() == MotionEvent.ACTION_HOVER_MOVE)){
|
||||||
|
|
||||||
|
if(mPreviousMovePoint == null) {
|
||||||
|
mPreviousMovePoint = currentPoint;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int dx = Math.abs(currentPoint.x - mPreviousMovePoint.x);
|
||||||
|
int dy = Math.abs(currentPoint.y - mPreviousMovePoint.y);
|
||||||
|
int distance = (int) Math.sqrt(dx*dx + dy*dy);
|
||||||
|
if(distance > mDistanceJitteringLongPress) {
|
||||||
|
mHandler.removeCallbacks(mLongPressed);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ev.getAction() == MotionEvent.ACTION_UP){
|
||||||
|
mHandler.removeCallbacks(mLongPressed);
|
||||||
|
if(mLongPressHandlerActivated){
|
||||||
|
mLongPressHandlerActivated = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
mDisplayWidth= this.getResources().getDisplayMetrics().widthPixels;
|
||||||
|
mDisplayHeight= this.getResources().getDisplayMetrics().heightPixels;
|
||||||
|
|
||||||
mModeRecord = false;
|
mModeRecord = false;
|
||||||
|
|
||||||
mTextView = (TextView) findViewById(R.id.bpmText);
|
mTextView = (TextView) findViewById(R.id.bpmText);
|
||||||
@@ -51,34 +160,12 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
|||||||
mDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
mDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
||||||
|
|
||||||
public boolean onDoubleTap(MotionEvent ev) {
|
public boolean onDoubleTap(MotionEvent ev) {
|
||||||
Log.d("Test", "onDoubleTap: " + ev.toString());
|
Log.d("Gesture", "onDoubleTap: " + ev.toString());
|
||||||
|
|
||||||
mModeRecord = !mModeRecord;
|
|
||||||
|
|
||||||
if(mModeRecord){
|
|
||||||
WorkerFragment worker = new WorkerFragment();
|
|
||||||
|
|
||||||
//provide the fragment with the bpm set
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putInt("bpm", mCroller.getProgress());
|
|
||||||
worker.setArguments(args);
|
|
||||||
|
|
||||||
//create fragment instance
|
|
||||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
|
||||||
transaction.replace(R.id.layout, worker);
|
|
||||||
transaction.addToBackStack(null);
|
|
||||||
transaction.commit();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
getFragmentManager().popBackStack();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
//TODO: Callback Function for BPM estimation for textview, processbar and BackCircle
|
});
|
||||||
|
|
||||||
// Enables Always-on
|
// Enables Always-on
|
||||||
setAmbientEnabled();
|
setAmbientEnabled();
|
||||||
@@ -86,12 +173,14 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||||
|
|
||||||
//if record mode is on, we are not able to use the croller
|
//if record mode is on, we are not able to use the croller
|
||||||
if(mModeRecord){
|
if(mModeRecord){
|
||||||
return mDetector.onTouchEvent(ev);
|
return onLongPressCustomized(ev);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return mDetector.onTouchEvent(ev) || super.dispatchTouchEvent(ev);
|
boolean changeColor = onColorChanging(ev);
|
||||||
|
return onLongPressCustomized(ev) || super.dispatchTouchEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -99,6 +188,10 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFragmentStopped(Vector<Float> bpmList) {
|
public void onFragmentStopped(Vector<Float> bpmList) {
|
||||||
|
|
||||||
|
//TODO: save the bpmList into a file
|
||||||
|
|
||||||
|
|
||||||
Log.d("FragmentListener", "Received bpmList");
|
Log.d("FragmentListener", "Received bpmList");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,8 @@ import android.util.Log;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.sdsmdg.harjot.crollerTest.Croller;
|
|
||||||
|
|
||||||
import java.util.Observable;
|
|
||||||
import java.util.Observer;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,7 +23,7 @@ import java.util.Vector;
|
|||||||
public class WorkerFragment extends Fragment implements Metronome.OnMetronomeListener, BpmEstimator.OnBpmEstimatorListener{
|
public class WorkerFragment extends Fragment implements Metronome.OnMetronomeListener, BpmEstimator.OnBpmEstimatorListener{
|
||||||
|
|
||||||
private OnFragmentInteractionListener mListener;
|
private OnFragmentInteractionListener mListener;
|
||||||
private Vector<Float> mBpmList;
|
private Vector<Float> mBpmList; //TODO save to file.
|
||||||
|
|
||||||
private BpmEstimator mBpmEstimator;
|
private BpmEstimator mBpmEstimator;
|
||||||
private Metronome mMetronome;
|
private Metronome mMetronome;
|
||||||
@@ -74,6 +70,9 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
|||||||
|
|
||||||
mVibrator = (Vibrator) this.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
mVibrator = (Vibrator) this.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
|
||||||
|
|
||||||
|
//keep screen always on
|
||||||
|
this.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,7 +86,7 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
|||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState){
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState){
|
||||||
mTextView = (TextView) getView().findViewById(R.id.bpmTextRed);
|
mTextView = (TextView) getView().findViewById(R.id.bpmTextRed);
|
||||||
mCroller = mCroller = (Croller) getView().findViewById(R.id.crollerRed);
|
mCroller = (Croller) getView().findViewById(R.id.croller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -152,6 +151,7 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
|||||||
public void onNewDataAvailable(float bpm) {
|
public void onNewDataAvailable(float bpm) {
|
||||||
|
|
||||||
//TODO: what if multiple threads access mBpmList? put into synchronized? @frank fragen :D
|
//TODO: what if multiple threads access mBpmList? put into synchronized? @frank fragen :D
|
||||||
|
//TODO: send this to smartphone
|
||||||
mBpmList.add(bpm);
|
mBpmList.add(bpm);
|
||||||
|
|
||||||
// we need this here, since ui elements can only be changed within activity thread and
|
// we need this here, since ui elements can only be changed within activity thread and
|
||||||
|
|||||||
@@ -16,13 +16,13 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
|
||||||
<com.sdsmdg.harjot.crollerTest.Croller
|
<de.tonifetzer.conductorswatch.Croller
|
||||||
android:id="@+id/croller"
|
android:id="@+id/croller"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:back_circle_color="#CCC"
|
app:back_circle_color="#CCC"
|
||||||
app:back_circle_radius="100"
|
app:back_circle_radius="100"
|
||||||
app:indicator_color="#CCC"
|
app:indicator_color="#00000000"
|
||||||
app:indicator_width="4"
|
app:indicator_width="4"
|
||||||
app:is_continuous="true"
|
app:is_continuous="true"
|
||||||
app:label=""
|
app:label=""
|
||||||
@@ -37,7 +37,9 @@
|
|||||||
app:progress_radius="120"
|
app:progress_radius="120"
|
||||||
app:progress_secondary_color="#CCC"
|
app:progress_secondary_color="#CCC"
|
||||||
app:progress_secondary_stroke_width="3"
|
app:progress_secondary_stroke_width="3"
|
||||||
app:start_offset="45" />
|
app:start_offset="45"
|
||||||
|
app:touch_circle_radius_max="150"
|
||||||
|
app:touch_circle_radius_min="90" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/bpmText"
|
android:id="@+id/bpmText"
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
|
||||||
<com.sdsmdg.harjot.crollerTest.Croller
|
<de.tonifetzer.conductorswatch.Croller
|
||||||
android:id="@+id/crollerRed"
|
android:id="@+id/croller"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:back_circle_color="#EE693F"
|
app:back_circle_color="#EE693F"
|
||||||
|
|||||||
Reference in New Issue
Block a user