8

This may be considered to be a repeat of this post, but that never did receive a proper answer, so maybe the question needs a bit more context to attract an answer.

Basically I have managed to set up a monitoring Service that watches for home screen rotation, and when that happens my AppWidgets are refreshed in response.

Whilst this works fine as far as it goes, a big pitfall with the method is that it actually only detects screen rotation and not specifically home screen rotation.

So, typically a device would support rotation of the screen within normal apps (i.e. rotation of an Activity). The problem is that rotation of the screen in those circumstances falsely triggers my monitoring Service.

My widgets then think that they need to fetch and show new content for the rotated view, but if the home screen itself does not support home screen rotation, then that work is not only wasted but also contributes to a bad UI.

So is there a way to check whether the launcher supports home screen rotation? Or alternatively, a way in which rotation of the home screen specifically can be detected, and not just rotation of the screen (e.g. in an app)?

I could just create an option to enable this rotation feature or not, with the default being off, but really I'd like the default to be that the feature is enabled... otherwise users with rotating home screens will consider that my widgets don't respond well to rotation, without taking the time to look into the options to enable the feature for their device.

Community
  • 1
  • 1
drmrbrewer
  • 11,491
  • 21
  • 85
  • 181

5 Answers5

1

Home (or launch) screens are very specific, and there aren't definitive means by which one can express the orientation of every single one. Hell, you could have a home screen that is diagonal!

Because there is a huge amount of launch screen implementations, the behavior on any given device would be indeterminate.

However: You could easily add a check-box of some sort on the first run that asks the user if their home screen supports shifts in orientation. This would be terribly easy to add in, and wouldn't impose too much of a hassle on the user! :)

Edit: If you want to determine which activity is having its orientation changed, you can simply get a list of all running applications with getRunningAppProcesses and then check each resulting item's importance for IMPORTANCE_FOREGROUND. This way, you'll know whether or not the user has changed the orientation whilst a running application had the foreground, and can check whether or not it was an app or the home screen that had called onConfigurationChanged!

Shane Duffy
  • 1,117
  • 8
  • 18
1

This answer should be bored you. But in fact, you cannot know exactly one launcher is supported rotation or not or detecting when launcher is rotated.

Launcher is just an normal android application. And for satisfying your requirement, they should:

  1. public data through Content Provider: for you to know they supports rotate or not. What can they do etc ... and have a well-known document.
  2. send an event when they rotate through BroastCastReceiver for you to listen to that event.

Often, they don't.

hqt
  • 29,632
  • 51
  • 171
  • 250
  • I'm detecting rotation through a `onConfigurationChanged(newConfig)` of a running `Service`, then looking at `newConfig.orientation` to see if there has been a change in orientation. Is there any way of telling from `newConfig` what `Activity` or app has had its orientation changed? – drmrbrewer Mar 05 '16 at 09:27
0
boolean  autoRotateOn  = (android.provider.Settings.System.getInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0) == 1) ; 
TanLingxiao
  • 402
  • 5
  • 7
  • 1
    Isn't that just detection whether rotation (in general) is supported/activated , rather than **home screen rotation** specifically? You can have apps that rotate, with the home screen being always fixed. – drmrbrewer Mar 05 '16 at 09:03
  • if we want to make app fixed,we can use: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); in Activity.onCreate method,or set AndroidManifest.xml android:configChanges=”orientation” – TanLingxiao Mar 05 '16 at 09:13
0

Now although there is no specific way to only detect the screen orientation change of the home screen, I would blindly approach this problem by detecting what app is in the foreground during the onConfigurationChanged event.

How to determine if the foreground app is the launcher?

The method in the post above retrieves the package name of the foreground app, and compares that with those of the launcher applications installed on the device.

Community
  • 1
  • 1
JTY
  • 1,009
  • 7
  • 13
0

You'd be better off detecting whether the system is a tablet. Here are my findings:

Test devices that can rotate their launcher:

Samsung Galaxy Note 2 -- No
Galaxy S4 -- No
Galaxy S5 with Nova Launcher -- No
Galaxy S6 -- No
HTC One M7 Sense Launcher -- No
Kyocera Hydro ICS Launcher -- No
Galaxy Reverb, Galaxy Centura -- No
Galaxy Note 4 TW -- No
LG G3 -- No
LG G2 -- No

Tablets:
Dell Venue 8 -- Yes, Stock Launcher
Verizon Ellipsis -- Yes
HP Slate -- Yes
Galaxy Tab 3 - Yes
Lenovo Tab - Yes
Acer Iconia Tab -- Yes

To detect a tablet, you can use this code:

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width=dm.widthPixels;
int height=dm.heightPixels;
int dens=dm.densityDpi;
double wi=(double)width/(double)dens;
double hi=(double)height/(double)dens;
double x = Math.pow(wi,2);
double y = Math.pow(hi,2);
double screenInches = Math.sqrt(x+y);

The double screenInches can be used against a number, say, 7 inches, to generally detect that the launcher can be rotated.

I don't think this is a workaround, this is honestly how I would do it if I were developing an app.

Hope it helps!

Aaron Gillion
  • 2,227
  • 3
  • 19
  • 31