Light sensor -value (lux) or current - Android Software Development

Hi. (htc desire android 2.1)
In my app-i'm trying to show on screen values of light (lux) , but i get only few values(0-min 40, 90, 160, 225, 640, 1280-max). Is there oportunity to get much more values between 0 - 1280?? Maybe i use wrong variable. Is there a variable of sensor's current or voltage ?? Can you help me??
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT), sensorManager.SENSOR_DELAY_GAME);
sensorManager.unregisterListener(this,sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT));
outputX.setText("E:"+Float.toString(event.values[0]));

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

FullScreen OpenGLES application

Hello,
I'm trying to do an OpenGLES application for my HTC Touch Diamond.
I create the window with CreateWindow :
Code:
INT width = ::GetSystemMetrics(SM_CXSCREEN) ;
INT height = ::GetSystemMetrics(SM_CYSCREEN) ;
hWnd = ::CreateWindow(
m_szAppName, m_szAppName,
WS_VISIBLE,
0, 0, width, height,
NULL, NULL, m_hInstance, NULL
) ;
SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON);
The problem is that (width,height) equals (240,320) even if the screen is VGA (480*640). So OpenGL windows just fills a quarter of the screen.
And when I try to set (width,height) to (480, 640), CreateWindow throws an "Error 4".
Has anybody the solution ?
Thanks
Hello !
I found the solution: I need to had the ressource HI_RES_AWARE.
We can find some tutorials on the web to explain how to had this.
Bye

InTheHand Bluetooth - Weird stream problems

I am currently working on my "SciLor's WiMoBlue". The new protocol is ready. Everything works fine, until I send much data at the same time.
For example if I try to send an image in that way:
Code:
Public Sub SendImage(ByVal Image As Bitmap, ByVal Position As Point, ByVal Format As ImageFormat)
Dim PosX, PosY, Width, Height As Byte()
Dim ImageStream As New IO.MemoryStream
Dim ImageLength As Integer
Dim ImageLengthBytes As Byte()
Dim ImageBuffer(MaxChunkSize - HeaderSize - 1) As Byte
PosX = BitConverter.GetBytes(Position.X)
PosY = BitConverter.GetBytes(Position.Y)
Width = BitConverter.GetBytes(Image.Width)
Height = BitConverter.GetBytes(Image.Height)
Image.Save(ImageStream, ImageFormat2ImagingFormat(Format))
ImageStream.Seek(0, SeekOrigin.Begin)
ImageLength = ImageStream.Length
ImageLengthBytes = BitConverter.GetBytes(ImageLength)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.Initiate, CombineBytes(PosX, PosY, Width, Height, ImageLengthBytes)))
Thread.Sleep(2000)
Dim DataPos As Integer
For DataPos = 0 To ImageStream.Length - MaxChunkSize - HeaderSize - 1 Step MaxChunkSize - HeaderSize
ImageStream.Read(ImageBuffer, 0, MaxChunkSize - HeaderSize)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.Data, ImageBuffer))
'WaitForNextChunk = True
'Do While WaitForNextChunk = True
'Loop
'Thread.Sleep(2000)
Next
ImageBuffer = New Byte(ImageLength - DataPos - 1) {}
ImageStream.Read(ImageBuffer, 0, ImageBuffer.Length)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.End, ImageBuffer))
End Sub
SendData:
Code:
If Data.Length > MaxChunkSize Then
MsgBox("Data to long... " & vbNewLine & "SendSize:" & Data.Length & vbNewLine & "MaxSize:" & MaxChunkSize)
Else
If btClient.Connected = True And isRecieving = True Then
btStream.Write(Data, 0, Data.Length)
btStream.Flush()
End If
End If
Recieving Part:
Code:
While isRecieving = True
If btStream IsNot Nothing And btStream.DataAvailable = True Then
Try
Recieved = btStream.Read(myHeader, 0, myHeader.Length)
If myHeader(0) = HeaderIdentifier And myHeader(1) = OtherModeHeader Then
btStream.Read(myDataSize, 0, 2)
DataLength = BitConverter.ToInt16(myDataSize, 0)
myBuffer = New Byte(DataLength - 1) {}
Recieved = 0
Do Until Recieved = DataLength
If btStream.DataAvailable = True Then
Recieved += btStream.Read(myBuffer, Recieved, DataLength - Recieved)
End If
Loop
ExecuteCommand(myHeader(2), myHeader(3), myBuffer)
Else
Debug.WriteLine("WrongData")
Exit While
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
If Recieved = 0 Then
Exit While
End If
End Try
End If
End While
If I send the image, without Thread.Sleeps (huighe ones). The recieving stream gets weird. The gets btStream.DataAvailable = False forever. If I remove that ckeck, it hangs at the btStream.Read.
I also tried to fix that with waiting for the answer of the server, but the problem doesn't get solved.
Do you have any idea how to fix that problem?. In that speed the image sending is worthless
SciLor

