Decimal to int - Java for Android App Development

I'm try to create a app to track my reps sales but I can't figure out how to get int to use 0.0
example
int points;
points = 0;
This works but how would I get it to register 0.0 instead 0
Thanks for your help. I'm still kinda new at this.

What's about this?
Code:
int points;
points = (int) 0.0;
This will cut off all decimals. If you want to have the decimals, use double instead of int.

cdbaugher said:
I'm try to create a app to track my reps sales but I can't figure out how to get int to use 0.0
example
int points;
points = 0;
This works but how would I get it to register 0.0 instead 0
Thanks for your help. I'm still kinda new at this.
Click to expand...
Click to collapse
An int is an integer (so, no fractional part)
For a floating point number, you'll need something else.
float is one option
Code:
float points = 0.0f;
This may be worth reading.

cdbaugher said:
I'm try to create a app to track my reps sales but I can't figure out how to get int to use 0.0
example
int points;
points = 0;
This works but how would I get it to register 0.0 instead 0
Thanks for your help. I'm still kinda new at this.
Click to expand...
Click to collapse
Use Double, it can store the decimal values in it. Int cannot store the decimal values.

use double instead of float...that will give you 0.0 instead of 0...

I say 0 is exactly the same like 0.0
But you can change the look when turn it to string:
String.format(...)
Regards

coolbud012 said:
use double instead of float...that will give you 0.0 instead of 0...
Click to expand...
Click to collapse
double and float are both floating point representations (64 bit vs 32 bit)

Related

RIL

