List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.nadmm.airports.wx.TafFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);/* w w w . j ava 2 s .co m*/ mFilter = new IntentFilter(); mFilter.addAction(mAction); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(mAction)) { String type = intent.getStringExtra(NoaaService.TYPE); if (type.equals(NoaaService.TYPE_TEXT)) { showTaf(intent); } } } }; }
From source file:com.google.android.gcm.demo.ui.TokenActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); setContentView(R.layout.activity_token); if (getSupportActionBar() != null) { getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(R.string.token_activity_title); }/*from ww w. j av a 2 s .co m*/ mLogger = new LoggingService.Logger(this); mInstanceIdHelper = new InstanceIdHelper(this); audienceIdTexView = (TextView) findViewById(R.id.token_audience); scopeTexView = (TextView) findViewById(R.id.token_scope); audienceIdTexView.setOnClickListener(this); findViewById(R.id.token_generate).setOnClickListener(this); ((TextView) findViewById(R.id.editable_map_title)).setText(R.string.token_extra); if (savedState != null) { if (savedState.containsKey(STATE_AUDIENCE)) { String senderId = savedState.getString(STATE_AUDIENCE); Sender sender = SenderCollection.getInstance(this).getSender(senderId); if (sender != null) { AbstractFragment.setValue(audienceIdTexView, sender.name, sender.senderId); } } } // Piggyback on the "NEW_LOG" event to refresh the activity UI. mLoggerCallback = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Quick hack until we introduce a proper manager for async events. String log = intent.getStringExtra(LoggingService.EXTRA_LOG_MESSAGE); if (log != null && log.contains("succeeded")) { NavUtils.navigateUpFromSameTask(TokenActivity.this); } } }; }
From source file:com.mjhram.ttaxi.login_register.LoginActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); phpErrorMsgs = AppSettings.getInstance().getPhpErrorMsg(); inputName = (EditText) findViewById(R.id.name); inputPassword = (EditText) findViewById(R.id.password); btnLogin = (Button) findViewById(R.id.btnLogin); btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen); setButtons(true);/*from w w w . java 2s . co m*/ // Progress dialog pDialog = new ProgressDialog(this); pDialog.setCancelable(false); //get GCM registeration ID: mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(Constants.SENT_TOKEN_TO_SERVER, false); /*if (sentToken) { setButtons(true); } else { setButtons(false); }*/ } }; if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } // Session manager //session = new SessionManager(getApplicationContext()); // Check if user is already logged in or not if (AppSettings.isLoggedIn()) { // User is already logged in. Take him to main activity Intent intent = new Intent(LoginActivity.this, com.mjhram.ttaxi.GpsMainActivity.class); //intent.putExtra(Constants.KEY_UID, AppSettings.getUid()); //intent.putExtra(Constants.KEY_EMAIL, AppSettings.getEmail()); startActivity(intent); finish(); } // Login button Click Event btnLogin.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { String name = inputName.getText().toString(); String password = inputPassword.getText().toString(); //check for regId if (AppSettings.regId == null) { Toast.makeText(getApplicationContext(), getString(R.string.loginMsgNotRegistered), Toast.LENGTH_LONG).show(); finish(); } // Check for empty data in the form if (name.trim().length() > 0 && password.trim().length() > 0) { // login user checkLogin(name, password); } else { // Prompt user to enter credentials Toast.makeText(getApplicationContext(), getString(R.string.loginMsgEnterCredentials), Toast.LENGTH_LONG).show(); } } }); // Link to Register Screen btnLinkToRegister.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(getApplicationContext(), RegisterActivity.class); startActivity(i); finish(); } }); //registerReceiver(registrationStatusReceiver, new IntentFilter(Constants.ACTION_REGISTER)); //get registeration id //gcmUtil = new GcmUtil(getApplicationContext()); //mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); //mRegistrationProgressBar.setVisibility(View.VISIBLE); }
From source file:au.id.micolous.frogjump.LoginActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); lblStatus = (TextView) findViewById(R.id.lblStatus); txtGroupId = (EditText) findViewById(R.id.txtGroupId); sensitize(false);// w w w. ja va 2s .com txtGroupId.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_GO) { onBtnJoinGroupClick(textView); } return false; } }); setupUI(); // Lets see if there was a Web Intent fired to start us up resolveIntent(getIntent()); lblStatus.setText("Connecting to Frogjump API..."); Util.updateCheck(this); lblStatus.setText( "Connecting to Cloud Messaging... If this takes more than a few seconds, rotate your device to try again."); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(ApplicationPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { lblStatus.setText("Acquired token from Cloud Messaging."); // Leave any group we are a member of. Util.sendGcmMessage("part"); sensitize(true); // Check if there is an auto-join for us if (auto_join) { auto_join = false; onBtnJoinGroupClick(txtGroupId); } } else { lblStatus.setText("Could not acquire token from Cloud Messaging. Check network connection."); sensitize(false); } } }; if (isPlayServicesAvailable()) { Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } }
From source file:com.continuesvoicerecognition.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent service = new Intent(getBaseContext(), SpeechRecognizerService.class); getBaseContext().startService(service); mBindFlag = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH ? 0 : Context.BIND_ABOVE_CLIENT; receiver = new BroadcastReceiver() { @Override/*from ww w . ja v a2 s .co m*/ public void onReceive(Context context, Intent intent) { String s = intent.getStringExtra(SpeechRecognizerService.RECOGNIZER_MESSAGE); result_tv.setText(s); } }; setContentView(R.layout.activity_main); findViews(); setClickListeners(); }
From source file:com.nadmm.airports.wx.MetarFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);//from w ww . j a v a2s.c o m mRemarks = new ArrayList<String>(); mFilter = new IntentFilter(); mFilter.addAction(mAction); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (mLocation == null) { // This was probably intended for wx list view return; } String action = intent.getAction(); if (action.equals(mAction)) { String type = intent.getStringExtra(NoaaService.TYPE); if (type.equals(NoaaService.TYPE_TEXT)) { showMetar(intent); } } } }; }
From source file:eu.power_switch.gui.fragment.configure_call.ConfigureCallDialogPage2ActionsFragment.java
@Nullable @Override//w ww . j a va2 s .co m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.dialog_fragment_configure_call_page_2, container, false); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (LocalBroadcastConstants.INTENT_CALL_ACTION_ADDED.equals(intent.getAction())) { // actions.add((Action) intent.getSerializableExtra("action")); sendActionsChangedBroadcast(getContext(), actions); } } }; final Fragment fragment = this; FloatingActionButton addActionFAB = (FloatingActionButton) rootView.findViewById(R.id.add_action); addActionFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); addActionFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddCallActionDialog addCallActionDialog = new AddCallActionDialog(); addCallActionDialog.setTargetFragment(fragment, 0); addCallActionDialog.show(getActivity().getSupportFragmentManager(), null); } }); actionRecyclerViewAdapter = new ActionRecyclerViewAdapter(getActivity(), actions); actionRecyclerViewAdapter.setOnDeleteClickListener(new ActionRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, int position) { actions.remove(position); actionRecyclerViewAdapter.notifyDataSetChanged(); sendActionsChangedBroadcast(getContext(), actions); } }); RecyclerView recyclerViewActions = (RecyclerView) rootView.findViewById(R.id.recyclerview_list_of_actions); recyclerViewActions.setAdapter(actionRecyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL); recyclerViewActions.setLayoutManager(layoutManager); Bundle args = getArguments(); if (args != null && args.containsKey(ConfigureCallEventDialog.CALL_EVENT_ID_KEY)) { callEventId = args.getLong(ConfigureCallEventDialog.CALL_EVENT_ID_KEY); initializeCallData(callEventId); } return rootView; }
From source file:eu.power_switch.gui.dialog.ConfigurationDialogTabbed.java
@Nullable @Override//w ww .jav a 2 s .c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (LocalBroadcastConstants.INTENT_CONFIGURATION_DIALOG_CHANGED.equals(intent.getAction())) { notifyConfigurationChanged(); } } }; rootView = inflater.inflate(R.layout.dialog_configuration_tabbed, container); tabViewPager = (ViewPager) rootView.findViewById(R.id.tabHost); tabViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { updateBottomBarButtons(); } @Override public void onPageScrollStateChanged(int state) { } }); tabViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout = (TabLayout) rootView.findViewById(R.id.tabLayout_configure_dialog); imageButtonDelete = (ImageButton) rootView.findViewById(R.id.imageButton_delete); imageButtonDelete.setImageDrawable(IconicsHelper.getDeleteIcon(getActivity(), ContextCompat.getColor(getActivity(), R.color.delete_color))); imageButtonDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deleteExistingConfigurationFromDatabase(); } }); imageButtonCancel = (ImageButton) rootView.findViewById(R.id.imageButton_cancel); imageButtonCancel.setImageDrawable(IconicsHelper.getCancelIcon(getActivity())); imageButtonCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (modified) { // ask to really close new AlertDialog.Builder(getActivity()).setTitle(R.string.are_you_sure) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getDialog().cancel(); } }).setNeutralButton(android.R.string.no, null) .setMessage(R.string.all_changes_will_be_lost).show(); } else { getDialog().dismiss(); } } }); imageButtonNext = (ImageButton) rootView.findViewById(R.id.imageButton_next); imageButtonNext.setImageDrawable(IconicsHelper.getNextIcon(getActivity())); imageButtonNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { tabViewPager.setCurrentItem(tabViewPager.getCurrentItem() + 1, true); updateBottomBarButtons(); } }); imageButtonSave = (ImageButton) rootView.findViewById(R.id.imageButton_save); imageButtonSave.setImageDrawable(IconicsHelper.getSaveIcon(getActivity())); imageButtonSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!modified) { getDialog().dismiss(); } else { saveCurrentConfigurationToDatabase(); getDialog().dismiss(); } } }); init(inflater, container, savedInstanceState); // hide/show delete button if existing data is initialized boolean isInitializedFromExistingData = initializeFromExistingData(getArguments()); if (isInitializedFromExistingData) { imageButtonDelete.setVisibility(View.VISIBLE); } else { imageButtonDelete.setVisibility(View.GONE); } setSaveButtonState(isInitializedFromExistingData); setModified(false); return rootView; }
From source file:com.facebook.CustomTabActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_CANCELED) { // We weren't able to open CustomTabMainActivity from the back stack. Send a broadcast // instead. Intent broadcast = new Intent(CUSTOM_TAB_REDIRECT_ACTION); broadcast.putExtra(CustomTabMainActivity.EXTRA_URL, getIntent().getDataString()); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); // Wait for the custom tab to be removed from the back stack before finishing. closeReceiver = new BroadcastReceiver() { @Override//from w w w.ja v a 2 s . c o m public void onReceive(Context context, Intent intent) { CustomTabActivity.this.finish(); } }; LocalBroadcastManager.getInstance(this).registerReceiver(closeReceiver, new IntentFilter(CustomTabActivity.DESTROY_ACTION)); } }
From source file:eu.power_switch.gui.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // set Theme before anything else in onCreate ThemeHelper.applyTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // allow always-on screen setAmbientEnabled();//from w ww . j a v a 2s . c om dataApiHandler = new DataApiHandler(getApplicationContext()); // 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("MainActivity", "received intent: " + intent.getAction()); if (ListenerService.DATA_UPDATED.equals(intent.getAction())) { ArrayList<Room> rooms = (ArrayList<Room>) intent .getSerializableExtra(ListenerService.ROOM_DATA); replaceRoomList(rooms); ArrayList<Scene> scenes = (ArrayList<Scene>) intent .getSerializableExtra(ListenerService.SCENE_DATA); replaceSceneList(scenes); } refreshUI(); } }; // // Obtain the DismissOverlayView element // dismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay); // dismissOverlayView.setIntroText(R.string.long_press_intro); // dismissOverlayView.showIntroIfNecessary(); // // // Configure a gesture detector // gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { // public void onLongPress(MotionEvent ev) { // dismissOverlayView.show(); // } // }); final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { // Status layout relativeLayoutStatus = (RelativeLayout) findViewById(R.id.relativeLayout_status); textViewStatus = (TextView) findViewById(R.id.textView_Status); Button rooms = (Button) findViewById(R.id.button_rooms); rooms.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent startIntent = new Intent(getApplicationContext(), RoomsActivity.class); startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startIntent.putExtra(ListenerService.ROOM_DATA, roomList); startActivity(startIntent); } }); Button scenes = (Button) findViewById(R.id.button_scenes); scenes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent startIntent = new Intent(getApplicationContext(), ScenesActivity.class); startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startIntent.putExtra(ListenerService.SCENE_DATA, sceneList); startActivity(startIntent); } }); // Get Room/Receiver/Button/Scene configuration from Smartphone App new FetchDataAsyncTask().execute(); } }); if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // // Should we show an explanation? // if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { // // Show an expanation to the user *asynchronously* -- don't block // // this thread waiting for the user's response! After the user // // sees the explanation, try again to request the permission. // // } else { // // No explanation needed, we can request the permission. Log.d("Write external storage permission is missing, asking for it..."); ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); // } } else { Log.d("Write external storage permission already granted"); } }