android-screen

Find exact coordinates of a single Character inside a TextView

为君一笑 提交于 2019-12-04 02:51:51
Currently I'm using paintObject.measureText(textCopy.substring(0,i)) while iterating through a copy of the TextView's text. For example, measureText("abc".substring(0,1)) will give me the relative x coordinates of 'b'. The y coordinate I get from layout.getLineTop() . This is working but not accurate for x coordinates for non-monospaced fonts. I can calibrate a little, but on each device it works differently. The best solution I can think of is to overwrite the class that is responsible for drawing the TextView on the screen and, hopefully, get the coordinates of each character drawn to screen

How to create different layout for Galaxy S3 and Nexus 7?

删除回忆录丶 提交于 2019-12-03 07:54:53
问题 I have created an android application which works properly for nexus 7. Inside resources folder, I have created two folders, layout , layout-land for Nexus 7" tab. Everything was working fine till date. Now I want to create a different layout for Samsung Galaxy S3. For that, I have created a folders inside resources with layout-large & layout-large-land . But, here is the problem. Now, for Nexus 7 also, the layout defined in layout-large folder is getting loaded. How to stop that? How can I

Android screen resolution

被刻印的时光 ゝ 提交于 2019-12-02 23:52:49
There are some screen resolutions already defined in Android. They are: QVGA (240×320, low density, small screen) WQVGA (240×400, low density, normal screen) FWQVGA (240×432, low density, normal screen) HVGA (320×480, medium density, normal screen) WVGA800 (480×800, high density, normal screen) WVGA854 (480×854 high density, normal screen) How do I know which type my device screen resolution is? Use DisplayMetrics to get screen info from your device. Sample code: DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); final int height = dm.heightPixels;

How to create different layout for Galaxy S3 and Nexus 7?

不打扰是莪最后的温柔 提交于 2019-12-02 21:22:51
I have created an android application which works properly for nexus 7. Inside resources folder, I have created two folders, layout , layout-land for Nexus 7" tab. Everything was working fine till date. Now I want to create a different layout for Samsung Galaxy S3. For that, I have created a folders inside resources with layout-large & layout-large-land . But, here is the problem. Now, for Nexus 7 also, the layout defined in layout-large folder is getting loaded. How to stop that? How can I create different layout for Nexus 7" tab & Galaxy S3 mobile? I have read Supporting Multiple Screens

Android: How to detect when phone is active and idle?

时光毁灭记忆、已成空白 提交于 2019-12-02 11:42:07
问题 I want to create an app that will know when user is using the phone(start the screen and close the screen). After a period of time I need to call doSomething() method. Question: 1.How can I know when user start using the phone and when he close the screen? 2.Should I use Service or IntentService? Which is better in my case? 回答1: You can try something like this using a BroadcastReceiver and a Service: Your class using The BroadcastReceiver: public class ScreenReceiver extends BroadcastReceiver

Why camera2 supported preview size width always bigger than height?

风流意气都作罢 提交于 2019-12-02 05:09:54
I'm working on a project which using camera2 API. When I get the list of supported output preview size using: StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); Size[] choices = map.getOutputSizes(SurfaceTexture.class); the output size list always return values which have width>height despite the fact that screen's width When I use getResources().getDisplayMetrics() (or any similar method) to check width/height it's always return width And based on the value I see that in 2 cases the width/height are likely swap their value. (w: 1920, h:

Freeze screen orientation

纵饮孤独 提交于 2019-12-02 00:10:32
There is CheckBox with following code: CheckBox cb = (CheckBox)findViewById(R.id.freezer); cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); } } }); So, when i check it, screen is rotated to default system orientation (landscape for my tablet). I need to freeze CURRENT orientation. If you turned device to portrait and

android get screen size including the size of status bar and software navigation bar

天大地大妈咪最大 提交于 2019-12-01 18:24:46
How can I get the size of the screen in pixels with navigation bar and status bar being included? I have already tried getting the size using DisplayMetrics but the size doesn't include the software navigation bar. software navigation is added since API 17 (JELLY_BEAN_MR1) so we need the to include the size of navigation bar only in API 17 and above. and note that when you get the screen size it is based on the current orientation. public void setScreenSize(Context context) { int x, y, orientation = context.getResources().getConfiguration().orientation; WindowManager wm = ((WindowManager)

How to dim screen to zero without conflicting with FLAG_KEEP_SCREEN_ON

◇◆丶佛笑我妖孽 提交于 2019-12-01 18:21:44
I found several methods to dim the screen but I am unsure how they work in concert with FLAG_KEEP_SCREEN_ON : Settings.System.SCREEN_BRIGHTNESS IHardwareService.setScreenBacklight() WindowManager.LayoutParams.screenBrightness Which of the above methods will keep the screen on, even if I set brightness to 0.0 ? Nothing will work reliably. If you set the brightness to 0 on some devices it will turn off the screen (but the device will be in a funny state for about 5 seconds or so before really realizing it's off and acting as such). Some devices it will be on but black. IIRC LayoutParams

android get screen size including the size of status bar and software navigation bar

橙三吉。 提交于 2019-12-01 18:20:02
问题 How can I get the size of the screen in pixels with navigation bar and status bar being included? I have already tried getting the size using DisplayMetrics but the size doesn't include the software navigation bar. 回答1: software navigation is added since API 17 (JELLY_BEAN_MR1) so we need the to include the size of navigation bar only in API 17 and above. and note that when you get the screen size it is based on the current orientation. public void setScreenSize(Context context) { int x, y,