List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:alaindc.memenguage.View.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkLoggedIn();//from w ww.j a v a 2s . co m setContentView(R.layout.activity_main); dbmanager = new DBManager(getApplicationContext()); crs = dbmanager.getAllWords(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); if (fab != null) fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent createWordIntentActivity = new Intent(MainActivity.this, CreateEditActivity.class); createWordIntentActivity.setAction(Constants.ACTION_ADD_WORD); MainActivity.this.startActivity(createWordIntentActivity); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); if (drawer != null) drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); if (navigationView != null) navigationView.setNavigationItemSelectedListener(this); ImageView navlogo = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.navLogoImageView); TextView navtitle = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navTitle); TextView navsubtitle = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navSubTitle); progressDialog = new ProgressDialog(this); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Constants.INTENT_VIEW_UPDATE)) { adapter.getFilter().filter(""); adapter.notifyDataSetChanged(); } else if (intent.getAction().equals(Constants.INTENT_COMMSERV_UPDATE)) { boolean success = intent.getBooleanExtra(Constants.EXTRA_COMMSERV_SUCCESS, false); String message = (intent.getIntExtra(Constants.EXTRA_COMMSERV_TYPE, 0) == Constants.UPLOAD) ? "Databased uploaded " : "Databased downloaded "; message = (success) ? message + "successfully!" : "An error occurred, try again."; progressDialog.setMessage(message); new Handler().postDelayed(new Runnable() { @Override public void run() { progressDialog.dismiss(); } }, 1500); } else { Log.d("", ""); } } }; IntentFilter updateviewIntFilt = new IntentFilter(Constants.INTENT_VIEW_UPDATE); IntentFilter serverCommIntFilt = new IntentFilter(Constants.INTENT_COMMSERV_UPDATE); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateviewIntFilt); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, serverCommIntFilt); SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); personName = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_NAME, ""); personEmail = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_EMAIL, ""); personId = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_ID, ""); personPhoto = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_PHOTOURI, ""); // if (!personPhoto.equals("")) // new AsyncImageTask(navlogo).execute(personPhoto); navtitle.setText(personName); navsubtitle.setText(personEmail); // TODO Just one time and in bcast receiver start phone Intent randomStart = new Intent(MainActivity.this, RandomIntentService.class); randomStart.setAction(Constants.ACTION_RANDOM_START); getApplicationContext().startService(randomStart); updateWordsList(); }
From source file:com.ayaseya.nolnotification.GcmIntentService.java
@Override public void onCreate() { super.onCreate(); ringerMode = false;//from ww w . ja v a 2 s . c om silentMode = false; vibrateMode = false; isPlugged = false; sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true); checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false); Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null); ArrayList<String> timeZone = new ArrayList<String>(); if (multiValues != null) { timeZone.addAll(multiValues); Collections.sort(timeZone); for (int i = 0; i < timeZone.size(); i++) { // Log.v(TAG, "TimeZone=" + timeZone.get(i)); } Calendar calendar = Calendar.getInstance(); int hour = calendar.get(Calendar.HOUR_OF_DAY); if (timeZone.indexOf(String.valueOf(hour)) == -1) { notificationPermission = false; // Log.v(TAG, "?????????"); } else { notificationPermission = true; // Log.v(TAG, "??????"); } } vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); ringerModeStateChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // ? if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) { // ringerMode = true; } else { ringerMode = false; } if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_VIBRATE) { // vibrateMode = true; } else { vibrateMode = false; } if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) { // silentMode = true; } else { silentMode = false; } } } }; plugStateChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // ? if (intent.getIntExtra("state", 0) > 0) { isPlugged = true; // Log.v(TAG, "IN"); } else { isPlugged = false; // Log.v(TAG, "OUT"); } } }; // Broadcast Receiver??? registerReceiver(plugStateChangeReceiver, plugIntentFilter); registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter); }
From source file:io.imoji.sdk.grid.components.BaseSearchWidget.java
public BaseSearchWidget(Context context, final int spanCount, int orientation, boolean autoSearchEnabled, @ResultView.ResultViewSize int resultViewSize, WidgetDisplayOptions options, SearchResultAdapter.ImageLoader imageLoader) { super(context); inflate(getContext(), R.layout.imoji_base_widget, this); this.context = context; this.options = options; this.searchHandler = new SearchHandler(autoSearchEnabled) { @Override/* w w w . j a va 2s. co m*/ public void onSearchCompleted(List<SearchResult> newResults, int dividerPosition, boolean isRecents) { repopulateAdapter(newResults, dividerPosition, isRecents); } @Override public void beforeSearchStarted() { switcher.setDisplayedChild(0); } @Override public void onHistoryChanged() { updateText(); } }; switcher = (ViewSwitcher) this.findViewById(R.id.widget_switcher); recyclerView = (RecyclerView) this.findViewById(R.id.widget_recycler); searchBarLayout = (SearchBarLayout) this.findViewById(R.id.widget_search); searchBarLayout.setImojiSearchListener(this); searchBarLayout.setActionButtonsVisibility(options.isIncludeRecentsAndCreate()); resultAdapter = new SearchResultAdapter(context, imageLoader, resultViewSize, orientation, options); resultAdapter.setSearchTapListener(this); gridLayoutManager = new GridLayoutManager(context, spanCount, orientation, false); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch (resultAdapter.getItemViewType(position)) { case SearchResultAdapter.DIVIDER_VIEW_TYPE: return spanCount; default: return 1; } } }); recyclerView.setLayoutManager(gridLayoutManager); recyclerView.setHasFixedSize(true); recyclerView.setItemAnimator(null); recyclerView.setAdapter(resultAdapter); searchHandler.searchTrending(context); imojiCreatedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { searchHandler.searchRecents(context); searchBarLayout.showRecentsView(); LocalBroadcastManager.getInstance(context).unregisterReceiver(this); } }; }
From source file:io.github.tjg1.nori.APISettingsActivity.java
@Override public void editService(final long rowId, final String name, final String url, final String username, final String passphrase) { // Show progress dialog during the service type detection process. final ProgressDialog dialog = new ProgressDialog(this); dialog.setIndeterminate(true);/*from w w w . j av a 2 s.c om*/ dialog.setCancelable(false); dialog.setMessage(getString(R.string.dialog_message_detectingApiType)); dialog.show(); // Register broadcast receiver to get results from the background service type detection service. registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Get result code from received intent. int resultCode = intent.getIntExtra(ServiceTypeDetectionService.RESULT_CODE, -1); if (resultCode == ServiceTypeDetectionService.RESULT_OK) { // Add a new service to the database on a background thread. // This is so database I/O doesn't block the UI thread. SearchClient.Settings.APIType apiType = SearchClient.Settings.APIType.values()[intent .getIntExtra(ServiceTypeDetectionService.API_TYPE, 0)]; final SearchClient.Settings settings = new SearchClient.Settings(apiType, name, url, username, passphrase); new Thread(new Runnable() { @Override public void run() { APISettingsDatabase database = new APISettingsDatabase(APISettingsActivity.this); if (rowId == ROW_ID_INSERT) { database.insert(settings); } else { database.update(rowId, settings); } database.close(); } }).start(); } else if (resultCode == ServiceTypeDetectionService.RESULT_FAIL_INVALID_URL) { Toast.makeText(APISettingsActivity.this, R.string.toast_error_serviceUriInvalid, Toast.LENGTH_LONG).show(); } else if (resultCode == ServiceTypeDetectionService.RESULT_FAIL_NETWORK) { Toast.makeText(APISettingsActivity.this, R.string.toast_error_noNetwork, Toast.LENGTH_LONG) .show(); } else if (resultCode == ServiceTypeDetectionService.RESULT_FAIL_NO_API) { Toast.makeText(APISettingsActivity.this, R.string.toast_error_noServiceAtGivenUri, Toast.LENGTH_LONG).show(); } // Unregister the broadcast receiver. unregisterReceiver(this); // Dismiss progress dialog. dialog.dismiss(); } }, new IntentFilter(ServiceTypeDetectionService.ACTION_DONE)); // Start the background service type detection service. Intent serviceIntent = new Intent(this, ServiceTypeDetectionService.class); serviceIntent.putExtra(ServiceTypeDetectionService.ENDPOINT_URL, url); startService(serviceIntent); }
From source file:fr.gotorennes.AbstractMapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayout());//from www . j a v a 2s .c om mapView = (MapView) findViewById(R.id.mapView); mapController = mapView.getController(); myLocationOverlay = new MyLocationOverlay(this, mapView); // Add ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomControl); zoomControls.setOnZoomInClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mapController.zoomIn(); onMapChange(); } }); zoomControls.setOnZoomOutClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { mapController.zoomOut(); onMapChange(); } }); addMyLocationOverlay(); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { finish(); } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(AbstractActivity.ACTION_LOGOUT); registerReceiver(receiver, intentFilter); BackgroundTask<Boolean> backgroundInit = new BackgroundTask<Boolean>() { @Override protected Boolean execute() { try { goToRennes = GoToRennes.getInstance(AbstractMapActivity.this, null); } catch (Exception ex) { return false; } return true; } @Override protected void callback(Boolean result) { if (result == null || !result) { showError(getString(R.string.erreurInitialisation), true); } else { init(); goToRennes.track(getTrackingName()); } } }; backgroundInit.start(this); }
From source file:com.gsma.rcs.provisioning.local.Provisioning.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mActivity = this; setContentView(R.layout.provisioning); LocalContentResolver localContentResolver = new LocalContentResolver(getApplicationContext()); mRcsSettings = RcsSettings.getInstance(localContentResolver); AndroidFactory.setApplicationContext(this, mRcsSettings); ViewPager pager = (ViewPager) findViewById(R.id.viewpager); SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs); mAdapter = new ViewPagerAdapter(getSupportFragmentManager(), titles, mRcsSettings); pager.setAdapter(mAdapter);//from w w w . j a v a2 s .c o m slidingTabLayout.setViewPager(pager); slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { @Override public int getIndicatorColor(int position) { return Color.WHITE; } }); IntentFilter filter = new IntentFilter(RcsService.ACTION_SERVICE_UP); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { for (IProvisioningFragment fragment : mAdapter.getFragments()) { fragment.displayRcsSettings(); } } }; registerReceiver(mReceiver, filter); }
From source file:eu.power_switch.gui.fragment.main.RoomSceneTabFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.main_tabs, container, false); // Create the adapter that will return a fragment // for each of the two primary sections of the app. customTabAdapter = new CustomTabAdapter(getChildFragmentManager(), getActivity()); // Set up the tabViewPager, attaching the adapter and setting up a listener // for when the user swipes between sections. tabViewPager = (ViewPager) rootView.findViewById(R.id.tabHost); tabViewPager.setAdapter(customTabAdapter); LinearLayout linearLayout_currentApartmentInfo = (LinearLayout) rootView .findViewById(R.id.linearLayout_currentApartmentInfo); linearLayout_currentApartmentInfo.setOnClickListener(new View.OnClickListener() { @Override/* ww w . ja v a 2 s .c o m*/ public void onClick(View v) { SelectApartmentDialog selectApartmentDialog = new SelectApartmentDialog(); selectApartmentDialog.show(getFragmentManager(), null); } }); textView_currentApartmentInfo = (TextView) rootView.findViewById(R.id.textView_currentApartmentInfo); updateCurrentApartmentInfo(); tabViewPager.setOffscreenPageLimit(customTabAdapter.getCount()); tabViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { currentTab = position; if (!skipTutorial) { showTutorial(position); } } @Override public void onPageScrollStateChanged(int state) { } }); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(this, "received intent: " + intent.getAction()); updateCurrentApartmentInfo(); } }; skipTutorial = true; tabLayout = (TabLayout) rootView.findViewById(R.id.tabLayout); tabLayout.setupWithViewPager(tabViewPager); Bundle args = getArguments(); if (args != null && args.containsKey(TAB_INDEX_KEY)) { currentTab = args.getInt(TAB_INDEX_KEY); tabViewPager.setCurrentItem(currentTab); } skipTutorial = false; return rootView; }
From source file:com.lukekorth.ez_loaders.EzLoader.java
@Override protected void onStartLoading() { if (mT != null) { // Deliver any previously loaded data immediately. deliverResult(mT);//w ww . j a v a 2 s. c o m } // Register the BroadcastReceiver that will notify the Loader when changes are // made. if (mBroadcastReceiver == null) { IntentFilter filter = new IntentFilter(); filter.addAction(mBroadcastAction); mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { onContentChanged(); } }; if (mUseLocalBroadcastManager) { LocalBroadcastManager.getInstance(getContext()).registerReceiver(mBroadcastReceiver, filter); } else { getContext().registerReceiver(mBroadcastReceiver, filter); } } if (takeContentChanged()) { // When the observer detects new data, it will call // onContentChanged() on the Loader, which will cause the next call // to takeContentChanged() to return true. If this is ever the case // (or if the current data is null), we force a new load. forceLoad(); } else if (mT == null) { // If the current data is null... then we should make it non-null forceLoad(); } }
From source file:de.lespace.apprtc.ConnectChatActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_connect); // Get setting keys. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); missingPermissions = new ArrayList(); for (String permission : MANDATORY_PERMISSIONS) { if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { missingPermissions.add(permission); }// ww w.ja va 2 s . c o m } requestPermission(); //Bring Call2Front when bringToFrontBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Intent intentStart = new Intent(getApplicationContext(), ConnectChatActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); startActivity(intentStart); // newFragment.show(transaction,"loading"); // showDialog(); } }; registerBringToFrontReceiver(); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } ImageButton connectButton = (ImageButton) findViewById(R.id.connect_button); connectButton.setOnClickListener(connectListener); // If an implicit VIEW intent is launching the app, go directly to that URL. //final Intent intent = getIntent(); Uri wsurl = Uri.parse(Configs.ROOM_URL); //intent.getData(); Log.d(TAG, "connecting to:" + wsurl.toString()); if (wsurl == null) { logAndToast(getString(R.string.missing_wsurl)); Log.e(TAG, "Didn't get any URL in intent!"); setResult(RESULT_CANCELED); finish(); return; } if (from == null || from.length() == 0) { logAndToast(getString(R.string.missing_from)); Log.e(TAG, "Incorrect from in intent!"); setResult(RESULT_CANCELED); finish(); return; } roomConnectionParameters = new AppRTCClient.RoomConnectionParameters(wsurl.toString(), from, false); Log.i(TAG, "creating appRtcClient with roomUri:" + wsurl.toString() + " from:" + from); // Create connection client and connection parameters. appRtcClient = new WebSocketRTCClient(this, new LooperExecutor()); connectToWebsocket(); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. }
From source file:eu.power_switch.gui.fragment.phone.CallEventsFragment.java
@Override public void onCreateViewEvent(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_call_events, container, false); setHasOptionsMenu(true);/*from w w w . j a v a 2 s . co m*/ recyclerViewCalls = (RecyclerView) rootView.findViewById(R.id.recyclerView); callRecyclerViewAdapter = new CallRecyclerViewAdapter(getActivity(), callEvents); recyclerViewCalls.setAdapter(callRecyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); recyclerViewCalls.setLayoutManager(layoutManager); final RecyclerViewFragment recyclerViewFragment = this; 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.isPhonePermissionAvailable(getContext())) { new AlertDialog.Builder(getContext()).setTitle(R.string.missing_permission) .setMessage(R.string.missing_contacts_permission).setNeutralButton(R.string.close, null) .show(); return; } ConfigureCallEventDialog configureCallEventDialog = new ConfigureCallEventDialog(); configureCallEventDialog.setTargetFragment(recyclerViewFragment, 0); configureCallEventDialog.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_CALL_EVENTS_CHANGED: refreshCalls(); 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_PHONE_PERMISSION) { boolean allGranted = true; for (int i = 0; i < result.length; i++) { allGranted &= result[i] == PackageManager.PERMISSION_GRANTED; } if (allGranted) { StatusMessageHandler.showInfoMessage(getRecyclerView(), R.string.permission_granted, Snackbar.LENGTH_SHORT); sendCallEventsChangedBroadcast(context); } else { StatusMessageHandler.showPermissionMissingMessage(getActivity(), getRecyclerView(), Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_CONTACTS); } } break; } } }; }