Browse Source

fixed #12

main
James Fenn 2 years ago
parent
commit
fe67281c0b
5 changed files with 219 additions and 38 deletions
  1. +20
    -5
      wear/src/main/java/james/metronome/MainActivity.java
  2. +46
    -0
      wear/src/main/java/james/metronome/WhileHeldListener.java
  3. +9
    -0
      wear/src/main/res/drawable/ic_less.xml
  4. +9
    -0
      wear/src/main/res/drawable/ic_more.xml
  5. +135
    -33
      wear/src/main/res/layout/activity_main.xml

+ 20
- 5
wear/src/main/java/james/metronome/MainActivity.java View File

@@ -14,7 +14,6 @@ import android.os.VibrationEffect;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.wearable.activity.WearableActivity;
import android.support.wearable.view.BoxInsetLayout;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
@@ -27,7 +26,7 @@ public class MainActivity extends WearableActivity implements Runnable {
public static final String PREF_VIBRATION = "vibration";
public static final String PREF_INTERVAL = "interval";

private BoxInsetLayout container;
private View container;
private ImageView vibrationView;
private ImageView playView;
private TextView bpmView;
@@ -48,7 +47,7 @@ public class MainActivity extends WearableActivity implements Runnable {
private Vibrator vibrator;

@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
@@ -92,7 +91,7 @@ public class MainActivity extends WearableActivity implements Runnable {
bpmView.setText(String.format(Locale.getDefault(), getString(R.string.bpm), String.valueOf(bpm)));
seekBar.setProgress(bpm);

vibrationView.setOnClickListener(new View.OnClickListener() {
findViewById(R.id.vibrationButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isVibration = !isVibration;
@@ -106,7 +105,7 @@ public class MainActivity extends WearableActivity implements Runnable {
}
});

playView.setOnClickListener(new View.OnClickListener() {
findViewById(R.id.playButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isPlaying = !isPlaying;
@@ -120,6 +119,22 @@ public class MainActivity extends WearableActivity implements Runnable {
}
});

findViewById(R.id.moreButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (seekBar.getProgress() < 300)
seekBar.setProgress(seekBar.getProgress() + 1);
}
});

findViewById(R.id.lessButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (seekBar.getProgress() > 1)
seekBar.setProgress(seekBar.getProgress() - 1);
}
});

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {


+ 46
- 0
wear/src/main/java/james/metronome/WhileHeldListener.java View File

@@ -0,0 +1,46 @@
package james.metronome;

import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;

public abstract class WhileHeldListener implements View.OnTouchListener, Runnable {

private Handler handler;
private int interval;

public WhileHeldListener() {
interval = 100;
}

public WhileHeldListener(int interval) {
this.interval = interval;
}

public abstract void onHeld();

@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (handler != null)
return true;
handler = new Handler();
handler.postDelayed(this, interval);
break;
case MotionEvent.ACTION_UP:
if (handler == null)
return true;
handler.removeCallbacks(this);
handler = null;
break;
}
return false;
}

@Override
public void run() {
onHeld();
handler.postDelayed(this, interval);
}
}

+ 9
- 0
wear/src/main/res/drawable/ic_less.xml View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z" />
</vector>

+ 9
- 0
wear/src/main/res/drawable/ic_more.xml View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z" />
</vector>

+ 135
- 33
wear/src/main/res/layout/activity_main.xml View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -8,42 +9,143 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_box="all">
android:orientation="horizontal">

<ImageView
android:id="@+id/vibration"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_gravity="center_horizontal"
android:scaleType="fitCenter"
android:tint="@android:color/white"
android:src="@drawable/ic_vibration" />

<ImageView
android:id="@+id/play"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerInside"
android:tint="@android:color/white"
android:src="@drawable/ic_play" />

<SeekBar
android:id="@+id/seekBar"
<FrameLayout
android:id="@+id/lessButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#30000000"
android:layout_weight="1">

<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical|end"
android:layout_margin="8dp"
android:scaleType="centerInside"
android:src="@drawable/ic_less"
android:tint="@android:color/white" />

</FrameLayout>

<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#8AFFFFFF" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical">

<FrameLayout
android:id="@+id/vibrationButton"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

<ImageView
android:id="@+id/vibration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:scaleType="centerInside"
android:layout_margin="8dp"
android:src="@drawable/ic_vibration"
android:tint="@android:color/white" />

</FrameLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#8AFFFFFF" />

<FrameLayout
android:id="@+id/playButton"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

<ImageView
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:scaleType="centerInside"
android:layout_margin="8dp"
android:src="@drawable/ic_play"
android:tint="@android:color/white" />

</FrameLayout>

</LinearLayout>

<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#8AFFFFFF" />

<FrameLayout
android:id="@+id/moreButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#30000000"
android:layout_weight="1">

<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical|start"
android:layout_margin="8dp"
android:scaleType="centerInside"
android:src="@drawable/ic_more"
android:tint="@android:color/white" />

</FrameLayout>

</LinearLayout>

<android.support.wearable.view.BoxInsetLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:layout_gravity="top">

<View
android:layout_width="match_parent"
android:layout_height="42dp"
android:max="300" />
android:layout_height="1dip"
android:layout_gravity="bottom"
android:background="#8AFFFFFF" />

<TextView
android:id="@+id/bpm"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="14sp" />
android:orientation="vertical"
app:layout_box="left|right|bottom">

</LinearLayout>
<TextView
android:id="@+id/bpm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="-8dp"
android:gravity="center"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="14sp"
tools:text="140bpm" />

<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="32dp"
android:max="300" />

</LinearLayout>

</android.support.wearable.view.BoxInsetLayout>

</android.support.wearable.view.BoxInsetLayout>
</FrameLayout>

Loading…
Cancel
Save