0

I am displaying a panoramic photo, and I want my ImageView to move according to the Sensor orientation (my phone's orientation determines the image view and it's too wide to display it entirely at once). When I invoke methods which change my ImageView (e.g. setX) my application crashes. I am doing it in the UI thread, so I don't know why this doesn't work. Code which refers to the sensor works fine.

Any help would be appreciated.

public class ImageActivity extends Activity
{
private ImageView imageView;
private LocationManager locationManager;
private String provider;
private SensorManager sensorManager;
public float val = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, false);
    Location location = locationManager.getLastKnownLocation(provider);
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    sensorManager.registerListener(new CustomOrientationListener(), sensor, 
                            SensorManager.SENSOR_DELAY_GAME);

    //imageView = (ImageView) findViewById(R.id.imageView1);    

}


class CustomOrientationListener implements SensorEventListener {

      public CustomOrientationListener() {}

      @Override
      public void onAccuracyChanged(Sensor sensor, int accuracy) {}

      @Override
      public void onSensorChanged(SensorEvent event) {
          final float[] values;
          if(event.sensor.getType() == Sensor.TYPE_ORIENTATION){
              values = event.values;
              runOnUiThread(new Runnable(){

                @Override
                public void run() {
                    imageView.setTranslationX((int)values[0]);

                }

              });
          }

      }

  }

}

  • 1
    Post the exception text – Sam Judd Jul 17 '13 at 14:40
  • I test it on my phone and it just says that the app crashes, or do you mean some kind of logs? If so, where can I find them? – user2587107 Jul 17 '13 at 14:45
  • 1
    If you have the sdk installed, and in your path, in a terminal, you can run: adb logcat. Most IDE's also have a built in version that is a little easier to read (you can search for things like exceptions). Whenever the app crashes you should see an exception and a stack trace. – Sam Judd Jul 17 '13 at 14:53
  • I get: [adb: not found], but I don't know what kind of SDK do you mean, I write my app on PC and I only test on my phone, I didn't install any SDK on my mobile – user2587107 Jul 17 '13 at 15:14
  • 1
    by SDK I mean the Android sdk. You must have installed it on the computer you are using to develop your Android app? Also are you using Eclipse or another IDE to write your code in? Take a look at: http://developer.android.com/tools/help/adb.html – Sam Judd Jul 17 '13 at 15:23

1 Answers1

-1

Yes, I do have Android SDK on my PC, but I test my app on my phone, so I don't know how to read logs, cause I don't know whe