Nest api multiple thermostat or smoke alarms - java

Im working with nest API to build an Android app.
Im connecting multiple Thermostats to one nest account. Next, I add Thermostat listeners. I can print out everything i would like to about the thermostats (temp, label, target, etc) but i can not figure out how to dynamically respond only to a specific thermostat. Each thermostat gets an index number, but the order of index number is random. does anyone know how one would set the order of thermostats indexes?
for example, if thermostat in the living room is triggered, do something specific in the living room. but how would i know the corresponding index to each device?

Like joseph-evans mentioned the device_id is static to you as a developer and wont change unless the devices is completely deleted from the Nest account and re-paired. Other developers will see a different ID, but for your sake you can always uniquely identify the device by its device_id

Related

get and display user location postcode in edittext on location button click like in just eat app

I am trying to do something like the picture below of just eat app using android studio. I am yet to start building my app but I would like to know how to implement getting user postcode and showing it in the edittext field. Any help will do.
![img1] https://drive.google.com/file/d/186D7fjSvJOhEQdep_fU4dnkUGV-Yi8Ya/view?usp=drivesdk
If you are looking to allow users to identify their post code from their address you might find the Post Office Adress File (PAF) useful although this is a paid for service.
https://en.wikipedia.org/wiki/Postcode_Address_File
https://www.royalmail.com/business/services/marketing/data-optimisation/paf
Some developers may be able to get free sample data for developing their application
https://www.poweredbypaf.com/access-to-free-paf-sample-data/
If you want to allow users to graphically find their postcode e.g. by clicking on a map you would need a map which returns a National Grid Reference and then use Codepoint data (https://digimap.edina.ac.uk/webhelp/os/data_information/os_products/supporting/codepoint_guidance.htm) which is also (an expensive) paid for service to find the nearest postcode co-ordinate using some data structure e.g. quadtree. This will not work correctly in all cases as post code boundaries are not always convex.
Hope that helps

java ldap - get info is something changes in to AD

I'm making a project with java spring where i do specific searches to the content of some attributes from a user or ad group. Also i write some text input to specific attributes.
Now i want to go a little but futher ..
The idea is that i do an open search on a specific AD group of users. When in this group an attributes or something else from a user changes, then the AD must send a message to my java program or something to tell me "attention user x has changed".
If i know that, i can do a new search to look if the attributes has changed of that user.
I know that i can solve this to do every time a search on the timestamp of the users in this AD group .. But it is not the perfect solution. Because then i must do everytime searches to every timestamp. And if there are for example 5000 users in this group. And i start with user 1 and user 4000 has changed yeah .. then it wil take a minut or something until i know that user 4000 has changed.
So i want a real time search thing.
Can you help me with this ? Can you put me into a direction that i can search futher on the web to find a solution or something. Or is this just not possible ?
Thanks a lot
Active Directory does not have a push notification feature, so this is not possible to do. You will need to search periodically to find the accounts you want.
You can, however, change your criteria to only find the accounts you want. The whenChanged attributes has the date the account was last changed. You can make a query to ask for members of that group, which have recently changed.
For example:
(&(objectClass=User)(whenChanged>=20190108000000.0Z)(memberOf=CN=mygroup,OU=Groups,DC=domain,DC=com))
A description of the date format used with whenChanged is here.
The memberOf condition should match the distinguishedName of the group. If the group has other groups inside it and you want to find members of those too, then you can do a recursive search:
(&(objectClass=User)(whenChanged>=20190108000000.0Z)(memberOf:1.2.840.113556.1.4.1941:=CN=mygroup,OU=Groups,DC=domain,DC=com))
That crazy number is called LDAP_MATCHING_RULE_IN_CHAIN and described here.

How can I keep track of a "like" system on android?

I am currently making an android app for a friend who is a photographer where he will display his images in a RecyclerView. We would like to have sort of like a "like" feature where they can like his pictures. My question is, how would I keep track of the "likes"? What I mean is, how can I make it so that if someone already liked it, they cannot exit the app, come back and like it again? I thought about adding a +1 every time there was a like to the image properties in a database, but how can I keep them from exiting the app, coming back, and liking it again? TIA!
your problem is just a matter of identity. To achieve your goal, you should have a way to identify every piece of the pictures and each of the person who will give up-votes to these pictures.
If you can identify different pictures and different users, you can achieve your goal by either of the following ways:
For each of the pictures store all the users that have liked it. And every time a user want to like a picture, you should check whether he is in this collection or not. Only add the identity of the user to this collection if he is not in this set which means he did not like this picture before
Or you can store all the pictures that are liked by the user.
Which way is better depends on your other use cases.
To identify your pictures you can just assign a distinct name for each of the picture.
So you can see the key problem it how to identify your users.
Since you do not provide a detailed use case of the like action, I will describe some general ideas.
If you have a server
If the user must login, you can identify your users by their login id
If your user do not need to login, you can use some other information to identify your user for example their device id, MAC address or other device-specific indentity.
If you do not have a server, then how can you identify all the users that use the same device? The only way I can come up with is that, you must implement a local user system and ask the user to log in before they want to like a photo.
If you have so signing in users my guess is that you can't. You could save on a hidden file on the device the ids of the photos the device "liked" but this can be easily deleted if the user deletes the apps cache files or uninstall/reinstall.
Not an android expert here, just mho
With login:
In your Database there are "User", "Image" and "User_like_image"
You just have to check if this user didnt already upvoted the image
without login:
You locally store the ID of every images he upvoted
A rough idea: with each item that can be liked store a list of ids that liked it on the server. Your like count is equals to the list length.
On each device generate a random device id token (UUID.randomUUID() is always a good candidate), persist it locally on the device (e.g. in SharedPreferences - wiping the app data will kill it but that can't be solved reliably) and send it to the server with each request.
The server can now
tell you whether you already liked an image which is nice to see on the device and
reject multiple likes from the same device
A simpler approach: store locally in e.g. SharedPreferences that you liked the item. Then behave nicely and don't send another like request to your server backend when you see that you already did. Can be abused because it relies no the client software to be nice but I doubt a small photographer app needs to care too much about that.
A more elaborate approach: require user accounts. That works accross devices and persists through app uninstalls. People that go far enough to create multiple accounts to vote multiple times can't be stopped anyways. The big downside is that people will most likely not want to have another account just to like some photos. Would not recommend if avoidable.
What I did to avoid having people like the same item twice was:
Have 2 states with the same button. If you clicked on "like" the button state changes to "Remove Like" Save the state of the button in shared prefs and check the state before a click is given.
Example:
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String ButtonText = button.getText().toString();
if(ButtonText.equals("Like"){
//code for Like
button.setText("Remove Like");
}
else{
//code for remove Like
button.setText("Like");
}
}
});

