Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/org/ratchetrockers1706/bluetransfer/MainActivity.java
  • Loading branch information
Scouting1706 committed Jan 17, 2023
2 parents dd1dc8a + c39950e commit 7e309a1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
Expand All @@ -26,6 +30,7 @@


public class BluetoothServerService extends IntentService {
int notificationId = (int)(Math.random() * 102400.0);

private class ToastRunner implements Runnable {
private String message;
Expand All @@ -35,7 +40,27 @@ public ToastRunner(String message) {

@Override
public void run() {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
try {
Log.e(this.getClass().getSimpleName(), "Sending notification message: " + message);
Context appCtxt = getApplicationContext();
// The string "my-integer" will be used to filer the intent
Intent intent = new Intent("scouting-message");
// Adding some data
intent.putExtra("message", message);
LocalBroadcastManager.getInstance(appCtxt).sendBroadcast(intent);

NotificationCompat.Builder builder = new NotificationCompat.Builder(appCtxt)
//.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Scouting 1706")
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(false);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(appCtxt);
notificationManager.notify(++notificationId, builder.build());
} catch (Exception e) {
Log.e(this.getClass().getSimpleName(), "Unable to send notification", e);
}
}
}

Expand Down Expand Up @@ -91,6 +116,22 @@ public void run() {
} else {
out.println("0");
}
} else if (input.toLowerCase().startsWith("put ")) {
String[] parts = input.split(" ");
if (parts.length == 3) {
String filename = parts[1];
int length = Integer.parseInt(parts[2]);
char buffer[] = new char[length];
int charsRead = 0;
while (charsRead < length) {
charsRead += in.read(buffer, charsRead, length - charsRead);
}
if (charsRead == length) {
File myDir = getUploadDirectory();
File outFile = new File(myDir, filename);
writeFile(outFile, new String(buffer));
}
}
} else if (input.toLowerCase().startsWith("delete ")) {
File myDir = getDataDirectory();
String filename = input.substring(6).trim();
Expand All @@ -106,6 +147,10 @@ public void run() {
}
} else if (input.toLowerCase().startsWith("toast ")) {
Log.i(BluetoothServerService.class.getName(), "Toast: " + input);

//Intent intent = new Intent(this, "com.example.robotics.deepspace");


myHandler.post(new ToastRunner(input.substring(6).trim()));
} else {
out.println("What?");
Expand Down Expand Up @@ -249,13 +294,32 @@ private static String readFile(File f) {
return "";
}

private static boolean writeFile(File f, String content) {
try {
FileWriter writer = new FileWriter(f);
writer.write(content);
writer.close();
} catch (IOException e) {
Log.e(BluetoothServerService.class.getName(), "Unable to write file " + f.getName(), e);
return false;
}
return true;
}

public static File getDataDirectory() {
File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
File myDir = new File(directory + "/ScoutingData");
myDir.mkdirs();
return myDir;
}

public static File getUploadDirectory() {
File directory = Environment.getExternalStorageDirectory();
File myDir = new File(directory + "/Documents");
myDir.mkdirs();
return myDir;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
tools:context=".MainActivity">

<TextView
android:id="@+id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.5.3'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Mar 02 08:55:02 CST 2019
#Sat Feb 08 14:21:04 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

0 comments on commit 7e309a1

Please sign in to comment.