Search in sources :

Example 71 with BroadcastReceiver

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);
}
Also used : Context(android.content.Context) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 72 with BroadcastReceiver

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();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 73 with BroadcastReceiver

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;
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Point(android.graphics.Point) BroadcastReceiver(android.content.BroadcastReceiver) Point(android.graphics.Point) WindowManager(android.view.WindowManager) LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) Display(android.view.Display)

Example 74 with BroadcastReceiver

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();
        }
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Point(android.graphics.Point) BroadcastReceiver(android.content.BroadcastReceiver) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 75 with BroadcastReceiver

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);
    }
}
Also used : DetailAdapter(com.simplecity.amp_library.ui.adapters.DetailAdapter) Context(android.content.Context) Serializable(java.io.Serializable) Playlist(com.simplecity.amp_library.model.Playlist) Album(com.simplecity.amp_library.model.Album) Intent(android.content.Intent) Genre(com.simplecity.amp_library.model.Genre) BroadcastReceiver(android.content.BroadcastReceiver) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)637 Intent (android.content.Intent)564 Context (android.content.Context)493 IntentFilter (android.content.IntentFilter)441 PendingIntent (android.app.PendingIntent)120 Test (org.junit.Test)109 ArrayList (java.util.ArrayList)34 RemoteException (android.os.RemoteException)29 Bundle (android.os.Bundle)24 IOException (java.io.IOException)23 Point (android.graphics.Point)20 Semaphore (java.util.concurrent.Semaphore)20 View (android.view.View)19 Handler (android.os.Handler)18 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)17 ComponentName (android.content.ComponentName)16 TextView (android.widget.TextView)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ApplicationInfo (android.content.pm.ApplicationInfo)14 AndroidRuntimeException (android.util.AndroidRuntimeException)14