Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint / Arctic Fox #15

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
14 changes: 6 additions & 8 deletions .github/workflows/Android-CI-Espresso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ on:
branches:
- master
pull_request:
branches:
- master

jobs:
buildTest:
name: Build & Test JDK ${{ matrix.java_version }}
name: Build & Test
runs-on: macOS-latest
steps:
- name: Checkout
Expand All @@ -20,7 +18,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
distribution: "adopt"
java-version: 11
- name: Install Android SDK
uses: malinskiy/action-android/install-sdk@release/0.1.2
Expand All @@ -39,14 +37,14 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
distribution: "adopt"
java-version: 11
- name: Install Android SDK
uses: malinskiy/action-android/install-sdk@release/0.0.7
uses: malinskiy/action-android/install-sdk@release/0.1.2
- name: Code checks
run: ./gradlew check --stacktrace
run: ./gradlew check
- name: Archive Lint report
uses: actions/upload-artifact@v2.0.1
uses: actions/upload-artifact@v2.2.4
if: ${{ always() }}
with:
name: LEGO-Lint-report
Expand Down
6 changes: 3 additions & 3 deletions MindDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 31
versionCode getGitCommitCount()
versionName getVersion()
}
Expand All @@ -33,7 +33,7 @@ static def getTag() {

dependencies {
implementation "androidx.appcompat:appcompat:1.3.1"
implementation "androidx.annotation:annotation:1.2.0"
implementation "androidx.annotation:annotation:1.3.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
Expand Down
13 changes: 8 additions & 5 deletions MindDroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,34 @@

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:icon="@drawable/logo_new"
android:theme="@style/AppTheme"
android:label="@string/app_name"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
android:name=".MINDdroid"
android:label="@string/app_name"
android:screenOrientation="portrait" />
android:screenOrientation="fullSensor" />
<activity
android:name=".UniversalUploader"
android:label="@string/uul_name"
android:screenOrientation="portrait" />
android:screenOrientation="fullSensor" />
<activity
android:name=".DeviceListActivity"
android:label="@string/select_device"
android:screenOrientation="portrait"
android:screenOrientation="fullSensor"
android:theme="@android:style/Theme.Dialog" />
<activity
android:name=".SplashMenu"
android:label="@string/app_name"
android:screenOrientation="portrait">
android:screenOrientation="fullSensor"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
25 changes: 12 additions & 13 deletions MindDroid/src/main/java/com/lego/minddroid/BTCommunicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;

/**
* This class is for talking to a LEGO NXT robot via bluetooth.
Expand Down Expand Up @@ -74,16 +74,16 @@ public class BTCommunicator extends Thread {
// this is the only OUI registered by LEGO, see http://standards.ieee.org/regauth/oui/index.shtml
public static final String OUI_LEGO = "00:16:53";

private Resources mResources;
private BluetoothAdapter btAdapter;
private final Resources mResources;
private final BluetoothAdapter btAdapter;
private BluetoothSocket nxtBTsocket = null;
private OutputStream nxtOutputStream = null;
private InputStream nxtInputStream = null;
private boolean connected = false;

private Handler uiHandler;
private final Handler uiHandler;
private String mMACaddress;
private BTConnectable myOwner;
private final BTConnectable myOwner;

private byte[] returnMessage;

Expand Down Expand Up @@ -123,7 +123,7 @@ public void run() {
try {
createNXTconnection();
}
catch (IOException e) {
catch (IOException ignored) {
}

while (connected) {
Expand Down Expand Up @@ -153,7 +153,7 @@ public void run() {
public void createNXTconnection() throws IOException {
try {
BluetoothSocket nxtBTSocketTemporary;
BluetoothDevice nxtDevice = null;
BluetoothDevice nxtDevice;
nxtDevice = btAdapter.getRemoteDevice(mMACaddress);
if (nxtDevice == null) {
if (uiHandler == null)
Expand Down Expand Up @@ -181,8 +181,8 @@ public void createNXTconnection() throws IOException {

// try another method for connection, this should work on the HTC desire, credits to Michael Biermann
try {
Method mMethod = nxtDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
nxtBTSocketTemporary = (BluetoothSocket) mMethod.invoke(nxtDevice, Integer.valueOf(1));
Method mMethod = nxtDevice.getClass().getMethod("createRfcommSocket", int.class);
nxtBTSocketTemporary = (BluetoothSocket) mMethod.invoke(nxtDevice, 1);
nxtBTSocketTemporary.connect();
}
catch (Exception e1){
Expand Down Expand Up @@ -396,8 +396,7 @@ private void findFiles(boolean findFirst, int handle) {
private void waitSomeTime(int millis) {
try {
Thread.sleep(millis);

} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
}

Expand All @@ -421,7 +420,7 @@ private void sendBundle(Bundle myBundle) {
}

// receive messages from the UI
private final Handler myHandler = new Handler() {
private final Handler myHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message myMessage) {

Expand Down Expand Up @@ -472,7 +471,7 @@ public void handleMessage(Message myMessage) {
try {
destroyNXTconnection();
}
catch (IOException e) { }
catch (IOException ignored) { }
break;
}
}
Expand Down
10 changes: 4 additions & 6 deletions MindDroid/src/main/java/com/lego/minddroid/FileDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@

class FileDialog {

private Activity myActivity;
private List<String> myList;
private CharSequence[] programs;
private final Activity myActivity;
private final CharSequence[] programs;

public FileDialog(Activity activity, List<String> list) {
myActivity = activity;
myList = list;
// copy Strings from list to CharSequence array
programs = new CharSequence[myList.size()];
Iterator<String> iterator = myList.iterator();
programs = new CharSequence[list.size()];
Iterator<String> iterator = list.iterator();
int position = 0;
while(iterator.hasNext()) {
programs[position++] = iterator.next();
Expand Down
31 changes: 10 additions & 21 deletions MindDroid/src/main/java/com/lego/minddroid/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Vibrator;
import android.util.Log;
Expand Down Expand Up @@ -66,9 +66,9 @@ class GameThread extends Thread {
/** The drawable to use as the background of the animation canvas */
private Bitmap mBackgroundImage;

private Drawable mIconOrange;
private final Drawable mIconOrange;

private Drawable mIconWhite;
private final Drawable mIconWhite;

private Bitmap mTarget;

Expand Down Expand Up @@ -122,11 +122,6 @@ class GameThread extends Thread {
*/
long mElapsedSinceNXTCommand = 0;

/**
* count how many times we took tilt readings in 100ms so we can average
* position
*/
int mAvCount = 0;
/**
* time when tilt icon should change color
*/
Expand All @@ -144,7 +139,6 @@ class GameThread extends Thread {

/** digital filtering variables **/
private float xX0 = 0;
private float xX1 = 0;
private float xY0 = 0;
private float xY1 = 0;

Expand Down Expand Up @@ -580,7 +574,7 @@ public void vibrate() {
void updateMoveIndicator(float mAcX, float mAcY) {

// IIR filtering for x direction
xX1 = xX0;
float xX1 = xX0;
xX0 = mAcX;
xY1 = xY0;
xY0 = (float) 0.07296293 * xX0 + (float) 0.07296293 * xX1 + (float) 0.8540807 * xY1;
Expand Down Expand Up @@ -608,24 +602,20 @@ public boolean isInGoal() {
return false;
}

if (((mCanvasHeight - (mActionButton.getHeight() + (GOAL_HEIGHT))) / 2 > mY || ((mCanvasHeight - mActionButton.getHeight()) + (GOAL_HEIGHT)) / 2 < mY)) {
return false;
}

return true;
return !((mCanvasHeight - (mActionButton.getHeight() + (GOAL_HEIGHT))) / 2 > mY) && !(((mCanvasHeight - mActionButton.getHeight()) + (GOAL_HEIGHT)) / 2 < mY);
}

}

/** used for logging */
private static final String TAG = GameView.class.getName();

private MINDdroid mActivity;
private final MINDdroid mActivity;

/** The thread that actually draws the animation */
private GameThread thread;

private SensorManager mSensorManager;
private final SensorManager mSensorManager;

/** orientation (tilt) readings */
private float mAccelX = 0;
Expand Down Expand Up @@ -663,7 +653,7 @@ public GameView(Context context, MINDdroid uiActivity) {
holder.addCallback(this);
this.context = context;
// create thread only; it's started in surfaceCreated()
thread = new GameThread(holder, context, (Vibrator) uiActivity.getSystemService(Context.VIBRATOR_SERVICE), new Handler() {
thread = new GameThread(holder, context, (Vibrator) uiActivity.getSystemService(Context.VIBRATOR_SERVICE), new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message m) {

Expand Down Expand Up @@ -729,7 +719,7 @@ public void surfaceCreated(SurfaceHolder holder) {

getThread().start();
} else {
thread = new GameThread(holder, context, (Vibrator) mActivity.getSystemService(Context.VIBRATOR_SERVICE), new Handler() {
thread = new GameThread(holder, context, (Vibrator) mActivity.getSystemService(Context.VIBRATOR_SERVICE), new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message m) {

Expand All @@ -752,7 +742,7 @@ public void surfaceDestroyed(SurfaceHolder holder) {
try {
getThread().join();
retry = false;
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
}
}
Expand All @@ -763,4 +753,3 @@ public void unregisterListener() {
}

}

7 changes: 2 additions & 5 deletions MindDroid/src/main/java/com/lego/minddroid/MINDdroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import android.bluetooth.BluetoothAdapter
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.os.Vibrator
import android.os.*
import android.speech.tts.TextToSpeech
import android.speech.tts.TextToSpeech.OnInitListener
import android.view.Menu
Expand Down Expand Up @@ -441,7 +438,7 @@ class MINDdroid : AppCompatActivity(), BTConnectable, OnInitListener {
/**
* Receive messages from the BTCommunicator
*/
val myHandler: Handler = object : Handler() {
private val myHandler: Handler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(myMessage: Message) {
when (myMessage.data.getInt("message")) {
BTCommunicator.DISPLAY_TOAST -> showToast(myMessage.data.getString("toastText"))
Expand Down
Loading