5

I have a simple Activity called SingleTouchTest to make sense of screen touches. What is strange is that SingleTouchTest starts in whatever orientation I'm in but rotating the device does not result in screen rotation.

My test device is an Acer A100 running Android 4.0.3.

The main Activity contains a ListView that navigates to my test Activityes, including SingleTouchTest. I can run SingleTouchTest (full code below) without problems except rotation. In AndroidManifest.xml (full code below) I have tried every combination of

android:configChanges="keyboard|keyboardHidden|orientation" android:screenOrientation="unspecified"

and it does not auto rotate. I even removed the onConfigurationChanged() method from SingleTouchTest and nothing happens.

Full code of AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest 
    package="com.Bespoke.AndroidBasics"
    android:versionCode="1"
    android:versionName="1.0"
    android:installLocation="preferExternal" xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="Android Basics">
        <activity
            android:name=".AndroidBasicsStarter"
            android:label="Android Basics"
            android:screenOrientation="unspecified">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LifeCycleTest"
            android:label="Life Cycle Test"
            android:configChanges="keyboard|keyboardHidden|orientation" android:screenOrientation="unspecified"/>
        <activity
            android:name=".SingleTouchTest"
            android:label="Single Touch Test"
            android:configChanges="keyboard|keyboardHidden|orientation" android:screenOrientation="unspecified"/>
        <activity
            android:name=".MultiTouchTest"
            android:label="Single Touch Test"
            android:configChanges="keyboard|keyboardHidden|orientation" android:screenOrientation="unspecified"/>
        <activity
            android:name=".KeyTest"
            android:label="Key Test" android:screenOrientation="unspecified"/>
    </application>

</manifest>

Full code of SingleTouchTest:

package com.Bespoke.AndroidBasics;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class SingleTouchTest extends Activity
                             implements OnTouchListener {

    StringBuilder builder = new StringBuilder();
    TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        textView = new TextView(this);
        textView.setText("Touch and drag (one finger only!)");
        textView.setOnTouchListener(this);
        this.setContentView(textView);
    }

    public boolean onTouch(View v, MotionEvent event) {
        builder.setLength(0);  // clear the builder
        switch(event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            builder.append("down, ");
            break;
        case MotionEvent.ACTION_MOVE:
            builder.append("move, ");
            break;
        case MotionEvent.ACTION_CANCEL:
            builder.append("cancel, ");
            break;
        case MotionEvent.ACTION_UP:
            builder.append("up, ");
            break;
        }
        builder.append(event.getX());
        builder.append(", ");
        builder.append(event.getY());
        String text = builder.toString();
        Log.d("TouchTest", text);
        textView.setText(text);
        return true;  // Consume the event, if false super.onTouch superceeds us
    }

     @Override
     public void onConfigurationChanged(Configuration  newConfig) {
       super.onConfigurationChanged(newConfig);

     }

}
MathMax
  • 571
  • 7
  • 22
uMinded
  • 595
  • 1
  • 9
  • 21

3 Answers3

9

since you are using

 android:screenOrientation="unspecified"

for each activity and it is defined according to google as

The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.

Which makes me think that the device is declaring the desired orientation for some reason. Maybe try switching the screenorientation to

android:screenOrientation="fullSensor"

that should take it out of the specific devices hands.

MikeIsrael
  • 2,871
  • 2
  • 22
  • 34
  • I just found a web post that let my hook up my HTC Incredible to ADB. Rotation works fine on my phone but not on the A100. All my other apps rotate normally whats going on? – uMinded Jun 11 '12 at 10:40
  • @uMinded did you try and change the orientation? – MikeIsrael Jun 11 '12 at 11:12
  • The HTC Incredible (2.3.3) rotates with: `` but the A100 (4.0.3) stays in the parent orentation. I can only force it to be landscape or portrait. – uMinded Jun 11 '12 at 11:14
  • no, but what happens if you add android:screenOrientation="fullSensor"? – MikeIsrael Jun 11 '12 at 11:35
  • HTC rotates as expected and A100 does nothing at all. The only android:screenOrentation setting that does anything is portrait or landscape. – uMinded Jun 12 '12 at 00:02
  • That seems like a bug with the device, because according to the documentation it should rotate according to the sensors, unless there is an issue with the sensors on the device. Seems like there is a lock orientation option on the device, are you sure it is set to false? http://www.acertabletforum.com/forum/acer-a100-help/2769-screen-rotation.html – MikeIsrael Jun 12 '12 at 07:11
  • Wow... I fell like a total tool, I just put the tablet into a new aftermarket case and must have slid the lock button on. I thought that was a "screen lock" button like my MP3 player so the screen was locked "off" not in landscape... – uMinded Jun 13 '12 at 11:00
  • @uMinded hardware switches are the bane of us all :) – MikeIsrael Jun 13 '12 at 13:33
2

Try this:

android:screenOrientation="fullSensor"

The orientation is determined by the device orientation sensor. The orientation of the display depends on how the user is holding the device. This should be what you want. Also for more options check out this link-Activity Element.

user1092042
  • 1,297
  • 5
  • 24
  • 44
  • 1
    sorry don't know how I missed your answer, and basically wrote the samething so deleting my answer – MikeIsrael Jun 11 '12 at 11:11
  • I dont think you have to delete it as you have put in your own effort to write the answer. Things like this do happen. Not an issue. – user1092042 Jun 11 '12 at 12:26
2

In your AndroidManifest, get rid of |orientation. The reason for this is as follows:

android:configChanges allows you to handle specific configuration changes manually. Since you are not telling your app to rotate manually (via code inside onConfigurationChanged()), it is not doing anything at all. To allow your application to use rotation automatically, you must tell the Manifest that you are not handling orientation manually.

The documentation explaining this is here at the Android Developers Site.

Fuzzical Logic
  • 12,947
  • 2
  • 30
  • 58
  • I just found a web post that let my hook up my HTC Incredible to ADB. Rotation works fine on my phone but not on the A100. All my other apps rotate normally whats going on? – uMinded Jun 11 '12 at 10:41
  • @uMinded If it is device-specific only, you may check the settings of the device. They may also be interrupting the orientation change. – Fuzzical Logic Jun 11 '12 at 10:53
  • Is their a hidden option in (4.0.3) for screen orientation control for apps? (2.3.3) has it under "settings -> Display -> auto-rotate screen" but I found so such option in (4.0.3) – uMinded Jun 12 '12 at 00:08
  • That's all dependent on the ROM (i.e. Manufacturer) Who makes the A100? – Fuzzical Logic Jun 12 '12 at 00:32
  • Acer makes the A100 (7" Tegra 2) build is Acer_AV041_A100_1.012.00_ww_GEN1 its an official ICS update for the device but I did the install manually as the settings -> about -> system update would not find the update. – uMinded Jun 12 '12 at 00:41
  • That doesn't matter. Every manufacturer adjusts the ROM to meet the market in what they feel is the best way. The ROM may be simple software replacement/additions, or may even modify some of the core Android. I would do a search for A100 and orientation support and see if others have had the same issue. I'll do some research when I'm done editing this tag wiki. – Fuzzical Logic Jun 12 '12 at 00:58
  • Wow... I fell like a total tool, I just put the tablet into a new aftermarket case and must have slid the lock button on. I thought that was a "screen lock" button like my MP3 player so the screen was locked "off" not in landscape... – uMinded Jun 13 '12 at 10:55