mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 08:05:55 +01:00
use LocalBroadcastManager
This commit is contained in:
parent
42e53c3c8d
commit
6ec1fa9e23
@ -6,6 +6,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -21,6 +22,7 @@ import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
|
||||
public class AppManagerActivity extends Activity {
|
||||
public static final String ACTION_REFRESH_APPLIST
|
||||
= "nodomain.freeyourgadget.gadgetbride.appmanager.action.refresh_applist";
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -61,7 +63,8 @@ public class AppManagerActivity extends Activity {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
filter.addAction(ACTION_REFRESH_APPLIST);
|
||||
registerReceiver(mReceiver, filter);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
||||
|
||||
Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_APPINFO);
|
||||
@ -97,7 +100,7 @@ public class AppManagerActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import android.os.ParcelUuid;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -164,7 +165,8 @@ public class BluetoothCommunicationService extends Service {
|
||||
appInfoIntent.putExtra("app_id" + i.toString(), appInfoCmd.apps[i].getId());
|
||||
appInfoIntent.putExtra("app_index" + i.toString(), appInfoCmd.apps[i].getIndex());
|
||||
}
|
||||
sendBroadcast(appInfoIntent);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(appInfoIntent);
|
||||
break;
|
||||
case APP_MANAGEMENT_RES:
|
||||
GBDeviceCommandAppManagementResult appMgmtRes = (GBDeviceCommandAppManagementResult) deviceCmd;
|
||||
@ -195,7 +197,8 @@ public class BluetoothCommunicationService extends Service {
|
||||
deviceUpdateIntent.putExtra("device_address", gbdevice.getAddress());
|
||||
deviceUpdateIntent.putExtra("device_state", gbdevice.getState().ordinal());
|
||||
deviceUpdateIntent.putExtra("firmware_version", gbdevice.getFirmwareVersion());
|
||||
sendBroadcast(deviceUpdateIntent);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(deviceUpdateIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,6 +6,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
public class BluetoothStateChangeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
@ -38,7 +39,8 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver {
|
||||
context.stopService(stopIntent);
|
||||
|
||||
Intent quitIntent = new Intent(ControlCenter.ACTION_QUIT);
|
||||
context.sendBroadcast(quitIntent);
|
||||
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -91,7 +92,7 @@ public class ControlCenter extends Activity {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_QUIT);
|
||||
filter.addAction(ACTION_REFRESH_DEVICELIST);
|
||||
registerReceiver(mReceiver, filter);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
||||
|
||||
refreshPairedDevices();
|
||||
/*
|
||||
@ -140,7 +141,8 @@ public class ControlCenter extends Activity {
|
||||
stopService(stopIntent);
|
||||
|
||||
Intent quitIntent = new Intent(ControlCenter.ACTION_QUIT);
|
||||
sendBroadcast(quitIntent);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
|
||||
return true;
|
||||
} else if (id == R.id.action_refresh) {
|
||||
if (deviceList.isEmpty()) {
|
||||
refreshPairedDevices();
|
||||
@ -153,8 +155,8 @@ public class ControlCenter extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private void refreshPairedDevices() {
|
||||
|
Loading…
Reference in New Issue
Block a user