Example usage for android.content BroadcastReceiver BroadcastReceiver

List of usage examples for android.content BroadcastReceiver BroadcastReceiver

Introduction

In this page you can find the example usage for android.content BroadcastReceiver BroadcastReceiver.

Prototype

public BroadcastReceiver() 

Source Link

Usage

From source file:eu.power_switch.gui.fragment.configure_receiver.ConfigureReceiverDialogPage3SetupFragment.java

@Nullable
@Override//from   w w w  .jav a 2 s  . c o  m
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dialog_fragment_configure_receiver_page_3, container, false);

    // BroadcastReceiver to get notifications from background service if room data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(LocalBroadcastConstants.INTENT_BRAND_MODEL_CHANGED)) {
                String model = intent.getStringExtra("model");

                try {
                    Receiver receiver = ReceiverReflectionMagic.getDummy(getActivity(),
                            Receiver.getJavaPath(model));
                    initType(receiver);

                    sendChannelDetailsChangedBroadcast(getActivity(), getSelectedChannelMaster(),
                            getSelectedChannelSlave(), dipSwitchArrayList, getCurrentSeed(),
                            getCurrentUniversalButtons());
                } catch (Exception e) {
                    StatusMessageHandler.showErrorMessage(getActivity(), e);
                }
            }
        }
    };

    // Master/Slave
    layoutMasterSlave = (TableLayout) rootView.findViewById(R.id.tableLayout_MasterSlave);
    channelMasterListView = (ListView) rootView.findViewById(R.id.listView_channelMaster);
    channelMasterNamesAdapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_list_item_single_choice);
    channelMasterListView.setAdapter(channelMasterNamesAdapter);
    channelMasterListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            sendChannelDetailsChangedBroadcast(getActivity(), getSelectedChannelMaster(),
                    getSelectedChannelSlave(), null, getCurrentSeed(), null);
        }
    });

    channelSlaveListView = (ListView) rootView.findViewById(R.id.listView_channelSlave);
    channelSlaveNamesAdapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_list_item_single_choice);
    channelSlaveListView.setAdapter(channelSlaveNamesAdapter);
    channelSlaveListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            sendChannelDetailsChangedBroadcast(getActivity(), getSelectedChannelMaster(),
                    getSelectedChannelSlave(), null, getCurrentSeed(), null);
        }
    });

    // Dips
    layoutDip = (NestedScrollView) rootView.findViewById(R.id.scrollView_dip);
    dipViewList = new ArrayList<>();
    SwitchCompat dip0 = (SwitchCompat) rootView.findViewById(R.id.switch_dip0);
    SwitchCompat dip1 = (SwitchCompat) rootView.findViewById(R.id.switch_dip1);
    SwitchCompat dip2 = (SwitchCompat) rootView.findViewById(R.id.switch_dip2);
    SwitchCompat dip3 = (SwitchCompat) rootView.findViewById(R.id.switch_dip3);
    SwitchCompat dip4 = (SwitchCompat) rootView.findViewById(R.id.switch_dip4);
    SwitchCompat dip5 = (SwitchCompat) rootView.findViewById(R.id.switch_dip5);
    SwitchCompat dip6 = (SwitchCompat) rootView.findViewById(R.id.switch_dip6);
    SwitchCompat dip7 = (SwitchCompat) rootView.findViewById(R.id.switch_dip7);
    SwitchCompat dip8 = (SwitchCompat) rootView.findViewById(R.id.switch_dip8);
    SwitchCompat dip9 = (SwitchCompat) rootView.findViewById(R.id.switch_dip9);
    dipViewList.add(dip0);
    dipViewList.add(dip1);
    dipViewList.add(dip2);
    dipViewList.add(dip3);
    dipViewList.add(dip4);
    dipViewList.add(dip5);
    dipViewList.add(dip6);
    dipViewList.add(dip7);
    dipViewList.add(dip8);
    dipViewList.add(dip9);

    CompoundButton.OnCheckedChangeListener dipCheckedChangedListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            ArrayList<DipSwitch> dips = new ArrayList<>();
            for (SwitchCompat switchCompat : dipViewList) {
                if (switchCompat.getVisibility() == View.VISIBLE) {
                    dips.add(new DipSwitch(switchCompat.getText().toString(), switchCompat.isChecked()));
                }
            }

            sendChannelDetailsChangedBroadcast(getActivity(), '\n', 0, dips, getCurrentSeed(), null);
        }
    };

    for (SwitchCompat switchCompat : dipViewList) {
        switchCompat.setOnCheckedChangeListener(dipCheckedChangedListener);
    }

    // AutoPair
    layoutAutoPair = (NestedScrollView) rootView.findViewById(R.id.scrollView_autoPair);
    android.widget.Button buttonPair = (android.widget.Button) rootView.findViewById(R.id.button_pair);
    buttonPair.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                List<Gateway> activeGateways = DatabaseHandler.getAllGateways(true);

                if (activeGateways.isEmpty()) {
                    StatusMessageHandler.showNoActiveGatewayMessage(getActivity());
                    return;
                }

                ArrayList<NetworkPackage> networkPackages = new ArrayList<>();
                for (Gateway gateway : activeGateways) {
                    try {
                        networkPackages.add(
                                currentAutoPairReceiver.getNetworkPackage(gateway, getString(R.string.pair)));
                        networkPackages.add(
                                currentAutoPairReceiver.getNetworkPackage(gateway, getString(R.string.pair)));
                    } catch (Exception e) {
                        Log.e(e);
                    }
                }

                NetworkHandler.init(getContext());
                NetworkHandler.send(networkPackages);

            } catch (Exception e) {
                StatusMessageHandler.showErrorMessage(getActivity(), e);
            }
        }
    });
    android.widget.Button buttonUnpair = (android.widget.Button) rootView.findViewById(R.id.button_unpair);
    buttonUnpair.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                List<Gateway> activeGateways = DatabaseHandler.getAllGateways(true);

                if (activeGateways.isEmpty()) {
                    StatusMessageHandler.showNoActiveGatewayMessage(getActivity());
                    return;
                }

                ArrayList<NetworkPackage> networkPackages = new ArrayList<>();
                for (Gateway gateway : activeGateways) {
                    try {
                        networkPackages.add(
                                currentAutoPairReceiver.getNetworkPackage(gateway, getString(R.string.unpair)));
                        networkPackages.add(
                                currentAutoPairReceiver.getNetworkPackage(gateway, getString(R.string.unpair)));
                    } catch (Exception e) {
                        Log.e(e);
                    }
                }

                NetworkHandler.init(getContext());
                NetworkHandler.send(networkPackages);
            } catch (Exception e) {
                StatusMessageHandler.showErrorMessage(getActivity(), e);
            }
        }
    });
    android.widget.Button buttonUnpairAll = (android.widget.Button) rootView
            .findViewById(R.id.button_unpairAll);
    buttonUnpairAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                List<Gateway> activeGateways = DatabaseHandler.getAllGateways(true);

                if (activeGateways.isEmpty()) {
                    StatusMessageHandler.showNoActiveGatewayMessage(getActivity());
                    return;
                }

                ArrayList<NetworkPackage> networkPackages = new ArrayList<>();
                for (Gateway gateway : activeGateways) {
                    try {
                        networkPackages.add(currentAutoPairReceiver.getNetworkPackage(gateway,
                                getString(R.string.unpair_all)));
                        networkPackages.add(currentAutoPairReceiver.getNetworkPackage(gateway,
                                getString(R.string.unpair_all)));
                    } catch (Exception e) {
                        Log.e(e);
                    }
                }

                NetworkHandler.init(getContext());
                NetworkHandler.send(networkPackages);
            } catch (Exception e) {
                StatusMessageHandler.showErrorMessage(getActivity(), e);
            }
        }
    });

    // Universal
    layoutUniversal = (LinearLayout) rootView.findViewById(R.id.linearLayout_universalButtons);
    FloatingActionButton addUniversalButtonFAB = (FloatingActionButton) rootView
            .findViewById(R.id.add_universalButton_fab);
    addUniversalButtonFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(),
            ContextCompat.getColor(getActivity(), android.R.color.white)));
    buttonsList = (LinearLayout) rootView.findViewById(R.id.universalButtons_List);

    addUniversalButtonFAB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            addUniversalButtonLayoutToDialogView();
            sendChannelDetailsChangedBroadcast(getActivity(), null, 0, null, -1, getCurrentUniversalButtons());
        }
    });

    updateUi(null);

    Bundle args = getArguments();
    if (args != null && args.containsKey(ConfigureReceiverDialog.RECEIVER_ID_KEY)) {
        long receiverId = args.getLong(ConfigureReceiverDialog.RECEIVER_ID_KEY);
        initializeReceiverData(receiverId);
    }

    return rootView;
}

