- close #6 - verbindung klappt und macht was sie soll. sonderfälle fehlen halt noch wie verbindung kackt ab etc.

- ref #8 mal einen filewriter geschrieben, welcher die sensordaten rausschreiben soll.
- viele kleine sachen
This commit is contained in:
toni
2017-12-20 17:23:23 +01:00
parent 88047672d0
commit b00c845c5c
12 changed files with 201 additions and 36 deletions

View File

@@ -1,6 +1,10 @@
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
}
}
compileSdkVersion 26
defaultConfig {
applicationId "de.tonifetzer.conductorswatch"
@@ -19,7 +23,7 @@ android {
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'

View File

@@ -22,8 +22,8 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name">
>
android:label="@string/app_name"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View File

@@ -28,7 +28,7 @@ public class DataLayerListenerService extends WearableListenerService {
@Override
public void onMessageReceived(MessageEvent messageEvent) {
LOGD(TAG, "onMessageReceived: " + messageEvent);
//LOGD(TAG, "onMessageReceived: " + messageEvent);
// Check to see if the message is to start an activity
if (messageEvent.getPath().equals(START_ACTIVITY_PATH)) {

View File

@@ -1,25 +1,30 @@
package de.tonifetzer.conductorswatch;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.SoundEffectConstants;
import android.widget.TextView;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.MessageClient;
import com.google.android.gms.wearable.Wearable;
import java.util.Timer;
public class MainActivity extends AppCompatActivity implements MessageClient.OnMessageReceivedListener{
private TextView mTextView;
private String mCurBPM;
Timer mTimer;
private static final String TAG = "DataLayerService";
private static final String START_ACTIVITY_PATH = "/start-activity";
private static final String START_RECORD_PATH = "/start-record";
private static final String STOP_RECORD_PATH = "/stop-record";
private static final String UPDATE_PATH = "/update";
private boolean mIsRecording = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -44,14 +49,36 @@ public class MainActivity extends AppCompatActivity implements MessageClient.OnM
@Override
public void onMessageReceived(MessageEvent messageEvent) {
String[] parts = messageEvent.getPath().split(":");
// Check to see if the message is to start an activity
if (messageEvent.getPath().equals(START_ACTIVITY_PATH)) {
Log.d(TAG, "onStartReceived: " + messageEvent);
//this happens if the app is already running
//TODO: handle this in wear app
}
else{
//update bpm
Log.d(TAG, "onBPMReceived: " + messageEvent);
//mTextView.setText(messageEvent.getPath());
else if (messageEvent.getPath().contains(START_RECORD_PATH)){
if(mIsRecording){
mTextView.setText(parts[2]);
}
else {
mTimer = new Timer();
mTimer.scheduleAtFixedRate(new Metronome(this) , 0, 60000 / Integer.parseInt(parts[1]));
mTextView.setTextColor(Color.parseColor("#EE693F"));
mIsRecording = true;
}
}
else if (messageEvent.getPath().contains(STOP_RECORD_PATH)){
mTimer.cancel();
mTextView.setTextColor(Color.parseColor("#158b69"));
mIsRecording = false;
}
else if (messageEvent.getPath().contains(UPDATE_PATH)){
mTextView.setText(parts[2]);
}
}
}

View File

@@ -0,0 +1,41 @@
package de.tonifetzer.conductorswatch;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import java.util.TimerTask;
/**
* Created by toni on 20/12/17.
*/
public class Metronome extends TimerTask {
//private MediaPlayer mMediaPlayer;
private SoundPool soundPool;
boolean loaded = false;
private int soundID;
public Metronome(Context context){
soundPool = new SoundPool.Builder().setMaxStreams(10).build();
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
loaded = true;
}
});
soundID = soundPool.load(context, R.raw.metronom4, 1);
}
//TODO: better solution. create sound with the exact length and then loop forever with loop: -1
public void run() {
if (loaded) {
soundPool.stop(soundID);
soundPool.play(soundID, 1, 1, 1, 0, 1f);
}
}
}

View File

@@ -8,13 +8,14 @@
<TextView
android:id="@+id/bpmText"
android:soundEffectsEnabled="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="240"
android:text="80"
android:textStyle="bold"
android:textColor="#158b69"
android:textSize="100sp"/>