orientation

Android: Algorithms for SensorManager.getRotationMatrix and SensorManager.getOrientation()

独自空忆成欢 提交于 2020-01-01 03:42:05
问题 To get orientation as a from of euler angles (e.g., pitch, roll, azimuth) in Android, it is required to execute followings: SensorManager.getRotationMatrix(float[] R, float[] I, float[] gravity, float[] geomagnetic); SensorManager.getOrientation(float[] R, float[] orientation); In the first one, I realize that it uses a kind of TRIAD algorithms; Rotation matrix (R[]) is composed of gravity, geomagnetic X gravity, gravity X (geomagnetic X gravity) --- X is cross product. See codes below: float

Programmatic interface orientation change not working for iOS

99封情书 提交于 2020-01-01 03:40:44
问题 So, I've got a project where I need to force an orientation change when a user presses a button. I've created a sample app on github to demonstrate the issue. @interface DefaultViewController () { UIInterfaceOrientation _preferredOrientation; } Some rotation handling bits - (BOOL)shouldAutorotate { return YES; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return _preferredOrientation; } And a toggle - (IBAction)toggleButtonPressed:(id)sender {

Maintain Scroll Position of GridView through Screen Rotation

a 夏天 提交于 2019-12-31 12:59:47
问题 How can I maintain the scroll position of a GridView (it's filled with search results) throughout a screen reorientation? I have the GridView inside a Fragment, and when I rotate the screen it jumps back up to the top of the list. To make it even more tricky, in landscape mode my GridView has 3 columns.. in portrait mode it has 2 columns. I can't seem to figure out how to keep the fragment's GridView scrolled to anywhere near where it should be when the screen orientation changes. 回答1: You

Centering a background image in Android

假装没事ソ 提交于 2019-12-31 08:57:29
问题 I have a background image about 100 x 100 that I want to center in an Android app. Is there a way to do this? I'm thinking it would greatly help with orientation changes for simple apps. 回答1: You can use BitmapDrawable for the case. Create centered.xml in res/drawable folder: <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/your_image" android:gravity="center"/> Then you can use centered drawable as background. 回答2: Question is old and answer has one

Check Landscape/Portrait orientation in an iMessage app (extension)

ε祈祈猫儿з 提交于 2019-12-31 05:23:10
问题 Have seen a lot of solutions to check the orientation, but strangely, none works!! Below is the code snippet, override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { let screenSize = UIScreen.main.bounds let screenWidth = screenSize.width let screenHeight = screenSize.height print("Screen Width = \(screenWidth)") print("Screen Height = \(screenHeight)") if (screenWidth > screenHeight) { print("Landscape") alertView.removeFromSuperview()

Android app crashes if the orientation changes

百般思念 提交于 2019-12-31 05:15:12
问题 I have created a game app where I share some details to Facebook through a button called Share. When I finish the game it asks for the name in a dialog box, it shows no problem when working on the same orientation (landscape/portrait). If I'm playing in landscape, finish the game, flip the phone to portrait to type my name in, then click "Share" it will crash. How to overcome this problem? 回答1: An activity is restarted when the orientation changes. I'm guessing your code isn't saving needed

How to use ExifInterface with a stream or URI

两盒软妹~` 提交于 2019-12-30 17:43:23
问题 I'm writing an app that can be sent a photo URI from the "Share via" menu in Android. The kind of URI you get is content://media/external/images/media/556 however ExifInterface wants a standard file name. So how do I read the exif data (I just want orientation) of that file? Here's my (non-working) code: Uri uri = (Uri)extras.getParcelable(Intent.EXTRA_STREAM); ContentResolver cr = getContentResolver(); InputStream is = cr.openInputStream(uri); Bitmap bm = BitmapFactory.decodeStream(is); //

Image rotation on input type=“file”

非 Y 不嫁゛ 提交于 2019-12-30 08:09:32
问题 I am using react-firebase-file-uploader to upload an avatar to firebase storage. However, any time I upload an image of Portrait Orientation (specifically, images taken on Android and IOS devices - they tend to have OrientationRotate 90 CW in their metadata) the image is rotated 90 degrees. I have read about this previously and I believe that these smartphone images taken are always in Landscape but the orientation is stored EXIF meta . Please correct me if I am mistaken? Below is an example

How to restrict a moveable view by Pan gesture

会有一股神秘感。 提交于 2019-12-30 06:33:29
问题 I have a UIImageView which is moveable via a pan gesture. UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self.photoMask addGestureRecognizer:pan]; I would like to restrict the area this can be moved on screen. Rather than the user be able to drag the view right to the side of the screen, I want to restrict it by a margin of some sort. How can I do this? Also, how is this then handled when rotated? EDIT --- #pragma mark -

Android app resets on orientation change, best way to handle?

百般思念 提交于 2019-12-30 05:09:07
问题 So I am making a basic chess app to play around with some various elements of android programming and so far I am learning a lot, but this time I am lost. When the orientation of the emulator changes the activity gets reset. Based on my research the same thing will happen anytime the application is paused/interrupted, ie. keyboard change, phone call, hitting the home key etc. Obviously, it is not viable to have a chess game constantly reset, so once again I find myself needing to learn how to