use of android.content.BroadcastReceiver in project UltimateAndroid by cymcsg.
the class StaggeredGridEmptyViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.staggered_grid_view_activity_sgv_empy_view);
setTitle("SGV");
mGridView = (StaggeredGridView) findViewById(R.id.grid_view);
LayoutInflater layoutInflater = getLayoutInflater();
View header = layoutInflater.inflate(R.layout.staggered_grid_view_list_item_header_footer, null);
View footer = layoutInflater.inflate(R.layout.staggered_grid_view_list_item_header_footer, null);
TextView txtHeaderTitle = (TextView) header.findViewById(R.id.txt_title);
TextView txtFooterTitle = (TextView) footer.findViewById(R.id.txt_title);
txtHeaderTitle.setText("THE HEADER!");
txtFooterTitle.setText("THE FOOTER!");
mGridView.addHeaderView(header);
mGridView.addFooterView(footer);
mGridView.setEmptyView(findViewById(android.R.id.empty));
mAdapter = new SampleAdapter(this, R.id.txt_line1);
// do we have saved data?
if (savedInstanceState != null) {
mData = savedInstanceState.getStringArrayList(SAVED_DATA_KEY);
fillAdapter();
}
if (mData == null) {
mData = SampleData.generateSampleData();
}
mGridView.setAdapter(mAdapter);
mGridView.setOnItemClickListener(this);
fetchDataReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context receiverContext, Intent receiverIntent) {
fillAdapter();
}
};
LocalBroadcastManager.getInstance(this).registerReceiver(fetchDataReceiver, new IntentFilter(FETCH_DATA_FILTER));
fetchData();
}
use of android.content.BroadcastReceiver in project AntennaPod by AntennaPod.
the class PlaybackServiceFlavorHelper method registerWifiBroadcastReceiver.
void registerWifiBroadcastReceiver() {
if (wifiBroadcastReceiver != null) {
return;
}
wifiBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
boolean isConnected = info.isConnected();
//apparently this method gets called twice when a change happens, but one run is enough.
if (isConnected && !wifiConnectivity) {
wifiConnectivity = true;
castManager.startCastDiscovery();
castManager.reconnectSessionIfPossible(RECONNECTION_ATTEMPT_PERIOD_S, NetworkUtils.getWifiSsid());
} else {
wifiConnectivity = isConnected;
}
}
}
};
callback.registerReceiver(wifiBroadcastReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
}
use of android.content.BroadcastReceiver in project react-native-push-notification by zo0r.
the class RNPushNotification method registerNotificationsReceiveNotificationActions.
private void registerNotificationsReceiveNotificationActions(ReadableArray actions) {
IntentFilter intentFilter = new IntentFilter();
// Add filter for each actions.
for (int i = 0; i < actions.size(); i++) {
String action = actions.getString(i);
intentFilter.addAction(getReactApplicationContext().getPackageName() + "." + action);
}
getReactApplicationContext().registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getBundleExtra("notification");
// Notify the action.
mJsDelivery.notifyNotificationAction(bundle);
// Dismiss the notification popup.
NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
int notificationID = Integer.parseInt(bundle.getString("id"));
manager.cancel(notificationID);
}
}, intentFilter);
}
use of android.content.BroadcastReceiver in project react-native-push-notification by zo0r.
the class RNPushNotification method registerNotificationsRegistration.
private void registerNotificationsRegistration() {
IntentFilter intentFilter = new IntentFilter(getReactApplicationContext().getPackageName() + ".RNPushNotificationRegisteredToken");
getReactApplicationContext().registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String token = intent.getStringExtra("token");
WritableMap params = Arguments.createMap();
params.putString("deviceToken", token);
mJsDelivery.sendEvent("remoteNotificationsRegistered", params);
}
}, intentFilter);
}
use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.
the class BluetoothTestUtils method disable.
/**
* Disables Bluetooth and checks to make sure that Bluetooth was turned off and that the correct
* actions were broadcast.
*
* @param adapter The BT adapter.
*/
public void disable(BluetoothAdapter adapter) {
writeOutput("Disabling Bluetooth adapter.");
assertTrue(adapter.isEnabled());
int btState = adapter.getState();
final Semaphore completionSemaphore = new Semaphore(0);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
return;
}
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if (state == BluetoothAdapter.STATE_OFF) {
completionSemaphore.release();
}
}
};
final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
mContext.registerReceiver(receiver, filter);
assertTrue(adapter.disable());
boolean success = false;
try {
success = completionSemaphore.tryAcquire(ENABLE_DISABLE_TIMEOUT, TimeUnit.MILLISECONDS);
writeOutput(String.format("disable() completed in 0 ms"));
} catch (final InterruptedException e) {
// This should never happen but just in case it does, the test will fail anyway.
}
mContext.unregisterReceiver(receiver);
if (!success) {
fail(String.format("disable() timeout: state=%d (expected %d)", btState, BluetoothAdapter.STATE_OFF));
}
}
Aggregations