From source file:de.grundid.plusrad.recording.RecordingService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "recording service create");
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    dbAdapter = new DbAdapter(getApplicationContext());
    Intent intent = new Intent(this, ActivityRecognitionIntentService.class);
    pendingIntentForActivityRecorgnition = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    apiClient = new GoogleApiClient.Builder(this).addApi(ActivityRecognition.API).addApi(LocationServices.API)
            .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    apiClient.connect();//from  w  w w .j  a  v a 2s.c  o m
    broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
    broadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i("PRAD", "activity update: " + intent.getStringExtra("activityName"));
            activityType = intent.getIntExtra("activityType", DetectedActivity.UNKNOWN);
        }
    };
}

From source file:com.google.android.gms.samples.appinvite.MainActivity.java

/**
 * There are two broadcast receivers in this application.  The first is ReferrerReceiver, it
 * is a global receiver declared in the manifest.  It receives broadcasts from the Play Store
 * and then broadcasts messages to the local broadcast receiver, which is registered here.
 * Since the broadcast is asynchronous, it can occur after the app has started, so register
 * for the notification immediately in onStart. The Play Store broadcast should be very soon
 * after the app is first opened, so this receiver should trigger soon after start
 *///ww  w .j  a  va 2 s  .com
// [START register_unregister_launch]
private void registerDeepLinkReceiver() {
    // Create local Broadcast receiver that starts DeepLinkActivity when a deep link
    // is found
    mDeepLinkReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (AppInviteReferral.hasReferral(intent)) {
                launchDeepLinkActivity(intent);
            }
        }
    };

    IntentFilter intentFilter = new IntentFilter(getString(R.string.action_deep_link));
    LocalBroadcastManager.getInstance(this).registerReceiver(mDeepLinkReceiver, intentFilter);
}

