use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project sexytopo by richsmith.
the class DeviceActivity method onResume.
@SuppressLint("SourceLockedOrientationActivity")
@Override
protected void onResume() {
super.onResume();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
logUpdateReceiver.update();
updateStatuses();
registerReceiver(scanReceiver, scanFilter);
registerReceiver(stateChangeReceiver, statusFilter);
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
broadcastManager.registerReceiver(logUpdateReceiver, logFilter);
if (!requestComms().isConnected()) {
updateComms();
}
}
use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project sexytopo by richsmith.
the class GraphActivity method registerReceivers.
private void registerReceivers() {
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
broadcastManager.registerReceiver(updatedReceiver, new IntentFilter(SexyTopo.SURVEY_UPDATED_EVENT));
broadcastManager.registerReceiver(createdReceiver, new IntentFilter(SexyTopo.NEW_STATION_CREATED_EVENT));
}
use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project fdroidclient by f-droid.
the class InstallHistoryService method unregister.
public static void unregister(Context context) {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
localBroadcastManager.unregisterReceiver(broadcastReceiver);
broadcastReceiver = null;
}
use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project fdroidclient by f-droid.
the class AppListItemController method onActionButtonPressed.
protected void onActionButtonPressed(App app) {
if (app == null) {
return;
}
// When the button says "Open", then launch the app.
if (currentStatus != null && currentStatus.status == AppUpdateStatusManager.Status.Installed) {
Intent intent = activity.getPackageManager().getLaunchIntentForPackage(app.packageName);
if (intent != null) {
activity.startActivity(intent);
// Once it is explicitly launched by the user, then we can pretty much forget about
// any sort of notification that the app was successfully installed. It should be
// apparent to the user because they just launched it.
AppUpdateStatusManager.getInstance(activity).removeApk(currentStatus.getCanonicalUrl());
}
return;
}
if (currentStatus != null && currentStatus.status == AppUpdateStatusManager.Status.ReadyToInstall) {
String canonicalUrl = currentStatus.apk.getCanonicalUrl();
File apkFilePath = ApkCache.getApkDownloadPath(activity, canonicalUrl);
Utils.debugLog(TAG, "skip download, we have already downloaded " + currentStatus.apk.getCanonicalUrl() + " to " + apkFilePath);
final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(activity);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
broadcastManager.unregisterReceiver(this);
if (Installer.ACTION_INSTALL_USER_INTERACTION.equals(intent.getAction())) {
PendingIntent pendingIntent = intent.getParcelableExtra(Installer.EXTRA_USER_INTERACTION_PI);
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException ignored) {
}
}
}
};
Uri canonicalUri = Uri.parse(canonicalUrl);
broadcastManager.registerReceiver(receiver, Installer.getInstallIntentFilter(canonicalUri));
Installer installer = InstallerFactory.create(activity, currentStatus.apk);
installer.installPackage(Uri.parse(apkFilePath.toURI().toString()), canonicalUri);
} else {
final Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(activity, app);
InstallManagerService.queue(activity, app, suggestedApk);
}
}
use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project fdroidclient by f-droid.
the class BluetoothManager method start.
/**
* Starts the service, triggering a status broadcast via {@link #ACTION_STATUS}.
* {@link #STATUS_STARTED} can be broadcast multiple times for the same session,
* so make sure {@link android.content.BroadcastReceiver}s handle duplicates.
*/
public static void start(final Context context) {
BluetoothManager.context = new WeakReference<>(context);
if (handlerThread != null && handlerThread.isAlive()) {
sendBroadcast(STATUS_STARTED, null);
return;
}
sendBroadcast(STATUS_STARTING, null);
final BluetoothServer bluetoothServer = new BluetoothServer(context.getFilesDir());
handlerThread = new HandlerThread("BluetoothManager", Process.THREAD_PRIORITY_LESS_FAVORABLE) {
@Override
protected void onLooperPrepared() {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
localBroadcastManager.registerReceiver(bluetoothDeviceFound, new IntentFilter(BluetoothDevice.ACTION_FOUND));
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String name = bluetoothAdapter.getName();
if (name != null) {
SwapService.putBluetoothNameBeforeSwap(name);
}
if (!bluetoothAdapter.enable()) {
sendBroadcast(STATUS_ERROR, context.getString(R.string.swap_error_cannot_start_bluetooth));
return;
}
bluetoothServer.start();
if (bluetoothAdapter.startDiscovery()) {
sendBroadcast(STATUS_STARTED, null);
} else {
sendBroadcast(STATUS_ERROR, context.getString(R.string.swap_error_cannot_start_bluetooth));
}
for (BluetoothDevice device : bluetoothAdapter.getBondedDevices()) {
sendFoundBroadcast(context, device);
}
}
};
handlerThread.start();
handler = new Handler(handlerThread.getLooper()) {
@Override
public void handleMessage(Message msg) {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
localBroadcastManager.unregisterReceiver(bluetoothDeviceFound);
bluetoothServer.close();
if (bluetoothAdapter != null) {
bluetoothAdapter.cancelDiscovery();
if (!SwapService.wasBluetoothEnabledBeforeSwap()) {
bluetoothAdapter.disable();
}
String name = SwapService.getBluetoothNameBeforeSwap();
if (name != null) {
bluetoothAdapter.setName(name);
}
}
handlerThread.quit();
handlerThread = null;
sendBroadcast(STATUS_STOPPED, null);
}
};
}
Aggregations