Search in sources :

Example 6 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SurveyMixinTest method onPause_removesReceiverIfPreviouslySet.

@Test
public void onPause_removesReceiverIfPreviouslySet() {
    // Pretend there is a survey in memory
    when(mProvider.getSurveyExpirationDate(any(), any())).thenReturn(-1L);
    // Pretend we are an activity that starts and stops
    FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
    when(mFragment.getActivity()).thenReturn(temp);
    when(mProvider.createAndRegisterReceiver(any())).thenReturn(mReceiver);
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(temp);
    SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
    mixin.onResume();
    manager.registerReceiver(mReceiver, new IntentFilter());
    mixin.onPause();
    // Verify we remove the receiver
    HashMap<BroadcastReceiver, ArrayList<IntentFilter>> map = ReflectionHelpers.getField(manager, "mReceivers");
    assertThat(map.containsKey(mReceiver)).isFalse();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) BroadcastReceiver(android.content.BroadcastReceiver) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) Test(org.junit.Test)

Example 7 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project sexytopo by richsmith.

the class SystemLogActivity method onPause.

@Override
protected void onPause() {
    super.onPause();
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
    broadcastManager.unregisterReceiver(logUpdateReceiver);
}
Also used : LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Example 8 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project sexytopo by richsmith.

the class SystemLogActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
    IntentFilter logFilter = new IntentFilter();
    logFilter.addAction(SexyTopo.SYSTEM_LOG_UPDATED_EVENT);
    broadcastManager.registerReceiver(logUpdateReceiver, logFilter);
    logUpdateReceiver.update();
}
Also used : IntentFilter(android.content.IntentFilter) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Example 9 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project sexytopo by richsmith.

the class TableActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
    broadcastManager.registerReceiver(receiver, new IntentFilter(SexyTopo.SURVEY_UPDATED_EVENT));
    syncTableWithSurvey();
    Bundle bundle = getIntent().getExtras();
    if (bundle != null && bundle.getString(SexyTopo.JUMP_TO_STATION) != null) {
        String requestedStationName = bundle.getString(SexyTopo.JUMP_TO_STATION);
        Station requestedStation = getSurvey().getStationByName(requestedStationName);
        jumpToStation(requestedStation);
    } else {
        final ScrollView scrollView = findViewById(R.id.BodyTableScrollView);
        scrollView.fullScroll(View.FOCUS_DOWN);
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) IntentFilter(android.content.IntentFilter) ScrollView(android.widget.ScrollView) Bundle(android.os.Bundle) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Example 10 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project fdroidclient by f-droid.

the class InstallHistoryService method register.

public static void register(Context context) {
    if (broadcastReceiver != null) {
        // already registered
        return;
    }
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataScheme("http");
    intentFilter.addDataScheme("https");
    intentFilter.addDataScheme("package");
    intentFilter.addAction(Installer.ACTION_INSTALL_STARTED);
    intentFilter.addAction(Installer.ACTION_INSTALL_COMPLETE);
    intentFilter.addAction(Installer.ACTION_INSTALL_INTERRUPTED);
    intentFilter.addAction(Installer.ACTION_INSTALL_USER_INTERACTION);
    intentFilter.addAction(Installer.ACTION_UNINSTALL_STARTED);
    intentFilter.addAction(Installer.ACTION_UNINSTALL_COMPLETE);
    intentFilter.addAction(Installer.ACTION_UNINSTALL_INTERRUPTED);
    intentFilter.addAction(Installer.ACTION_UNINSTALL_USER_INTERACTION);
    broadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            queue(context, intent);
        }
    };
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
    localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) 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