List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:eu.power_switch.gui.activity.ScenesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // set Theme before anything else in onCreate ThemeHelper.applyTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_scenes); // allow always-on screen setAmbientEnabled();//from w w w . j a va 2 s. c o m 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()); ArrayList<Scene> scenes = (ArrayList<Scene>) intent .getSerializableExtra(ListenerService.SCENE_DATA); replaceSceneList(scenes); refreshUI(); } }; final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { relativeLayoutAmbientMode = (RelativeLayout) findViewById(R.id.relativeLayout_ambientMode); scenesRecyclerView = (RecyclerView) findViewById(R.id.scenes_recyclerView); sceneRecyclerViewAdapter = new SceneRecyclerViewAdapter(stub.getContext(), scenesRecyclerView, sceneList, dataApiHandler); scenesRecyclerView.setAdapter(sceneRecyclerViewAdapter); SnappingLinearLayoutManager layoutManager = new SnappingLinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false); scenesRecyclerView.setLayoutManager(layoutManager); } }); }
From source file:io.autem.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mInformationTextView = (TextView) findViewById(R.id.informationTextView); mTokenEditText = (EditText) findViewById(R.id.tokenEditText); mChromeTokenEditText = (EditText) findViewById(R.id.chromeTokenEditText); mApiKeyEditText = (EditText) findViewById(R.id.apiKeyEditText); mProjectNumberEditText = (EditText) findViewById(R.id.projectNumberEditText); mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override/*w ww . j a va 2 s. c o m*/ public void onReceive(Context context, Intent intent) { mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(AutemPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { mInformationTextView.setText(getString(R.string.gcm_send_message)); } else { mInformationTextView.setText(getString(R.string.token_error_message)); } String token = sharedPreferences.getString(AutemPreferences.REGISTRATION_TOKEN, ""); mTokenEditText.setText(token); } }; SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String token = sharedPreferences.getString(AutemPreferences.REGISTRATION_TOKEN, ""); mTokenEditText.setText(token); String apiKey = sharedPreferences.getString(AutemPreferences.API_KEY, ""); mApiKeyEditText.setText(apiKey); String chromeToken = sharedPreferences.getString(AutemPreferences.CHROME_TOKEN, ""); mChromeTokenEditText.setText(chromeToken); String projectNumber = sharedPreferences.getString(AutemPreferences.PROJECT_NUMBER, ""); mProjectNumberEditText.setText(projectNumber); if (checkPlayServices()) { final Intent intent = new Intent(this, RegistrationIntentService.class); final Button registerDeviceButton = (Button) findViewById(R.id.registerDeviceButton); registerDeviceButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Start IntentService to register this application with GCM. mProjectNumberEditText = (EditText) findViewById(R.id.projectNumberEditText); if (!mProjectNumberEditText.getText().toString().isEmpty()) { mRegistrationProgressBar.setVisibility(ProgressBar.VISIBLE); mInformationTextView.setVisibility(View.VISIBLE); SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(MainActivity.this.getApplicationContext()); sharedPreferences.edit().putString(AutemPreferences.PROJECT_NUMBER, mProjectNumberEditText.getText().toString()).commit(); startService(intent); } else { Toast.makeText(MainActivity.this, getString(R.string.project_number_required), Toast.LENGTH_LONG).show(); } } }); } final Button testMessageButton = (Button) findViewById(R.id.testMessageButton); testMessageButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mChromeTokenEditText = (EditText) findViewById(R.id.chromeTokenEditText); mApiKeyEditText = (EditText) findViewById(R.id.apiKeyEditText); SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(MainActivity.this.getApplicationContext()); sharedPreferences.edit().putString(AutemPreferences.API_KEY, mApiKeyEditText.getText().toString()) .commit(); sharedPreferences.edit() .putString(AutemPreferences.CHROME_TOKEN, mChromeTokenEditText.getText().toString()) .commit(); sendTestMessage(mChromeTokenEditText.getText().toString(), mApiKeyEditText.getText().toString()); } }); }
From source file:com.groksolutions.grok.mobile.metric.MetricListFragment.java
public MetricListFragment() { _metricDataChangedReceiver = new BroadcastReceiver() { @Override//from www. j a v a 2 s .co m public void onReceive(Context context, Intent intent) { updateMetricData(); } }; _metricChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateMetricList(); } }; _annotationChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateMetricData(); } }; }
From source file:eu.power_switch.gui.dialog.ConfigurationDialog.java
@Nullable @Override//from w w w . ja va 2s.c o m 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, null); FrameLayout contentViewContainer = (FrameLayout) rootView.findViewById(R.id.contentView); contentView = initContentView(inflater, contentViewContainer, savedInstanceState); 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(); } } }); 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(); } } }); boolean isInitializedFromExistingData = initExistingData(getArguments()); if (isInitializedFromExistingData) { imageButtonDelete.setVisibility(View.VISIBLE); } else { imageButtonDelete.setVisibility(View.GONE); } try { setSaveButtonState(isValid()); } catch (Exception e) { Log.e(e); setSaveButtonState(false); } setModified(false); return rootView; }
From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.FixturesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fixtures_layout, container, false); ButterKnife.inject(this, view); buildGoogleApiClient();/* ww w .j a va 2s. c o m*/ //Registering events to detect radio changes final BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { updateBluetoothStatusDisplay(); } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { updateWifiStatusDisplay(); } else if (action.equals(LocationManager.PROVIDERS_CHANGED_ACTION)) { updateGPSStatusDisplay(); } else if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) { updateNFCStatusDisplay(); } } }; IntentFilter filter = new IntentFilter(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { filter.addAction(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); } filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION); updateWifiStatusDisplay(); updateBluetoothStatusDisplay(); updateGPSStatusDisplay(); updateNFCStatusDisplay(); getActivity().registerReceiver(receiver, filter); return view; }
From source file:be.ehb.fallwear.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(/*from w ww . j a v a 2 s . c o m*/ new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems .penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mBtnReg = (Button) findViewById(R.id.btnReg); mBtnUnReg = (Button) findViewById(R.id.bntUnReg); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mRegistrationProgressBar.setVisibility(ProgressBar.GONE); mBtnReg.setVisibility(View.GONE); mBtnUnReg.setVisibility(View.VISIBLE); mBtnReg.setEnabled(true); mInformationTextView.setVisibility(View.VISIBLE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); String token = sharedPreferences.getString(QuickstartPreferences.TOKEN, "00"); if (sentToken) { String message = getResources().getString(R.string.gcm_send_message); mInformationTextView.setText(String.format(message, token)); } else { mInformationTextView.setText(getString(R.string.token_error_message)); } } }; mUnRegisterBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mRegistrationProgressBar.setVisibility(ProgressBar.GONE); mInformationTextView.setVisibility(View.VISIBLE); mBtnReg.setVisibility(View.VISIBLE); mBtnUnReg.setVisibility(View.GONE); mBtnUnReg.setEnabled(true); mInformationTextView.setText(R.string.unregistered); } }; mInformationTextView = (TextView) findViewById(R.id.informationTextView); }
From source file:com.telestax.mayday_customer.fragment.CustomerOfferFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View viewInfo = inflater.inflate(R.layout.customer_offer, container, false); // Initialize UI mImageViewCustomerMayDayCall = (ImageView) viewInfo.findViewById(R.id.imageView_customer_three_mayday); ImageView imageViewCustomerOfferBack = (ImageView) viewInfo .findViewById(R.id.imageView_customer_offer_back); mImageViewCustomerMayDayCall.setOnClickListener(this); imageViewCustomerOfferBack.setOnClickListener(this); String mayDayAction = MainActivity.getMaydaySharePref(getActivity()); if (mayDayAction != null) { if (mayDayAction.equalsIgnoreCase(Constant.YES)) { mImageViewCustomerMayDayCall.setVisibility(View.INVISIBLE); } else {//from w w w.j av a 2s .com mImageViewCustomerMayDayCall.setVisibility(View.VISIBLE); } } mInitReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mImageViewCustomerMayDayCall.setVisibility(View.VISIBLE); } }; //Register broadcast receiver LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mInitReceiver, new IntentFilter(Constant.BROADCAST_INTENT)); return viewInfo; }
From source file:com.nexmo.sdk.sample.verifysample_pushenabled.SampleApplication.java
/** * Acquire a new verify client./*from w w w .ja v a2 s . co m*/ * If the user changes the settings shared preferences, a new verify client needs * to be created to reflect the new configuration. * Storing the credentials: applicationId and sharedSecretKey is up to the developer: * you may choose to use SharedPreferences, a file or define meta-data in the AndroidManifest.xml */ public void acquireVerifyClient() { if (TextUtils.isEmpty(Config.NexmoAppId) || TextUtils.isEmpty(Config.NexmoSharedSecretKey)) { Log.e(TAG, "You must supply valid appId and sharedSecretKey, provided by Nexmo"); return; } // Acquire the NexmoClient with all the necessary parameters. Context context = getApplicationContext(); try { this.nexmoClient = new NexmoClient.NexmoClientBuilder().context(context) .applicationId(Config.NexmoAppId).sharedSecretKey(Config.NexmoSharedSecretKey).build(); } catch (ClientBuilderException e) { e.printStackTrace(); return; } this.verifyClient = new VerifyClient(nexmoClient); if (TextUtils.isEmpty(Config.PushSenderID)) Log.e(TAG, "You haven't provided a valid SENDER_ID for GCM to be enabled."); else { mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.hasExtra(GcmRegistrationIntentService.INTENT_EXTRA_PUSH_TOKEN)) nexmoClient.setGcmRegistrationToken( intent.getStringExtra(GcmRegistrationIntentService.INTENT_EXTRA_PUSH_TOKEN)); } }; LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(GcmRegistrationIntentService.REGISTRATION_COMPLETE)); } }
From source file:com.sbhstimetable.sbhs_timetable_android.backend.service.DashclockService.java
@Override protected void onInitialize(boolean isReconnect) { super.onInitialize(isReconnect); setUpdateWhenScreenOn(true);/*from www . j a v a2 s .co m*/ mine = TodayJson.getInstance(); bells = BelltimesJson.getInstance(); if (mine == null) { Log.i("dashclock", "today"); JsonObject temp = StorageCache.getTodayJson(this); if (temp != null) { mine = new TodayJson(temp); } ApiAccessor.getToday(this); } if (bells == null) { Log.i("dashclock", "bells"); JsonObject temp = StorageCache.getBelltimes(this); if (temp != null) { bells = new BelltimesJson(temp); } ApiAccessor.getBelltimes(this); } IntentFilter wanted = new IntentFilter(); wanted.addAction(ApiAccessor.ACTION_TODAY_JSON); final DashclockService that = this; LocalBroadcastManager.getInstance(this).registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ApiAccessor.ACTION_TODAY_JSON)) { mine = new TodayJson( JsonUtil.safelyParseJson(intent.getStringExtra(ApiAccessor.EXTRA_JSON_DATA))); } else if (intent.getAction().equals(ApiAccessor.ACTION_BELLTIMES_JSON)) { bells = new BelltimesJson( JsonUtil.safelyParseJson(intent.getStringExtra(ApiAccessor.EXTRA_JSON_DATA))); } that.onUpdateData(DashClockExtension.UPDATE_REASON_MANUAL); } }, wanted); }
From source file:com.android.settings.profiles.ProfilesSettings.java
public ProfilesSettings() { mFilter = new IntentFilter(); mFilter.addAction(ProfileManager.PROFILES_STATE_CHANGED_ACTION); mReceiver = new BroadcastReceiver() { @Override//from w w w . j a v a2 s . c o m public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ProfileManager.PROFILES_STATE_CHANGED_ACTION.equals(action)) { updateProfilesEnabledState(); } } }; }