Skip to content
Open
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
22 changes: 11 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ android {


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:25.1.0'
implementation 'com.android.support:gridlayout-v7:25.1.0'
implementation 'com.google.android.gms:play-services-drive:10.0.1'
implementation 'com.getpebble:pebblekit:3.1.0'
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
implementation 'com.jakewharton.timber:timber:4.3.1'
implementation 'com.pavelsikun:material-seekbar-preference:2.3.0+'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.0'
implementation "com.github.hotchemi:permissionsdispatcher:2.2.0"
annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:2.2.0"
compile fileTree(dir: 'libs', include: ['*.jar'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile instruction deprecated, please update Android studio/graddle

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was probably added automatically... or stayed there when I merged with your most current code. Will update.

compile 'com.android.support:design:25+'
compile 'com.android.support:gridlayout-v7:25.1.0'
compile 'com.google.android.gms:play-services-drive:10.0.1'
compile 'com.getpebble:pebblekit:3.1.0'
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
compile 'com.jakewharton.timber:timber:4.3.1'
compile 'com.pavelsikun:material-seekbar-preference:2.3.0+'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.0'
compile 'com.github.hotchemi:permissionsdispatcher:2.2.0'
annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.2.0'
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/cooper/wheellog/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ private void loadPreferences() {
wheelView.invalidate();

boolean alarms_enabled = sharedPreferences.getBoolean(getString(R.string.alarms_enabled), false);
boolean inMotion_general_alarms_enable = sharedPreferences.getBoolean(getString(R.string.inMotion_alarms_enabled),false);
boolean use_ratio = sharedPreferences.getBoolean(getString(R.string.use_ratio), false);
WheelData.getInstance().setUseRatio(use_ratio);

Expand All @@ -974,6 +975,8 @@ private void loadPreferences() {
//WheelData.getInstance().setGotway84V(gotway_84v);
WheelData.getInstance().setAlarmsEnabled(alarms_enabled);

WheelData.getInstance().setInmotionAlarmsEnabled(inMotion_general_alarms_enable);

if (alarms_enabled) {
int alarm1Speed = sharedPreferences.getInt(getString(R.string.alarm_1_speed), 0);
int alarm2Speed = sharedPreferences.getInt(getString(R.string.alarm_2_speed), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
case "alarms_enabled":
hideShowSeekBars();
break;
case "inMotion_alarms_enabled":
WheelData.getInstance().setInmotionAlarmsEnabled(getPreferenceManager().getSharedPreferences()
.getBoolean(getString(R.string.inMotion_alarms_enabled), false));
break;
case "auto_upload":
if (SettingsUtil.isAutoUploadEnabled(getActivity()) && !mDataWarningDisplayed) {
SettingsUtil.setAutoUploadEnabled(getActivity(), false);
Expand Down
49 changes: 49 additions & 0 deletions app/src/main/java/com/cooper/wheellog/WheelData.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.cooper.wheellog;

import android.app.Activity;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that it is needed?
import android.app.Activity;
import android.app.Application;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. Will check.

import android.app.AlertDialog;
import android.app.Application;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Vibrator;

import android.text.InputType;
Expand All @@ -28,6 +31,7 @@ public class WheelData {
private static final int TIME_BUFFER = 10;
private static WheelData mInstance;
private Timer ridingTimerControl;
private MediaPlayer mAlertSoundPlayer;

private BluetoothLeService mBluetoothLeService;

Expand Down Expand Up @@ -68,6 +72,7 @@ public class WheelData {
private String mBtName = "";

private String mAlert = "";
private int mAlertId = 0;

// private int mVersion; # sorry King, but INT not good for Inmo
private String mVersion = "";
Expand All @@ -84,6 +89,7 @@ public class WheelData {
private int mWheelTiltHorizon = 0;

private boolean mAlarmsEnabled = false;
private boolean mInmotionAlarmsEnabled = false;
private boolean mDisablePhoneVibrate = false;
private int mAlarm1Speed = 0;
private int mAlarm2Speed = 0;
Expand All @@ -101,6 +107,7 @@ public class WheelData {
private boolean mSpeedAlarmExecuted = false;
private boolean mCurrentAlarmExecuted = false;
private boolean mTemperatureAlarmExecuted = false;
private boolean mGeneralInMotionAlarmExecuted = false;

static void initiate() {
if (mInstance == null)
Expand Down Expand Up @@ -573,6 +580,10 @@ void setConnected(boolean connected) {
void setAlarmsEnabled(boolean enabled) {
mAlarmsEnabled = enabled;
}

void setInmotionAlarmsEnabled(boolean enabled){
mInmotionAlarmsEnabled = enabled;
}

void setUseRatio(boolean enabled) {
mUseRatio = enabled;
Expand Down Expand Up @@ -680,11 +691,25 @@ else if (mAlarm3Speed > 0 && mAlarm3Battery > 0 &&
if (mTemperature < mAlarmTemperature)
mTemperatureAlarmExecuted = false;
}


}

private void checkInMotionAlarmStatus(Context mContext) {
// GENERAL inMotion Alarm
if (!mGeneralInMotionAlarmExecuted)
{
if (mAlertId != 0) {
raiseAlarm(ALARM_TYPE.GENERAL,mContext);
mAlertId = 0;
}
}
}

private void raiseAlarm(ALARM_TYPE alarmType, Context mContext) {
Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
MediaPlayer mp = new MediaPlayer();

long[] pattern = {0};
Intent intent = new Intent(Constants.ACTION_ALARM_TRIGGERED);
intent.putExtra(Constants.INTENT_EXTRA_ALARM_TYPE, alarmType);
Expand All @@ -702,8 +727,24 @@ private void raiseAlarm(ALARM_TYPE alarmType, Context mContext) {
pattern = new long[]{0, 500, 100, 100, 100, 500, 100, 100, 100, 500, 100, 100, 100};
mCurrentAlarmExecuted = true;
break;
case GENERAL:
if (mp.isPlaying() == false) {
mp = MediaPlayer.create(mContext, R.raw.bicycle_bell);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bicycle_bell? I think it should be separate sound, something like inmotion sound.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a //TODO to change it. Will do, use the SCV default sound for that.

mp.start();
//That fires after the sound has played so it releases the resourse.
//Needed otherwise it would stop working after a while
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.reset();
mp.release();
mGeneralInMotionAlarmExecuted = false;
}
});
}
break;
}
mContext.sendBroadcast(intent);

if (v.hasVibrator() && !mDisablePhoneVibrate)
v.vibrate(pattern, -1);
}
Expand Down Expand Up @@ -758,6 +799,9 @@ else if (mWheelType == WHEEL_TYPE.NINEBOT_Z) {

if (mAlarmsEnabled)
checkAlarmStatus(mContext);
if (mInmotionAlarmsEnabled)
checkInMotionAlarmStatus(mContext);

mContext.sendBroadcast(intent);


Expand Down Expand Up @@ -998,6 +1042,11 @@ private boolean decodeInmotion(byte[] data) {
} else {
mAlert = mAlert + " | " + ((InMotionAdapter.Alert) status).getfullText();
}
mAlertId = ((InMotionAdapter.Alert) status).getAlertId(); //mAlertId is checked on checkAlarms function.
if (mAlertId == 0x05) //Discards alerts that the user does not need.
{
mAlertId = 0;
}
} else {
mSpeed = (int) (status.getSpeed() * 360d);
mVoltage = (int) (status.getVoltage() * 100d);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/cooper/wheellog/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public int getValue() {
public enum ALARM_TYPE {
SPEED(0),
CURRENT(1),
TEMPERATURE(2);
TEMPERATURE(2),
GENERAL(3);


private final int value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ public String getfullText() {
return fullText;

}
public int getAlertId(){
return alertId;
}


}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/cooper/wheellog/views/WheelView.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ protected void onDraw(Canvas canvas) {
canvas.drawText(getResources().getString(R.string.distance), blRect.centerX(), blRect.centerY() - (box_inner_padding / 2), textPaint);
canvas.drawText(getResources().getString(R.string.total), brRect.centerX(), brRect.centerY() - (box_inner_padding / 2), textPaint);

//canvas.drawText(String.format(Locale.US, "%.2fV (%.2fV)", mVoltage, (mVoltage/16.0)), tlRect.centerX(), tlRect.centerY() + boxTextHeight, textPaint);
canvas.drawText(String.format(Locale.US, "%.2fV", mVoltage), tlRect.centerX(), tlRect.centerY() + boxTextHeight, textPaint);
//canvas.drawText(String.format(Locale.US, "%.2fW", mCurrent), trRect.centerX(), trRect.centerY() + boxTextHeight, textPaint);
canvas.drawText(mCurrentTime, mlRect.centerX(), mlRect.centerY() + boxTextHeight + (box_inner_padding / 2), textPaint);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@


// ALARM PREFERENCES
<string name="inMotion_alarms_enabled" translatable="false">inMotion_alarms_enabled</string>
<string name="alarms_enabled" translatable="false">alarms_enabled</string>
<string name="disable_phone_vibrate" translatable="false">disable_phone_vibrate</string>
<string name="alarm_1_speed" translatable="false">alarm_1_speed</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preferences_alarms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
android:title="Enable Alarms"
android:summary="Allow the phone to vibrate as a warning" />

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it is good idea to put inmotion-specific option to general menu. Maybe it's better to move it to inmotion_preferences, or at least make it disabled by default?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Youre right. Ill move it.

<CheckBoxPreference
android:key="@string/inMotion_alarms_enabled"
android:title="Enable InMotion Alarms"
android:summary="Enable InMotion Specific General Alarms" />

<CheckBoxPreference
android:key="@string/disable_phone_vibrate"
android:dependency="alarms_enabled"
Expand Down