From source file:com.liferay.alerts.activity.CommentsActivity.java

private void _registerBroadcastReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_ADD_COMMENT);
    filter.addAction(ACTION_UPDATE_COMMENTS_LIST);

    _receiver = new BroadcastReceiver() {

        @Override/*ww  w. jav a2  s  . c  o  m*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            ListView listView = (ListView) findViewById(R.id.comments);

            if (ACTION_UPDATE_COMMENTS_LIST.equals(action)) {
                ArrayList<Alert> alerts = intent.getParcelableArrayListExtra(EXTRA_ALERTS);

                ArrayAdapter<Alert> adapter = new CommentListAdapter(getApplicationContext(), alerts);

                listView.setAdapter(adapter);
            } else if (ACTION_ADD_COMMENT.equals(action)) {
                Alert alert = intent.getParcelableExtra(EXTRA_ALERT);

                ArrayAdapter<Alert> adapter = (ArrayAdapter<Alert>) listView.getAdapter();

                adapter.add(alert);
            }
        }

    };

    _getBroadcastManager().registerReceiver(_receiver, filter);
}

From source file:com.cellbots.local.EyesView.java

public EyesView(CellDroidActivity ct, String url, boolean torch) {
    Log.e("remote eyes", "started " + url);
    mParent = ct;/*  w  ww  .j  av  a  2  s .com*/
    putUrl = url;

    PowerManager pm = (PowerManager) ct.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            "Cellbot Eyes");
    mWakeLock.acquire();

    out = new ByteArrayOutputStream();

    if (putUrl != null) {
        isLocalUrl = putUrl.contains("127.0.0.1") || putUrl.contains("localhost");
        server = putUrl.replace("http://", "");
        server = server.substring(0, server.indexOf("/"));
        mTorchMode = torch;
        resetConnection();
        mHttpState = new HttpState();
    }

    ct.setContentView(R.layout.eyes_main);
    mPreview = (SurfaceView) ct.findViewById(R.id.eyes_preview);
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mPreview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            setTorchMode(!mTorchMode);
        }
    });

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean useTorch = intent.getBooleanExtra("TORCH", false);
            boolean shouldTakePicture = intent.getBooleanExtra("PICTURE", false);
            setTorchMode(useTorch);
            setTakePicture(shouldTakePicture);
        }
    };

    ct.registerReceiver(mReceiver, new IntentFilter(EyesView.EYES_COMMAND));

    mFrame = (FrameLayout) ct.findViewById(R.id.eyes_frame);
    mImageView = new ImageView(ct);
    mImageView.setScaleType(ScaleType.FIT_CENTER);
    mImageView.setBackgroundColor(Color.BLACK);

    setPersona(PERSONA_READY);

    mFrame.addView(mImageView);
}

