v1.0
1
app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
29
app/build.gradle
Normal file
@@ -0,0 +1,29 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'org.eu.octt.notetand'
|
||||
compileSdk 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId "org.eu.octt.notetand"
|
||||
minSdk 10
|
||||
targetSdk 35
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {}
|
21
app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
BIN
app/release/app-release.apk
Normal file
21
app/release/output-metadata.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "org.eu.octt.notetand",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1,
|
||||
"versionName": "1.0",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File",
|
||||
"minSdkVersionForDexing": 10
|
||||
}
|
95
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
|
||||
|
||||
<!-- Bluetooth permissions -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<!-- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> -->
|
||||
|
||||
<!-- For Android 12+ (API 31+) -->
|
||||
<!-- <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
|
||||
<!-- Storage permissions -->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
|
||||
|
||||
<!-- Location for Bluetooth scanning on Android 6+ -->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> -->
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
tools:targetApi="31">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- <activity
|
||||
android:name=".MainActivity1"
|
||||
android:exported="true" /> -->
|
||||
|
||||
<activity
|
||||
android:name=".NoteActivity"
|
||||
android:label="@string/note"
|
||||
android:exported="true"
|
||||
android:parentActivityName=".MainActivity">
|
||||
|
||||
<intent-filter android:label="@string/new_note_activity">
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ReceiveActivity"
|
||||
android:label="@string/receive_notes"
|
||||
android:exported="false"
|
||||
android:parentActivityName=".MainActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".SendActivity"
|
||||
android:label="@string/send_note"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:label="@string/settings"
|
||||
android:exported="false"
|
||||
android:parentActivityName=".MainActivity" />
|
||||
|
||||
<!-- <activity
|
||||
android:name=".BluetoothSyncActivity"
|
||||
android:exported="false"
|
||||
android:parentActivityName=".MainActivity1" /> -->
|
||||
|
||||
<provider
|
||||
android:name=".NotesProvider"
|
||||
android:authorities="org.eu.octt.notetand"
|
||||
android:exported="true"
|
||||
android:grantUriPermissions="true"
|
||||
android:permission="android.permission.MANAGE_DOCUMENTS">
|
||||
<intent-filter>
|
||||
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
|
||||
</intent-filter>
|
||||
</provider>
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
BIN
app/src/main/ic_launcher-playstore.png
Normal file
After Width: | Height: | Size: 193 KiB |
38
app/src/main/java/org/eu/octt/notetand/BluetoothManager.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
|
||||
public class BluetoothManager {
|
||||
static final int REQUEST_ENABLE_BT = 1001;
|
||||
static final int REQUEST_PERMISSION_BT = 1002;
|
||||
|
||||
static boolean getPermission(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && activity.checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||
activity.requestPermissions(new String[]{Manifest.permission.BLUETOOTH_CONNECT}, REQUEST_PERMISSION_BT);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission") // we're checking it but the IDE won't budge
|
||||
static boolean requireBluetooth(Activity activity) {
|
||||
if (!getPermission(activity))
|
||||
return false;
|
||||
var adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (adapter != null) {
|
||||
if (adapter.isEnabled()) {
|
||||
return true;
|
||||
} else {
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
activity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,797 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothServerSocket;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BluetoothSyncActivity extends Activity {
|
||||
|
||||
private static final String TAG = "BluetoothSync";
|
||||
private static final UUID SERVICE_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
|
||||
private static final String SERVICE_NAME = "SyncNotesApp";
|
||||
private static final int REQUEST_DISCOVERABLE = 2001;
|
||||
private static final int DISCOVERABLE_DURATION = 300; // 5 minutes
|
||||
|
||||
// Protocol constants
|
||||
private static final String PROTOCOL_HANDSHAKE = "SYNCNOTES_HANDSHAKE";
|
||||
private static final String PROTOCOL_FILE_LIST = "FILE_LIST";
|
||||
private static final String PROTOCOL_FILE_REQUEST = "FILE_REQUEST";
|
||||
private static final String PROTOCOL_FILE_DATA = "FILE_DATA";
|
||||
private static final String PROTOCOL_SYNC_COMPLETE = "SYNC_COMPLETE";
|
||||
private static final String PROTOCOL_ERROR = "ERROR";
|
||||
|
||||
private BluetoothAdapter bluetoothAdapter;
|
||||
private TextView txtBluetoothStatus;
|
||||
private TextView txtSyncProgress;
|
||||
private Button btnMakeDiscoverable;
|
||||
private Button btnScanDevices;
|
||||
private Button btnCancelSync;
|
||||
private ListView listPairedDevices;
|
||||
private ListView listDiscoveredDevices;
|
||||
|
||||
private ArrayAdapter<String> pairedDevicesAdapter;
|
||||
private ArrayAdapter<String> discoveredDevicesAdapter;
|
||||
private ArrayList<BluetoothDevice> pairedDevicesList;
|
||||
private ArrayList<BluetoothDevice> discoveredDevicesList;
|
||||
|
||||
private AcceptThread acceptThread;
|
||||
private ConnectThread connectThread;
|
||||
private ConnectedThread connectedThread;
|
||||
private Handler mainHandler;
|
||||
private File notesDirectory;
|
||||
private boolean isScanning = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.bluetooth_sync_activity);
|
||||
|
||||
// Enable up navigation
|
||||
if (getActionBar() != null) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getActionBar().setTitle("Bluetooth Sync");
|
||||
}
|
||||
|
||||
mainHandler = new Handler(Looper.getMainLooper());
|
||||
initializeViews();
|
||||
setupNotesDirectory();
|
||||
initializeBluetooth();
|
||||
setupListeners();
|
||||
}
|
||||
|
||||
private void initializeViews() {
|
||||
txtBluetoothStatus = findViewById(R.id.txt_bluetooth_status);
|
||||
txtSyncProgress = findViewById(R.id.txt_sync_progress);
|
||||
btnMakeDiscoverable = findViewById(R.id.btn_make_discoverable);
|
||||
btnScanDevices = findViewById(R.id.btn_scan_devices);
|
||||
btnCancelSync = findViewById(R.id.btn_cancel_sync);
|
||||
listPairedDevices = findViewById(R.id.list_paired_devices);
|
||||
listDiscoveredDevices = findViewById(R.id.list_discovered_devices);
|
||||
|
||||
// Initialize device lists
|
||||
pairedDevicesList = new ArrayList<>();
|
||||
discoveredDevicesList = new ArrayList<>();
|
||||
|
||||
pairedDevicesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
|
||||
discoveredDevicesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
|
||||
|
||||
listPairedDevices.setAdapter(pairedDevicesAdapter);
|
||||
listDiscoveredDevices.setAdapter(discoveredDevicesAdapter);
|
||||
}
|
||||
|
||||
private void setupNotesDirectory() {
|
||||
String notesPath = getIntent().getStringExtra("notes_directory");
|
||||
if (notesPath != null) {
|
||||
notesDirectory = new File(notesPath);
|
||||
} else {
|
||||
File externalFilesDir = getExternalFilesDir(null);
|
||||
if (externalFilesDir != null) {
|
||||
notesDirectory = new File(externalFilesDir, "notes");
|
||||
} else {
|
||||
notesDirectory = new File(getFilesDir(), "notes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeBluetooth() {
|
||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
if (bluetoothAdapter == null) {
|
||||
updateStatus("Bluetooth not supported on this device");
|
||||
disableAllButtons();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bluetoothAdapter.isEnabled()) {
|
||||
updateStatus("Bluetooth is disabled");
|
||||
disableAllButtons();
|
||||
return;
|
||||
}
|
||||
|
||||
updateStatus("Bluetooth ready");
|
||||
loadPairedDevices();
|
||||
startAcceptThread();
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
btnMakeDiscoverable.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
makeDiscoverable();
|
||||
}
|
||||
});
|
||||
|
||||
btnScanDevices.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isScanning) {
|
||||
stopDeviceDiscovery();
|
||||
} else {
|
||||
startDeviceDiscovery();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
btnCancelSync.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
listPairedDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
BluetoothDevice device = pairedDevicesList.get(position);
|
||||
connectToDevice(device);
|
||||
}
|
||||
});
|
||||
|
||||
listDiscoveredDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
BluetoothDevice device = discoveredDevicesList.get(position);
|
||||
connectToDevice(device);
|
||||
}
|
||||
});
|
||||
|
||||
// Register for broadcasts when a device is discovered
|
||||
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
|
||||
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
|
||||
registerReceiver(discoveryReceiver, filter);
|
||||
}
|
||||
|
||||
private void loadPairedDevices() {
|
||||
pairedDevicesList.clear();
|
||||
pairedDevicesAdapter.clear();
|
||||
|
||||
if (checkBluetoothPermission()) {
|
||||
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
|
||||
if (pairedDevices.size() > 0) {
|
||||
for (BluetoothDevice device : pairedDevices) {
|
||||
pairedDevicesList.add(device);
|
||||
String deviceInfo = device.getName() + "\n" + device.getAddress();
|
||||
pairedDevicesAdapter.add(deviceInfo);
|
||||
}
|
||||
} else {
|
||||
pairedDevicesAdapter.add("No paired devices found");
|
||||
}
|
||||
} else {
|
||||
pairedDevicesAdapter.add("Bluetooth permission required");
|
||||
}
|
||||
|
||||
pairedDevicesAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void makeDiscoverable() {
|
||||
if (!checkBluetoothPermission()) {
|
||||
Toast.makeText(this, "Bluetooth permission required", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
|
||||
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, DISCOVERABLE_DURATION);
|
||||
startActivityForResult(discoverableIntent, REQUEST_DISCOVERABLE);
|
||||
}
|
||||
|
||||
private void startDeviceDiscovery() {
|
||||
if (!checkBluetoothPermission()) {
|
||||
Toast.makeText(this, "Bluetooth permission required", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
discoveredDevicesList.clear();
|
||||
discoveredDevicesAdapter.clear();
|
||||
discoveredDevicesAdapter.notifyDataSetChanged();
|
||||
|
||||
if (bluetoothAdapter.isDiscovering()) {
|
||||
bluetoothAdapter.cancelDiscovery();
|
||||
}
|
||||
|
||||
boolean started = bluetoothAdapter.startDiscovery();
|
||||
if (started) {
|
||||
isScanning = true;
|
||||
btnScanDevices.setText("Stop Scan");
|
||||
updateProgress("Scanning for devices...");
|
||||
} else {
|
||||
Toast.makeText(this, "Failed to start device discovery", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void stopDeviceDiscovery() {
|
||||
if (checkBluetoothPermission() && bluetoothAdapter.isDiscovering()) {
|
||||
bluetoothAdapter.cancelDiscovery();
|
||||
}
|
||||
isScanning = false;
|
||||
btnScanDevices.setText("Scan for Devices");
|
||||
updateProgress("");
|
||||
}
|
||||
|
||||
private void connectToDevice(final BluetoothDevice device) {
|
||||
if (!checkBluetoothPermission()) {
|
||||
Toast.makeText(this, "Bluetooth permission required", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop discovery to save resources
|
||||
if (bluetoothAdapter.isDiscovering()) {
|
||||
bluetoothAdapter.cancelDiscovery();
|
||||
isScanning = false;
|
||||
btnScanDevices.setText("Scan for Devices");
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Connect to Device")
|
||||
.setMessage("Connect to " + device.getName() + " (" + device.getAddress() + ") for sync?")
|
||||
.setPositiveButton("Connect", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startConnectThread(device);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void startConnectThread(BluetoothDevice device) {
|
||||
// Cancel any existing connection attempts
|
||||
if (connectThread != null) {
|
||||
connectThread.cancel();
|
||||
connectThread = null;
|
||||
}
|
||||
|
||||
connectThread = new ConnectThread(device);
|
||||
connectThread.start();
|
||||
updateProgress("Connecting to " + device.getName() + "...");
|
||||
}
|
||||
|
||||
private void startAcceptThread() {
|
||||
if (acceptThread != null) {
|
||||
acceptThread.cancel();
|
||||
}
|
||||
acceptThread = new AcceptThread();
|
||||
acceptThread.start();
|
||||
}
|
||||
|
||||
private boolean checkBluetoothPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
return checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateStatus(String status) {
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
txtBluetoothStatus.setText(status);
|
||||
}
|
||||
});
|
||||
Log.d(TAG, "Status: " + status);
|
||||
}
|
||||
|
||||
private void updateProgress(String progress) {
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
txtSyncProgress.setText(progress);
|
||||
}
|
||||
});
|
||||
Log.d(TAG, "Progress: " + progress);
|
||||
}
|
||||
|
||||
private void disableAllButtons() {
|
||||
btnMakeDiscoverable.setEnabled(false);
|
||||
btnScanDevices.setEnabled(false);
|
||||
}
|
||||
|
||||
// BroadcastReceiver for Bluetooth device discovery
|
||||
private final BroadcastReceiver discoveryReceiver = new BroadcastReceiver() {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
|
||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
if (device != null && checkBluetoothPermission()) {
|
||||
String deviceName = device.getName();
|
||||
if (deviceName == null) {
|
||||
deviceName = "Unknown Device";
|
||||
}
|
||||
|
||||
// Avoid duplicates
|
||||
boolean alreadyAdded = false;
|
||||
for (BluetoothDevice existingDevice : discoveredDevicesList) {
|
||||
if (existingDevice.getAddress().equals(device.getAddress())) {
|
||||
alreadyAdded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!alreadyAdded) {
|
||||
discoveredDevicesList.add(device);
|
||||
String deviceInfo = deviceName + "\n" + device.getAddress();
|
||||
discoveredDevicesAdapter.add(deviceInfo);
|
||||
discoveredDevicesAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
|
||||
isScanning = false;
|
||||
btnScanDevices.setText("Scan for Devices");
|
||||
updateProgress("Discovery finished. Found " + discoveredDevicesList.size() + " devices.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Thread for accepting incoming connections
|
||||
private class AcceptThread extends Thread {
|
||||
private BluetoothServerSocket serverSocket;
|
||||
|
||||
public AcceptThread() {
|
||||
try {
|
||||
if (checkBluetoothPermission()) {
|
||||
serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord(
|
||||
SERVICE_NAME, SERVICE_UUID);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Socket listen() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
BluetoothSocket socket = null;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
socket = serverSocket.accept();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Socket accept() failed", e);
|
||||
break;
|
||||
}
|
||||
|
||||
if (socket != null) {
|
||||
// Connection accepted
|
||||
manageConnectedSocket(socket);
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not close server socket", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
try {
|
||||
if (serverSocket != null) {
|
||||
serverSocket.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not close server socket", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Thread for connecting to a device
|
||||
private class ConnectThread extends Thread {
|
||||
private BluetoothSocket socket;
|
||||
private BluetoothDevice device;
|
||||
|
||||
public ConnectThread(BluetoothDevice device) {
|
||||
this.device = device;
|
||||
|
||||
try {
|
||||
if (checkBluetoothPermission()) {
|
||||
socket = device.createRfcommSocketToServiceRecord(SERVICE_UUID);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Socket create() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Cancel discovery to save resources
|
||||
if (checkBluetoothPermission() && bluetoothAdapter.isDiscovering()) {
|
||||
bluetoothAdapter.cancelDiscovery();
|
||||
}
|
||||
|
||||
try {
|
||||
if (checkBluetoothPermission()) {
|
||||
socket.connect();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not connect to device", e);
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress("Connection failed: " + e.getMessage());
|
||||
Toast.makeText(BluetoothSyncActivity.this, "Connection failed", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException closeException) {
|
||||
Log.e(TAG, "Could not close client socket", closeException);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Connection successful
|
||||
manageConnectedSocket(socket);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
try {
|
||||
if (socket != null) {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not close client socket", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Thread for managing a connected socket
|
||||
private class ConnectedThread extends Thread {
|
||||
private BluetoothSocket socket;
|
||||
private InputStream inputStream;
|
||||
private OutputStream outputStream;
|
||||
|
||||
public ConnectedThread(BluetoothSocket socket) {
|
||||
this.socket = socket;
|
||||
|
||||
try {
|
||||
inputStream = socket.getInputStream();
|
||||
outputStream = socket.getOutputStream();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error occurred when creating input/output streams", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
byte[] buffer = new byte[1024];
|
||||
int numBytes;
|
||||
|
||||
// Keep listening to the InputStream while connected
|
||||
while (true) {
|
||||
try {
|
||||
numBytes = inputStream.read(buffer);
|
||||
String receivedMessage = new String(buffer, 0, numBytes, "UTF-8");
|
||||
handleReceivedMessage(receivedMessage);
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Input stream was disconnected", e);
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress("Connection lost");
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(String message) {
|
||||
try {
|
||||
byte[] bytes = message.getBytes("UTF-8");
|
||||
outputStream.write(bytes);
|
||||
Log.d(TAG, "Sent: " + message);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error occurred when sending data", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not close connected socket", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void manageConnectedSocket(BluetoothSocket socket) {
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress("Connected! Starting sync...");
|
||||
}
|
||||
});
|
||||
|
||||
// Cancel existing threads
|
||||
if (connectThread != null) {
|
||||
connectThread.cancel();
|
||||
connectThread = null;
|
||||
}
|
||||
if (acceptThread != null) {
|
||||
acceptThread.cancel();
|
||||
acceptThread = null;
|
||||
}
|
||||
|
||||
// Start the connected thread
|
||||
connectedThread = new ConnectedThread(socket);
|
||||
connectedThread.start();
|
||||
|
||||
// Start the sync protocol
|
||||
startSyncProtocol();
|
||||
}
|
||||
|
||||
private void handleReceivedMessage(String message) {
|
||||
Log.d(TAG, "Received: " + message);
|
||||
|
||||
String[] parts = message.split("\\|", 2);
|
||||
String command = parts[0];
|
||||
String data = parts.length > 1 ? parts[1] : "";
|
||||
|
||||
switch (command) {
|
||||
case PROTOCOL_HANDSHAKE:
|
||||
handleHandshake(data);
|
||||
break;
|
||||
case PROTOCOL_FILE_LIST:
|
||||
handleFileList(data);
|
||||
break;
|
||||
case PROTOCOL_FILE_REQUEST:
|
||||
handleFileRequest(data);
|
||||
break;
|
||||
case PROTOCOL_FILE_DATA:
|
||||
handleFileData(data);
|
||||
break;
|
||||
case PROTOCOL_SYNC_COMPLETE:
|
||||
handleSyncComplete();
|
||||
break;
|
||||
case PROTOCOL_ERROR:
|
||||
handleError(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void startSyncProtocol() {
|
||||
if (connectedThread != null) {
|
||||
connectedThread.write(PROTOCOL_HANDSHAKE + "|" + android.os.Build.MODEL);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleHandshake(String deviceInfo) {
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress("Handshake received from " + deviceInfo);
|
||||
}
|
||||
});
|
||||
|
||||
// Send our file list
|
||||
sendFileList();
|
||||
}
|
||||
|
||||
private void sendFileList() {
|
||||
List<NoteManager.NoteInfo> notes = NoteManager.getAllNoteInfo(notesDirectory);
|
||||
StringBuilder fileList = new StringBuilder();
|
||||
|
||||
for (NoteManager.NoteInfo note : notes) {
|
||||
if (fileList.length() > 0) {
|
||||
fileList.append(";");
|
||||
}
|
||||
fileList.append(note.name).append(",")
|
||||
.append(note.lastModified).append(",")
|
||||
.append(note.hash);
|
||||
}
|
||||
|
||||
if (connectedThread != null) {
|
||||
connectedThread.write(PROTOCOL_FILE_LIST + "|" + fileList.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFileList(String fileListData) {
|
||||
// Parse remote file list and determine what files to sync
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress("Comparing files...");
|
||||
}
|
||||
});
|
||||
|
||||
// Simple implementation: request all files that are different
|
||||
// In a full implementation, you'd compare timestamps and hashes
|
||||
String[] files = fileListData.split(";");
|
||||
for (String fileInfo : files) {
|
||||
if (!fileInfo.isEmpty()) {
|
||||
String[] parts = fileInfo.split(",");
|
||||
if (parts.length >= 3) {
|
||||
String fileName = parts[0];
|
||||
long timestamp = Long.parseLong(parts[1]);
|
||||
String hash = parts[2];
|
||||
|
||||
// Check if we need this file
|
||||
NoteManager.NoteInfo localNote = NoteManager.getNoteInfo(notesDirectory, fileName);
|
||||
if (localNote == null || localNote.lastModified < timestamp || !localNote.hash.equals(hash)) {
|
||||
// Request this file
|
||||
if (connectedThread != null) {
|
||||
connectedThread.write(PROTOCOL_FILE_REQUEST + "|" + fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send sync complete when done
|
||||
mainHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (connectedThread != null) {
|
||||
connectedThread.write(PROTOCOL_SYNC_COMPLETE + "|");
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
private void handleFileRequest(String fileName) {
|
||||
String content = NoteManager.loadNote(notesDirectory, fileName);
|
||||
if (content != null) {
|
||||
if (connectedThread != null) {
|
||||
connectedThread.write(PROTOCOL_FILE_DATA + "|" + fileName + ":" + content);
|
||||
}
|
||||
} else {
|
||||
if (connectedThread != null) {
|
||||
connectedThread.write(PROTOCOL_ERROR + "|File not found: " + fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFileData(String fileData) {
|
||||
int colonIndex = fileData.indexOf(':');
|
||||
if (colonIndex > 0) {
|
||||
String fileName = fileData.substring(0, colonIndex);
|
||||
String content = fileData.substring(colonIndex + 1);
|
||||
|
||||
boolean saved = NoteManager.saveNote(notesDirectory, fileName, content);
|
||||
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (saved) {
|
||||
updateProgress("Received file: " + fileName);
|
||||
} else {
|
||||
updateProgress("Failed to save: " + fileName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSyncComplete() {
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress("Sync completed successfully!");
|
||||
Toast.makeText(BluetoothSyncActivity.this, "Sync completed!", Toast.LENGTH_LONG).show();
|
||||
|
||||
// Close connection after a delay
|
||||
mainHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
finish();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleError(String error) {
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress("Error: " + error);
|
||||
Toast.makeText(BluetoothSyncActivity.this, "Sync error: " + error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == REQUEST_DISCOVERABLE) {
|
||||
if (resultCode > 0) {
|
||||
updateStatus("Device is discoverable for " + resultCode + " seconds");
|
||||
updateProgress("Waiting for incoming connections...");
|
||||
} else {
|
||||
updateStatus("Discoverable request denied");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
// Clean up threads
|
||||
if (connectThread != null) {
|
||||
connectThread.cancel();
|
||||
}
|
||||
if (connectedThread != null) {
|
||||
connectedThread.cancel();
|
||||
}
|
||||
if (acceptThread != null) {
|
||||
acceptThread.cancel();
|
||||
}
|
||||
|
||||
// Unregister broadcast receiver
|
||||
try {
|
||||
unregisterReceiver(discoveryReceiver);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Receiver was not registered
|
||||
}
|
||||
|
||||
// Stop discovery
|
||||
if (bluetoothAdapter != null && checkBluetoothPermission() && bluetoothAdapter.isDiscovering()) {
|
||||
bluetoothAdapter.cancelDiscovery();
|
||||
}
|
||||
}
|
||||
}
|
60
app/src/main/java/org/eu/octt/notetand/CustomActivity.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.Window;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
abstract public class CustomActivity extends Activity {
|
||||
@SuppressLint("InlinedApi")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
SettingsManager.setup(this);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
switch (SettingsManager.getTheme()) {
|
||||
case "holo_dark":
|
||||
setTheme(android.R.style.Theme_Holo);
|
||||
break;
|
||||
case "holo_light":
|
||||
setTheme(android.R.style.Theme_Holo_Light);
|
||||
break;
|
||||
case "material_dark":
|
||||
setTheme(android.R.style.Theme_Material);
|
||||
break;
|
||||
case "material_light":
|
||||
setTheme(android.R.style.Theme_Material_Light);
|
||||
break;
|
||||
default:
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
setTheme(android.R.style.Theme_DeviceDefault_DayNight);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuOpened(int featureId, Menu menu) {
|
||||
if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
|
||||
try {
|
||||
Method method = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
|
||||
method.setAccessible(true);
|
||||
method.invoke(menu, true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return super.onMenuOpened(featureId, menu);
|
||||
}
|
||||
|
||||
void setActionBarBack() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && getActionBar() != null) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
87
app/src/main/java/org/eu/octt/notetand/MainActivity.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends CustomActivity {
|
||||
ListView listNotes;
|
||||
List<String> notesList;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
NoteManager.setup(this);
|
||||
|
||||
listNotes = findViewById(R.id.list_notes);
|
||||
// var notesList = NoteManager.getAllNoteNames(); // new ArrayList<String>();
|
||||
// var notesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, notesList);
|
||||
// listNotes.setAdapter(notesAdapter);
|
||||
|
||||
// // Use Android/data/packagename/files/notes structure
|
||||
// var notesDirectory = new File(getExternalFilesDir(null), "notes");
|
||||
// if (!notesDirectory.exists()) {
|
||||
// notesDirectory.mkdirs();
|
||||
// }
|
||||
|
||||
// for (var file : notesDirectory.listFiles()) {
|
||||
// for (var file : NoteManager.notesDirectory.listFiles()) {
|
||||
// if (file.isFile() && file.getName().toLowerCase().endsWith(".txt")) {
|
||||
// notesList.add(file.getName());
|
||||
// }
|
||||
// }
|
||||
// notesAdapter.notifyDataSetChanged();
|
||||
|
||||
listNotes.setOnItemClickListener((parent, view, position, id) ->
|
||||
launchNote(notesList.get(position), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
notesList = NoteManager.getAllNoteNames(); // new ArrayList<String>();
|
||||
var notesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, notesList);
|
||||
listNotes.setAdapter(notesAdapter);
|
||||
notesAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
var id = item.getItemId();
|
||||
if (id == R.id.action_new) {
|
||||
launchNote(null, true);
|
||||
} else if (id == R.id.action_receive) {
|
||||
startActivity(new Intent(this, ReceiveActivity.class));
|
||||
} else if (id == R.id.action_settings) {
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
} else if (id == R.id.action_about) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://gitlab.com/octospacc/NoteTand")));
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void launchNote(String name, boolean isNew) {
|
||||
startActivity(
|
||||
new Intent(this, NoteActivity.class)
|
||||
.putExtra("is_new", isNew)
|
||||
.putExtra("note_name", name)
|
||||
);
|
||||
}
|
||||
}
|
380
app/src/main/java/org/eu/octt/notetand/MainActivity1.java
Normal file
@@ -0,0 +1,380 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MainActivity1 extends Activity {
|
||||
|
||||
private static final int REQUEST_ENABLE_BT = 1001;
|
||||
private static final int REQUEST_PERMISSIONS = 1002;
|
||||
private static final int REQUEST_BLUETOOTH_PERMISSIONS = 1003;
|
||||
|
||||
private ListView listNotes;
|
||||
private TextView txtStatus;
|
||||
private TextView txtNoteCount;
|
||||
private Button btnSync;
|
||||
private Button btnAddNote;
|
||||
|
||||
private ArrayList<String> notesList;
|
||||
private ArrayAdapter<String> notesAdapter;
|
||||
private File notesDirectory;
|
||||
private BluetoothAdapter bluetoothAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main_activity_1);
|
||||
|
||||
initializeViews();
|
||||
setupNotesDirectory();
|
||||
checkPermissions();
|
||||
initializeBluetooth();
|
||||
loadNotes();
|
||||
setupListeners();
|
||||
}
|
||||
|
||||
private void initializeViews() {
|
||||
listNotes = findViewById(R.id.list_notes);
|
||||
txtStatus = findViewById(R.id.txt_status);
|
||||
txtNoteCount = findViewById(R.id.txt_note_count);
|
||||
btnSync = findViewById(R.id.btn_sync);
|
||||
btnAddNote = findViewById(R.id.btn_add_note);
|
||||
|
||||
notesList = new ArrayList<>();
|
||||
notesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, notesList);
|
||||
listNotes.setAdapter(notesAdapter);
|
||||
|
||||
// Register context menu for long press
|
||||
registerForContextMenu(listNotes);
|
||||
}
|
||||
|
||||
private void setupNotesDirectory() {
|
||||
// Use Android/data/packagename/files/notes structure
|
||||
File externalFilesDir = getExternalFilesDir(null);
|
||||
if (externalFilesDir != null) {
|
||||
notesDirectory = new File(externalFilesDir, "notes");
|
||||
if (!notesDirectory.exists()) {
|
||||
boolean created = notesDirectory.mkdirs();
|
||||
if (created) {
|
||||
updateStatus("Notes directory created");
|
||||
} else {
|
||||
updateStatus("Failed to create notes directory");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fallback to internal storage
|
||||
notesDirectory = new File(getFilesDir(), "notes");
|
||||
if (!notesDirectory.exists()) {
|
||||
notesDirectory.mkdirs();
|
||||
}
|
||||
updateStatus("Using internal storage");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
ArrayList<String> permissionsNeeded = new ArrayList<>();
|
||||
|
||||
// Storage permissions (for API < 30)
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
permissionsNeeded.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
}
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
permissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
}
|
||||
|
||||
// Location permission for Bluetooth scanning
|
||||
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
permissionsNeeded.add(Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
}
|
||||
|
||||
if (!permissionsNeeded.isEmpty()) {
|
||||
requestPermissions(permissionsNeeded.toArray(new String[0]), REQUEST_PERMISSIONS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeBluetooth() {
|
||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
if (bluetoothAdapter == null) {
|
||||
updateStatus("Bluetooth not supported");
|
||||
btnSync.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bluetoothAdapter.isEnabled()) {
|
||||
updateStatus("Bluetooth disabled");
|
||||
btnSync.setText("Enable BT");
|
||||
} else {
|
||||
updateStatus("Bluetooth ready");
|
||||
btnSync.setText("Sync");
|
||||
}
|
||||
}
|
||||
|
||||
private void loadNotes() {
|
||||
notesList.clear();
|
||||
|
||||
if (notesDirectory != null && notesDirectory.exists()) {
|
||||
File[] files = notesDirectory.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isFile() && file.getName().endsWith(".txt")) {
|
||||
String noteName = file.getName().replace(".txt", "");
|
||||
notesList.add(noteName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notesAdapter.notifyDataSetChanged();
|
||||
updateNoteCount();
|
||||
|
||||
if (notesList.isEmpty()) {
|
||||
updateStatus("No notes found. Tap + to create one.");
|
||||
} else {
|
||||
updateStatus("Loaded " + notesList.size() + " notes");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
btnAddNote.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
createNewNote();
|
||||
}
|
||||
});
|
||||
|
||||
btnSync.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handleSyncButtonClick();
|
||||
}
|
||||
});
|
||||
|
||||
listNotes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String noteName = notesList.get(position);
|
||||
openNote(noteName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
if (v.getId() == R.id.list_notes) {
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
String noteName = notesList.get(info.position);
|
||||
menu.setHeaderTitle(noteName);
|
||||
menu.add(0, 1, 0, "Open");
|
||||
menu.add(0, 2, 0, "Delete");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
|
||||
final String noteName = notesList.get(info.position);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case 1: // Open
|
||||
openNote(noteName);
|
||||
return true;
|
||||
case 2: // Delete
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Delete Note")
|
||||
.setMessage("Are you sure you want to delete '" + noteName + "'?")
|
||||
.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
deleteNote(noteName);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", null)
|
||||
.show();
|
||||
return true;
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void createNewNote() {
|
||||
// For now, create a simple numbered note
|
||||
String newNoteName = "Note_" + System.currentTimeMillis();
|
||||
Intent intent = new Intent(this, NoteActivity.class);
|
||||
intent.putExtra("note_name", newNoteName);
|
||||
intent.putExtra("is_new", true);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void openNote(String noteName) {
|
||||
Intent intent = new Intent(this, NoteActivity.class);
|
||||
intent.putExtra("note_name", noteName);
|
||||
intent.putExtra("is_new", false);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void deleteNote(String noteName) {
|
||||
File noteFile = new File(notesDirectory, noteName + ".txt");
|
||||
if (noteFile.exists()) {
|
||||
boolean deleted = noteFile.delete();
|
||||
if (deleted) {
|
||||
updateStatus("Note deleted: " + noteName);
|
||||
loadNotes();
|
||||
} else {
|
||||
updateStatus("Failed to delete note");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSyncButtonClick() {
|
||||
if (bluetoothAdapter == null) {
|
||||
Toast.makeText(this, "Bluetooth not supported", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bluetoothAdapter.isEnabled()) {
|
||||
// Request to enable Bluetooth
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
} else {
|
||||
// Check Bluetooth permissions for newer Android versions
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
checkBluetoothPermissions();
|
||||
} else {
|
||||
startBluetoothSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkBluetoothPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
ArrayList<String> permissionsNeeded = new ArrayList<>();
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.BLUETOOTH_SCAN)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
permissionsNeeded.add(Manifest.permission.BLUETOOTH_SCAN);
|
||||
}
|
||||
if (checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
permissionsNeeded.add(Manifest.permission.BLUETOOTH_CONNECT);
|
||||
}
|
||||
if (checkSelfPermission(Manifest.permission.BLUETOOTH_ADVERTISE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
permissionsNeeded.add(Manifest.permission.BLUETOOTH_ADVERTISE);
|
||||
}
|
||||
|
||||
if (!permissionsNeeded.isEmpty()) {
|
||||
requestPermissions(permissionsNeeded.toArray(new String[0]),
|
||||
REQUEST_BLUETOOTH_PERMISSIONS);
|
||||
} else {
|
||||
startBluetoothSync();
|
||||
}
|
||||
} else {
|
||||
startBluetoothSync();
|
||||
}
|
||||
}
|
||||
|
||||
private void startBluetoothSync() {
|
||||
Intent intent = new Intent(this, BluetoothSyncActivity.class);
|
||||
intent.putExtra("notes_directory", notesDirectory.getAbsolutePath());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == REQUEST_ENABLE_BT) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
updateStatus("Bluetooth enabled");
|
||||
btnSync.setText("Sync");
|
||||
} else {
|
||||
updateStatus("Bluetooth enable cancelled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
switch (requestCode) {
|
||||
case REQUEST_PERMISSIONS:
|
||||
boolean allGranted = true;
|
||||
for (int result : grantResults) {
|
||||
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||
allGranted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allGranted) {
|
||||
updateStatus("Permissions granted");
|
||||
} else {
|
||||
updateStatus("Some permissions denied");
|
||||
}
|
||||
break;
|
||||
|
||||
case REQUEST_BLUETOOTH_PERMISSIONS:
|
||||
boolean bluetoothGranted = true;
|
||||
for (int result : grantResults) {
|
||||
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||
bluetoothGranted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bluetoothGranted) {
|
||||
startBluetoothSync();
|
||||
} else {
|
||||
Toast.makeText(this, "Bluetooth permissions required for sync",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
loadNotes(); // Refresh notes list when returning from editor
|
||||
}
|
||||
|
||||
private void updateStatus(String status) {
|
||||
txtStatus.setText(status);
|
||||
}
|
||||
|
||||
private void updateNoteCount() {
|
||||
int count = notesList.size();
|
||||
txtNoteCount.setText(count + (count == 1 ? " note" : " notes"));
|
||||
}
|
||||
|
||||
public File getNotesDirectory() {
|
||||
return notesDirectory;
|
||||
}
|
||||
}
|
334
app/src/main/java/org/eu/octt/notetand/NoteActivity.java
Normal file
@@ -0,0 +1,334 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
public class NoteActivity extends CustomActivity {
|
||||
String[] EMOJIS = {"🐕", "🐶", "🐩", "🐈", "🐱", "🐀", "🐁", "🐭", "🐹", "🐢", "🐇", "🐰", "🐓", "🐔", "🐣", "🐤", "🐥", "🐦", "🐏", "🐑", "🐐", "🐺", "🐃", "🐂", "🐄", "🐮", "🐴", "🐗", "🐖", "🐷", "🐽", "🐸", "🐍", "🐼", "🐧", "🐘", "🐨", "🐒", "🐵", "🐆", "🐯", "🐻", "🐫", "🐪", "🐊", "🐳", "🐋", "🐟", "🐠", "🐡", "🐙", "🐚", "🐬", "🐌", "🐛", "🐜", "🐝", "🐞", "🐲", "🐉", "🐾", "👻", "👹", "👺", "👽", "👾", "👿", "💀", "💖", "💗", "💘", "💝", "💞", "💟", "🍙", "🍘", "🍠", "🍌", "🍎", "🍏", "🍊", "🍋", "🍄", "🍅", "🍆", "🍇", "🍈", "🍉", "🍐", "🍑", "🍒", "🍓", "🍍", "🌰", "🌱", "🌲", "🌳", "🌴", "🌵", "🌷", "🌸", "🌹", "🍀", "🍁", "🍂", "🍃", "🌺", "🌻", "🌼", "🌽", "🌾", "🌿"};
|
||||
|
||||
private EditText editNoteName;
|
||||
private EditText editNoteContent;
|
||||
private TextView txtNoteInfo;
|
||||
// private Button btnSave;
|
||||
// private Button btnDelete;
|
||||
|
||||
private String originalNoteName;
|
||||
private String originalContent;
|
||||
private boolean isNewNote;
|
||||
private boolean hasUnsavedChanges;
|
||||
private File notesDirectory;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_note);
|
||||
setActionBarBack();
|
||||
|
||||
NoteManager.setup(this);
|
||||
|
||||
initializeViews();
|
||||
setupNotesDirectory();
|
||||
loadNoteFromIntent();
|
||||
setupListeners();
|
||||
updateNoteInfo();
|
||||
}
|
||||
|
||||
private void initializeViews() {
|
||||
editNoteName = findViewById(R.id.edit_note_name);
|
||||
editNoteContent = findViewById(R.id.edit_note_content);
|
||||
txtNoteInfo = findViewById(R.id.txt_note_info);
|
||||
// btnSave = findViewById(R.id.btn_save);
|
||||
// btnDelete = findViewById(R.id.btn_delete);
|
||||
}
|
||||
|
||||
private void setupNotesDirectory() {
|
||||
// Get notes directory from MainActivity
|
||||
File externalFilesDir = getExternalFilesDir(null);
|
||||
if (externalFilesDir != null) {
|
||||
notesDirectory = new File(externalFilesDir, "notes");
|
||||
} else {
|
||||
notesDirectory = new File(getFilesDir(), "notes");
|
||||
}
|
||||
}
|
||||
|
||||
private void loadNoteFromIntent() {
|
||||
Intent intent = getIntent();
|
||||
|
||||
if (Intent.ACTION_SEND.equals(intent.getAction()) && "text/plain".equals(intent.getType())) {
|
||||
originalContent = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
} else {
|
||||
originalContent = intent.getStringExtra("content");
|
||||
originalNoteName = intent.getStringExtra("note_name");
|
||||
isNewNote = intent.getBooleanExtra("is_new", false);
|
||||
}
|
||||
|
||||
if (originalNoteName == null) {
|
||||
// originalNoteName = "Note_" + System.currentTimeMillis() + ".txt";
|
||||
originalNoteName = (new SimpleDateFormat("yyyy-MM-dd HH-mm-ss.SSS")).format(new Date()) + ' ' + EMOJIS[(new Random()).nextInt(EMOJIS.length)] + ".txt";
|
||||
isNewNote = true;
|
||||
}
|
||||
|
||||
editNoteName.setText(originalNoteName);
|
||||
|
||||
if (!isNewNote || originalContent != null) {
|
||||
// Load existing note content
|
||||
if (originalNoteName != null && originalContent == null)
|
||||
originalContent = NoteManager.loadNote(notesDirectory, originalNoteName);
|
||||
if (originalContent != null) {
|
||||
editNoteContent.setText(originalContent);
|
||||
editNoteContent.setSelection(originalContent.length()); // Move cursor to end
|
||||
} else {
|
||||
originalContent = "";
|
||||
Toast.makeText(this, "Error loading note", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
// btnDelete.setVisibility(View.VISIBLE);
|
||||
//} else if (originalNoteName == null && originalContent == null) {
|
||||
// originalContent = intent.getStringExtra("content");
|
||||
} // else {
|
||||
// originalContent = "";
|
||||
// // btnDelete.setVisibility(View.GONE);
|
||||
// }
|
||||
|
||||
if (originalContent == null) {
|
||||
originalContent = "";
|
||||
}
|
||||
|
||||
hasUnsavedChanges = (isNewNote && !originalContent.isEmpty()); // false;
|
||||
if (hasUnsavedChanges)
|
||||
setTitle("* " + getString(R.string.note));
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
// btnSave.setOnClickListener(v -> saveNote());
|
||||
//
|
||||
// btnDelete.setOnClickListener(v -> confirmDeleteNote());
|
||||
|
||||
// Track changes to note name
|
||||
editNoteName.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
checkForChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {}
|
||||
});
|
||||
|
||||
// Track changes to note content
|
||||
editNoteContent.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
checkForChanges();
|
||||
updateNoteInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkForChanges() {
|
||||
String currentName = editNoteName.getText().toString().trim();
|
||||
String currentContent = editNoteContent.getText().toString();
|
||||
|
||||
hasUnsavedChanges = !currentName.equals(originalNoteName) || !currentContent.equals(originalContent);
|
||||
|
||||
// Update title to indicate unsaved changes
|
||||
//if (getActionBar() != null) {
|
||||
if (hasUnsavedChanges) {
|
||||
/*getActionBar().*/setTitle("* " + getString(R.string.note) /* currentName */);
|
||||
} else {
|
||||
/*getActionBar().*/setTitle(getString(R.string.note) /* currentName */);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
private void updateNoteInfo() {
|
||||
String content = editNoteContent.getText().toString();
|
||||
int characterCount = content.length();
|
||||
int wordCount = content.trim().isEmpty() ? 0 : content.trim().split("\\s+").length;
|
||||
int lineCount = content.split("\n").length;
|
||||
|
||||
if (isNewNote && !hasUnsavedChanges) {
|
||||
txtNoteInfo.setText(R.string.new_note);
|
||||
} else {
|
||||
txtNoteInfo.setText(String.format(Locale.getDefault(), "%d chars, %d words, %d lines", characterCount, wordCount, lineCount));
|
||||
}
|
||||
}
|
||||
|
||||
private void saveNote() {
|
||||
String noteName = editNoteName.getText().toString().trim();
|
||||
// String content = editNoteContent.getText().toString();
|
||||
|
||||
// Validate note name
|
||||
if (noteName.isEmpty()) {
|
||||
editNoteName.setError("Note name cannot be empty");
|
||||
editNoteName.requestFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
// Sanitize note name
|
||||
String sanitizedName = NoteManager.sanitizeNoteName(noteName);
|
||||
if (!sanitizedName.equals(noteName)) {
|
||||
editNoteName.setText(sanitizedName);
|
||||
noteName = sanitizedName;
|
||||
Toast.makeText(this, "Note name was sanitized for compatibility", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// Check if we're renaming and the new name already exists
|
||||
if (!noteName.equals(originalNoteName) && NoteManager.noteExists(notesDirectory, noteName)) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Note Already Exists")
|
||||
.setMessage("A note with the name '" + noteName + "' already exists. Do you want to overwrite it?")
|
||||
.setPositiveButton("Overwrite", (dialog, which) -> performSave())
|
||||
.setNeutralButton("Cancel", null)
|
||||
.show();
|
||||
} else {
|
||||
performSave();
|
||||
}
|
||||
}
|
||||
|
||||
private void performSave() {
|
||||
String noteName = editNoteName.getText().toString().trim();
|
||||
String content = editNoteContent.getText().toString();
|
||||
|
||||
// Delete old note if we're renaming
|
||||
if (!isNewNote && !noteName.equals(originalNoteName)) {
|
||||
NoteManager.deleteNote(notesDirectory, originalNoteName);
|
||||
}
|
||||
|
||||
// Save the note
|
||||
boolean success = NoteManager.saveNote(notesDirectory, noteName, content);
|
||||
|
||||
if (success) {
|
||||
originalNoteName = noteName;
|
||||
originalContent = content;
|
||||
isNewNote = false;
|
||||
hasUnsavedChanges = false;
|
||||
// btnDelete.setVisibility(View.VISIBLE);
|
||||
|
||||
//if (getActionBar() != null) {
|
||||
/*getActionBar().*/setTitle(getString(R.string.note) /* noteName */);
|
||||
//}
|
||||
|
||||
Toast.makeText(this, R.string.note_saved, Toast.LENGTH_SHORT).show();
|
||||
updateNoteInfo();
|
||||
} else {
|
||||
Toast.makeText(this, "Error saving note", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void confirmDeleteNote() {
|
||||
if (isNewNote) {
|
||||
// Just finish if it's a new unsaved note
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.delete_note)
|
||||
.setMessage(getString(R.string.delete_note_message, originalNoteName))
|
||||
.setPositiveButton(R.string.delete, (dialog, which) -> deleteNote())
|
||||
.setNeutralButton(R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void deleteNote() {
|
||||
boolean success = NoteManager.deleteNote(notesDirectory, originalNoteName);
|
||||
if (success) {
|
||||
Toast.makeText(this, R.string.note_deleted, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
} else {
|
||||
Toast.makeText(this, "Error deleting note", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.note_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
var id = item.getItemId();
|
||||
if (id == R.id.action_save) {
|
||||
saveNote();
|
||||
} else if (id == R.id.action_delete) {
|
||||
confirmDeleteNote();
|
||||
} else if (id == R.id.action_send) {
|
||||
startActivity(new Intent(this, SendActivity.class).putExtra("note", originalNoteName));
|
||||
} else if (id == R.id.action_share) {
|
||||
startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, originalContent));
|
||||
} else if (id == android.R.id.home) {
|
||||
onBackPressed();
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// switch (item.getItemId()) {
|
||||
// case android.R.id.home:
|
||||
// onBackPressed();
|
||||
// return true;
|
||||
// default:
|
||||
// return super.onOptionsItemSelected(item);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (hasUnsavedChanges) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.unsaved_changes)
|
||||
.setMessage(R.string.unsaved_changes_message)
|
||||
.setPositiveButton(R.string.save, (dialog, which) -> {
|
||||
saveNote();
|
||||
if (!hasUnsavedChanges) { // Only finish if save was successful
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.discard, (dialog, which) -> finish())
|
||||
.setNeutralButton(R.string.cancel, null)
|
||||
.show();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// Handle Ctrl+S for save (for external keyboards)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && keyCode == KeyEvent.KEYCODE_S && event.isCtrlPressed()) {
|
||||
saveNote();
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
328
app/src/main/java/org/eu/octt/notetand/NoteManager.java
Normal file
@@ -0,0 +1,328 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class NoteManager {
|
||||
private static final String TAG = "NoteManager";
|
||||
|
||||
public static File notesDirectory;
|
||||
|
||||
public static class NoteInfo {
|
||||
public String name;
|
||||
public String content;
|
||||
public long lastModified;
|
||||
public String hash;
|
||||
public long size;
|
||||
|
||||
public NoteInfo(String name, String content, long lastModified) {
|
||||
this.name = name;
|
||||
this.content = content;
|
||||
this.lastModified = lastModified;
|
||||
this.size = content.getBytes().length;
|
||||
this.hash = calculateHash(content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a note to the specified directory
|
||||
*/
|
||||
public static boolean saveNote(File notesDir, String noteName, String content) {
|
||||
try {
|
||||
File noteFile = new File(notesDir, noteName /* + ".txt" */);
|
||||
FileOutputStream fos = new FileOutputStream(noteFile);
|
||||
fos.write(content.getBytes("UTF-8"));
|
||||
fos.close();
|
||||
Log.d(TAG, "Note saved: " + noteName);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error saving note: " + noteName, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean saveNote(String noteName, String content) {
|
||||
try {
|
||||
File noteFile = new File(notesDirectory, noteName /* + ".txt" */);
|
||||
FileOutputStream fos = new FileOutputStream(noteFile);
|
||||
fos.write(content.getBytes("UTF-8"));
|
||||
fos.close();
|
||||
Log.d(TAG, "Note saved: " + noteName);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error saving note: " + noteName, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a note from the specified directory
|
||||
*/
|
||||
public static String loadNote(File notesDir, String noteName) {
|
||||
try {
|
||||
File noteFile = new File(notesDir, noteName /* + ".txt" */);
|
||||
if (!noteFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FileInputStream fis = new FileInputStream(noteFile);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
|
||||
StringBuilder content = new StringBuilder();
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
content.append(line).append("\n");
|
||||
}
|
||||
|
||||
reader.close();
|
||||
fis.close();
|
||||
|
||||
// Remove last newline if present
|
||||
if (content.length() > 0 && content.charAt(content.length() - 1) == '\n') {
|
||||
content.deleteCharAt(content.length() - 1);
|
||||
}
|
||||
|
||||
return content.toString();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error loading note: " + noteName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String loadNote(String noteName) {
|
||||
try {
|
||||
File noteFile = new File(notesDirectory, noteName);
|
||||
if (!noteFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(noteFile);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
|
||||
StringBuilder content = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
content.append(line).append("\n");
|
||||
}
|
||||
reader.close();
|
||||
fis.close();
|
||||
// Remove last newline if present
|
||||
if (content.length() > 0 && content.charAt(content.length() - 1) == '\n') {
|
||||
content.deleteCharAt(content.length() - 1);
|
||||
}
|
||||
return content.toString();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error loading note: " + noteName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a note from the specified directory
|
||||
*/
|
||||
public static boolean deleteNote(File notesDir, String noteName) {
|
||||
File noteFile = new File(notesDir, noteName /* + ".txt" */);
|
||||
if (noteFile.exists()) {
|
||||
boolean deleted = noteFile.delete();
|
||||
if (deleted) {
|
||||
Log.d(TAG, "Note deleted: " + noteName);
|
||||
} else {
|
||||
Log.e(TAG, "Failed to delete note: " + noteName);
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all notes from the specified directory
|
||||
*/
|
||||
// public static List<String> getAllNoteNames(File notesDir) {
|
||||
// List<String> noteNames = new ArrayList<>();
|
||||
//
|
||||
// if (notesDir != null && notesDir.exists()) {
|
||||
// File[] files = notesDir.listFiles();
|
||||
// if (files != null) {
|
||||
// for (File file : files) {
|
||||
// if (file.isFile() && file.getName().toLowerCase().endsWith(".txt")) {
|
||||
// String noteName = file.getName();//.replace(".txt", "");
|
||||
// noteNames.add(noteName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return noteNames;
|
||||
// }
|
||||
|
||||
public static List<String> getAllNoteNames() {
|
||||
var noteNames = new ArrayList<String>();
|
||||
var files = notesDirectory.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isFile() && file.getName().toLowerCase().endsWith(".txt")) {
|
||||
noteNames.add(file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.reverse(noteNames);
|
||||
return noteNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get detailed information about all notes
|
||||
*/
|
||||
public static List<NoteInfo> getAllNoteInfo(File notesDir) {
|
||||
List<NoteInfo> noteInfoList = new ArrayList<>();
|
||||
|
||||
if (notesDir != null && notesDir.exists()) {
|
||||
File[] files = notesDir.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isFile() && file.getName().toLowerCase().endsWith(".txt")) {
|
||||
String noteName = file.getName();//.replace(".txt", "");
|
||||
String content = loadNote(notesDir, noteName);
|
||||
if (content != null) {
|
||||
NoteInfo info = new NoteInfo(noteName, content, file.lastModified());
|
||||
noteInfoList.add(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return noteInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a specific note
|
||||
*/
|
||||
public static NoteInfo getNoteInfo(File notesDir, String noteName) {
|
||||
File noteFile = new File(notesDir, noteName /* + ".txt" */);
|
||||
if (!noteFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String content = loadNote(notesDir, noteName);
|
||||
if (content != null) {
|
||||
return new NoteInfo(noteName, content, noteFile.lastModified());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate SHA-256 hash of content for sync comparison
|
||||
*/
|
||||
public static String calculateHash(String content) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hash = digest.digest(content.getBytes("UTF-8"));
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
|
||||
for (byte b : hash) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException | IOException e) {
|
||||
Log.e(TAG, "Error calculating hash", e);
|
||||
return String.valueOf(content.hashCode()); // Fallback to simple hash
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a note exists
|
||||
*/
|
||||
public static boolean noteExists(File notesDir, String noteName) {
|
||||
File noteFile = new File(notesDir, noteName /* + ".txt" */);
|
||||
return noteFile.exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of notes directory
|
||||
*/
|
||||
public static long getDirectorySize(File notesDir) {
|
||||
long size = 0;
|
||||
if (notesDir != null && notesDir.exists()) {
|
||||
File[] files = notesDir.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isFile()) {
|
||||
size += file.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate note name (no special characters that could cause file system issues)
|
||||
*/
|
||||
public static boolean isValidNoteName(String noteName) {
|
||||
if (noteName == null || noteName.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for invalid characters
|
||||
String invalidChars = "\\/:*?\"<>|";
|
||||
for (char c : invalidChars.toCharArray()) {
|
||||
if (noteName.indexOf(c) != -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check length (filesystem limitations)
|
||||
return noteName.length() <= 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize note name for file system compatibility
|
||||
*/
|
||||
public static String sanitizeNoteName(String noteName) {
|
||||
if (noteName == null) {
|
||||
return "untitled";
|
||||
}
|
||||
|
||||
// Replace invalid characters with underscores
|
||||
String sanitized = noteName.replaceAll("[\\\\/:*?\"<>|]", "_");
|
||||
|
||||
// Trim and limit length
|
||||
sanitized = sanitized.trim();
|
||||
if (sanitized.length() > 100) {
|
||||
sanitized = sanitized.substring(0, 100);
|
||||
}
|
||||
|
||||
// Ensure it's not empty
|
||||
if (sanitized.isEmpty()) {
|
||||
sanitized = "untitled";
|
||||
}
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
public static void setup(Context context) {
|
||||
if (NoteManager.notesDirectory == null) {
|
||||
var notesDirectory = new File(context.getExternalFilesDir(null), "notes");
|
||||
if (!notesDirectory.exists()) {
|
||||
notesDirectory.mkdirs();
|
||||
}
|
||||
NoteManager.notesDirectory = notesDirectory;
|
||||
}
|
||||
}
|
||||
}
|
16
app/src/main/java/org/eu/octt/notetand/NoteTand.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NoteTand {
|
||||
static final UUID SERVICE_UUID = UUID.fromString("fb7befa5-311b-436e-9c2f-9150fe635a40");
|
||||
|
||||
static String censorMac(String mac) {
|
||||
if (SettingsManager.getCensorMac()) {
|
||||
var parts = mac.split(":");
|
||||
return parts[0] + ":••:••:••:••:" + parts[5];
|
||||
} else {
|
||||
return mac;
|
||||
}
|
||||
}
|
||||
}
|
40
app/src/main/java/org/eu/octt/notetand/NotesProvider.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.database.Cursor;
|
||||
import android.os.Build;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.DocumentsProvider;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public class NotesProvider extends DocumentsProvider {
|
||||
|
||||
@Override
|
||||
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
NoteManager.setup(getContext());
|
||||
return false;
|
||||
}
|
||||
}
|
163
app/src/main/java/org/eu/octt/notetand/ReceiveActivity.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothServerSocket;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class ReceiveActivity extends CustomActivity {
|
||||
BluetoothServerSocket server;
|
||||
BluetoothSocket socket;
|
||||
TextView textStatus;
|
||||
boolean stopped = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_receive);
|
||||
|
||||
textStatus = findViewById(R.id.text_status);
|
||||
runServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigateUp() {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
if (requestCode == BluetoothManager.REQUEST_PERMISSION_BT) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
runServer();
|
||||
else {
|
||||
Toast.makeText(this, "Bluetooth permission not granted! Please retry.", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == BluetoothManager.REQUEST_ENABLE_BT && resultCode == RESULT_OK)
|
||||
runServer();
|
||||
else {
|
||||
Toast.makeText(this, "Bluetooth permission not granted! Please retry.", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
void runServer() {
|
||||
if (!BluetoothManager.requireBluetooth(this)) return;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
writeStatus("Initializing Bluetooth server...");
|
||||
server = BluetoothAdapter.getDefaultAdapter().listenUsingRfcommWithServiceRecord(getString(R.string.app_name), NoteTand.SERVICE_UUID);
|
||||
|
||||
while (true) {
|
||||
writeStatus("Waiting for new client connection...");
|
||||
socket = server.accept();
|
||||
|
||||
// if (!socket.isConnected()) return;
|
||||
|
||||
var client = socket.getRemoteDevice();
|
||||
// textStatus.append("Connected to client!\n");
|
||||
// textStatus.append("Connected: " + client.getName() + " : " + client.getAddress() + '\n');
|
||||
writeStatus("Connected: " + client.getName() + " : " + NoteTand.censorMac(client.getAddress()));
|
||||
|
||||
// byte[] buffer = new byte[1024];
|
||||
// int bytes;
|
||||
//
|
||||
// while ((bytes = socket.getInputStream().read(buffer)) != -1) {
|
||||
// var received = new String(buffer, 0, bytes);
|
||||
//
|
||||
// // runOnUiThread(() -> Toast.makeText(this, "Received: " + received, Toast.LENGTH_SHORT).show());
|
||||
// // textStatus.append(received + '\n');
|
||||
// writeStatus("Receiving data...");
|
||||
// writeStatus("> " + received);
|
||||
// }
|
||||
|
||||
writeStatus("Reading data...");
|
||||
|
||||
var titleLength = ByteBuffer.wrap(readFully(4)).getInt(); // ByteBuffer.wrap(intBuffer).order(ByteOrder.BIG_ENDIAN).getInt(); // or LITTLE_ENDIAN
|
||||
var titleBytes = readFully(titleLength);
|
||||
var noteTitle = new String(titleBytes, "UTF-8");
|
||||
|
||||
var bodyLength = ByteBuffer.wrap(readFully(4)).getInt(); // ByteBuffer.wrap(intBuffer).order(ByteOrder.BIG_ENDIAN).getInt();
|
||||
var bodyBytes = readFully(bodyLength);
|
||||
var noteBody = new String(bodyBytes, "UTF-8");
|
||||
|
||||
if (titleLength == titleBytes.length && bodyLength == bodyBytes.length) {
|
||||
NoteManager.saveNote(noteTitle, noteBody);
|
||||
writeStatus("Received and saved note (" + titleLength + " + " + bodyLength + " bytes): " + noteTitle);
|
||||
} else {
|
||||
writeStatus("Content length mismatch! Expected " + titleLength + " + " + bodyLength + ", got " + titleBytes.length + " + " + bodyBytes.length);
|
||||
}
|
||||
|
||||
// writeStatus("Finished receiving!");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (!stopped) {
|
||||
writeStatus("Fatal error! Restarting...");
|
||||
e.printStackTrace();
|
||||
runServer();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
void stopServer() {
|
||||
stopped = true;
|
||||
if (server != null) {
|
||||
try {
|
||||
if (socket != null) {
|
||||
socket.getInputStream().close();
|
||||
socket.getOutputStream().close();
|
||||
socket.close();
|
||||
}
|
||||
server.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeStatus(String text) {
|
||||
runOnUiThread(() -> textStatus.append(text + '\n'));
|
||||
}
|
||||
|
||||
byte[] readFully(/* InputStream in, byte[] buffer, */ int length) throws IOException {
|
||||
byte[] buffer = new byte[length];
|
||||
int offset = 0;
|
||||
while (offset < length) {
|
||||
int count = socket.getInputStream().read(buffer, offset, length - offset);
|
||||
if (count == -1) throw new EOFException("Stream ended early");
|
||||
offset += count;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
170
app/src/main/java/org/eu/octt/notetand/SendActivity.java
Normal file
@@ -0,0 +1,170 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class SendActivity extends CustomActivity {
|
||||
BluetoothSocket socket;
|
||||
AlertDialog dialog;
|
||||
String statusLog;
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_send);
|
||||
|
||||
setActionBarBack();
|
||||
showTargets();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigateUp() {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
if (requestCode == BluetoothManager.REQUEST_PERMISSION_BT) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
showTargets();
|
||||
else {
|
||||
Toast.makeText(this, "Bluetooth permission not granted! Please retry.", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == BluetoothManager.REQUEST_ENABLE_BT && resultCode == RESULT_OK)
|
||||
showTargets();
|
||||
else {
|
||||
Toast.makeText(this, "Bluetooth permission not granted! Please retry.", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
void showTargets() {
|
||||
if (!BluetoothManager.requireBluetooth(this)) return;
|
||||
|
||||
ListView listPairedDevices = findViewById(R.id.list_paired_devices);
|
||||
var pairedDevicesList = new ArrayList<BluetoothDevice>();
|
||||
var pairedDevicesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
|
||||
listPairedDevices.setAdapter(pairedDevicesAdapter);
|
||||
|
||||
var pairedDevices = BluetoothAdapter.getDefaultAdapter().getBondedDevices();
|
||||
for (BluetoothDevice device : pairedDevices) {
|
||||
pairedDevicesList.add(device);
|
||||
pairedDevicesAdapter.add(device.getName() + '\n' + NoteTand.censorMac(device.getAddress()));
|
||||
}
|
||||
pairedDevicesAdapter.notifyDataSetChanged();
|
||||
|
||||
listPairedDevices.setOnItemClickListener((parent, view, position, id) -> {
|
||||
statusLog = "";
|
||||
dialog = new AlertDialog.Builder(this)
|
||||
.setTitle("Sending Note")
|
||||
.setMessage("Preparing...")
|
||||
// .setNegativeButton("Abort", null)
|
||||
.setNeutralButton("Close", null)
|
||||
.show();
|
||||
//.create();
|
||||
setDialogCancelable(false);
|
||||
//dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(false);
|
||||
//dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(ListView.GONE);
|
||||
//dialog.show();
|
||||
var device = pairedDevicesList.get(position);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
writeStatus("Creating socket to target device...");
|
||||
socket = device.createRfcommSocketToServiceRecord(NoteTand.SERVICE_UUID);
|
||||
|
||||
writeStatus("Trying to connect...");
|
||||
socket.connect();
|
||||
writeStatus("Connected successfully!");
|
||||
Log.d("Bluetooth", "Connection successful");
|
||||
var output = socket.getOutputStream();
|
||||
|
||||
var noteName = getIntent().getStringExtra("note");
|
||||
var noteContent = NoteManager.loadNote(noteName);
|
||||
|
||||
var nameBytes = noteName.getBytes("UTF-8");
|
||||
var contentBytes = noteContent.getBytes("UTF-8");
|
||||
|
||||
writeStatus("Sending data...");
|
||||
|
||||
output.write(ByteBuffer.allocate(4).putInt(nameBytes.length /*noteName.length()*/).array());
|
||||
output.write(nameBytes);
|
||||
|
||||
output.write(ByteBuffer.allocate(4).putInt(contentBytes.length /*noteContent.length()*/).array());
|
||||
output.write(contentBytes);
|
||||
|
||||
writeStatus("Note sent!");
|
||||
//dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(ListView.VISIBLE);
|
||||
//dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(true);
|
||||
//dialog.setCancelable(true);
|
||||
setDialogCancelable(true);
|
||||
|
||||
socket.getInputStream().close();
|
||||
socket.getOutputStream().close();
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
Log.e("Bluetooth", "Connection failed", e);
|
||||
writeStatus(e.getMessage());
|
||||
setDialogCancelable(true);
|
||||
}
|
||||
closeSocket();
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
void closeSocket() {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.getInputStream().close();
|
||||
socket.getOutputStream().close();
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeStatus(String text) {
|
||||
statusLog = statusLog + text + '\n';
|
||||
runOnUiThread(() -> dialog.setMessage(statusLog.trim()));
|
||||
}
|
||||
|
||||
void setDialogCancelable(boolean status) {
|
||||
runOnUiThread(() -> {
|
||||
//dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(ListView.VISIBLE);
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(status);
|
||||
dialog.setCancelable(status);
|
||||
});
|
||||
}
|
||||
}
|
128
app/src/main/java/org/eu/octt/notetand/SettingsActivity.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SettingsActivity extends CustomActivity {
|
||||
// @Override
|
||||
// protected void onCreate(Bundle savedInstanceState) {
|
||||
// super.onCreate(savedInstanceState);
|
||||
// // getFragmentManager().beginTransaction().add(new SettingsFragment(), "").commit();
|
||||
// // addPreferencesFromResource(R.xml.preferences);
|
||||
//
|
||||
// }
|
||||
|
||||
// class SettingsFragment extends Fragment {
|
||||
//
|
||||
// }
|
||||
|
||||
private ListView listView;
|
||||
private ArrayList<View> settingViews = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
listView = new ListView(this);
|
||||
|
||||
settingViews.add(createCheckboxSetting(getString(R.string.censor_mac), "censor_mac", true));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||
settingViews.add(createSpinnerSetting(getString(R.string.app_theme), "theme", new String[]{"system", "material_dark", "material_light", "holo_dark", "holo_light"}, "system"));
|
||||
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
settingViews.add(createSpinnerSetting(getString(R.string.app_theme), "theme", new String[]{"system", "holo_dark", "holo_light"}, "system"));
|
||||
|
||||
// settingViews.add(createNumberSetting(getString(R.string.font_size), "font_size"));
|
||||
|
||||
// Adapter to wrap views into ListView
|
||||
listView.setAdapter(new BaseAdapter() {
|
||||
@Override
|
||||
public int getCount() {
|
||||
return settingViews.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return settingViews.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return settingViews.get(position);
|
||||
}
|
||||
});
|
||||
|
||||
setContentView(listView);
|
||||
}
|
||||
|
||||
private View createCheckboxSetting(String label, String key, boolean defaultValue) {
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
layout.setPadding(32, 32, 32, 32);
|
||||
|
||||
TextView textView = new TextView(this);
|
||||
textView.setText(label);
|
||||
textView.setTextSize(16);
|
||||
textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1));
|
||||
|
||||
CheckBox checkBox = new CheckBox(this);
|
||||
checkBox.setChecked(SettingsManager.prefs.getBoolean(key, defaultValue));
|
||||
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
SettingsManager.prefs.edit().putBoolean(key, isChecked).apply();
|
||||
});
|
||||
|
||||
layout.addView(textView);
|
||||
layout.addView(checkBox);
|
||||
return layout;
|
||||
}
|
||||
|
||||
private View createSpinnerSetting(String label, String key, String[] options, String defaultValue) {
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
layout.setPadding(32, 32, 32, 32);
|
||||
|
||||
TextView textView = new TextView(this);
|
||||
textView.setText(label);
|
||||
textView.setTextSize(16);
|
||||
|
||||
Spinner spinner = new Spinner(this);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, options);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinner.setAdapter(adapter);
|
||||
|
||||
String currentValue = SettingsManager.prefs.getString(key, defaultValue);
|
||||
int selectedIndex = Arrays.asList(options).indexOf(currentValue);
|
||||
spinner.setSelection(Math.max(selectedIndex, 0));
|
||||
|
||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
SettingsManager.prefs.edit().putString(key, options[position]).apply();
|
||||
}
|
||||
public void onNothingSelected(AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
layout.addView(textView);
|
||||
layout.addView(spinner);
|
||||
return layout;
|
||||
}
|
||||
}
|
23
app/src/main/java/org/eu/octt/notetand/SettingsManager.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.eu.octt.notetand;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public class SettingsManager {
|
||||
static SharedPreferences prefs;
|
||||
|
||||
static void setup(Context context) {
|
||||
if (prefs == null)
|
||||
prefs = context.getSharedPreferences("settings", MODE_PRIVATE);
|
||||
}
|
||||
|
||||
static boolean getCensorMac() {
|
||||
return prefs.getBoolean("censor_mac", true);
|
||||
}
|
||||
|
||||
static String getTheme() {
|
||||
return prefs.getString("theme", "system");
|
||||
}
|
||||
}
|
30
app/src/main/res/drawable-v24/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
170
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
13
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_notes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
68
app/src/main/res/layout/activity_note.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Header with note name and buttons -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_note_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/note_name"
|
||||
android:textStyle="bold"
|
||||
android:singleLine="true"
|
||||
android:imeOptions="actionNext" />
|
||||
|
||||
<!-- <Button
|
||||
android:id="@+id/btn_save"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Save" /> -->
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Note content editor -->
|
||||
<EditText
|
||||
android:id="@+id/edit_note_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/note_typing_hint"
|
||||
android:gravity="start|top"
|
||||
android:inputType="textMultiLine"
|
||||
android:scrollbars="vertical"
|
||||
android:fadeScrollbars="false" />
|
||||
|
||||
<!-- Footer with info and actions -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_note_info"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#666666" />
|
||||
|
||||
<!-- <Button
|
||||
android:id="@+id/btn_delete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Delete"
|
||||
android:visibility="gone" /> -->
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
13
app/src/main/res/layout/activity_receive.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="monospace" />
|
||||
|
||||
</LinearLayout>
|
12
app/src/main/res/layout/activity_send.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_paired_devices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
152
app/src/main/res/layout/bluetooth_sync_activity.xml
Normal file
@@ -0,0 +1,152 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<!-- Header -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Bluetooth Sync"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#333333"
|
||||
android:paddingBottom="16dp" />
|
||||
|
||||
<!-- Status Section -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="#F5F5F5"
|
||||
android:padding="12dp"
|
||||
android:layout_marginBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Status"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#333333"
|
||||
android:paddingBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_bluetooth_status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Initializing..."
|
||||
android:textSize="14sp"
|
||||
android:textColor="#666666" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_sync_progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textSize="14sp"
|
||||
android:textColor="#666666"
|
||||
android:paddingTop="4dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginBottom="16dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_make_discoverable"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Make Discoverable"
|
||||
android:background="@android:drawable/btn_default"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginEnd="8dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_scan_devices"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Scan for Devices"
|
||||
android:background="@android:drawable/btn_default"
|
||||
android:textColor="#333333" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Devices Section -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Available Devices"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#333333"
|
||||
android:paddingBottom="8dp" />
|
||||
|
||||
<!-- Paired Devices -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Paired Devices:"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#666666"
|
||||
android:paddingBottom="4dp" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_paired_devices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="80dp"
|
||||
android:maxHeight="120dp"
|
||||
android:background="#FAFAFA"
|
||||
android:divider="#E0E0E0"
|
||||
android:dividerHeight="1dp"
|
||||
android:layout_marginBottom="12dp" />
|
||||
|
||||
<!-- Discovered Devices -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Discovered Devices:"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#666666"
|
||||
android:paddingBottom="4dp" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_discovered_devices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#FAFAFA"
|
||||
android:divider="#E0E0E0"
|
||||
android:dividerHeight="1dp" />
|
||||
|
||||
<!-- Bottom Actions -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="16dp"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_cancel_sync"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Cancel"
|
||||
android:background="@android:drawable/btn_default"
|
||||
android:textColor="#333333"
|
||||
android:minWidth="100dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
84
app/src/main/res/layout/main_activity_1.xml
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<!-- Header with title and buttons -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="My Notes"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#333333" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_sync"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Sync"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="@android:drawable/btn_default"
|
||||
android:textColor="#333333"
|
||||
android:minWidth="80dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_add_note"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="+"
|
||||
android:textSize="20sp"
|
||||
android:background="@android:drawable/btn_default"
|
||||
android:textColor="#333333"
|
||||
android:minWidth="50dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Notes List -->
|
||||
<ListView
|
||||
android:id="@+id/list_notes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:divider="#E0E0E0"
|
||||
android:dividerHeight="1dp"
|
||||
android:background="#FAFAFA" />
|
||||
|
||||
<!-- Status Bar -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="16dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_status"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Ready"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#666666" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_note_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0 notes"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#666666" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
26
app/src/main/res/menu/main_menu.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/action_new"
|
||||
android:icon="@android:drawable/ic_menu_add"
|
||||
android:title="@string/new_note"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_receive"
|
||||
android:icon="@android:drawable/ic_menu_set_as"
|
||||
android:title="@string/receive_notes"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:icon="@android:drawable/ic_menu_preferences"
|
||||
android:title="@string/settings"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_about"
|
||||
android:icon="@android:drawable/ic_menu_info_details"
|
||||
android:title="@string/about"
|
||||
android:showAsAction="never" />
|
||||
</menu>
|
26
app/src/main/res/menu/note_menu.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/action_save"
|
||||
android:icon="@android:drawable/ic_menu_save"
|
||||
android:title="@string/save"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_send"
|
||||
android:icon="@android:drawable/ic_menu_send"
|
||||
android:title="@string/send"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:icon="@android:drawable/ic_menu_share"
|
||||
android:title="@string/share_externally"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:icon="@android:drawable/ic_menu_delete"
|
||||
android:title="@string/delete"
|
||||
android:showAsAction="never" />
|
||||
</menu>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 9.0 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 20 KiB |
29
app/src/main/res/values-it/strings.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="new_note_activity">Nuova Nota in NoteTand</string>
|
||||
|
||||
<string name="about">Info</string>
|
||||
<string name="settings">Impostazioni</string>
|
||||
<string name="censor_mac">Censura Indirizzi MAC</string>
|
||||
<string name="app_theme">Tema della App</string>
|
||||
|
||||
<string name="note">Nota</string>
|
||||
<string name="note_name">Nome della Nota</string>
|
||||
<string name="new_note">Nuova Nota</string>
|
||||
<string name="send_note">Invia Nota</string>
|
||||
<string name="receive_notes">Ricevi Note</string>
|
||||
<string name="delete_note">Elimina Nota</string>
|
||||
<string name="delete_note_message">Vuoi davvero eliminare \"%s\"?</string>
|
||||
<string name="note_saved">Nota Salvata</string>
|
||||
<string name="note_deleted">Nota Eliminata</string>
|
||||
<string name="note_typing_hint">Scrivi la tua nota qui...</string>
|
||||
|
||||
<string name="share_externally">Condividi Esternamente</string>
|
||||
<string name="send">Invia</string>
|
||||
<string name="save">Salva</string>
|
||||
<string name="discard">Scarta</string>
|
||||
<string name="delete">Elimina</string>
|
||||
<string name="cancel">Annulla</string>
|
||||
<string name="unsaved_changes">Modifiche Non Salvate</string>
|
||||
<string name="unsaved_changes_message">Hai modifiche non salvate. Cosa vuoi fare?</string>
|
||||
</resources>
|
10
app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
4
app/src/main/res/values/ic_launcher_background.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#4289D4</color>
|
||||
</resources>
|
5
app/src/main/res/values/ids.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="txt_sync_progress" type="id" />
|
||||
<item name="txt_bluetooth_status" type="id" />
|
||||
</resources>
|
112
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,112 @@
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">NoteTand</string>
|
||||
<string name="new_note_activity">Nuova Nota in NoteTand</string>
|
||||
|
||||
<string name="about">About</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="censor_mac">Censor MAC Addresses</string>
|
||||
<string name="app_theme">App Theme</string>
|
||||
|
||||
<string name="note">Note</string>
|
||||
<string name="note_name">Note Name</string>
|
||||
<string name="new_note">New Note</string>
|
||||
<string name="send_note">Send Note</string>
|
||||
<string name="receive_notes">Receive Notes</string>
|
||||
<string name="delete_note">Delete Note</string>
|
||||
<string name="delete_note_message">Are you sure you want to delete \'%s\'?</string>
|
||||
<string name="note_saved">Note Saved</string>
|
||||
<string name="note_deleted">Note Deleted</string>
|
||||
<string name="note_typing_hint">Type your note here...</string>
|
||||
|
||||
<string name="share_externally">Share Externally</string>
|
||||
<string name="send">Send</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="discard">Discard</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="unsaved_changes">Unsaved Changes</string>
|
||||
<string name="unsaved_changes_message">You have unsaved changes. What would you like to do?</string>
|
||||
|
||||
<!-- Main Activity -->
|
||||
<string name="main_title">My Notes</string>
|
||||
<string name="btn_sync">Sync</string>
|
||||
<string name="btn_add_note">+</string>
|
||||
<string name="status_ready">Ready</string>
|
||||
<string name="no_notes">0 notes</string>
|
||||
<string name="one_note">1 note</string>
|
||||
<string name="multiple_notes">%d notes</string>
|
||||
|
||||
<!-- Note Edit Activity -->
|
||||
<string name="hint_note_name">Note name</string>
|
||||
<string name="hint_note_content">Start typing your note here...</string>
|
||||
<string name="btn_save">Save</string>
|
||||
<string name="btn_delete">Delete</string>
|
||||
<string name="note_info_format">%d chars, %d words, %d lines</string>
|
||||
|
||||
<!-- Bluetooth Sync Activity -->
|
||||
<string name="bluetooth_sync_title">Bluetooth Sync</string>
|
||||
<string name="status_label">Status</string>
|
||||
<string name="btn_make_discoverable">Make Discoverable</string>
|
||||
<string name="btn_scan_devices">Scan for Devices</string>
|
||||
<string name="btn_stop_scan">Stop Scan</string>
|
||||
<string name="btn_cancel">Cancel</string>
|
||||
<string name="paired_devices_label">Paired Devices:</string>
|
||||
<string name="discovered_devices_label">Discovered Devices:</string>
|
||||
<string name="available_devices">Available Devices</string>
|
||||
|
||||
<!-- Messages -->
|
||||
<string name="bluetooth_not_supported">Bluetooth not supported</string>
|
||||
<string name="bluetooth_disabled">Bluetooth disabled</string>
|
||||
<string name="bluetooth_ready">Bluetooth ready</string>
|
||||
<string name="bluetooth_permission_required">Bluetooth permission required</string>
|
||||
<string name="no_paired_devices">No paired devices found</string>
|
||||
<string name="scanning_devices">Scanning for devices...</string>
|
||||
<string name="discovery_finished">Discovery finished. Found %d devices.</string>
|
||||
<string name="connecting_to_device">Connecting to %s...</string>
|
||||
<string name="connection_failed">Connection failed</string>
|
||||
<string name="connected_starting_sync">Connected! Starting sync...</string>
|
||||
<string name="sync_completed">Sync completed!</string>
|
||||
<string name="sync_error">Sync error: %s</string>
|
||||
<string name="connection_lost">Connection lost</string>
|
||||
<string name="comparing_files">Comparing files...</string>
|
||||
<string name="received_file">Received file: %s</string>
|
||||
<string name="failed_to_save">Failed to save: %s</string>
|
||||
<string name="waiting_connections">Waiting for incoming connections...</string>
|
||||
<string name="discoverable_for_seconds">Device is discoverable for %d seconds</string>
|
||||
<string name="discoverable_denied">Discoverable request denied</string>
|
||||
|
||||
<!-- Dialogs -->
|
||||
<string name="delete_note_title">Delete Note</string>
|
||||
<string name="delete_confirm">Delete</string>
|
||||
|
||||
<string name="unsaved_changes_title">Unsaved Changes</string>
|
||||
|
||||
<string name="note_exists_title">Note Already Exists</string>
|
||||
<string name="note_exists_message">A note with the name \'%s\' already exists. Do you want to overwrite it?</string>
|
||||
<string name="overwrite">Overwrite</string>
|
||||
|
||||
<string name="connect_device_title">Connect to Device</string>
|
||||
<string name="connect_device_message">Connect to %s (%s) for sync?</string>
|
||||
<string name="connect">Connect</string>
|
||||
|
||||
<!-- Errors -->
|
||||
<string name="error_note_name_empty">Note name cannot be empty</string>
|
||||
<string name="error_loading_note">Error loading note</string>
|
||||
<string name="error_saving_note">Error saving note</string>
|
||||
<string name="error_deleting_note">Error deleting note</string>
|
||||
<string name="note_name_sanitized">Note name was sanitized for compatibility</string>
|
||||
<string name="notes_directory_created">Notes directory created</string>
|
||||
<string name="failed_create_directory">Failed to create notes directory</string>
|
||||
<string name="using_internal_storage">Using internal storage</string>
|
||||
<string name="loaded_notes">Loaded %d notes</string>
|
||||
<string name="no_notes_create_one">No notes found. Tap + to create one.</string>
|
||||
<string name="permissions_granted">Permissions granted</string>
|
||||
<string name="some_permissions_denied">Some permissions denied</string>
|
||||
<string name="failed_start_discovery">Failed to start device discovery</string>
|
||||
|
||||
<!-- Content Descriptions -->
|
||||
<string name="add_note_button">Add new note</string>
|
||||
<string name="sync_button">Sync notes via Bluetooth</string>
|
||||
<string name="save_note_button">Save note</string>
|
||||
<string name="delete_note_button">Delete note</string>
|
||||
</resources>
|
13
app/src/main/res/xml/backup_rules.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample backup rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/guide/topics/data/autobackup
|
||||
for details.
|
||||
Note: This file is ignored for devices older that API 31
|
||||
See https://developer.android.com/about/versions/12/backup-restore
|
||||
-->
|
||||
<full-backup-content>
|
||||
<!--
|
||||
<include domain="sharedpref" path="."/>
|
||||
<exclude domain="sharedpref" path="device.xml"/>
|
||||
-->
|
||||
</full-backup-content>
|
19
app/src/main/res/xml/data_extraction_rules.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|