use of android.content.BroadcastReceiver in project android_frameworks_base by AOSPA.
the class BroadcastTest method testLocalBroadcastPermissionDenied.
public void testLocalBroadcastPermissionDenied() throws Exception {
setExpectedReceivers(new String[] { RECEIVER_RESULTS });
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_LOCAL), PERMISSION_DENIED, finish, null, Activity.RESULT_CANCELED, null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
}
use of android.content.BroadcastReceiver in project android_frameworks_base by AOSPA.
the class MediaRouterService method systemRunning.
public void systemRunning() {
IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_USER_SWITCHED)) {
switchUser();
}
}
}, filter);
switchUser();
}
use of android.content.BroadcastReceiver in project kcanotify by antest1.
the class KcaViewButtonService method onCreate.
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
// Can not draw overlays: pass
stopSelf();
} else {
clickcount = 0;
mHandler = new Handler();
broadcaster = LocalBroadcastManager.getInstance(this);
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
battleinfo_receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//String s = intent.getStringExtra(KCA_MSG_DATA);
String s = dbHelper.getValue(DB_KEY_BATTLEINFO);
broadcaster.sendBroadcast(new Intent(KCA_MSG_BATTLE_VIEW_REFRESH));
Log.e("KCA", "KCA_MSG_BATTLE_INFO Received: \n".concat(s));
}
};
battlenode_receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//String s = intent.getStringExtra(KCA_MSG_DATA);
String s = dbHelper.getValue(DB_KEY_BATTLENODE);
broadcaster.sendBroadcast(new Intent(KCA_MSG_BATTLE_VIEW_REFRESH));
Log.e("KCA", "KCA_MSG_BATTLE_NODE Received: \n".concat(s));
}
};
battlehdmg_receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String s = intent.getStringExtra(KCA_MSG_DATA);
if (s.contains("1")) {
((ImageView) mView.findViewById(R.id.viewbutton)).getDrawable().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorHeavyDmgStateWarn), PorterDuff.Mode.MULTIPLY);
} else {
((ImageView) mView.findViewById(R.id.viewbutton)).getDrawable().clearColorFilter();
}
Log.e("KCA", "KCA_MSG_BATTLE_HDMG Received");
}
};
LocalBroadcastManager.getInstance(this).registerReceiver((battleinfo_receiver), new IntentFilter(KCA_MSG_BATTLE_INFO));
LocalBroadcastManager.getInstance(this).registerReceiver((battlenode_receiver), new IntentFilter(KCA_MSG_BATTLE_NODE));
LocalBroadcastManager.getInstance(this).registerReceiver((battlehdmg_receiver), new IntentFilter(KCA_MSG_BATTLE_HDMG));
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
notificationManager = NotificationManagerCompat.from(getApplicationContext());
mView = mInflater.inflate(R.layout.view_button, null);
// Button (Fairy) Settings
viewbutton = (ImageView) mView.findViewById(R.id.viewbutton);
String fairyIdValue = getStringPreferences(getApplicationContext(), PREF_FAIRY_ICON);
String fairyPath = "noti_icon_".concat(fairyIdValue);
viewBitmapId = getId(fairyPath, R.mipmap.class);
viewBitmapSmallId = getId(fairyPath.concat("_small"), R.mipmap.class);
viewbutton.setImageResource(viewBitmapId);
int index = Arrays.binarySearch(FAIRY_REVERSE_LIST, Integer.parseInt(fairyIdValue));
if (index >= 0)
viewbutton.setScaleX(-1.0f);
else
viewbutton.setScaleX(1.0f);
viewbutton.setOnTouchListener(mViewTouchListener);
viewbutton.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
buttonWidth = viewbutton.getMeasuredWidth();
buttonHeight = viewbutton.getMeasuredHeight();
mParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.TOP | Gravity.START;
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
Log.e("KCA", "w/h: " + String.valueOf(screenWidth) + " " + String.valueOf(screenHeight));
mParams.y = screenHeight - buttonHeight;
mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mManager.addView(mView, mParams);
battleviewEnabled = false;
questviewEnabled = false;
}
}
use of android.content.BroadcastReceiver in project kcanotify by antest1.
the class KcaBattleViewService method onCreate.
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
// Can not draw overlays: pass
stopSelf();
} else {
try {
active = true;
contextWithLocale = getContextWithLocale(getApplicationContext(), getBaseContext());
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
//mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mInflater = LayoutInflater.from(contextWithLocale);
mView = mInflater.inflate(R.layout.view_sortie_battle, null);
mView.setVisibility(View.GONE);
battleview = (ScrollView) mView.findViewById(R.id.battleview);
battleview.setOnTouchListener(mViewTouchListener);
setBattleViewMenu();
itemView = mInflater.inflate(R.layout.view_battleview_items, null);
acView = mInflater.inflate(R.layout.view_battleview_aircombat, null);
acView.findViewById(R.id.view_ac_head).setOnTouchListener(acViewTouchListener);
mParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.CENTER;
mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mManager.addView(mView, mParams);
Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point size = new Point();
display.getSize(size);
displayWidth = size.x;
refreshreceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("KCA", "=> Received Intent");
//mViewBackup = mView;
//mManager.removeView(mView);
api_data = KcaBattle.getCurrentApiData();
if (api_data != null && api_data.has("api_heavy_damaged")) {
int value = api_data.get("api_heavy_damaged").getAsInt();
if (value == HD_DANGER) {
mView.findViewById(R.id.battleviewpanel).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorHeavyDmgStatePanel));
} else {
mView.findViewById(R.id.battleviewpanel).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
}
}
int setViewResult = setView();
if (setViewResult == 0) {
if (KcaViewButtonService.getClickCount() == 0) {
mView.setVisibility(View.GONE);
}
//mManager.addView(mView, mParams);
mView.invalidate();
mManager.updateViewLayout(mView, mParams);
}
}
};
LocalBroadcastManager.getInstance(this).registerReceiver(refreshreceiver, new IntentFilter(KCA_MSG_BATTLE_VIEW_REFRESH));
} catch (Exception e) {
active = false;
error_flag = true;
sendReport(e, ERORR_INIT);
stopSelf();
}
}
}
use of android.content.BroadcastReceiver in project Shuttle by timusus.
the class DetailFragment method onCreate.
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
setHasOptionsMenu(true);
setEnterSharedElementCallback(enterSharedElementCallback);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
Serializable object = getArguments().getSerializable(ARG_MODEL);
if (object instanceof AlbumArtist) {
albumArtist = (AlbumArtist) object;
} else if (object instanceof Album) {
album = (Album) object;
} else if (object instanceof Genre) {
genre = (Genre) object;
} else if (object instanceof Playlist) {
playlist = (Playlist) object;
}
if (adapter == null) {
adapter = new DetailAdapter();
adapter.setListener(this);
}
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals("restartLoader")) {
refreshAdapterItems();
}
}
};
sharedPreferenceChangeListener = (sharedPreferences, key) -> {
if (key.equals("pref_theme_highlight_color") || key.equals("pref_theme_accent_color") || key.equals("pref_theme_white_accent")) {
themeUIComponents();
} else if (key.equals("songWhitelist")) {
refreshAdapterItems();
}
};
prefs.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
if (requestManager == null) {
requestManager = Glide.with(this);
}
if (headerItem == null) {
headerItem = new HeaderView();
}
if (horizontalRecyclerView == null) {
horizontalRecyclerView = new HorizontalRecyclerView();
horizontalRecyclerView.setListener(this);
}
}
Aggregations