From source file:com.klinker.android.twitter.activities.tweet_viewer.TweetPager.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.activity_slide_up, R.anim.activity_slide_down);

    try {/*from   ww  w.  j  a  va 2s  .c o m*/
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
    } catch (Exception e) {

    }

    context = this;
    settings = AppSettings.getInstance(this);

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

    getFromIntent();

    mSectionsPagerAdapter = new TweetPagerAdapter(getFragmentManager(), context, name, screenName, tweet, time,
            retweeter, webpage, proPic, tweetId, picture, users, hashtags, otherLinks, isMyTweet, isMyRetweet,
            secondAcc, animatedGif);

    // methods for advancing windowed
    boolean settingsVal = settings.advanceWindowed;
    boolean fromWidget = getIntent().getBooleanExtra("from_widget", false);
    final boolean youtube;

    youtube = mSectionsPagerAdapter.getHasYoutube() || mSectionsPagerAdapter.getHasGif()
            || mSectionsPagerAdapter.hasVine();

    if (fromWidget || settingsVal) {
        setUpWindow(youtube);
    }

    setUpTheme();

    int currentOrientation = getResources().getConfiguration().orientation;
    if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    }

    if (getIntent().getBooleanExtra("clicked_youtube", false)) {
        IntentFilter i = new IntentFilter("com.klinker.android.twitter.YOUTUBE_READY");
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                TweetYouTubeFragment.resume();

                context.unregisterReceiver(this);
            }
        }, i);
    }

    setContentView(R.layout.tweet_pager);
    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(mSectionsPagerAdapter);
    pager.setOffscreenPageLimit(5);

    final int numberOfPages = mSectionsPagerAdapter.getCount();

    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i2) {

        }

        @Override
        public void onPageSelected(int i) {
            if (youtube) {
                try {
                    switch (numberOfPages) {
                    case 3:
                    case 4:
                        if (i != 0) {
                            TweetYouTubeFragment.pause();
                        } else {
                            TweetYouTubeFragment.resume();
                        }
                        break;
                    case 5:
                        if (i != 1) {
                            TweetYouTubeFragment.pause();
                        } else {
                            TweetYouTubeFragment.resume();
                        }
                        break;
                    }
                } catch (Exception e) {

                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int i) {

        }
    });

    switch (numberOfPages) {
    case 2:
        if (settings.pageToOpen == AppSettings.PAGE_CONVO) {
            pager.setCurrentItem(1);
        } else {
            pager.setCurrentItem(0);
        }
        break;
    case 3:
        if (mSectionsPagerAdapter.getHasWebpage()) {
            switch (settings.pageToOpen) {
            case AppSettings.PAGE_CONVO:
                pager.setCurrentItem(2);
                break;
            case AppSettings.PAGE_WEB:
                pager.setCurrentItem(0);
                break;
            default:
                pager.setCurrentItem(1);
                break;
            }
        } else { // no web page
            switch (settings.pageToOpen) {
            case AppSettings.PAGE_CONVO:
                pager.setCurrentItem(2);
                break;
            default:
                pager.setCurrentItem(1);
                break;
            }
        }
        break;
    case 4: // webpage and youtube
        switch (settings.pageToOpen) {
        case AppSettings.PAGE_CONVO:
            pager.setCurrentItem(3);
            break;
        case AppSettings.PAGE_WEB:
            pager.setCurrentItem(1);
            break;
        default:
            pager.setCurrentItem(0);
            break;
        }
        break;
    }

    if (getIntent().getBooleanExtra("clicked_youtube", false)) {
        pager.setCurrentItem(0);
    }

    if (settings.addonTheme) {
        PagerTitleStrip strip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
        strip.setBackgroundColor(settings.pagerTitleInt);

        if (!settings.showTitleStrip) {
            strip.setVisibility(View.GONE);
        }
    }

}