How/Where to implement onItemClick handlers with several fragments

I am currently a student taking a Mobile Device Applications development class and am getting stuck on my final project, an Address Book style app. I have used the example from our book (Dietel's Android for Programmers An App-Driver Approach, Volume 1, Second Edition) as the basis and have been editing code from there. The biggest thing I want to change/enable is to allow the user to select different fields within the contact (address, email, etc) and pass an Intent that will open Maps when address is selected, eMail when email is selected and so on. Where I am lost is where to place my listener and declare it. Our book and subsequent searches are not really clearing this up at all. I understand the onItemClick call, but am not sure where to place it, within MainActivity.java or the DetailsFragment.java, which is all the code to handle anything that happens when the contact is open and displayed. I feel like I can put it all within the DetailsFragment.java but have a nagging suspicion that I am missing something. I have not had the time to edit and test this yet as I am actually heading out for work in a minute but I thought I could maybe get a better understanding or maybe even better links to read to learn from as my Google search doesnt seem to address what I am looking for. Also, not sure if it matters or not, but I am not using a ListView at all and everything I find tries to force a ListView use. Thank you guys for your help/consideration and time.

Java identifying more than 2 monitors

I am developing an Java swing based application which will 3 distinct main JFrames and each one of these will have to be displayed on one of the three display-monitors present in the system. Moreover application is going to have capability to alertif a particular display-monitor gone disconnected or reconnecetd.
Each main-JFrame must be displayed on a specific display-screen. This is due to the place where these monitors are going to be located. More like a point of sale scenario where one monitor can show things for sale-person and other for client and other for a security person.
Now the main issue is how to know which monitor is which. I solved this issue by getting serial-no of each monitor by calling a VBScript from within Java.
But still another problem is how map serial-no information of the monitor in Java. In Java what I can get corresponding to each monitor is a java.awt.GraphicsDevice instance and I have no idea how I can map serial-no information to this as the only way to have these instances of java.awt.GraphicsDevice is GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() and this function does not ensure that it will return the devices in a sepecific sequence, each time the function is called.
Thanking in anticipation
Java supports multiple monitors via a GraphicsEnvironment and GraphicsDevice objects. Check the GraphicsDevice javadoc for more info.
Does the GraphicsDevice.getIDString() method give you a stable value that you can compare against the serial numbers? If so, you can write all identified serial numbers to a property file, and do a comparison each time your program starts (if the ID isn't already the serial num). This property file could also store the position of each display (left, center, right or top, middle, bottom, etc)
If you cannot determine the correspondance between the id and the serial number, you could trigger a 'display setup routine' whenever you see an display id that is not in your properties file.
This routine would prompt the user to confirm the display model number and enter the position of each display (consider the display orientation settings in Win,OS X, Linux etc). If you can draw widgets to a specific display, you should be able to collect this information. Also, if the user rearranges the physical position of their displays (perhaps swapping the position of two displays), then they could manually execute this routine.

Categories

Resources