Search in sources :

Example 26 with LocalBroadcastManager

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();
    }
}
Also used : LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) SuppressLint(android.annotation.SuppressLint)

Example 27 with LocalBroadcastManager

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));
}
Also used : IntentFilter(android.content.IntentFilter) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Example 28 with LocalBroadcastManager

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;
}
Also used : LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Example 29 with LocalBroadcastManager

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);
    }
}
Also used : Context(android.content.Context) Installer(org.fdroid.fdroid.installer.Installer) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver) File(java.io.File) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) Uri(android.net.Uri) Apk(org.fdroid.fdroid.data.Apk)

Example 30 with LocalBroadcastManager

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);
        }
    };
}
Also used : IntentFilter(android.content.IntentFilter) HandlerThread(android.os.HandlerThread) BluetoothDevice(android.bluetooth.BluetoothDevice) Message(android.os.Message) Handler(android.os.Handler) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Aggregations

LocalBroadcastManager (androidx.localbroadcastmanager.content.LocalBroadcastManager)30 IntentFilter (android.content.IntentFilter)15 BroadcastReceiver (android.content.BroadcastReceiver)9 Intent (android.content.Intent)8 Context (android.content.Context)7 ArrayList (java.util.ArrayList)4 Bundle (android.os.Bundle)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Apk (org.fdroid.fdroid.data.Apk)3 Uri (android.net.Uri)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 BluetoothDevice (android.bluetooth.BluetoothDevice)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 Message (android.os.Message)1 ScrollView (android.widget.ScrollView)1 FirebaseCrashlytics (com.google.firebase.crashlytics.FirebaseCrashlytics)1