From source file:com.github.sryze.wirebug.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    boolean isConnected = NetworkUtils.isConnectedToWifi(connectivityManager);
    connectedView.setVisibility(isConnected ? View.VISIBLE : View.GONE);
    notConnectedView.setVisibility(isConnected ? View.GONE : View.VISIBLE);

    boolean isEnabled = DebugManager.isTcpDebuggingEnabled();
    updateInstructions(isEnabled);/*  w ww  .j a  va2 s. co  m*/
    updateStatus();

    toggleDebuggingButton.setOnCheckedChangeListener(null);
    toggleDebuggingButton.setChecked(isEnabled);
    toggleDebuggingButton.setOnCheckedChangeListener(enableSwitchChangeListener);

    networkStateChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "Received network state changed broadcast");
            NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
            switch (networkInfo.getState()) {
            case CONNECTED:
                connectedView.setVisibility(View.VISIBLE);
                notConnectedView.setVisibility(View.INVISIBLE);
                break;
            case DISCONNECTED:
                connectedView.setVisibility(View.GONE);
                notConnectedView.setVisibility(View.VISIBLE);
                break;
            }
            updateConnectionInfo();
        }
    };
    registerReceiver(networkStateChangedReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));

    debugStatusChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "Received debug state change broadcast");
            boolean isEnabled = intent.getBooleanExtra(DebugStatusService.EXTRA_IS_ENABLED, false);
            updateInstructions(isEnabled);
            toggleDebuggingButton.setOnCheckedChangeListener(null);
            toggleDebuggingButton.setChecked(isEnabled);
            toggleDebuggingButton.setOnCheckedChangeListener(enableSwitchChangeListener);
        }
    };
    registerReceiver(debugStatusChangedReceiver, new IntentFilter(DebugStatusService.ACTION_STATUS_CHANGED));
}

From source file:eu.power_switch.gui.fragment.main.ScenesFragment.java

@Override
public void onCreateViewEvent(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_scenes, container, false);

    setHasOptionsMenu(true);/*  ww w.  ja v  a 2s. co m*/

    recyclerViewScenes = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    sceneRecyclerViewAdapter = new SceneRecyclerViewAdapter(this, getActivity(), scenes);
    recyclerViewScenes.setAdapter(sceneRecyclerViewAdapter);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(),
            StaggeredGridLayoutManager.VERTICAL);
    recyclerViewScenes.setLayoutManager(layoutManager);

    final RecyclerViewFragment recyclerViewFragment = this;
    sceneRecyclerViewAdapter.setOnItemLongClickListener(new SceneRecyclerViewAdapter.OnItemLongClickListener() {
        @Override
        public void onItemLongClick(View itemView, int position) {
            final Scene scene = scenes.get(position);

            ConfigureSceneDialog configureSceneDialog = ConfigureSceneDialog.newInstance(scene.getId());
            configureSceneDialog.setTargetFragment(recyclerViewFragment, 0);
            configureSceneDialog.show(getFragmentManager(), null);
        }
    });

    fab = (FloatingActionButton) rootView.findViewById(R.id.add_fab);
    fab.setImageDrawable(IconicsHelper.getAddIcon(getActivity(),
            ContextCompat.getColor(getActivity(), android.R.color.white)));
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                if (SettingsConstants.INVALID_APARTMENT_ID == SmartphonePreferencesHandler
                        .getCurrentApartmentId()) {
                    new AlertDialog.Builder(getContext())
                            .setMessage(R.string.please_create_or_activate_apartment_first)
                            .setNeutralButton(android.R.string.ok, null).show();
                    return;
                }
            } catch (Exception e) {
                StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e);
                return;
            }

            ConfigureSceneDialog configureSceneDialog = new ConfigureSceneDialog();
            configureSceneDialog.setTargetFragment(recyclerViewFragment, 0);
            configureSceneDialog.show(getFragmentManager(), null);
        }
    });

    // BroadcastReceiver to get notifications from background service if room data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("ScenesFragment", "received intent: " + intent.getAction());
            updateUI();
        }
    };
}

