List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.google.android.gcm.demo.ui.GroupActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); setContentView(R.layout.activity_group); if (getSupportActionBar() != null) { getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }/*www .jav a 2 s .c om*/ mLogger = new LoggingService.Logger(this); mDeviceGroupsHelper = new DeviceGroupsHelper(this); mSenders = SenderCollection.getInstance(this); if (savedState != null) { if (savedState.containsKey(STATE_NEW_MEMBERS)) { newMembers = savedState.getBundle(STATE_NEW_MEMBERS); } if (savedState.containsKey(STATE_REMOVED_MEMBERS)) { removedMembers = savedState.getBundle(STATE_REMOVED_MEMBERS); } sender.senderId = savedState.getString(STATE_SELECTED_SENDER_ID); senderApiKey = savedState.getString(STATE_SELECTED_SENDER_ID); group.notificationKeyName = savedState.getString(STATE_SELECTED_SENDER_ID); } newMembersView = findViewById(R.id.group_new_members); noNewMembersView = findViewById(R.id.group_no_new_members); removedMembersView = findViewById(R.id.group_removed_members); currentMembersView = findViewById(R.id.group_current_members); senderIdTexView = (TextView) findViewById(R.id.group_sender_id); chooseSenderIdTexView = (TextView) findViewById(R.id.group_choose_sender_id); chooseApiKeyTextView = (TextView) findViewById(R.id.group_api_key); newNameEditText = (EditText) findViewById(R.id.group_new_name); newMembersList = (LinearLayout) findViewById(R.id.group_new_members_list); removedMembersList = (LinearLayout) findViewById(R.id.group_removed_members_list); currentMembersList = (LinearLayout) findViewById(R.id.group_current_members_list); Button submit = (Button) findViewById(R.id.group_submit); if (getIntent().hasExtra(EXTRA_GROUP_NAME)) { // Caller provided a group name, entering EDIT mode. editMode = true; getSupportActionBar().setTitle(R.string.group_activity_title_edit_group); String senderId = getIntent().getStringExtra(EXTRA_SENDER_ID); String groupName = getIntent().getStringExtra(EXTRA_GROUP_NAME); sender = mSenders.getSender(senderId); group = sender.groups.get(groupName); senderIdTexView.setVisibility(View.VISIBLE); senderIdTexView.setText(sender.senderId); chooseSenderIdTexView.setVisibility(View.GONE); TextView nameTextView = (TextView) findViewById(R.id.group_name); TextView keyTextView = (TextView) findViewById(R.id.group_key); nameTextView.setText(group.notificationKeyName); keyTextView.setText(AbstractFragment.truncateToMediumString(group.notificationKey)); submit.setText(R.string.group_submit_edit_group); newNameEditText.setVisibility(View.GONE); } else { // Caller did not provide a group name, entering NEW-GROUP mode. editMode = false; getSupportActionBar().setTitle(R.string.group_activity_title_new_group); findViewById(R.id.group_key_view).setVisibility(View.GONE); senderIdTexView.setVisibility(View.GONE); chooseSenderIdTexView.setOnClickListener(this); submit.setText(R.string.group_submit_new_group); } submit.setOnClickListener(this); findViewById(R.id.group_new_member).setOnClickListener(this); refresh(); // Piggyback on the "NEW_LOG" event to refresh the activity UI. mLoggerCallback = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { refresh(); } }; }
From source file:com.example.linhdq.test.main_menu.language.OCRLanguageActivity.java
private void registerDownloadReceiver() { mDownloadReceiver = new BroadcastReceiver() { @Override/*w w w .j a v a2s. co m*/ public void onReceive(Context context, Intent intent) { String lang = intent.getStringExtra(OCRLanguageInstallService.EXTRA_OCR_LANGUAGE); int status = intent.getIntExtra(OCRLanguageInstallService.EXTRA_STATUS, -1); updateLanguageList(lang, status); } }; mFailedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String lang = intent.getStringExtra(OCRLanguageInstallService.EXTRA_OCR_LANGUAGE_DISPLAY); int status = intent.getIntExtra(OCRLanguageInstallService.EXTRA_STATUS, -1); updateLanguageListByDisplayValue(lang, status); } }; registerReceiver(mFailedReceiver, new IntentFilter(OCRLanguageInstallService.ACTION_INSTALL_FAILED)); registerReceiver(mDownloadReceiver, new IntentFilter(OCRLanguageInstallService.ACTION_INSTALL_COMPLETED)); mReceiverRegistered = true; }
From source file:bolts.AppLinkTest.java
public void testAppLinkNavInEventBroadcast() throws Exception { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); Bundle appLinkData = new Bundle(); appLinkData.putString("target_url", "http://www.example2.com"); Bundle appLinkRefererData = new Bundle(); appLinkRefererData.putString("url", "referer://"); appLinkRefererData.putString("app_name", "Referrer App"); appLinkRefererData.putString("package", "com.bolts.referrer"); appLinkData.putBundle("referer_app_link", appLinkRefererData); Bundle applinkExtras = new Bundle(); applinkExtras.putString("token", "a_token"); appLinkData.putBundle("extras", applinkExtras); i.putExtra("al_applink_data", appLinkData); final CountDownLatch lock = new CountDownLatch(1); final String[] receivedStrings = new String[7]; LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext()); manager.registerReceiver(new BroadcastReceiver() { @Override//ww w. j ava 2 s .com public void onReceive(Context context, Intent intent) { String eventName = intent.getStringExtra("event_name"); Bundle eventArgs = intent.getBundleExtra("event_args"); receivedStrings[0] = eventName; receivedStrings[1] = eventArgs.getString("targetURL"); receivedStrings[2] = eventArgs.getString("inputURL"); receivedStrings[3] = eventArgs.getString("refererURL"); receivedStrings[4] = eventArgs.getString("refererAppName"); receivedStrings[5] = eventArgs.getString("extras/token"); receivedStrings[6] = eventArgs.getString("sourceApplication"); lock.countDown(); } }, new IntentFilter("com.parse.bolts.measurement_event")); Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(getInstrumentation().getTargetContext(), i); lock.await(2000, TimeUnit.MILLISECONDS); assertEquals("al_nav_in", receivedStrings[0]); assertEquals("http://www.example2.com", receivedStrings[1]); assertEquals("http://www.example.com", receivedStrings[2]); assertEquals("referer://", receivedStrings[3]); assertEquals("Referrer App", receivedStrings[4]); assertEquals("a_token", receivedStrings[5]); assertEquals("com.bolts.referrer", receivedStrings[6]); }
From source file:eu.power_switch.gui.fragment.geofences.ApartmentGeofencesFragment.java
@Override public void onCreateViewEvent(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_apartment_geofences, container, false); setHasOptionsMenu(true);/* w w w .j a va2 s . co m*/ geofenceApiHandler = new GeofenceApiHandler(getActivity()); recyclerViewGeofences = (RecyclerView) rootView.findViewById(R.id.recyclerView); geofenceRecyclerViewAdapter = new GeofenceRecyclerViewAdapter(getActivity(), geofences, geofenceApiHandler); recyclerViewGeofences.setAdapter(geofenceRecyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); recyclerViewGeofences.setLayoutManager(layoutManager); final RecyclerViewFragment recyclerViewFragment = this; geofenceRecyclerViewAdapter .setOnItemLongClickListener(new GeofenceRecyclerViewAdapter.OnItemLongClickListener() { @Override public void onItemLongClick(View itemView, int position) { final Geofence geofence = geofences.get(position); ConfigureApartmentGeofenceDialog configureApartmentGeofenceDialog = ConfigureApartmentGeofenceDialog .newInstance(geofenceIdApartmentMap.get(geofence.getId()).getId()); configureApartmentGeofenceDialog.setTargetFragment(recyclerViewFragment, 0); configureApartmentGeofenceDialog.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) { if (!PermissionHelper.isLocationPermissionAvailable(getContext())) { new AlertDialog.Builder(getContext()).setTitle(R.string.missing_permission) .setMessage(R.string.missing_location_permission).setNeutralButton(R.string.close, null) .show(); return; } try { int apartmentsCount = DatabaseHandler.getAllApartments().size(); if (apartmentsCount == 0) { new AlertDialog.Builder(getContext()) .setMessage(R.string.please_create_or_activate_apartment_first) .setNeutralButton(android.R.string.ok, null).show(); return; } else if (DatabaseHandler.getAllApartments().size() == geofences.size()) { new AlertDialog.Builder(getContext()).setMessage(R.string.all_apartments_have_geofence) .setNeutralButton(android.R.string.ok, null).show(); return; } } catch (Exception e) { StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e); return; } SelectApartmentForGeofenceDialog selectApartmentForGeofenceDialog = new SelectApartmentForGeofenceDialog(); selectApartmentForGeofenceDialog.setTargetFragment(recyclerViewFragment, 0); selectApartmentForGeofenceDialog.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(this, "received intent: " + intent.getAction()); switch (intent.getAction()) { case LocalBroadcastConstants.INTENT_APARTMENT_GEOFENCE_CHANGED: refreshGeofences(); break; case LocalBroadcastConstants.INTENT_PERMISSION_CHANGED: int permissionRequestCode = intent.getIntExtra(PermissionConstants.KEY_REQUEST_CODE, 0); int[] result = intent.getIntArrayExtra(PermissionConstants.KEY_RESULTS); if (permissionRequestCode == PermissionConstants.REQUEST_CODE_LOCATION_PERMISSION) { if (result[0] == PackageManager.PERMISSION_GRANTED) { StatusMessageHandler.showInfoMessage(getRecyclerView(), R.string.permission_granted, Snackbar.LENGTH_SHORT); sendApartmentGeofencesChangedBroadcast(context); } else { StatusMessageHandler.showPermissionMissingMessage(getActivity(), getRecyclerView(), Manifest.permission.ACCESS_FINE_LOCATION); } } break; } } }; }
From source file:com.ekumen.tangobot.application.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); // Load raw resources for (Pair<Integer, String> ip : mResourcesToLoad) { mOpenedResources.add(new ParameterLoaderNode.Resource( getResources().openRawResource(ip.first.intValue()), ip.second)); }//from ww w. j a va 2 s . com mSharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); // UI initializeUI(); // USB handling code mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE); mUsbPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); mUsbAttachedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mLog.info("Received USB Intent"); if (intent.getAction() == ACTION_USB_PERMISSION && intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { onDeviceReady((UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)); } } }; mUsbDetachedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mLog.info("Received USB disconnection Intent"); UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); onDeviceDetached(device); } }; }
From source file:com.todotxt.todotxttouch.TodoTxtTouch.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); currentActivityPointer = this; setContentView(R.layout.main);// ww w. j a va 2s .c o m m_app = (TodoApplication) getApplication(); m_app.m_prefs.registerOnSharedPreferenceChangeListener(this); this.taskBag = m_app.getTaskBag(); m_adapter = new TaskAdapter(this, R.layout.list_item, taskBag.getTasks(), getLayoutInflater()); // listen to the ACTION_LOGOUT intent, if heard display LoginScreen // and finish() current activity IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constants.INTENT_ACTION_ARCHIVE); intentFilter.addAction(Constants.INTENT_SYNC_CONFLICT); intentFilter.addAction(Constants.INTENT_ACTION_LOGOUT); intentFilter.addAction(Constants.INTENT_UPDATE_UI); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); m_broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equalsIgnoreCase(Constants.INTENT_ACTION_ARCHIVE)) { // archive // refresh screen to remove completed tasks // push to remote //archiveTasks(); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_ACTION_LOGOUT)) { taskBag.clear(); m_app.broadcastWidgetUpdate(); // Intent i = new Intent(context, LoginScreen.class); // startActivity(i); // finish(); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_UPDATE_UI)) { updateSyncUI(intent.getBooleanExtra("redrawList", false)); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_SYNC_CONFLICT)) { handleSyncConflict(); } else if (intent.getAction().equalsIgnoreCase(ConnectivityManager.CONNECTIVITY_ACTION)) { handleConnectivityChange(context); } // Taskbag might have changed, update drawer adapter // to reflect new/removed contexts and projects updateNavigationDrawer(); } }; registerReceiver(m_broadcastReceiver, intentFilter); setListAdapter(this.m_adapter); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // Setup Navigation drawer m_drawerList = (ListView) findViewById(R.id.left_drawer); m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Set the adapter for the list view updateNavigationDrawer(); SwipeDismissList.OnDismissCallback callback = new SwipeDismissList.OnDismissCallback() { // Gets called whenever the user deletes an item. public SwipeDismissList.Undoable onDismiss(AbsListView listView, final int position) { m_swipeList.setEnabled(false); final Task task = m_adapter.getItem(position); m_adapter.remove(task); ArrayList<Task> tasks = new ArrayList<Task>(); tasks.add(task); final boolean wasComplete = task.isCompleted(); final String popupTitle = listView.getResources() .getString(wasComplete ? R.string.swipe_action_unComplete : R.string.swipe_action_complete); if (wasComplete) { undoCompleteTasks(tasks, false); } else { completeTasks(tasks, false); } // Return an Undoable implementing every method return new SwipeDismissList.Undoable() { // Method is called when user undoes this deletion public void undo() { // Reinsert item to list ArrayList<Task> tasks = new ArrayList<Task>(); tasks.add(task); if (wasComplete) { completeTasks(tasks, false); } else { undoCompleteTasks(tasks, false); } } @Override public String getTitle() { return popupTitle; } }; } }; m_swipeList = new SwipeDismissList(lv, callback, SwipeDismissList.UndoMode.SINGLE_UNDO); m_swipeList.setPopupYOffset(56); m_swipeList.setAutoHideDelay(250); m_swipeList.setSwipeLayout(R.id.swipe_view); m_pullToRefreshAttacher = PullToRefreshAttacher.get(this); DefaultHeaderTransformer ht = (DefaultHeaderTransformer) m_pullToRefreshAttacher.getHeaderTransformer(); ht.setPullText(getString(R.string.pull_to_refresh)); ht.setRefreshingText(getString(R.string.syncing)); m_pullToRefreshAttacher.addRefreshableView(lv, this); // Delegate OnTouch calls to both libraries that want to receive them // Don't forward swipes when swiping on the left lv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { // Don't listen to gestures on the left area of the list // to prevent interference with the DrawerLayout ViewConfiguration vc = ViewConfiguration.get(view.getContext()); int deadZoneX = vc.getScaledTouchSlop(); if (motionEvent.getX() < deadZoneX) { return false; } m_pullToRefreshAttacher.onTouch(view, motionEvent); // Only listen to item swipes if we are not scrolling the // listview if (!mListScrolling && m_swipeList.onTouch(view, motionEvent)) { return false; } return false; } }); // We must set the scrollListener after the onTouchListener, // otherwise it will not fire lv.setOnScrollListener(this); initializeTasks(false); // Show search results Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { m_app.m_search = intent.getStringExtra(SearchManager.QUERY); Log.v(TAG, "Searched for " + m_app.m_search); m_app.storeFilters(); setFilteredTasks(false); } }
From source file:com.kasungunathilaka.sarigama.ui.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); myReceiver = new MusicIntentReceiver(); flMiniPlayer = (FrameLayout) findViewById(R.id.flMiniPlayer); flPlay = (FrameLayout) findViewById(R.id.flPlay); flMiniPb = (FrameLayout) findViewById(R.id.flMiniPb); cvMiniPlayer = (CardView) findViewById(R.id.cvMiniPlayer); tvSongTitle = (TextView) findViewById(R.id.tvSongTitle); tvSongArtist = (TextView) findViewById(R.id.tvSongArtist); ibPlay = (CircleImageView) findViewById(R.id.ibPlay); ivNext = (ImageButton) findViewById(R.id.ivNext); playerQueue = PlayerQueue.getInstance(HomeActivity.this); setFragment(new MainFragment()); if (playerService != null && playerService.isPlaying()) { int position = playerQueue.getCurrentPosition(); Song currentSong = playerQueue.getSongByPosition(position); setupMiniPlayer(currentSong.getSongTitle(), currentSong.getSongArtist()); showMiniPlayer(true);//from ww w .j av a 2s . c o m } broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case ON_PLAYER_EXIT: if (playerService.isPlaying()) { ibPlay.setImageResource(R.drawable.ic_pause_white); showMiniPlayer(true); } else { ibPlay.setImageResource(R.drawable.ic_play_white); if (!isCanceled) { showMiniPlayer(true); } else { isCanceled = false; } } break; case ON_PLAYER_ENTER: showMiniPlayer(false); break; case ON_PREPARING: flMiniPb.setVisibility(flMiniPlayer.getVisibility() == View.VISIBLE ? View.VISIBLE : View.GONE); break; case ON_PREPARED: flMiniPb.setVisibility(View.GONE); int position = playerQueue.getCurrentPosition(); Song currentSong = playerQueue.getSongByPosition(position); setupMiniPlayer(currentSong.getSongTitle(), currentSong.getSongArtist()); ibPlay.setImageResource(R.drawable.ic_pause_white); break; case ON_COMPLETED: ibPlay.setImageResource(R.drawable.ic_play_white); break; } } }; cvMiniPlayer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { Bundle bundle = new Bundle(); bundle.putString(HomeActivity.PLAYER_FRAGMENT_LAUNCH_MODE, HomeActivity.PLAYER_FRAGMENT_LAUNCH_MODE_MINI_PLAYER); PlayerFragment playerFragment = new PlayerFragment(); playerFragment.setData(bundle); setFragment(playerFragment); } return true; } }); ivNext.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { playerService.next(); } return true; } }); flPlay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (playerService.isPlaying()) { ibPlay.setImageResource(R.drawable.ic_play_white); playerService.setPlayPause(); } else { ibPlay.setImageResource(R.drawable.ic_pause_white); playerService.setPlayPause(); } } }); }
From source file:eu.power_switch.gui.fragment.alarm_clock.StockAlarmClockFragment.java
@Override public void onCreateViewEvent(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_stock_alarm_clock, container, false); setHasOptionsMenu(true);//from ww w. j av a2s.c om final RecyclerViewFragment recyclerViewFragment = this; Switch switchOnOff = (Switch) rootView.findViewById(R.id.switch_on_off); switchOnOff.setChecked(SmartphonePreferencesHandler.getStockAlarmClockEnabled()); switchOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.isPressed()) { SmartphonePreferencesHandler.setStockAlarmClockEnabled(isChecked); } } }); spinnerEventType = (Spinner) rootView.findViewById(R.id.spinner_sleep_as_android_event); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.stock_alarm_clock_event_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerEventType.setAdapter(adapter); SpinnerInteractionListener spinnerInteractionListener = new SpinnerInteractionListener() { @Override public void onItemSelectedByUser(AdapterView<?> parent, View view, int pos, long id) { updateUI(); } }; spinnerEventType.setOnItemSelectedListener(spinnerInteractionListener); spinnerEventType.setOnTouchListener(spinnerInteractionListener); recyclerViewActions = (RecyclerView) rootView.findViewById(R.id.recyclerView); recyclerViewAdapter = new ActionRecyclerViewAdapter(getContext(), actions); recyclerViewAdapter.setOnDeleteClickListener(new ActionRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, final int position) { new AlertDialog.Builder(getContext()).setTitle(R.string.delete).setMessage(R.string.are_you_sure) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { actions.remove(position); DatabaseHandler.setAlarmActions( Event.getById(spinnerEventType.getSelectedItemPosition()), actions); StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(), R.string.action_removed, Snackbar.LENGTH_LONG); } catch (Exception e) { StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e); } recyclerViewAdapter.notifyDataSetChanged(); } }).setNeutralButton(android.R.string.cancel, null).show(); } }); recyclerViewActions.setAdapter(recyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); recyclerViewActions.setLayoutManager(layoutManager); addActionFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab); addActionFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); addActionFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddStockAlarmClockEventActionDialog addAlarmEventActionDialog = AddStockAlarmClockEventActionDialog .newInstance(spinnerEventType.getSelectedItemPosition()); addAlarmEventActionDialog.setTargetFragment(recyclerViewFragment, 0); addAlarmEventActionDialog.show(getActivity().getSupportFragmentManager(), 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(this, "received intent: " + intent.getAction()); if (LocalBroadcastConstants.INTENT_ALARM_EVENT_ACTION_ADDED.equals(intent.getAction())) { updateUI(); } else { updateUI(); } } }; }
From source file:com.paranoid.gerrit.GerritControllerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { mTheme = Prefs.getCurrentThemeID(this); setTheme(mTheme);//from w w w .j ava2s . co m super.onCreate(savedInstanceState); // check if caller has a gerrit instance start screen preference String suppliedGerritInstance = getIntent().getStringExtra(GERRIT_INSTANCE); if (suppliedGerritInstance != null && !suppliedGerritInstance.isEmpty() && suppliedGerritInstance.contains("http")) { // just set the prefs and allow normal loading Prefs.setCurrentGerrit(this, suppliedGerritInstance); } GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(this); String trackingId = getString(R.string.ga_trackingId); Tracker tracker = googleAnalytics.getTracker(trackingId); googleAnalytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE); tracker.send(MapBuilder.createAppView().build()); // keep a log of what ROM our users run EasyTracker easyTracker = EasyTracker.getInstance(this); easyTracker.send(MapBuilder.createEvent(AnalyticsConstants.GA_APP_OPEN, // Event category (required) AnalyticsConstants.GA_ROM_VERSION, // Event action (required) ROMHelper.determineRom(this), // Event label null) // Event value (long) .build()); // note this screen as viewed easyTracker.send(MapBuilder.createAppView().build()); // Keep track of what theme is being used easyTracker.send(MapBuilder.createEvent(AnalyticsConstants.GA_APP_OPEN, AnalyticsConstants.GA_THEME_SET_ON_OPEN, Prefs.getCurrentTheme(this), null).build()); // note this screen as viewed easyTracker.send(MapBuilder.createAppView().build()); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.main); FragmentManager fm = getSupportFragmentManager(); if (findViewById(R.id.change_detail_fragment) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mTwoPane = true; mChangeDetail = (PatchSetViewerFragment) fm.findFragmentById(R.id.change_detail_fragment); } Prefs.setTabletMode(this, mTwoPane); mChangeList = (ChangeListFragment) fm.findFragmentById(R.id.change_list_fragment); mGerritWebsite = Prefs.getCurrentGerrit(this); /* Initially set the current Gerrit globally here. * We can rely on callbacks to know when they change */ GerritURL.setGerrit(Prefs.getCurrentGerrit(this)); GerritURL.setProject(Prefs.getCurrentProject(this)); // Don't register listeners here. It is registered in onResume instead. mChangeListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String changeid = intent.getStringExtra(PatchSetViewerFragment.CHANGE_ID); String status = intent.getStringExtra(PatchSetViewerFragment.STATUS); boolean expand = intent.getBooleanExtra(PatchSetViewerFragment.EXPAND_TAG, false); onChangeSelected(changeid, status, expand); } }; handleIntent(this.getIntent()); }
From source file:com.iride.ayride.HomePageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_homepage); try {//from w w w . jav a 2 s .com this.markers = new HashMap<>(); this.markersIdKeyPair = new HashMap<>(); this.ridesList = new ArrayList<>(); this.hashTags = new ArrayList<>(); Toolbar toolbar = (Toolbar) findViewById(R.id.homepage_toolbar); setSupportActionBar(toolbar); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); if (!isGPSEnable()) { buildAlertMessageNoGps(); } this.buildGoogleApiClient(); this.initializeMobileService(); this.initializeLocalStores(); if (isNullOrWhiteSpace(rideLocalStorage.getOwnInstanceId())) { this.storeRegistrationInstanceId(); } this.initializeLayoutEntities(); registrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(StoragePreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { Log.d(loggerTag, getString(R.string.gcmSendMessage)); } else { Log.d(loggerTag, getString(R.string.tokenErrorMessage)); } } }; // Registering BroadcastReceiver registerReceiver(); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } this.initializeFirebaseEntities(); this.getAllRides(); } catch (Exception exc) { Log.e(loggerTag, "THIS MSG: " + exc.getMessage()); Log.e(loggerTag, "THIS CAUSE:" + String.valueOf(exc.getCause())); } }