This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.

131 lines
4.0 KiB
Java

package io.guh.nymeaapp;
import java.io.File;
import android.util.Log;
import android.content.Intent;
import android.content.Context;
import android.os.Bundle;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.provider.Settings.Secure;
import android.os.Vibrator;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import android.content.res.Configuration;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.location.LocationManager;
public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActivity
{
private static final String TAG = "nymea-app: NymeaAppActivity";
private static Context context = null;
private static native void darkModeEnabledChangedJNI();
private static native void notificationActionReceivedJNI(String data);
private static native void locationServicesEnabledChangedJNI();
private BroadcastReceiver m_gpsSwitchStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "**** Intent received!!!" + intent.getAction());
if (LocationManager.MODE_CHANGED_ACTION.equals(intent.getAction())) {
locationServicesEnabledChangedJNI();
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.context = getApplicationContext();
}
public void onNewIntent (Intent intent) {
Log.d(TAG, "New intent: " + intent);
String notificationData = intent.getStringExtra("notificationData");
if (notificationData != null) {
Log.d(TAG, "Intent data: " + notificationData);
notificationActionReceivedJNI(notificationData);
}
}
@Override
public void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter(LocationManager.MODE_CHANGED_ACTION);
// filter.addAction(Intent.ACTION_PROVIDER_CHANGED);
registerReceiver(m_gpsSwitchStateReceiver, filter);
}
@Override
public void onPause() {
super.onPause();
unregisterReceiver(m_gpsSwitchStateReceiver);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
NymeaAppActivity.darkModeEnabledChangedJNI();
}
public String notificationData() {
return getIntent().getStringExtra("notificationData");
}
public static Context getAppContext() {
return NymeaAppActivity.context;
}
public String deviceSerial()
{
return Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
}
public static String deviceManufacturer()
{
return Build.MANUFACTURER;
}
public static String deviceModel()
{
return Build.MODEL;
}
public static String device()
{
return Build.DEVICE;
}
public void vibrate(int duration)
{
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(duration);
}
public void shareFile(String fileName) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
Uri uri = FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".fileprovider", new File(fileName));
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
} else {
Log.d(TAG, "Intent not resolved");
}
}
public boolean darkModeEnabled() {
return (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
public boolean locationServicesEnabled() {
LocationManager lm = (LocationManager)getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
return lm.isLocationEnabled();
}
}