From source file:com.tomi.ginatask.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.tomi.ginatask.R.layout.activity_main);

    // 0. The initial step: register your license. This must be done before using MapView!
    // You can get your free/commercial license from: http://developer.nutiteq.com
    // The license string used here is intended only for Nutiteq demos and WILL NOT WORK with other apps!
    MapView.registerLicense(LICENSE_KEY, getApplicationContext());

    // 1. Basic map setup
    // Create map view 
    mapView = (EditableMapView) this.findViewById(com.tomi.ginatask.R.id.map_view);

    // Set the base projection, that will be used for most MapView, MapEventListener and Options methods
    proj = new EPSG3857();
    mapView.getOptions().setBaseProjection(proj); // note: EPSG3857 is the default, so this is actually not required

    // General options
    mapView.getOptions().setRotatable(true); // make map rotatable (this is also the default)
    mapView.getOptions().setTileThreadPoolSize(2); // use 2 download threads for tile downloading

    mapView.getOptions().setTileDrawSize(128);
    // Set initial location and other parameters, don't animate
    mapView.setFocusPos(proj.fromWgs84(new MapPos(16.9, 49.2)), 0); // Berlin
    mapView.setZoom(13, 0); // zoom 2, duration 0 seconds (no animation)
    mapView.setMapRotation(0, 0);//from  w  w  w  .j  ava2  s. c  om
    mapView.setTilt(90, 0);

    // following goes normally to onCreate() of your Activity with map
    Layers retainObject = (Layers) getLastNonConfigurationInstance();
    if (retainObject != null) {
        // just restore configuration, skip other initializations
        for (int i = 0; i < retainObject.count(); i++) {
            mapView.getLayers().add(retainObject.get(i));
            retainObject.get(i).refresh();

        }
    } else {
        // Create base layer. Use vector style from assets (osmbright.zip)
        TileDataSource source = new HTTPTileDataSource(0, 20,
                "http://a.tile.openstreetmap.org/{zoom}/{x}/{y}.png");
        RasterTileLayer baseLayer = new RasterTileLayer(source);
        mapView.getLayers().add(baseLayer);
    }

    cameraButton = (Button) findViewById(com.tomi.ginatask.R.id.cameraButton);
    qrButton = (Button) findViewById(com.tomi.ginatask.R.id.qrButton);
    deviceInfoButton = (Button) findViewById(com.tomi.ginatask.R.id.deviceInfoButton);
    drawButton = (ToggleButton) findViewById(com.tomi.ginatask.R.id.drawButton);

    cameraButton.setOnClickListener(cameraButtonListener);
    qrButton.setOnClickListener(qrButtonListener);
    deviceInfoButton.setOnClickListener(deviceInfoButtonListener);

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822");
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.putExtra(Intent.EXTRA_EMAIL, new String[] { "tomisky008@gmail.com" });
            i.putExtra(Intent.EXTRA_SUBJECT, "new token");
            i.putExtra(Intent.EXTRA_TEXT, sharedPreferences.getString(QuickstartPreferences.TOKEN, ""));
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ignored) {
            }
        }
    };

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}

From source file:com.ibm.pickmeup.activities.MapActivity.java

/**
 * Create and register coordinatesChangedBroadcastReceiver
 *//*w  ww . j  av a2  s.  c  o m*/
private void registerReceivers() {
    Log.d(TAG, ".registerReceivers() entered");
    if (coordinatesChangedBroadcastReceiver == null) {
        Log.d(TAG, ".registerReceivers() - Registering coordinatesChangedBroadcastReceiver");
        coordinatesChangedBroadcastReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                // update map with new coordinates
                updateMap(intent);
            }
        };
    }

    // registering coordinatesChangedBroadcastReceiver
    getApplicationContext().registerReceiver(coordinatesChangedBroadcastReceiver,
            new IntentFilter(Constants.ACTION_INTENT_COORDINATES_CHANGED));
}