Madhu Nandan

Ranch Hand
+ Follow
since Dec 16, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Madhu Nandan

Hi,

I have a strange problem. In the strings.xml file of my project, the first line is <?xml version="1.0" encoding="utf-8"?> But every time I close and open the file, the first line changes automatically to <?xml version="1.0" encoding="utf-8" standalone="no"?> and this I guess is not allowing me to run the project on real phone (it runs on emulator). Though I remove standalone="no" and save the file, it appears again when I open the file.

What is the reason for this and how to overcome this?

Thank you for your time.

Cheers,
Madhu
13 years ago
Hi,

I tried using textview.setTranslationY(float) to change the y-coordinate of the textview but it does not seem to work. textview.setTop() seems to do the same function but the documentation says this method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout. I use textview.getTranslationY() to get the y-coordinate.

How can I set the y-coordinate of textview? If what I am doing above is wrong, kindly suggest an alternative way. Maybe there is another method to set y-coordinate which I have not found yet!

My situation: I have a textview whose height should change based on some value received. If I use textview.setHeight(int), the height increases from top to bottom. I want it to increase from bottom to top. So I change the y-coordinate of the textview every time I set it's height.

Cheers,
Madhu
13 years ago
down vote favorite


Hello,

I have a layout- an ImageView with TextViews on its top and bottom. Now I want to add a rectangular vertical bar (to the left or right of this setup) which changes its height (and also colour) from bottom to top. At the moment, I have used a TextView which increases height from top to bottom (I couldn't make it the other way round).

I don't know how to use graphics to draw a rectangle and then add that rectangle to the above xml layout (with an ImageView and 2 TextViews).

Please suggest a way to do this-either to increase the height of TextView from bottom to top or a different better way than what I am following.

Thank you for your time.

Cheers,

Madhu
13 years ago
Hello,

I have modified the main.xml to include an ImageView and two text views-one each on top and bottom of the ImageView. I set the image and the text to be displayed. Now I want to add another vertical bar to the left or right of this setup (one image view and two text views) and I want to programmatically increase or decrease the height of this vertical bar. I tried using a TextView and set it's height with TextView.setHeight(int variable) but this does not work and I get an error.

Please tell me if my approach is right (I guess it is not) or kindly inform me of any better way of doing this.

Cheers,
Madhu

main.xml



Main activity:

13 years ago

Daniel Trebbien wrote:Does actionOnData ever get called a second time?



Of course... Every time there is a new message read in the client (thread), it is passed to the parser and after parsing, the actionOnData is called from the parser.
13 years ago
Hello,

I have the following main class and thread-TCP Client. The client runs in a loop, receives messages and passes it to main class. In the main class, I parse the message and try to show different images based on the name and value of the message received. Ex: shiftDirection1 name: shiftDirection & value: 1

But I can show only the image corresponding to the first received message and the images corresponding to the remaining received messages cannot be displayed.

Please go through the code below and kindly suggest the mistake/problem and alternative ways.

Thank you for your time and efforts.

Madhu

main class:



Only the image corresponding to the first if case is displayed. The program control enters the second if loop but does not show the image there.

Interface:



Thread (TCP Client):

13 years ago
Hello,

Please go through the code below.

String[] Info contains 2 values like this: shiftDirection & 1 or currGear & 5 and similar pairs. If I receive shiftDirection & 0, I should display the previously received value of currGear. So I create PresentGear as a global variable and when currGear is received, I store it's value in PresentGear. Then when I receive shiftDirection & 0, I try to display PresentGear but nothing gets displayed. PresentGear is assigned no value. It would be very helpful if someone could suggest why this is happening or if my approach is wrong, kindly suggest an alternative way.

Cheers,
Madhu

13 years ago

Monu Tripathi wrote:

check for new message every 100 ms


You might want to increase the polling interval for one thing.



Thank you for the response. Could you suggest how to increase the polling interval? I can think of TimerTask. But I am not sure where to use this TimerTask in the client thread.
13 years ago
Hello,

Firstly, I have been greatly helped by this forum. Now my problem this time.

I have a TCP client running in Android phone. It connects and receives data from a windows application. Once I receive a message, I parse it and I try to display an image. I have to keep checking for new messages from this windows app.

The client thread keeps running. When a message is received, I pass it to the main activity, parse it but I am not able to display the image. I want to make the client check for new message every 100 ms. At the moment, the LogCat gets flooded as the thread keeps running and I am not able to really see the contents of LogCat.

Basically I want to run the client, keep checking for new messages every 100 ms, when a new message is there, pass it to the main activity, parse it and display an image. Please go through the code below and suggest any corrections or a better approach if necessary.

Cheers,
Madhu

The client code is below.

Main activity:



Interface:



Client thread:

13 years ago

Swastik Dey wrote:I hope this time it solves your purpose





Hi Swastik,

When I used this code for client, it works alright. The server was another Java app running in Eclipse. When I tried to receive message from my colleague's app (developed in Rhapsody and I think C++), I receive the message only after his app is closed and not while his app is running and sending messages. Do you have any idea why this happens?

My situation: I run the client code on Android phone (HTC Desire). If the server is a java app running in Eclipse, then I can receive data sent by this server on my Android phone. When I try to receive data from another app (say abc, which can be considered to be acting as server), then I can connect to the app but cannot receive any data. Instead of connecting the real phone to abc, if I try connecting the client from emulator, then I can receive the data sent from abc only after abc is closed, not when it is running and sending data. Real phone & abc doesn't work-connection is established but no data

The java server is like this:

13 years ago

Swastik Dey wrote:I hope this time it solves your purpose





Hi Swastik,

When I run the application (with the above code), how can I stop the app? Once I start it, the app keeps running all the time, phone kind of hangs and is not possible to stop it. Only way is I have to keep pressing "Home" button on phone many times and then got o Settings-App-Manage app and stop this app by pressing "Force Stop". Could you suggest a way out of this?

Regards,
Madhu
13 years ago

Swastik Dey wrote:I hope this time it solves your purpose





Hi Swastik,

I tried the above without the changed SendServer. It helped a lot. Thank you.

The server is the app in the car PC which gets messages with updated values every 100 milliseconds and sends those messages to the Android app.

So when I receive more than one message and I have to display an image or a text info for each message received, it hangs. I am trying to incorporate some things like this: after a particular message is received, I have to kind of freeze all other execution so that I can show some image or info related to the received message and after that resume all the execution.

Thanks a lot again.
13 years ago

Swastik Dey wrote:Probably you are right. Another point is in the pull from server approach code maintainability will be better and overhead on server is less, because it will send a response only when it gets a request.



I will explain my situation. The Android app will run and communicate with the application running in the car PC. And the messages from the car PC are sent randomly based on how the car is being driven. For example, shiftDirection is a message which will be set to 1 and sent when the RPM is high enough and the driver has not shifted to the next gear. The Android app has to just respond to the messages it receives and do actions like show an image or display driver assistance info, etc. So the Android app really has no control over the messages it can receive. So will the pull approach really work here?
13 years ago

Swastik Dey wrote:Do you find anything wrong with the approach that I told you, i.e. instead of push to device go for pull from device.



About pull from server, I feel it is a good approach. Will try and inform you.

Regarding current situation, I think the TimerTask is running every second and each time it runs, it tries to connect on a different socket. The port number is fixed (1200 in this case) but the socket number keeps changing every time it connects. What I need to do is connect just once, then keep looking for new incoming messages. I have to run the part which looks for new incoming messages as/in a TimerTask. I think this is the cause of the problem. What do you feel?
13 years ago