AguaClara / post.bluetooth-DEPRECATED

The bluetooth widget for connecting POST with the turbidimeter.
0 stars 0 forks source link

UI help #6

Closed danelimjoco closed 7 years ago

danelimjoco commented 7 years ago

Hi @ethan92429!

Today I've been trying to learn more about UI development in java, starting with trying to understand the code you have for the buttons. In the "onCreate" method, you have the following:

Button openButton = (Button) findViewById(R.id.open); Button sendButton = (Button) findViewById(R.id.send); Button closeButton = (Button) findViewById(R.id.close); myLabel = (TextView) findViewById(R.id.label); myTextbox = (EditText) findViewById(R.id.entry);

I'm trying to use documentation to understand what you're doing here and it looks like you're giving the name openButton, sendButton, and closeButton to the buttons, but I don't get where you define them. According to documentation, defining a button should look something like this:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    ... />

It seems like a lot of the layout stuff is better done in xml rather than java, but I don't even know where to find the files for these. In the "res" folder, there's a file called activity_main.xml that looks like something i can work with, but I'm still very unfamiliar with how it works. I'd like to first understand how you got the buttons to end up at the bottom of the screen. Let me know, and I'll likely have many more questions for you as I keep learning new things.

Also not sure if you saw but the turbidimeter will arrive here Wednesday morning, so I'll be asking you a lot of stuff about that as well. I think it would be really helpful if we had more one-on-one Skype sessions.

Thanks in advance for bearing with me!

danelimjoco commented 7 years ago

@ethan92429

Update: I was able to click on the "text" tab in the activity_main.xml file and I can see now where you defined the TextView and three Buttons. This seems like the file I should be messing with in order to define whatever I want to include (tutorials for how to set up BT Turbidimeter (with images?), pop-up messages for when the turbidimeter isn't paired properly, and whatever else you can suggest). I'll try to work now on a simple error message that should appear since I can't connect to anything right now using Dialogs.

danelimjoco commented 7 years ago

@ethan92429

Update #2: I am able to make a Dialog show up once the app starts! I'm trying to put dialog.show() in the catch section for each of the buttons, but instead of displaying my error message, it displays an error message saying "Sorry, Unfortunately the POST_BT_Turbidimeter_Widget has stopped" and shuts down the whole app. Any ideas on where that error message is defined (I don't see it defined in the activity_main.xml file) and how I can prevent the app from just closing and show my message instead?

danelimjoco commented 7 years ago

@ethan92429 Update 3: I was able to avoid the "Sorry, Unfortunately the POST_BT_Turbidimeter_Widget has stopped" message and display my own message by making the catch statement catch "Exception" instead of "IOException", but I'm not sure if this has any consequences. If it does, let me know.

eak24 commented 7 years ago

@danelimjoco thanks so much for the update! Sorry for the delay in responding. You are right with the second take... each activity or fragment has its own xml defined 'view' in the res-layout folder. What I'm doing in that code is getting a handle on the view item. Once I have that handle (an object in Java that is related to the view), I'm able to detect changes (when the touch goes over or clicks) and make changes programmatically. Using handles that are connected to xml defined ui is called static ui, whereas changing ui elements dynamically using code is called programmatic ui. This will give you more info: https://developer.android.com/training/basics/firstapp/building-ui.html If you need to take some time and complete the tutorial during POST time, you absolutely should! It's important to have a well rounded understanding of how to make a UI. Let me know how else I can help!

danelimjoco commented 7 years ago

Hi @ethan92429

Since I already have the device working pretty well from last time, I was thinking of working more on UI today. I was thinking about the tutorial you mentioned if bluetooth isn't connected correctly, and I'm thinking if they hit "Open" and it fails, telling them to go to settings, pair the device named "HC-06", and try hitting "Open" again. Instead of putting all these step-by-step directions in multiple page views, wouldn't it be easier for them to see it all in one error message with arrows? Let me know what you think and if you have more suggestions.

Also, should I remove the close and send button since I'm forcing the BT app to close before sending the value anyway? Thanks!

eak24 commented 7 years ago

@danelimjoco is there any way to have the app connect automatically if the bt meter is on? So that the user can simply turn on the meter and not have to worry about connecting it? Then only if there is a problem (like it wasn't turned on) you can make an error message that says to please turn the meter on.

I'm not sure what you mean by the second question... IMO there should only be an 'accept' button and a nice big display of the read value. The user should be able to click the meter and read the turbidity any number of times, and that value on the screen should update accordingly. When they like it, they hit accept and the app closes and the field is populated in ODK. Just a proposal, please make any changes you think necessary!

eak24 commented 7 years ago

I think this was all figured out so I am closing this issue.