package com.sigseg.android.map;

import android.app.Activity;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

import com.sigseg.android.worldmap.R;


public class ImageViewerActivity extends Activity {
    private static final String TAG = "ImageViewerActivity";
    private static final String KEY_X = "X";
    private static final String KEY_Y = "Y";

    private static final String MAP_FILE = "world.jpg";
    
    private ImageSurfaceView imageSurfaceView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Hide the window title.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
        imageSurfaceView = (ImageSurfaceView) findViewById(R.id.worldview);

        // Setup/restore state
        if (savedInstanceState != null && savedInstanceState.containsKey(KEY_X) && savedInstanceState.containsKey(KEY_Y)) {
            Log.d(TAG, "restoring state");
            int x = (int) savedInstanceState.get(KEY_X);
            int y = (int) savedInstanceState.get(KEY_Y);

            try {
                imageSurfaceView.setInputStream(getAssets().open(MAP_FILE));
                imageSurfaceView.setViewport(new Point(x, y));
            } catch (java.io.IOException e) {
                Log.e(TAG, e.getMessage());
            }
        } else {
            // Centering the map to start
            try {
                imageSurfaceView.setInputStream(getAssets().open(MAP_FILE));
                imageSurfaceView.setViewportCenter();
            } catch (java.io.IOException e) {
                Log.e(TAG, e.getMessage());
            }
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        Point p = new Point();
        imageSurfaceView.getViewport(p);
        outState.putInt(KEY_X, p.x);
        outState.putInt(KEY_Y, p.y);
        super.onSaveInstanceState(outState);
    }
}

@@ -444,17 +444,16 @@
  = %22Y%22;%0A
-%0A
     priv
@@ -588,24 +588,30 @@
 id onCreate(
+final 
 Bundle saved
@@ -904,27 +904,8 @@
 ew =
- (ImageSurfaceView)
  fin
@@ -944,30 +944,176 @@
     
-// Setup/restore state
+try %7B%0A            imageSurfaceView.setInputStream(getAssets().open(MAP_FILE));%0A        %7D catch (java.io.IOException e) %7B%0A            Log.wtf(TAG, %22Fail%22, e);%0A        %7D%0A
 %0A   
@@ -1249,113 +1249,140 @@
     
-Log.d(TAG, %22restoring state%22);%0A            int x = (int) savedInstanceState.get(KEY_X);%0A           
+imageSurfaceView.post(new Runnable() %7B%0A                @Override%0A                public void run() %7B%0A                    final
  int 
-y
+x
  = (
@@ -1417,13 +1417,12 @@
 KEY_
-Y
+X
 );%0A
-%0A
     
@@ -1433,91 +1433,71 @@
     
-try %7B%0A
+ 
        
-         imageSurfaceView.setInputStream(getAssets().open(MAP_FILE));%0A
+final int y = (int) savedInstanceState.get(KEY_Y);%0A    
     
@@ -1571,411 +1571,293 @@
     
-%7D catch (java.io.IOException e) %7B%0A                Log.e(TAG, e.getMessage());%0A            %7D%0A        %7D else %7B%0A            // Centering the map to start%0A            try %7B%0A                imageSurfaceView.setInputStream(getAssets().open(MAP_FILE));%0A                imageSurfaceView.setViewportCenter();%0A            %7D catch (java.io.IOException e) %7B%0A                Log.e(TAG, e.getMessage());%0A            %7D
+    %7D%0A            %7D);%0A        %7D else %7B%0A            // Centering the map to start%0A            imageSurfaceView.post(new Runnable() %7B%0A                @Override%0A                public void run() %7B%0A                    imageSurfaceView.setViewportCenter();%0A                %7D%0A            %7D);
 %0A   
@@ -1950,16 +1950,22 @@
         
+final 
 Point p 

Simplify further