List of usage examples for android.content SharedPreferences getAll
Map<String, ?> getAll();
From source file:de.ub0r.android.callmeter.ui.Plans.java
@Override public void onCreate(final Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setTheme(Preferences.getTheme(this)); Utils.setLocale(this); super.onCreate(savedInstanceState); setContentView(R.layout.plans);/*from w ww . j av a2 s.com*/ getSupportActionBar().setHomeButtonEnabled(true); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); //noinspection ConstantConditions if (p.getAll().isEmpty()) { // show intro startActivity(new Intent(this, IntroActivity.class)); // set date of recordings to beginning of last month Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_MONTH, 0); c.add(Calendar.MONTH, -1); Log.i(TAG, "set date of recording: " + c); p.edit().putLong(Preferences.PREFS_DATE_BEGIN, c.getTimeInMillis()).apply(); } pager = (ViewPager) findViewById(R.id.pager); prefsNoAds = DonationHelper.hideAds(this); mAdView = (AdView) findViewById(R.id.ads); mAdView.setVisibility(View.GONE); if (!prefsNoAds) { mAdView.loadAd(new AdRequest.Builder().build()); mAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { mAdView.setVisibility(View.VISIBLE); super.onAdLoaded(); } }); } else { findViewById(R.id.cookieconsent).setVisibility(View.GONE); } initAdapter(); }
From source file:com.trigger_context.Main_Service.java
private void takeAction(String mac, InetAddress ip) { noti("comes to ", mac); SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE); Map<String, ?> cond_map = conditions.getAll(); Set<String> key_set = cond_map.keySet(); Main_Service.main_Service.noti(cond_map.toString(), ""); if (key_set.contains("SmsAction")) { String number = conditions.getString("SmsActionNumber", null); String message = conditions.getString("SmsActionMessage", null); try {//from w w w .ja va 2 s . com SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(number, null, message, null, null); noti("Sms Sent To : ", "" + number); } catch (Exception e) { noti("Sms Sending To ", number + "Failed"); } } if (key_set.contains("OpenWebsiteAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Open_Url.class); dialogIntent.putExtra("urlAction", (String) cond_map.get("urlAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("ToggleAction")) { if (key_set.contains("bluetoothAction") && conditions.getBoolean("bluetoothAction", false)) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.enable(); } else if (key_set.contains("bluetoothAction")) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.disable(); } if (key_set.contains("wifiAction") && conditions.getBoolean("wifiAction", false)) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(true); } else if (key_set.contains("wifiAction")) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(false); } } if (key_set.contains("TweetAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Post_Tweet.class); dialogIntent.putExtra("tweetTextAction", (String) cond_map.get("tweetTextAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("EmailAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Email_Client.class); dialogIntent.putExtra("toAction", (String) cond_map.get("toAction")); dialogIntent.putExtra("subjectAction", (String) cond_map.get("subjectAction")); dialogIntent.putExtra("emailMessageAction", (String) cond_map.get("emailMessageAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("RemoteServerCmd")) { String text = conditions.getString("cmd", null); new Thread(new SendData("224.0.0.1", 9876, text)).start(); } // network activities from here. // in all network actions send username first if (key_set.contains("FileTransferAction")) { String path = conditions.getString("filePath", null); SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 1 try { Socket socket = new Socket(ip, COMM_PORT); DataOutputStream out = null; out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(1); sendFile(out, path); noti("Sent " + path + " file to :", getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (key_set.contains("ccfMsgAction")) { String msg = conditions.getString("ccfMsg", null); SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 2 is msg try { Socket socket = new Socket(ip, COMM_PORT); DataOutputStream out = null; out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(2); out.writeUTF(msg); noti("Sent msg : '" + msg + "'", "to : " + getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (key_set.contains("sync")) { SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 3 is sync try { Socket socket = new Socket(ip, COMM_PORT); DataInputStream in = new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(3); senderSync(in, out, Environment.getExternalStorageDirectory().getPath() + "/TriggerSync/"); noti("Synced with:", getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.zhengde163.netguard.ActivitySettings.java
@Override @TargetApi(Build.VERSION_CODES.M)//w w w .ja v a 2 s. c o m public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { Object value = prefs.getAll().get(name); if (value instanceof String && "".equals(value)) prefs.edit().remove(name).apply(); // Dependencies if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("ip6".equals(name)) ServiceSinkhole.reload("changed " + name, this); }
From source file:com.trigger_context.Main_Service.java
@Override public void onCreate() { super.onCreate(); main_Service = this; SharedPreferences users_sp = getSharedPreferences(Main_Service.USERS, MODE_PRIVATE); SharedPreferences data_sp = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); conf_macs = new ArrayList<String>(users_sp.getAll().keySet()); noti(conf_macs.toString(), ""); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(android.net.ConnectivityManager.TYPE_WIFI); Intent ServiceIntent = new Intent(this, Network_Service.class); if (info != null) { if (info.isConnected()) { Main_Service.wifi = true; Network.setWifiOn(true);/*from w w w .j a v a 2 s . c o m*/ Thread z = new Thread(new Network()); z.start(); try { z.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // start service startService(ServiceIntent); } } users_sp.registerOnSharedPreferenceChangeListener(this); data_sp.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // timeout n username can only be added or modified. not removed if (key.equals("username")) { username = sharedPreferences.getString("username", "defUsername"); } else { timeout = sharedPreferences.getLong("timeout", 5 * 60) * 1000; } } }); Log.i(LOG_TAG, "Main_Service-onCreate"); noti("main serv", "started"); }
From source file:com.nsqre.insquare.Utilities.PushNotification.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * Manages how the notification will be shown in the notification bar. * @param message GCM message received.//from w w w. j ava 2 s .com */ private void sendNotification(String message, String squareName, String squareId) { Intent intent = new Intent(this, BottomNavActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); SharedPreferences notificationPreferences = getSharedPreferences("NOTIFICATION_MAP", MODE_PRIVATE); int notificationCount = 0; int squareCount = notificationPreferences.getInt("squareCount", 0); if (squareId.equals(notificationPreferences.getString("actualSquare", ""))) { return; } if (!notificationPreferences.contains(squareId)) { notificationPreferences.edit().putInt("squareCount", squareCount + 1).apply(); } notificationPreferences.edit().putInt(squareId, notificationPreferences.getInt(squareId, 0) + 1).apply(); for (String square : notificationPreferences.getAll().keySet()) { if (!"squareCount".equals(square) && !"actualSquare".equals(square)) { notificationCount += notificationPreferences.getInt(square, 0); } } squareCount = notificationPreferences.getInt("squareCount", 0); Log.d(TAG, notificationPreferences.getAll().toString()); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.nsqre_map_pin_empty_inside); notificationBuilder.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent)); if (squareCount == 1) { SharedPreferences messagePreferences = getSharedPreferences(squareId, MODE_PRIVATE); intent.putExtra("squareId", squareId); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); messagePreferences.edit().putString(String.valueOf(notificationCount), message).commit(); if (messagePreferences.getAll().size() <= 6) { for (int i = 1; i <= messagePreferences.getAll().keySet().size(); i++) { inboxStyle.addLine(messagePreferences.getString(String.valueOf(i), "")); } } else { for (int i = messagePreferences.getAll().size() - 6; i <= messagePreferences.getAll().keySet() .size(); i++) { inboxStyle.addLine(messagePreferences.getString(String.valueOf(i), "")); } } notificationBuilder.setContentTitle(squareName); notificationBuilder.setStyle(inboxStyle.setBigContentTitle(squareName).setSummaryText("inSquare")); notificationBuilder.setContentText( notificationCount > 1 ? "Hai " + notificationCount + " nuovi messaggi" : message); } else { intent.putExtra("map", 0); intent.removeExtra("squareId"); notificationBuilder.setContentTitle("inSquare"); notificationBuilder .setContentText("Hai " + (notificationCount) + " nuovi messaggi in " + squareCount + " piazze"); } notificationBuilder.setAutoCancel(true); notificationBuilder.setSound(defaultSoundUri); notificationBuilder.setVibrate(new long[] { 300, 300, 300, 300, 300 }); notificationBuilder.setLights(Color.RED, 1000, 3000); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_CANCEL_CURRENT); notificationBuilder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); updateSquares("", "", "update"); SharedPreferences mutePreferences = getSharedPreferences("NOTIFICATION_MUTE_MAP", MODE_PRIVATE); if (mutePreferences.contains(squareId)) { String expireDate = mutePreferences.getString(squareId, ""); long myExpireDate = Long.parseLong(expireDate, 10); if (myExpireDate < (new Date().getTime())) { mutePreferences.edit().remove(squareId).apply(); notificationManager.notify(0, notificationBuilder.build()); } } else { notificationManager.notify(0, notificationBuilder.build()); } }
From source file:com.juick.android.ThreadActivity.java
private void updateDraftsButton() { final SharedPreferences drafts = getSharedPreferences("drafts", MODE_PRIVATE); draftsButton.setVisibility(drafts.getAll().size() > 0 && enableDrafts ? View.VISIBLE : View.GONE); }
From source file:org.phillyopen.mytracks.cyclephilly.MainInput.java
/** Called when the activity is first created. */ @Override/* w w w .j ava 2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Firebase.setAndroidContext(this); final Firebase ref = new Firebase("https://cyclephilly.firebaseio.com"); final Firebase phlref = new Firebase("https://phl.firebaseio.com"); // Let's handle some launcher lifecycle issues: // If we're recording or saving right now, jump to the existing activity. // (This handles user who hit BACK button while recording) setContentView(R.layout.main); weatherFont = Typeface.createFromAsset(getAssets(), "cyclephilly.ttf"); weatherText = (TextView) findViewById(R.id.weatherView); weatherText.setTypeface(weatherFont); weatherText.setText(R.string.cloudy); Intent rService = new Intent(this, RecordingService.class); ServiceConnection sc = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { } public void onServiceConnected(ComponentName name, IBinder service) { IRecordService rs = (IRecordService) service; int state = rs.getState(); if (state > RecordingService.STATE_IDLE) { if (state == RecordingService.STATE_FULL) { startActivity(new Intent(MainInput.this, SaveTrip.class)); } else { // RECORDING OR PAUSED: startActivity(new Intent(MainInput.this, RecordingActivity.class)); } MainInput.this.finish(); } else { // Idle. First run? Switch to user prefs screen if there are no prefs stored yet SharedPreferences settings = getSharedPreferences("PREFS", 0); String anon = settings.getString("" + PREF_ANONID, "NADA"); if (settings.getAll().isEmpty()) { showWelcomeDialog(); } else if (anon == "NADA") { showWelcomeDialog(); } // Not first run - set up the list view of saved trips ListView listSavedTrips = (ListView) findViewById(R.id.ListSavedTrips); populateList(listSavedTrips); } MainInput.this.unbindService(this); // race? this says we no longer care } }; // This needs to block until the onServiceConnected (above) completes. // Thus, we can check the recording status before continuing on. bindService(rService, sc, Context.BIND_AUTO_CREATE); // And set up the record button final Button startButton = (Button) findViewById(R.id.ButtonStart); final Intent i = new Intent(this, RecordingActivity.class); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.US); SharedPreferences settings = getSharedPreferences("PREFS", 0); final String anon = settings.getString("" + PREF_ANONID, "NADA"); Firebase weatherRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia"); Firebase tempRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia/currently"); tempRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Object val = dataSnapshot.getValue(); String cardinal = null; TextView tempState = (TextView) findViewById(R.id.temperatureView); // TextView liveTemp = (TextView) findViewById(R.id.warning); String apparentTemp = ((Map) val).get("apparentTemperature").toString(); String windSpeed = ((Map) val).get("windSpeed").toString(); Double windValue = (Double) ((Map) val).get("windSpeed"); Long windBearing = (Long) ((Map) val).get("windBearing"); // liveTemp.setText(" "+apparentTemp.toString()+DEGREE); WindDirection[] windDirections = WindDirection.values(); for (int i = 0; i < windDirections.length; i++) { if (windDirections[i].startDegree < windBearing && windDirections[i].endDegree > windBearing) { //Get Cardinal direction cardinal = windDirections[i].cardinal; } } if (windValue > 4) { tempState.setTextColor(0xFFDC143C); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph. Ride with caution."); } else { tempState.setTextColor(0xFFFFFFFF); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph."); } } @Override public void onCancelled(FirebaseError firebaseError) { } }); connectedListener = ref.getRoot().child(".info/connected").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { boolean connected = (Boolean) dataSnapshot.getValue(); if (connected) { System.out.println("connected " + dataSnapshot.toString()); Firebase cycleRef = new Firebase(FIREBASE_REF + "/" + anon + "/connections"); // cycleRef.setValue(Boolean.TRUE); // cycleRef.onDisconnect().removeValue(); } else { System.out.println("disconnected"); } } @Override public void onCancelled(FirebaseError error) { // No-op } }); weatherRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Object value = snapshot.getValue(); Object hourly = ((Map) value).get("currently"); String alert = ((Map) hourly).get("summary").toString(); // TextView weatherAlert = (TextView) findViewById(R.id.weatherAlert); // weatherAlert.setText(alert); } @Override public void onCancelled(FirebaseError firebaseError) { } }); // Acquire a reference to the system Location Manager // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. mySpot = new LatLng(location.getLatitude(), location.getLongitude()); makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; nearbyStations = (RecyclerView) findViewById(R.id.nearbyStationList); nearbyStations.setLayoutManager(new LinearLayoutManager(getApplicationContext())); //Listener for Indego Changes indegoRef = new Firebase("https://phl.firebaseio.com/indego/kiosks"); indegoRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { //Updates! Add them to indego data list indegoDataList = dataSnapshot; } @Override public void onCancelled(FirebaseError firebaseError) { } }); // Register the listener with the Location Manager to receive location updates indegoGeofireRef = new Firebase("https://phl.firebaseio.com/indego/_geofire"); GeoFire geoFire = new GeoFire(indegoGeofireRef); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); mySpot = myCurrentLocation(); indegoList = new ArrayList<IndegoStation>(); System.out.println("lo: " + mySpot.toString()); GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mySpot.longitude, mySpot.latitude), 0.5); geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { @Override public void onKeyEntered(String key, GeoLocation location) { System.out.println(String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude)); //Create Indego Station object. To-do: check if object exists IndegoStation station = new IndegoStation(); station.kioskId = key; station.location = location; if (indegoDataList != null) { //get latest info from list station.name = (String) indegoDataList.child(key).child("properties").child("name").getValue(); } System.out.println(station.name); indegoList.add(station); //To-do: Add indego station info to RideIndegoAdapter } @Override public void onKeyExited(String key) { } @Override public void onKeyMoved(String key, GeoLocation location) { } @Override public void onGeoQueryReady() { System.out.println("GEO READY :" + indegoList.toString()); indegoAdapter = new RideIndegoAdapter(getApplicationContext(), indegoList); nearbyStations.setAdapter(indegoAdapter); } @Override public void onGeoQueryError(FirebaseError error) { System.out.println("GEO error"); } }); startButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Before we go to record, check GPS status final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } else { startActivity(i); MainInput.this.finish(); } } }); toolbar = (Toolbar) findViewById(R.id.dashboard_bar); toolbar.setTitle("Cycle Philly"); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); }
From source file:org.opensmc.mytracks.cyclesmc.MainInput.java
/** Called when the activity is first created. */ @Override/*from w w w. j av a 2 s. com*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Firebase.setAndroidContext(this); final Firebase ref = new Firebase("https://org.opensmc.mytracks.cyclesmc.firebaseio.com"); final Firebase phlref = new Firebase("https://phl.firebaseio.com"); // Let's handle some launcher lifecycle issues: // If we're recording or saving right now, jump to the existing activity. // (This handles user who hit BACK button while recording) setContentView(R.layout.main); weatherFont = Typeface.createFromAsset(getAssets(), "cyclesmc.ttf"); weatherText = (TextView) findViewById(R.id.weatherView); weatherText.setTypeface(weatherFont); weatherText.setText(R.string.cloudy); Intent rService = new Intent(this, RecordingService.class); ServiceConnection sc = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { } public void onServiceConnected(ComponentName name, IBinder service) { IRecordService rs = (IRecordService) service; int state = rs.getState(); if (state > RecordingService.STATE_IDLE) { if (state == RecordingService.STATE_FULL) { startActivity(new Intent(MainInput.this, SaveTrip.class)); } else { // RECORDING OR PAUSED: startActivity(new Intent(MainInput.this, RecordingActivity.class)); } MainInput.this.finish(); } else { // Idle. First run? Switch to user prefs screen if there are no prefs stored yet SharedPreferences settings = getSharedPreferences("PREFS", 0); String anon = settings.getString("" + PREF_ANONID, "NADA"); if (settings.getAll().isEmpty()) { showWelcomeDialog(); } else if (anon == "NADA") { showWelcomeDialog(); } // Not first run - set up the list view of saved trips ListView listSavedTrips = (ListView) findViewById(R.id.ListSavedTrips); populateList(listSavedTrips); } MainInput.this.unbindService(this); // race? this says we no longer care } }; // This needs to block until the onServiceConnected (above) completes. // Thus, we can check the recording status before continuing on. bindService(rService, sc, Context.BIND_AUTO_CREATE); // And set up the record button final Button startButton = (Button) findViewById(R.id.ButtonStart); final Intent i = new Intent(this, RecordingActivity.class); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.US); SharedPreferences settings = getSharedPreferences("PREFS", 0); final String anon = settings.getString("" + PREF_ANONID, "NADA"); Firebase weatherRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia"); Firebase tempRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia/currently"); tempRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Object val = dataSnapshot.getValue(); String cardinal = null; TextView tempState = (TextView) findViewById(R.id.temperatureView); // TextView liveTemp = (TextView) findViewById(R.id.warning); String apparentTemp = ((Map) val).get("apparentTemperature").toString(); String windSpeed = ((Map) val).get("windSpeed").toString(); Double windValue = (Double) ((Map) val).get("windSpeed"); Long windBearing = (Long) ((Map) val).get("windBearing"); // liveTemp.setText(" "+apparentTemp.toString()+DEGREE); WindDirection[] windDirections = WindDirection.values(); for (int i = 0; i < windDirections.length; i++) { if (windDirections[i].startDegree < windBearing && windDirections[i].endDegree > windBearing) { //Get Cardinal direction cardinal = windDirections[i].cardinal; } } if (windValue > 4) { tempState.setTextColor(0xFFDC143C); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph. Ride with caution."); } else { tempState.setTextColor(0xFFFFFFFF); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph."); } } @Override public void onCancelled(FirebaseError firebaseError) { } }); connectedListener = ref.getRoot().child(".info/connected").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { boolean connected = (Boolean) dataSnapshot.getValue(); if (connected) { System.out.println("connected " + dataSnapshot.toString()); // Firebase cycleRef = new Firebase(FIREBASE_REF+"/"+anon+"/connections"); // cycleRef.setValue(Boolean.TRUE); // cycleRef.onDisconnect().removeValue(); } else { System.out.println("disconnected"); } } @Override public void onCancelled(FirebaseError error) { // No-op } }); weatherRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Object value = snapshot.getValue(); Object hourly = ((Map) value).get("currently"); String alert = ((Map) hourly).get("summary").toString(); // TextView weatherAlert = (TextView) findViewById(R.id.weatherAlert); // weatherAlert.setText(alert); } @Override public void onCancelled(FirebaseError firebaseError) { } }); // Acquire a reference to the system Location Manager // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. mySpot = new LatLng(location.getLatitude(), location.getLongitude()); makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; //nearbyStations = (RecyclerView) findViewById(R.id.nearbyStationList); //nearbyStations.setLayoutManager(new LinearLayoutManager(getApplicationContext())); //Listener for Indego Changes /*indegoRef = new Firebase("https://phl.firebaseio.com/indego/kiosks"); indegoRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { //Updates! Add them to indego data list indegoDataList = dataSnapshot; } @Override public void onCancelled(FirebaseError firebaseError) { } });*/ // Register the listener with the Location Manager to receive location updates //indegoGeofireRef = new Firebase("https://phl.firebaseio.com/indego/_geofire"); //GeoFire geoFire = new GeoFire(indegoGeofireRef); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); mySpot = myCurrentLocation(); //indegoList = new ArrayList<IndegoStation>(); System.out.println("lo: " + mySpot.toString()); /* GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mySpot.latitude,mySpot.longitude), 0.5); geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { @Override public void onKeyEntered(String key, GeoLocation location) { System.out.println(String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude)); //Create Indego Station object. To-do: check if object exists // IndegoStation station = new IndegoStation(); //station.kioskId = key; //station.location = location; /* if(indegoDataList != null){ //get latest info from list station.name = (String) indegoDataList.child(key).child("properties").child("name").getValue(); } System.out.println(station.name); //indegoList.add(station); //To-do: Add indego station info to RideIndegoAdapter } @Override public void onKeyExited(String key) { } @Override public void onKeyMoved(String key, GeoLocation location) { } @Override /* public void onGeoQueryReady() { //System.out.println("GEO READY :"+indegoList.toString()); // indegoAdapter = new RideIndegoAdapter(getApplicationContext(),indegoList); //nearbyStations.setAdapter(indegoAdapter); } @Override public void onGeoQueryError(FirebaseError error) { System.out.println("GEO error"); } });*/ startButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Before we go to record, check GPS status final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } else { startActivity(i); MainInput.this.finish(); } } }); toolbar = (Toolbar) findViewById(R.id.dashboard_bar); toolbar.setTitle(getString(R.string.app_name)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); }
From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java
private void importNiLSFPPreferences() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (!prefs.getBoolean("prefs_imported", false)) { Context nilsfpCtx = null; try {//from w w w .jav a 2 s . c om nilsfpCtx = createPackageContext("com.roymam.android.nilsplus", 0); SharedPreferences nilsfpPrefs = nilsfpCtx.getSharedPreferences("shared_preferences", Context.MODE_WORLD_READABLE); // copy global_settings Map<String, ?> map = nilsfpPrefs.getAll(); for (String key : map.keySet()) { Object x = map.get(key); if (x instanceof Boolean) prefs.edit().putBoolean(key, (Boolean) x).commit(); else if (x instanceof Integer) prefs.edit().putInt(key, (Integer) x).commit(); else if (x instanceof Float) prefs.edit().putFloat(key, (Float) x).commit(); else if (x instanceof Long) prefs.edit().putLong(key, (Long) x).commit(); else if (x instanceof String) prefs.edit().putString(key, (String) x).commit(); } prefs.edit().putBoolean("prefs_imported", true).commit(); // handling old lock screen detection values if (prefs.getString(SettingsManager.LOCKSCREEN_APP, SettingsManager.DEFAULT_LOCKSCREEN_APP) .equals("auto")) { prefs.edit() .putString(SettingsManager.LOCKSCREEN_APP, prefs.getString("lockscreenapp_auto", SettingsManager.DEFAULT_LOCKSCREEN_APP)) .commit(); } if (prefs.getString(SettingsManager.LOCKSCREEN_APP, SettingsManager.DEFAULT_LOCKSCREEN_APP) .equals("android")) { prefs.edit().putString(SettingsManager.LOCKSCREEN_APP, SettingsManager.DEFAULT_LOCKSCREEN_APP) .commit(); } Toast.makeText(getApplicationContext(), "Preferences and license information has been imported successfully from NiLS Floating Panel", Toast.LENGTH_LONG).show(); } catch (PackageManager.NameNotFoundException e) { // NiLS FP not available - do not do anything } } }
From source file:eu.faircode.adblocker.ActivityMain.java
@Override public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name)); if ("enabled".equals(name)) { // Get enabled boolean enabled = prefs.getBoolean(name, false); // Display disabled warning TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE); // Check switch state SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView() .findViewById(R.id.swEnabled); if (swEnabled.isChecked() != enabled) swEnabled.setChecked(enabled); } else if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name) || "whitelist_other".equals(name) || "screen_other".equals(name) || "whitelist_roaming".equals(name) || "show_user".equals(name) || "show_system".equals(name) || "show_nointernet".equals(name) || "show_disabled".equals(name) || "sort".equals(name) || "imported".equals(name)) updateApplicationList(null);/*from ww w.j a v a 2 s . c o m*/ else if ("manage_system".equals(name)) { invalidateOptionsMenu(); updateApplicationList(null); } else if ("theme".equals(name) || "dark_theme".equals(name)) recreate(); }