List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.aniruddhc.acemusic.player.NowPlayingQueueActivity.NowPlayingQueueFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Inflate the correct layout based on the selected theme. mContext = getActivity().getApplicationContext(); mApp = (Common) mContext;/* ww w. jav a 2 s . co m*/ nowPlayingQueueFragment = this; sharedPreferences = mContext.getSharedPreferences("com.aniruddhc.acemusic.player", Context.MODE_PRIVATE); mCursor = mApp.getService().getCursor(); View rootView = (ViewGroup) inflater.inflate(R.layout.now_playing_queue_layout, container, false); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateSongInfo(); } }; //Notify the application that this fragment is now visible. sharedPreferences.edit().putBoolean("NOW_PLAYING_QUEUE_VISIBLE", true).commit(); //Get the screen's parameters. displayMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); screenWidth = displayMetrics.widthPixels; screenHeight = displayMetrics.heightPixels; noMusicPlaying = (TextView) rootView.findViewById(R.id.now_playing_queue_no_music_playing); nowPlayingAlbumArt = (ImageView) rootView.findViewById(R.id.now_playing_queue_album_art); nowPlayingSongTitle = (TextView) rootView.findViewById(R.id.now_playing_queue_song_title); nowPlayingSongArtist = (TextView) rootView.findViewById(R.id.now_playing_queue_song_artist); nowPlayingSongContainer = (RelativeLayout) rootView .findViewById(R.id.now_playing_queue_current_song_container); noMusicPlaying.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); nowPlayingSongTitle.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); nowPlayingSongArtist.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); nowPlayingQueueListView = (DragSortListView) rootView.findViewById(R.id.now_playing_queue_list_view); progressBar = (ProgressBar) rootView.findViewById(R.id.now_playing_queue_progressbar); playPauseButton = (ImageButton) rootView.findViewById(R.id.now_playing_queue_play); nextButton = (ImageButton) rootView.findViewById(R.id.now_playing_queue_next); previousButton = (ImageButton) rootView.findViewById(R.id.now_playing_queue_previous); //Apply the card layout's background based on the color theme. if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME").equals("LIGHT_CARDS_THEME")) { rootView.setBackgroundColor(0xFFEEEEEE); nowPlayingQueueListView.setDivider(getResources().getDrawable(R.drawable.transparent_drawable)); nowPlayingQueueListView.setDividerHeight(3); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(7, 3, 7, 3); nowPlayingQueueListView.setLayoutParams(layoutParams); } else if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME") .equals("DARK_CARDS_THEME")) { rootView.setBackgroundColor(0xFF000000); nowPlayingQueueListView.setDivider(getResources().getDrawable(R.drawable.transparent_drawable)); nowPlayingQueueListView.setDividerHeight(3); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(7, 3, 7, 3); nowPlayingQueueListView.setLayoutParams(layoutParams); } //Set the Now Playing container layout's background. nowPlayingSongContainer.setBackgroundColor(UIElementsHelper.getNowPlayingQueueBackground(mContext)); //Loop through the service's cursor and retrieve the current queue's information. if (sharedPreferences.getBoolean("SERVICE_RUNNING", false) == false || mApp.getService().getCurrentMediaPlayer() == null) { //No audio is currently playing. noMusicPlaying.setVisibility(View.VISIBLE); nowPlayingAlbumArt.setImageBitmap(mApp.decodeSampledBitmapFromResource(R.drawable.default_album_art, screenWidth / 3, screenWidth / 3)); nowPlayingQueueListView.setVisibility(View.GONE); nowPlayingSongTitle.setVisibility(View.GONE); nowPlayingSongArtist.setVisibility(View.GONE); progressBar.setVisibility(View.GONE); } else { //Set the current play/pause conditions. try { //Hide the progressBar and display the controls. progressBar.setVisibility(View.GONE); playPauseButton.setVisibility(View.VISIBLE); nextButton.setVisibility(View.VISIBLE); previousButton.setVisibility(View.VISIBLE); if (mApp.getService().getCurrentMediaPlayer().isPlaying()) { playPauseButton.setImageResource(R.drawable.pause_holo_light); } else { playPauseButton.setImageResource(R.drawable.play_holo_light); } } catch (Exception e) { /* The mediaPlayer hasn't been initialized yet, so let's just keep the controls * hidden for now. Once the mediaPlayer is initialized and it starts playing, * updateSongInfo() will be called, and we can show the controls/hide the progressbar * there. For now though, we'll display the progressBar. */ progressBar.setVisibility(View.VISIBLE); playPauseButton.setVisibility(View.GONE); nextButton.setVisibility(View.GONE); previousButton.setVisibility(View.GONE); } //Retrieve and set the current title/artist/artwork. mCursor.moveToPosition( mApp.getService().getPlaybackIndecesList().get(mApp.getService().getCurrentSongIndex())); String currentTitle = mCursor.getString(mCursor.getColumnIndex(DBAccessHelper.SONG_TITLE)); String currentArtist = mCursor.getString(mCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)); nowPlayingSongTitle.setText(currentTitle); nowPlayingSongArtist.setText(currentArtist); File file = new File(mContext.getExternalCacheDir() + "/current_album_art.jpg"); Bitmap bm = null; if (file.exists()) { bm = mApp.decodeSampledBitmapFromFile(file, screenWidth, screenHeight); nowPlayingAlbumArt.setScaleX(1.0f); nowPlayingAlbumArt.setScaleY(1.0f); } else { int defaultResource = UIElementsHelper.getIcon(mContext, "default_album_art"); bm = mApp.decodeSampledBitmapFromResource(defaultResource, screenWidth, screenHeight); nowPlayingAlbumArt.setScaleX(0.5f); nowPlayingAlbumArt.setScaleY(0.5f); } nowPlayingAlbumArt.setImageBitmap(bm); noMusicPlaying.setPaintFlags( noMusicPlaying.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); nowPlayingSongTitle.setPaintFlags(nowPlayingSongTitle.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG); nowPlayingSongArtist.setPaintFlags( nowPlayingSongArtist.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); /* Set the adapter. We'll pass in playbackIndecesList as the adapter's data backend. * The array can then be manipulated (reordered, items removed, etc) with no restrictions. * Each integer element in the array will be used as a pointer to a specific cursor row, * so there's no need to fiddle around with the actual cursor itself. */ nowPlayingQueueListViewAdapter = new NowPlayingQueueListViewAdapter(getActivity(), mApp.getService().getPlaybackIndecesList()); nowPlayingQueueListView.setAdapter(nowPlayingQueueListViewAdapter); nowPlayingQueueListView.setFastScrollEnabled(true); nowPlayingQueueListView.setDropListener(onDrop); nowPlayingQueueListView.setRemoveListener(onRemove); SimpleFloatViewManager simpleFloatViewManager = new SimpleFloatViewManager(nowPlayingQueueListView); simpleFloatViewManager.setBackgroundColor(Color.TRANSPARENT); nowPlayingQueueListView.setFloatViewManager(simpleFloatViewManager); //Scroll down to the current song. nowPlayingQueueListView.setSelection(mApp.getService().getCurrentSongIndex()); nowPlayingQueueListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int index, long arg3) { mApp.getService().skipToTrack(index); } }); playPauseButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mApp.getService().togglePlaybackState(); } }); nextButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mApp.getService().skipToNextTrack(); } }); previousButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mApp.getService().skipToPreviousTrack(); } }); } return rootView; }
From source file:com.mcongrove.pebble.TitaniumPebbleModule.java
@Kroll.method private void addReceivers() { if (isListeningToPebble) { if (connectedReceiver == null) { connectedReceiver = new BroadcastReceiver() { @Override/*from w ww .j a v a 2 s . c o m*/ public void onReceive(Context context, Intent intent) { Log.d(LCAT, "watchDidConnect"); setConnectedCount(0); fireEvent("watchConnected", new Object[] {}); } }; PebbleKit.registerPebbleConnectedReceiver(getApplicationContext(), connectedReceiver); } if (disconnectedReceiver == null) { disconnectedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(LCAT, "watchDidDisconnect"); setConnectedCount(0); fireEvent("watchDisconnected", new Object[] {}); } }; PebbleKit.registerPebbleDisconnectedReceiver(getApplicationContext(), disconnectedReceiver); } if (dataReceiver == null) { dataReceiver = new PebbleKit.PebbleDataReceiver(uuid) { @Override public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) { if (!data.contains(0)) { Log.e(LCAT, "listenToConnectedWatch: Received message, data corrupt"); PebbleKit.sendNackToPebble(context, transactionId); return; } PebbleKit.sendAckToPebble(context, transactionId); try { JSONArray jsonArray = new JSONArray(data.toJsonString()); if (jsonArray.length() > 0) { JSONObject jsonObject = jsonArray.getJSONObject(0); if (jsonObject.has("value")) { Log.i(LCAT, "listenToConnectedWatch: Received message"); HashMap message = new HashMap(); message.put("message", jsonObject.getString("value")); fireEvent("update", message); } } } catch (Throwable e) { Log.e(LCAT, "listenToConnectedWatch: Received message, data corrupt"); } } }; PebbleKit.registerReceivedDataHandler(getApplicationContext(), dataReceiver); } if (ackReceiver == null) { ackReceiver = new PebbleKit.PebbleAckReceiver(uuid) { @Override public void receiveAck(Context context, int transactionId) { Log.i(LCAT, "Received ACK for transaction: " + transactionId); if (callbacks.containsKey(transactionId)) { HashMap callbackArray = (HashMap) callbacks.get(transactionId); if (callbackArray.containsKey("success")) { KrollFunction successCallback = (KrollFunction) callbackArray.get("success"); successCallback.call(getKrollObject(), new Object[] {}); } } } }; PebbleKit.registerReceivedAckHandler(getApplicationContext(), ackReceiver); } if (nackReceiver == null) { nackReceiver = new PebbleKit.PebbleNackReceiver(uuid) { @Override public void receiveNack(Context context, int transactionId) { Log.e(LCAT, "Received NACK for transaction: " + transactionId); if (callbacks.containsKey(transactionId)) { HashMap callbackArray = (HashMap) callbacks.get(transactionId); if (callbackArray.containsKey("error")) { KrollFunction errorCallback = (KrollFunction) callbackArray.get("error"); errorCallback.call(getKrollObject(), new Object[] {}); } } } }; PebbleKit.registerReceivedNackHandler(getApplicationContext(), nackReceiver); } } }
From source file:alaindc.crowdroid.View.StakeholdersActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stakeholders); linearLayout = (LinearLayout) findViewById(R.id.subscribesLinearLayout); updateStakeButton = (Button) findViewById(R.id.updateStakeButton); sendStakeButton = (Button) findViewById(R.id.sendStakeButton); updateStakeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_GETSUBSCRIPTION); getApplicationContext().startService(subscrIntent); }// www .ja v a 2 s . c o m }); sendStakeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { JSONArray jsonArr = new JSONArray(); JSONObject jsonObj = new JSONObject(); jsonObj.put("user", RadioUtils.getMyDeviceId(getApplicationContext())); jsonArr.put(jsonObj); for (int i = 0; i < linearLayout.getChildCount(); i++) { View view = linearLayout.getChildAt(i); if (view instanceof CheckBox) { CheckBox c = (CheckBox) view; if (c.isChecked()) { jsonObj = new JSONObject(); jsonObj.put("id", c.getId()); jsonArr.put(jsonObj); } } } String body = jsonArr.toString(); Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_UPDATESUBSCRIPTION); subscrIntent.putExtra(Constants.EXTRA_BODY_UPDATESUBSCRIPTION, body); getApplicationContext().startService(subscrIntent); } catch (JSONException e) { return; } } }); Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_GETSUBSCRIPTION); getApplicationContext().startService(subscrIntent); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Constants.INTENTVIEW_RECEIVED_SUBSCRIPTION)) { String response = intent.getStringExtra(Constants.EXTRAVIEW_RECEIVED_SUBSCRIPTION); //Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show(); linearLayout.removeAllViews(); try { JSONArray jsonArray = new JSONArray(response); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); int id = jsonObject.getInt("id"); String name = jsonObject.getString("name"); boolean subscribed = jsonObject.getInt("subscribed") == 1; CheckBox checkBox = new CheckBox(getApplicationContext()); checkBox.setTextColor(Color.BLACK); checkBox.setText(name); checkBox.setId(id); checkBox.setChecked(subscribed); linearLayout.addView(checkBox); int idx = linearLayout.indexOfChild(checkBox); checkBox.setTag(Integer.toString(idx)); } } catch (JSONException e) { return; } } else { Log.d("", ""); } } }; IntentFilter rcvDataIntFilter = new IntentFilter(Constants.INTENTVIEW_RECEIVED_SUBSCRIPTION); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, rcvDataIntFilter); }
From source file:org.umit.icm.mobile.gui.ControlActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.controlactivity); WebsiteSuggestButton = (Button) this.findViewById(R.id.suggestWebsite); ServiceSuggestButton = (Button) this.findViewById(R.id.suggestService); scanButton = (Button) this.findViewById(R.id.scanButton); // filterButton = (Button) this.findViewById(R.id.filterButton); // servicesFilterButton = (Button) this.findViewById(R.id.serviceFilterButton); mapSelectionButton = (Button) this.findViewById(R.id.mapSelectionButton); enableTwitterButton = (Button) this.findViewById(R.id.enableTwitterButton); bugReportButton = (Button) this.findViewById(R.id.bugReportButton); aboutButton = (Button) this.findViewById(R.id.aboutButton); scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off)); try {// w w w . j a v a 2s . c om if (Globals.runtimeParameters.getTwitter().equals("Off")) { enableTwitterButton.setText(getString(R.string.enable_twitter_button)); } else { enableTwitterButton.setText(getString(R.string.disable_twitter_button)); } } catch (RuntimeException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("org.umit.icm.mobile.CONTROL_ACTIVITY")) { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on)); } } }; registerReceiver(receiver, new IntentFilter("org.umit.icm.mobile.CONTROL_ACTIVITY")); WebsiteSuggestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { WebsiteSuggestionDialog websiteSuggestionDialog = new WebsiteSuggestionDialog(ControlActivity.this, "", new OnReadyListener()); websiteSuggestionDialog.show(); } }); ServiceSuggestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { ServiceSuggestionDialog suggestionDialog = new ServiceSuggestionDialog(ControlActivity.this, "", new OnReadyListener()); suggestionDialog.show(); } }); enableTwitterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { try { if (Globals.runtimeParameters.getTwitter().equals("Off")) { progressDialog = ProgressDialog.show(ControlActivity.this, getString(R.string.loading), getString(R.string.retrieving_website), true, false); new LaunchBrowser().execute(); TwitterDialog twitterDialog = new TwitterDialog(ControlActivity.this, ""); twitterDialog.show(); enableTwitterButton.setText(getString(R.string.disable_twitter_button)); } else { Globals.runtimeParameters.setTwitter("Off"); enableTwitterButton.setText(getString(R.string.enable_twitter_button)); } } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); mapSelectionButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { MapSelectionDialog MapSelectionDialog = new MapSelectionDialog(ControlActivity.this, ""); MapSelectionDialog.show(); } }); /* filterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, WebsiteFilterActivity.class); startActivity(intent); } } ); servicesFilterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, ServiceFilterActivity.class); startActivity(intent); } } );*/ bugReportButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, BugReportActivity.class); startActivity(intent); } }); aboutButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String msg = getString(R.string.about_text) + "\n" + getString(R.string.link_to_open_monitor) + "\n" + getString(R.string.link_to_umit) + "\n" + getString(R.string.icons_by); final SpannableString spannableString = new SpannableString(msg); Linkify.addLinks(spannableString, Linkify.ALL); AlertDialog alertDialog = new AlertDialog.Builder(ControlActivity.this).create(); alertDialog.setTitle(getString(R.string.about_button)); alertDialog.setMessage(spannableString); alertDialog.setIcon(R.drawable.umit_128); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); } }); scanButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (Globals.scanStatus.equalsIgnoreCase(getString(R.string.scan_on))) { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on)); Globals.scanStatus = getString(R.string.scan_off); stopService(new Intent(ControlActivity.this, ConnectivityService.class)); } else { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off)); Globals.scanStatus = getString(R.string.scan_on); startService(new Intent(ControlActivity.this, ConnectivityService.class)); } try { Globals.runtimeParameters.setScanStatus(Globals.scanStatus); } catch (RuntimeException e) { e.printStackTrace(); } Context context = getApplicationContext(); CharSequence text = getString(R.string.toast_scan_change) + " " + Globals.scanStatus; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } }); }
From source file:name.gumartinm.weather.information.fragment.current.CurrentFragment.java
@Override public void onResume() { super.onResume(); this.mReceiver = new BroadcastReceiver() { @Override/*from w w w. j a v a 2s .c om*/ public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (action.equals(BROADCAST_INTENT_ACTION)) { final Current currentRemote = (Current) intent.getSerializableExtra("current"); // 1. Check conditions. They must be the same as the ones that triggered the AsyncTask. final DatabaseQueries query = new DatabaseQueries(context.getApplicationContext()); final WeatherLocation weatherLocation = query.queryDataBase(); final PermanentStorage store = new PermanentStorage(context.getApplicationContext()); final Current current = store.getCurrent(); if (current == null || !CurrentFragment.this.isDataFresh(weatherLocation.getLastCurrentUIUpdate())) { if (currentRemote != null) { // 2. Update UI. CurrentFragment.this.updateUI(currentRemote); // 3. Update current data. store.saveCurrent(currentRemote); // 4. Update location data. weatherLocation.setLastCurrentUIUpdate(new Date()); query.updateDataBase(weatherLocation); } else { // Empty UI and show error message CurrentFragment.this.getActivity().findViewById(R.id.weather_current_data_container) .setVisibility(View.GONE); CurrentFragment.this.getActivity().findViewById(R.id.weather_current_progressbar) .setVisibility(View.GONE); CurrentFragment.this.getActivity().findViewById(R.id.weather_current_error_message) .setVisibility(View.VISIBLE); } } } } }; // Register receiver final IntentFilter filter = new IntentFilter(); filter.addAction(BROADCAST_INTENT_ACTION); LocalBroadcastManager.getInstance(this.getActivity().getApplicationContext()) .registerReceiver(this.mReceiver, filter); // Empty UI this.getActivity().findViewById(R.id.weather_current_data_container).setVisibility(View.GONE); final DatabaseQueries query = new DatabaseQueries(this.getActivity().getApplicationContext()); final WeatherLocation weatherLocation = query.queryDataBase(); if (weatherLocation == null) { // Nothing to do. // Show error message final ProgressBar progress = (ProgressBar) getActivity().findViewById(R.id.weather_current_progressbar); progress.setVisibility(View.GONE); final TextView errorMessage = (TextView) getActivity().findViewById(R.id.weather_current_error_message); errorMessage.setVisibility(View.VISIBLE); return; } // If is new location update widgets. if (weatherLocation.getIsNew()) { WidgetProvider.refreshAllAppWidgets(this.getActivity().getApplicationContext()); // Update location data. weatherLocation.setIsNew(false); query.updateDataBase(weatherLocation); } final PermanentStorage store = new PermanentStorage(this.getActivity().getApplicationContext()); final Current current = store.getCurrent(); if (current != null && this.isDataFresh(weatherLocation.getLastCurrentUIUpdate())) { this.updateUI(current); } else { // Load remote data (asynchronous) // Gets the data from the web. this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.VISIBLE); this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.GONE); final CurrentTask task = new CurrentTask(this.getActivity().getApplicationContext(), new CustomHTTPClient(AndroidHttpClient.newInstance(this.getString(R.string.http_client_agent))), new ServiceCurrentParser(new JPOSCurrentParser())); task.execute(weatherLocation.getLatitude(), weatherLocation.getLongitude()); } }
From source file:com.app.cat.ui.PhoneBookActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set UI application context ApplicationContext.setActivity(this); // Mockup telephone book ui data. List<CATFriend> catAccounts = new ArrayList<CATFriend>(); telephoneBookAdapter = new TelephoneBookAdapter(this, catAccounts); listTBook.setAdapter(telephoneBookAdapter); receiver = new BroadcastReceiver() { @Override/* w w w .ja va 2s . c om*/ public void onReceive(Context context, Intent intent) { if (intent.hasExtra(ApplicationContext.KEY_SHOW_ERROR_MESSAGE)) { statusBarText.setText(intent.getStringExtra(ApplicationContext.KEY_SHOW_ERROR_MESSAGE)); statusBarLayout.setVisibility(View.VISIBLE); listTBook.setVisibility(View.GONE); } else if (intent.hasExtra(ApplicationContext.KEY_HIDE_ERROR_MESSAGE)) { statusBarText.setText(""); statusBarLayout.setVisibility(View.GONE); listTBook.setVisibility(View.VISIBLE); } } }; try { // ToDo: Check transport choosing in linphone implementation: {@link LinphonePreferenes} int udp = 0; int tcp = 5060; int tls = 0; // Get singleton object. client = LinphoneCATClient.getInstance(); client.setTransportType(udp, tcp, tls); configuration = PropertiesLoader.loadProperty(this.getAssets().open("config.properties"), Arrays.asList("username", "password", "domain", "friendUsername")); catUser = new CATUser(configuration.get("username"), configuration.get("password"), configuration.get("domain")); Log.v("Password_HA1", HashGenerator.ha1(catUser.getUsername(), catUser.getDomain(), configuration.get("password"))); Log.v("Password_HA1B", HashGenerator.ha1b(catUser.getUsername(), catUser.getDomain(), configuration.get("password"))); info.setText("User = " + configuration.get("username")); catFriend = new CATFriend(configuration.get("friendUsername"), configuration.get("domain")); catAccounts.add(catFriend); client.addCATFriend(catFriend); client.register(catUser); // Starts an service in background service = new Intent(PhoneBookActivity.this, CATService.class); startService(service); } catch (LinphoneCoreException | NoSuchAlgorithmException e) { ApplicationContext.showToast(ApplicationContext.getStringFromRessources(R.string.unknown_error_message), Toast.LENGTH_SHORT); e.printStackTrace(); } catch (IOException e) { info.setText("No mockup data set"); } }
From source file:com.liferay.alerts.activity.MainActivity.java
private void _registerAddCardReceiver() { _receiver = new BroadcastReceiver() { @Override//from w w w .j a v a2 s. c om public void onReceive(final Context context, Intent intent) { final Alert alert = intent.getParcelableExtra(Alert.ALERT); _alerts.add(alert); _addCard(alert); if (_paused) { AlertDAO dao = AlertDAO.getInstance(context); List<Alert> alerts = dao.getUnread(); NotificationUtil.notify(context, alerts); } else { NotificationUtil.cancel(context); } } }; _getBroadcastManager().registerReceiver(_receiver, new IntentFilter(ADD_CARD)); }
From source file:com.facebook.AccessTokenManagerTest.java
@Test public void testChangingAccessTokenSendsBroadcast() { AccessTokenManager accessTokenManager = createAccessTokenManager(); AccessToken accessToken = createAccessToken(); accessTokenManager.setCurrentAccessToken(accessToken); final Intent intents[] = new Intent[1]; final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override/*w w w. j a va 2 s . com*/ public void onReceive(Context context, Intent intent) { intents[0] = intent; } }; localBroadcastManager.registerReceiver(broadcastReceiver, new IntentFilter(AccessTokenManager.ACTION_CURRENT_ACCESS_TOKEN_CHANGED)); AccessToken anotherAccessToken = createAccessToken("another string", "1000"); accessTokenManager.setCurrentAccessToken(anotherAccessToken); localBroadcastManager.unregisterReceiver(broadcastReceiver); Intent intent = intents[0]; assertNotNull(intent); AccessToken oldAccessToken = (AccessToken) intent .getParcelableExtra(AccessTokenManager.EXTRA_OLD_ACCESS_TOKEN); AccessToken newAccessToken = (AccessToken) intent .getParcelableExtra(AccessTokenManager.EXTRA_NEW_ACCESS_TOKEN); assertEquals(accessToken.getToken(), oldAccessToken.getToken()); assertEquals(anotherAccessToken.getToken(), newAccessToken.getToken()); }
From source file:com.supremainc.biostar2.user.UserInquriyFragment.java
protected void registerBroadcast() { if (mReceiver == null) { mReceiver = new BroadcastReceiver() { @Override/*w w w . j a va 2s . c o m*/ public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (mIsDestroy) { return; } if (action.equals(Setting.BROADCAST_USER)) { User userInfo = getExtraData(Setting.BROADCAST_USER, intent); if (userInfo == null) { return; } try { if (userInfo.user_id.equals(mUserInfo.user_id)) { mUserInfo = userInfo; } } catch (Exception e) { Log.e(TAG, "registerBroadcast error:" + e.getMessage()); return; } initActionbar(mUserInfo.name, R.drawable.action_bar_bg); setView(); } else if (action.equals(Setting.BROADCAST_PREFRENCE_REFRESH)) { setView(); } else if (action.equals(Setting.BROADCAST_REROGIN)) { applyPermission(); } } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Setting.BROADCAST_USER); intentFilter.addAction(Setting.BROADCAST_PREFRENCE_REFRESH); intentFilter.addAction(Setting.BROADCAST_REROGIN); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, intentFilter); } }
From source file:com.openarc.nirmal.nestle.LoginActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); session = Session.getSession();//from www .j a v a 2 s . c o m sharedPreferences = getSharedPreferences(SharedPreferencesName.login, 0); initialize(); //region broadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case "NoData": if (isRunning()) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(LoginActivity.this, R.style.AlertDialogStyle); alertDialogBuilder.setMessage(getString(R.string.message_no_data)); alertDialogBuilder.setPositiveButton(getString(R.string.btn_txt_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); showProgressBar(false); } }); noDataAlertDialog = alertDialogBuilder.create(); noDataAlertDialog.show(); setDownloadStatus(false); } break; case "DownloadFailed": if (isRunning()) { Toast.makeText(LoginActivity.this, "Data Download Failed!", Toast.LENGTH_SHORT).show(); setDownloadStatus(false); showProgressBar(false); } break; case "DownloadInterrupted": setDownloadStatus(false); startHomeActivity(); break; case "DownloadFinished": if (isRunning()) { setDownloadStatus(true); startHomeActivity(); } break; default: showProgressBar(false); break; } } }; //endregion if (sharedPreferences.getBoolean(SharedPreferencesName.autoLogin, false)) this.automaticLogin(); }