XDA Developers,
Years ago I downloaded the RIL .dll and API from this site. Then it was only half complete and I had to patch it my self.
I am sure development has been completed since then.
Can anybody tell me if RIL is still maintained by this site? In which case, where can I get it?
Specifically I need signal quality on XDA II upwards. If anybody can help me?
Kind Regards,
Ben
After posting, my text RIL was shown with a link to most of the information.
There is one think I can't understand. The stucture returned as as follows:
int nMinSignalStrength; // @field TBD
int nMaxSignalStrength; // @field TBD
int nLowSignalStrength; // @field TBD
int nHighSignalStrength; // @field TBD
Which have the values (On XDA IIs) of -113, -51, -110, -60
Would any member know what the meaning of these values is?
I have then tried to convert the quality to a percentage. But the percentage always reads way to high, or zero.
My guess is that these are DB and therefore logarithmic. Would any member know how to convert to a linar scale?
My guess is something like: log10(n / 3) where n is any of the above or retuned figure.
Any ideas would be very useful!
Regards, Ben.
Hi,
Code:
HRESULT RIL_GetSignalQuality(
HRIL hRil // @parm handle to RIL instance returned by <f RIL_Initialize>
);
returns the following structure:
Code:
typedef struct rilsignalquality_tag {
DWORD cbSize; // @field structure size in bytes
DWORD dwParams; // @field indicates valid parameters
int nSignalStrength; // @field TBD
int nMinSignalStrength; // @field TBD
int nMaxSignalStrength; // @field TBD
DWORD dwBitErrorRate; // @field bit error rate in 1/100 of a percent
int nLowSignalStrength; // @field TBD
int nHighSignalStrength; // @field TBD
} RILSIGNALQUALITY, *LPRILSIGNALQUALITY;
Why don't you just use nSignalStrength? Sounds pretty simple and linear to me? Nothing to calculate...
In trying to make my posting simple. I think I forgot to clarify my problem
First is the problem that the nSignalStrength falls between two values.
But there are two fields it can fall between:
nMinSignalStrength <= nSignalStrength <= nMaxSignalStrength
nLowSignalStrength <= nSignalStrength <= nHighSignalStrength
Which one should be used? Why are there two?
Secondly, I want to show a percentage result between one of the above. But these figures are, I belive, Decibels (BD). Each 3 DB = a doubling of the value. So 1 = 10%, 4 = 20%, 7 = 40% etc...
Therefore a liniar percent placement of nSignalStrengh tells me nothing. Most values are close to Max, and then suddenly zero.
My math is a little rusty I was hoping somebody may have a nice function for returning the linear range from the logarithmic rageā€¦.
Thanks again to any members who can offer some help
Ben
Hmm... but what if min and max are just values currently encountered in your local cell? When you move to another cell you may receive different min/max values. Or maybe these are the values of the farest and nearest cell? I don't know either, but your explanation of min/max sounds worse to me than does mine...
This could be correct. The values I have are on my XDA IIs using O2 are:
Min -113
Low -110
High -60
Max -51
Therefore:
Min < Low < nSignalStrength < High < Max
So I am using Low = 0% and High = 100%. But this returnes figures of above 50% when signal is quite low.
I think the linear conversion is exp(value / 3)
Therefore percent is:
percent = (exp(nSignalStrength / 3) - exp(Low / 3)) / (exp(high / 3) - exp(Low / 3)) * 100;
Which seems to give better figures. But I am not sure how accurate it is..
Any experts on signal quality out there, I'd love to hear from them!
Ben
If anybody is following this thread, this *seems* to return a good percentage for signal quality. I am not sure of the quality or accuracy. But it works
static double dValue, dMax;
dValue = (int)data->nSignalStrength; // (int) to convert twos complement signed integer correctly.
dMax = (int)data->nHighSignalStrength; // (int) to convert twos complement signed integer correctly.
dValue -= (int)data->nLowSignalStrength;
dMax -= (int)data->nLowSignalStrength;
dValue = pow(dValue / -3.0, 2);
dMax = pow(dMax / -3.0, 2);
dValue /= dMax;
dValue *= 100;
if (dValue > 100) dValue = 100; // never
if (dValue < 0) dValue = 0; // never
Regards,
Ben
Hi there, i've been following this thread with interest I have a very limited knowlege of C++ but not even on the PPC.
Would you mind attaching or even PMing your cpp so i could possibly learn more ?
I find i learn more by examples, and am quite interested in making an application that can disable the radio then re-enable it after a set ammount of time (so i can swap between sims, i have a dual sim adapter)
Best thing to do is follow the sample code supplied by these nice gues from xda-developers, by clicking on this RIL link.
BUT replace the ril.h in the .zip archive with the ril.h you will find from the link.
(nb: if the author of this .zip archive is reading, it's way out of date to the ril.h on this site. ps, hows the ril development going?)
If you get the sample code working, this will give you some idea of what is possible. Your options may not be possible. But look at the ril.h and the functions listed. If one of them does what you want, give it a go.
Regards,
Ben

Simulate Button Click

Hi,
I am trying to simulate a PictureBox.Click event. I have searched these forums and the ones on MSDN with many different combinations of search terms.
However I cannot find anything!
Basically what I am trying to achieve is to fire the picturebox's click event from within my code. What I have read so far seems to indicate that I need to make a call to SendMessage (COM interop?) to actually make windows perform the click.
This is for the compact framework version 1.0.
Any help you can give would be great because this is all very new to me, I'm a web application developer by trade so i'm a fish out of water on this one!
OK, the other method that I am investigating is the use of the mouse_event as demonstrated in this article by Daniel Moth.
However I am struggling to find the namespace Win32Api anywhere in the framework so I'm struggling with that also.
*Update*
I have been able to simulate a click using mouse_event in a call to the coredll using the following code:
Code:
[DllImport("coredll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("coredll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
bool tempVal = SetCursorPos(x, y);
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
however I have one outstanding problem (that I know of!).
I am struggling to capture the corrext X and Y co-ordinates of the control. I have tried many different methods and they all return values of 0 for both axis.
How do you guys do it?
Many Thanks
I haven't answered till now since I don't know .NET
But since you found your way to using native APIs I think I can help you.
This is how I would do it in C/C++:
Code:
RECT wndRect; //this is a structure that contains window top, left, bottom and right coordinates.
GetWindowRect(FindWind(L"[I]window class[/I]", L"[I]window name[/I]"), &wndRect);
x = wndRect.left + 1; //add 1 to window position to make sure the click is inside
y = wndRect.top + 1;
GetWindowRect returns the window position in screen coordinates for top left and bottom right corners.
For FindWindow to work you need to know the class and name of the window you want to find. You can find them using a utility called SPY++ which comes with any Microsoft C++ compiler.
The class is window type (so it will probably be something like 'PictureBox' or 'Image') and window name is most likely blank.
Hope this helps.
Thanks fo your help
I don't know if your code would have done the trick or not but I managed to work my way through the different class definitions to find what i needed.
Code:
int x = selectedButton.PointToScreen(selectedButton.Bounds.Location).X + 2;
int y = selectedButton.PointToScreen(selectedButton.Bounds.Location).Y + 2;
This still doesn't work but I really don't have time to work out why, all I know is that the call to SetCursorPos() returns false. I know the mouse_event code works because if I position the cursor over the Start button it opens the menu.
Time is of an essence so for now I'm just going to have to drop this and pray that I have time to finish this when towards the end of my project.
/me thinks writing my first Mobile 5.0 application in 4 days (I'm a web application developer by trade) was bad planning on the management's fault anyway
Thanks for your input though
use this method signature:
[DllImport("coredll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
int instead of uint or long.
For me it worked.

[Q] How to get screen dimensions

I created some custom elements and I want to programmatically place them to the upper right corner (n pixels from the top edge and m pixels from the right edge) therefore I need to get the screen width and screen height and then set position:
int px = screenWidth - m;
int py = screenWidth - n;
Does anyone know how to get screenWidth and screenHeight in the main Activity?
emerals stream said:
I created some custom elements and I want to programmatically place them to the upper right corner (n pixels from the top edge and m pixels from the right edge) therefore I need to get the screen width and screen height and then set position:
int px = screenWidth - m;
int py = screenWidth - n;
Does anyone know how to get screenWidth and screenHeight in the main Activity?
Click to expand...
Click to collapse
Try google it
http://stackoverflow.com/questions/1016896/how-to-get-screen-dimensions
Try something like this
Code:
Point size = new Point();
WindowManager wManager = getWindowManager();
w.getDefaultDisplay().getSize(size);
(int)screenWidth = size.x;
(int)screenHeight = size.y;
Noted to self thrice via tapatalk
...or to use DisplayMetrics
Code:
DisplayMetrics dm = this.getContext().getResources().getDisplayMetrics();
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels

[Q] TableLayout columns equal width

Hello,
I want columns of equal width in a TableLayout, like this: http://androidadvice.blogspot.co.at/2010/10/tablelayout-columns-equal-width.html
but programmatically..
I create TextView's and add them to a TableRow, then I add the row to a TableLayout.
When I do the following:
Code:
tv.setLayoutParams(new TableLayout.LayoutParams(0, TableLayout.LayoutParams.WRAP_CONTENT, 1f));
the TextView's aren't visible.
How should I do that?
Anyone?
Did you set anything to the TextView? If you use this for eg:-
TextView txtview = (TextView) findbyViewId(r.id.txtview);
Then set it to
txtview.setText("Awesome");
Sent from my Nexus 4 using XDA Premium 4 mobile app
That's the code:
Code:
table = (TableLayout) findViewById(R.id.timetable_tablelayout);
for (int i2 = 1; i2 < 11; i2++) {
// create a new TableRow
TableRow row = new TableRow(this);
for (int i = 0; i < 5; i++) {
String date = getKeyForIndex(i);
// create a new TextView
TextView t = new TextView(this);
t.setText(date);
// set width, height and weight
t.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, 1f));
// with this line, the textview's are not visible. when i comment the line, everything is ok
// add the TextView to the new TableRow
row.addView(t);
}
// add the TableRow to the TableLayout
table.addView(row);
You should ideally be using
Code:
new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
In instead of of what you are using... At least some variation of it. I haven't tried it but damn it should work! Let me know!
Sent from my Nexus 4 using XDA Premium 4 mobile app
Im already using that..
// set width, height and weight
t.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, 1f));
Click to expand...
Click to collapse
have you tried setting width to 0 and weight to 1?
width must be 0 for weight to work
yes, then I get an 'java.lang.ArithmeticException: divide by zero' exception
ok, figured it out
you have to use the parents view layoutparams, so in your case you have to use TableRow
so just change to
Code:
t.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
thank you!
warlock9_0 said:
ok, figured it out
you have to use the parents view layoutparams, so in your case you have to use TableRow
so just change to
Code:
t.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
Click to expand...
Click to collapse
Thank you, it's working now!!

how to display and data in array

Hi there
JSONObject nodeRoot = new JSONObject(returnMsg);
JSONArray res = nodeRoot.getJSONArray("result");
for (int i = 0; i < res.length(); i++) {
JSONObject childJSON = res.getJSONObject(i);
if (childJSON.get("data")!=null){
String value = childJSON.getString("data");
dataList.add(value);
JSONObject node=new JSONObject(value);
atList.add(node.get("temperature").toString());
In the last line node I get the "temperature":"6"
which is the value i want but now i have no idea to display it out , can i hav a guide here? tq
eric3231559 said:
Hi there
JSONObject nodeRoot = new JSONObject(returnMsg);
JSONArray res = nodeRoot.getJSONArray("result");
for (int i = 0; i < res.length(); i++) {
JSONObject childJSON = res.getJSONObject(i);
if (childJSON.get("data")!=null){
String value = childJSON.getString("data");
dataList.add(value);
JSONObject node=new JSONObject(value);
atList.add(node.get("temperature").toString());
In the last line node I get the "temperature":"6"
which is the value i want but now i have no idea to display it out , can i hav a guide here? tq
Click to expand...
Click to collapse
You should go thought the gettings started guides and basic listAdapter tutorials on d.android.com
Well, where do u want to display the data? Do u want to populate some view with it or just print it out to the console?
Thanks
OkieKokie said:
Well, where do u want to display the data? Do u want to populate some view with it or just print it out to the console?
Click to expand...
Click to collapse
Actually i wanna display it on my text view. I just know that inorder to get the data i want i have to use array form after slicing it
eric3231559 said:
Actually i wanna display it on my text view. I just know that inorder to get the data i want i have to use array form after slicing it
Click to expand...
Click to collapse
In the last line of ur code, u add the string value of the data to the arraylist. So for displaying ull need to use atList.get(index) where index is the number of the element in the arraylist.
So if u want to display the 1st element in the list then use urTextViewReference.setText(atList.get(0));

Categories

Resources