Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/res/drawable/btn_gray.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2013 jonas.oreland@gmail.com
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that.
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient android:angle="270" android:endColor="#222222" android:startColor="#444444" />
<corners android:radius="5dp" />
</shape>
</item>
<item android:state_enabled="false">
<shape>
<gradient android:angle="270" android:endColor="#171717" android:startColor="#777777" />
<corners android:radius="5dp" />
</shape>
</item>
<item>
<shape>
<gradient android:angle="270" android:endColor="#222222" android:startColor="#555555" />
<corners android:radius="5dp" />
</shape>
</item>
</selector>
90 changes: 66 additions & 24 deletions app/src/main/org/runnerup/view/RunActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.runnerup.view;

import android.annotation.SuppressLint;
import android.app.KeyguardManager;
import android.content.ComponentName;
import android.content.ContentValues;
Expand Down Expand Up @@ -45,7 +46,6 @@
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
Expand Down Expand Up @@ -108,7 +108,7 @@ public class RunActivity extends AppCompatActivity implements TickListener {
private TextView countdownView = null;
private ListView workoutList = null;
private View tableRowInterval = null;
private org.runnerup.workout.Step currentStep = null;
private Step currentStep = null;
private Formatter formatter = null;
private TextView activityHr;
private TextView lapHr;
Expand All @@ -117,17 +117,19 @@ public class RunActivity extends AppCompatActivity implements TickListener {
private TextView activityHeaderHr;
private TextView hrDebug;
// A circular buffer for tap events
private final long[] mTapArray = {0, 0, 0, 0};
private final long[] mTapArray = {0, 0};
private int mTapIndex = 0;
private boolean buttonsLocked = false;

class WorkoutRow {
org.runnerup.workout.Step step = null;
Step step = null;
ContentValues lap = null;
public int level;
}

private final ArrayList<WorkoutRow> workoutRows = new ArrayList<>();

@SuppressLint("SourceLockedOrientationActivity")
@Override
public void onCreate(Bundle savedInstanceState) {
EdgeToEdge.enable(this);
Expand Down Expand Up @@ -174,29 +176,41 @@ public void onCreate(Bundle savedInstanceState) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
final Resources res = this.getResources();
final KeyguardManager km = ContextCompat.getSystemService(this, KeyguardManager.class);
final boolean active = prefs.getBoolean(res.getString(R.string.pref_lock_run), false);
final boolean lockButtons = prefs.getBoolean(res.getString(R.string.pref_lock_run), false);
final boolean showOnLockScreen =
prefs.getBoolean(res.getString(R.string.pref_show_on_lock_screen), true);
final boolean keepScreenOn =
prefs.getBoolean(res.getString(R.string.pref_keep_screen_on), false);
buttonsLocked = lockButtons && showOnLockScreen;
Comment thread
gerhardol marked this conversation as resolved.
Resolved
if (buttonsLocked) {
stopButton.setBackground(AppCompatResources.getDrawable(this, R.drawable.btn_gray));
}

if (!prefs.getBoolean(res.getString(R.string.pref_bt_debug), false)) {
hrDebug = null;
}

TableLayout t = findViewById(R.id.table_layout1);
t.setOnTouchListener(
View root = findViewById(R.id.start_view);
bindGpsTracker();

View.OnTouchListener touchListener =
(v, event) -> {
// Detect tapping on the header
// Detect tapping on the view
int action = event.getAction();
if (active && action == MotionEvent.ACTION_DOWN) {
if (lockButtons && action == MotionEvent.ACTION_DOWN) {
// Check circular buffer for mTapArray.length+1 tap events within time
final int maxTapTime = 1000;
long time = event.getEventTime();
if (mTapArray[mTapIndex] != 0 && time - mTapArray[mTapIndex] < maxTapTime) {
boolean enabled = !pauseButton.isEnabled();
pauseButton.setEnabled(enabled);
stopButton.setEnabled(enabled);
buttonsLocked = !buttonsLocked;
if (buttonsLocked) {
stopButton.setBackground(AppCompatResources.getDrawable(this, R.drawable.btn_gray));
} else {
stopButton.setBackground(AppCompatResources.getDrawable(this, R.drawable.btn_red));
}
Arrays.fill(mTapArray, 0);
// set index so next tap is not message
mTapIndex = 1;
} else {
if (mTapIndex == 0) {
Toast.makeText(
Expand All @@ -210,8 +224,12 @@ public void onCreate(Bundle savedInstanceState) {
}
}
return false;
Comment thread
gerhardol marked this conversation as resolved.
Resolved
});
bindGpsTracker();
};

root.setOnTouchListener(touchListener);
workoutList.setOnTouchListener(touchListener);
stopButton.setOnTouchListener(touchListener);
pauseButton.setOnTouchListener(touchListener);

getOnBackPressedDispatcher()
.addCallback(
Expand All @@ -220,6 +238,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void handleOnBackPressed() {
// Ignore back while in an activity and the device is unlocked
assert km != null;
if (km.isKeyguardLocked()) {
// Original state is re-enabled on resume
showOnLockScreen(false);
Expand Down Expand Up @@ -361,10 +380,10 @@ private void handleActivityResult(int requestCode, int resultCode, Intent data)
/*
* they saved
*/
Double manualDistance = null;
if (data != null && data.hasExtra("MANUAL_DISTANCE")) {
manualDistance = data.getDoubleExtra("MANUAL_DISTANCE", 0);
}
Double manualDistance =
data != null && data.hasExtra("MANUAL_DISTANCE")
? data.getDoubleExtra("MANUAL_DISTANCE", 0)
: null;
workout.onComplete(Scope.ACTIVITY, workout);
if (mTracker != null) {
mTracker.completeActivity(/* save= */ true, manualDistance);
Expand Down Expand Up @@ -447,8 +466,33 @@ private void doStop() {
}

private final OnClickListener newLapButtonClick = v -> newLap();
private final OnClickListener pauseButtonClick = v -> togglePause();
private final OnClickListener stopButtonClick = v -> doStop();
private final OnClickListener pauseButtonClick =
v -> {
if (buttonsLocked) {
Toast.makeText(
getApplicationContext(),
getResources()
.getString(org.runnerup.common.R.string.Lock_activity_buttons_message),
Toast.LENGTH_SHORT)
.show();
} else {
togglePause();
}
};

private final OnClickListener stopButtonClick =
v -> {
if (buttonsLocked) {
Toast.makeText(
getApplicationContext(),
getResources()
.getString(org.runnerup.common.R.string.Lock_activity_buttons_message),
Toast.LENGTH_SHORT)
.show();
} else {
doStop();
}
};

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Expand Down Expand Up @@ -587,8 +631,7 @@ private void updateView() {
}
}

private int getPosition(
ArrayList<WorkoutRow> workoutRows, org.runnerup.workout.Step currentActivity) {
private int getPosition(ArrayList<WorkoutRow> workoutRows, Step currentActivity) {
for (int i = 0; i < workoutRows.size(); i++) {
if (workoutRows.get(i).step == currentActivity) return i;
}
Expand Down Expand Up @@ -673,8 +716,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
}

private View getWorkoutRow(
org.runnerup.workout.Step step, int level, View convertView, ViewGroup parent) {
private View getWorkoutRow(Step step, int level, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(RunActivity.this);
View view = inflater.inflate(R.layout.workout_row, parent, false);
TextView intensity = view.findViewById(R.id.workout_step_intensity);
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
<string name="Lap_start">Lap start</string>
<string name="Lap_start_summary">Cue for start of laps and Active, Warmup, and Cooldown steps</string>
<string name="Lock_activity_buttons">Lock activity buttons</string>
<string name="Lock_activity_buttons_message">Lock activity buttons by fast tapping the header</string>
<string name="Lock_activity_buttons_message">Toggle lock stop/pause buttons by fast tapping the screen</string>
<string name="Volume_button_controls">Volume button controls</string>
<string name="Volume_button_controls_summary">Use volume up to lap and volume down to pause</string>
<string name="Speed">Speed</string>
Expand Down
Loading