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