Decompiled Camera APK

hi Guys
Ive decompiled the Camera APK from the HONE and found something interesting as below;
Code:
# static fields
.field private static final synthetic $VALUES:[Lcom/android/camera/HTCCameraSensor$Sensor_Type;
.field public static final enum SENSOR_13M:Lcom/android/camera/HTCCameraSensor$Sensor_Type;
.field public static final enum SENSOR_2M:Lcom/android/camera/HTCCameraSensor$Sensor_Type;
.field public static final enum SENSOR_3M:Lcom/android/camera/HTCCameraSensor$Sensor_Type;
.field public static final enum SENSOR_4M:Lcom/android/camera/HTCCameraSensor$Sensor_Type;
.field public static final enum SENSOR_5M:Lcom/android/camera/HTCCameraSensor$Sensor_Type;
.field public static final enum SENSOR_8M:Lcom/android/camera/HTCCameraSensor$Sensor_Type;
.field public static final enum SENSOR_UNDEFINED:Lcom/android/camera/HTCCameraSensor$Sensor_Type;
Notice the different sensor types?
Plus i think ive found that the HTC One maybe able to take higher than 4 MP photos... Dependant on the sensor of course ^__^
Attached are 3 files;
Notepad ++
APKTool Decompiler
HTC One Camera APK.
So u mean that the camera sensor is capable of taking higher res pix ?
Can u share how to decompile the camera apk
Thnx
Sent from my HTC One using xda app-developers app
Perhaps they have a standard cross-platform HTC camera app and it just limits itself dependant on what hardware it finds.
----------------------o('_')o----------------------
Sent from an HTC One with using xda app:
TrickDroid ROM 5.6
Bulletproof 1.10
Can you find jpeg compression somewhere?
sallam5010 said:
So u mean that the camera sensor is capable of taking higher res pix ?
Can u share how to decompile the camera apk
Thnx
Sent from my HTC One using xda app-developers app
Click to expand...
Click to collapse
Tetsumi06 said:
Perhaps they have a standard cross-platform HTC camera app and it just limits itself dependant on what hardware it finds.
----------------------o('_')o----------------------
Sent from an HTC One with using xda app:
TrickDroid ROM 5.6
Bulletproof 1.10
Click to expand...
Click to collapse
vegetaleb said:
Can you find jpeg compression somewhere?
Click to expand...
Click to collapse
There is that possibility , it depends though as mentioned above by Tetsumi06, if the software does not permit them because the sensor is truly a 4MP sensor... But knowing HTC and their history with cameras, i wouldn't be surprised if it was possible. back on earlier models, HTC never enabled 1080p & 720p recording and the community came together to get them enabled.
Im hunting now.... Tools i used to decompress are attached to the first post
fkofilee said:
There is that possibility , it depends though as mentioned above by Tetsumi06, if the software does not permit them because the sensor is truly a 4MP sensor... But knowing HTC and their history with cameras, i wouldn't be surprised if it was possible. back on earlier models, HTC never enabled 1080p & 720p recording and the community came together to get them enabled.
Im hunting now.... Tools i used to decompress are attached to the first post
Click to expand...
Click to collapse
EDIT:
Tetsumi06 said basically the same thing! Doh!
It could also be that the code is generic to all device types and models and so has a function to pickup the sensor size based on the hardware it sees. So there might be functions for other sensor sizes but they never get enabled because physically our phones are only 4M.
I would love to be wrong though! Good find!:laugh:
HTC is working with one !!! source base. So there are often parts inside a app which are handled differently regarding some build settings.
And same here for the camera sensor strings. The same camera.apk (build number will differ) will run on other devices like Butterfly, One X, One XL, ...
So there must be some checking in the source how to handle different sensors :laugh:
chrisch1974 said:
HTC is working with one !!! source base. So there are often parts inside a app which are handled differently regarding some build settings.
And same here for the camera sensor strings. The same camera.apk (build number will differ) will run on other devices like Butterfly, One X, One XL, ...
So there must be some checking in the source how to handle different sensors :laugh:
Click to expand...
Click to collapse
See what you say is very true, one source of android 4.2.2 for example, for all 2013 devices but they add and remove what is necessary to make those devices work... They develop one load of sense based firmware to then place with drivers for the individual devices ):
You can edit the media_profiles.xml to change the image compression, and video recording bitrate. Need to make the same changes in the camera apk and compile it again
cool worth keeping an eye on
HTC Uses a single base for all its phones so they all have the same encodings. This Apk would work on a phone with 8mpx camera and vice versa. You Cant Have More Pixelsssss.
I think our sensor has more abilities and functions but we need someone to hunt and edit it
Have a look here it's kinda long but interesting
BACK CAMERA (4.1 megapixel)
Ae Bracket Hdr: Off
Ae Bracket Hdr Values: Off, HDR, AE Bracket
Antibanding: Off
Antibanding Values: Off, 50hz, 60hz, Auto
Auto Exposure: Smart Metering
Auto Exposure Lock: False
Auto Exposure Lock Supported: True
Auto Exposure Values: Frame Average, Center Weighted, Spot Metering, Smart Metering
Auto Whitebalance Lock: False
Auto Whitebalance Lock Supported: True
Awb Calibration Check: Success
Camera Mode: 0
Camera Mode Values: 0, 1
Capture Burst Captures Values: 1
Capture Burst Exposures:
Capture Burst Exposures Values: 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
Capture Burst Interval: 1
Capture Burst Interval Max: 10
Capture Burst Interval Min: 1
Capture Burst Interval Supported: True
Capture Burst Retroactive: 0
Capture Burst Retroactive Max: 1
Capture Burst Timeinterval: 0
Capture Burst Timeinterval Max: 1000
Capture Burst Timeinterval Min: 0
Capture Burst Timeinterval Supported: True
Capture Mode Values: Normal, Contiburst, Contiburst One Shot, Hdr, Panorama, Zoe, Contizoe
Contrast: 5
Contrast Max: 10
Contrast Min: 0
Denoise: Denoise Off
Denoise Values: Denoise Off, Denoise On
Effect: None
Effect Values: None, Mono, Negative, Solarize, Sepia, Posterize, Whiteboard, Blackboard, Aqua, Emboss, Sketch, Neon
Exposure Compensation: 0
Exposure Compensation Step: 0.166667
Face Detection: Off
Face Detection Values: Off, On
Flash Calibration Check: Success
Flash Mode: Off
Flash Mode Values: Off, Auto, On, Torch
Focal Length: 3.82
Focus Areas: (0, 0, 0, 0, 0)
Focus Distances: 0.100000, 0.150000, 0.170000
Focus Mode: Auto
Focus Mode Values: Auto, Infinity, Normal, Macro, Continuous Picture, Continuous Video
Hdr Supported: True
Hfr Size Values: 800x480, 640x480
Histogram: Disable
Histogram Values: Enable, Disable
Horizontal View Angle: 69.6
Iso: Auto
Iso Values: Auto, ISO_HJR, ISO100, ISO200, ISO400, ISO800, ISO1600
Jpeg Quality: 85
Jpeg Thumbnail Height: 384
Jpeg Thumbnail Quality: 90
Jpeg Thumbnail Size Values: 512x288, 480x288, 432x288, 512x384, 352x288, 0x0
Jpeg Thumbnail Width: 512
Lensshade: Enable
Lensshade Values: Enable, Disable
Lsc Calibration Check: Success
Luma Adaptation: 3
Max Exposure Compensation: 12
Max Num Detected Faces Hw: 10
Max Num Detected Faces Sw: 0
Max Num Focus Areas: 1
Max Num Metering Areas: 1
Max Zoom: 59
Mce: Enable
Mce Values: Enable, Disable
Metering Areas: (0, 0, 0, 0, 0)
Min Exposure Compensation: 12
No Display Mode: 0
Num Jpegs Per Shutter: 1
Num Queue Depth: 2
Num Snaps Per Shutter: 1
Ois Setting: True
Ois_support: True
Orientation: 90
Overlay Format: 265
Picture Format: Jpeg
Picture Format Values: Jpeg, Raw
Picture Size: 640x480
Picture Size Values: 2688x1520, 2592x1456, 2048x1520, 2048x1216, 2048x1152, 1920x1088, 1600x1200, 1600x896, 1520x1520, 1456x1088, 1456x880, 1456x832, 1440x1088, 1280x960, 1280x768, 1280x720, 1024x768, 1088x1088, 800x600, 800x480, 720x720, 640x480, 640x384, 640x368, 352x288, 320x240, 176x144
Power Mode: Normal_Power
Power Mode Supported: True
Preview Format: Yuv420sp
Preview Format Values: Yuv420sp, Yuv420sp Adreno, Yuv420p, Yuv420p, Nv12
Preview Fps Range: 1, 200000
Preview Fps Range Values: (1, 200000)
Preview Frame Rate: 120
Preview Frame Rate Mode: Frame Rate Auto
Preview Frame Rate Modes: Frame Rate Auto, Frame Rate Fixed
Preview Frame Rate Values: 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120
Preview Size: 640x480
Preview Size Values: 1920x1088, 1440x1088, 1280x720, 1088x1088, 960x720, 960x544, 800x480, 768x464, 768x432, 720x720, 720x480, 640x480, 640x384, 640x368, 576x432, 480x320, 384x288, 352x288, 320x240, 240x160, 176x144
Recording Hint: False
Redeye Reduction: Disable
Redeye Reduction Values: Enable, Disable
Saturation: 5
Saturation Max: 10
Saturation Min: 0
Scene Detect: Off
Scene Detect Values: Off, On
Scene Mode: Auto
Scene Mode Values: Off, Auto, Action, Portrait, Landscape, Night, Night Portrait, Theatre, Beach, Snow, Sunset, Steadyphoto, Fireworks, Sports, Party, Candlelight, Backlight, Flowers, AR, Text
Selectable Zone Af: Auto
Selectable Zone Af Values: Auto, Spot Metering, Center Weighted, Frame Average
Sharpness: 10
Sharpness Max: 30
Sharpness Min: 0
Single Isp Output Enabled: False
SkinToneEnhancement: 0
SkinToneEnhancement Values: Enable, Disable
Slow Motion Res: 768x432
Slow Motion X: 4
Strtextures: OFF
Time Cons Post Processing: Enable
Touch Af Aec: Touch Off
Touch Af Aec Values: Touch Off, Touch On
TouchAfAec Dx: 100
TouchAfAec Dy: 100
Vertical View Angle: 43
Video 720p60fps Supported: True
Video Frame Format: Yuv420sp
Video Hdr: False
Video Hdr Supported: True
Video Hfr: Off
Video Hfr Values: Off, 60
Video Mode: 0
Video Slow Motion Supported: True
Video Snapshot Supported: False
Video Stabilization: False
Video Stabilization Supported: True
Video Zoom Support: True
Whitebalance: Auto
Whitebalance Values: Auto, Incandescent, Fluorescent, Daylight, Cloudy Daylight
Zoom: 0
Zoom Ratios: 100, 102, 104, 107, 109, 112, 114, 117, 120, 123, 125, 128, 131, 135, 138, 141, 144, 148, 151, 155, 158, 162, 166, 170, 174, 178, 182, 186, 190, 195, 200, 204, 209, 214, 219, 224, 229, 235, 240, 246, 251, 257, 263, 270, 276, 282, 289, 296, 303, 310, 317, 324, 332, 340, 348, 356, 364, 373, 381, 390
Zoom Supported: True
Zsl: Off
Zsl Values: Off, On
Sent from my HTC One using xda app-developers app
They might make all their apps compatible with various hardware to allow easier updating of each device's Android version.
Sent from my HTC One using xda premium
I kinda doubt what u sayin cuz look at picture size values u will notice that it's limited to max 4mp which is for HTC one
Anyways am not looking to increase the megapixels there's much more options like jpeg quality is 85% ! I can see higher video frames ! More scenes !
Maybe we can increase the quality if slow motion video ! Or make it even slower than 4x
Am I right !
Sent from my HTC One using xda app-developers app
The one thing that caught my eye was the different metering options. Being able to choose different types of metering would be awesome, along with changing the jpeg compression
Galactus said:
The one thing that caught my eye was the different metering options. Being able to choose different types of metering would be awesome, along with changing the jpeg compression
Click to expand...
Click to collapse
Yeah it would be awesome if we could control that !
Sent from my HTC One using xda app-developers app
Ugh, the bane of having TMI.
Now scumbag brain wants.
Can someone tell me how to decomplile and re-compile the APK? I will play around with the settings and see what happens
eRajesh said:
Can someone tell me how to decomplile and re-compile the APK? I will play around with the settings and see what happens
Click to expand...
Click to collapse
Use virtuous studio.
Anyway from the code we can pretty much change anything the only issue is we don't know the sensor capabilities, what is max that it can do.
For example max exposure is 12 if I remember right from the code, so if the sensor is capable of doing 16 and we set it to 14 we would get better low light photos.
We could change metering distance but again we need to know sensor capabilities for example if minimum is 5 cm we could add 3 cm which would allows us closer macro shots.
We could boost the flash as well, Make the duration longer = more time for sensor to pick up the light = better pic.
Or we could increase zoom distance as well since we can assume HTC gave us short zoom since our pixel count sux , tho I'm sure 20/30% won't ruin that much the quality ( anyway not like anyone is ever using zoom lol)
Best of all would be adding touch focus flash @ night since we lack that option. Then set it to lock focus for let's say 4 sec and take a pic.
We could even add 60 fps1080p recording tho that would make 1 min clip 300 mb + lol.
We have sh1t load opportunities here all we need is either to test on blind some stuff or somehow get the hardware specs of our sensor
Sent from my HTC One using xda premium
anyone know how to enable the histogram?

[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

Categories

Resources