Hello Guys,

We have met a strange behavior in a very simple code, may be it is already 
known issue, and someone can advise us something.

We have TabHost with 2 views: first one is a FrameLayout which contains 
SurfaceView, second one is a fake view - any View.

The problem is in following: 

We select second tab, and then it doesn't matter how we receive a sequences 
on Pause -> on Resume (e.g. incoming call, or we just pressed home button 
and the returned back).

First of all the Resuming time is quite long.

And then, if we press menu button to show context menu,  this menu is shown 
as transparent, but it still handles clicks.

 

This problem does not appear if the same happened when the tab with Surface 
View is current.

 

The code is attached; please help us to solve this.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
package com.example.testtabhost;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.View.OnClickListener;

import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabContentFactory;

import com.example.testtabhost.VRView.PreviewState;
import com.example.testtabhost.VRView.VRVPosition;

public class MainActivity extends Activity implements OnTabChangeListener, SurfaceHolder.Callback {
    protected static final String TAG = "MainScreen";

    private TabHost             mTabHost;
    private VRView              mVRView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mVRView = new VRView(this);
        mVRView.init(PreviewState.FULL_SCREEN, VRVPosition.CENTER, new OnClickListener() {
            @Override
            public void onClick(View v) {
                    //do something
                    }
        } , this);

       //mVideoSurface = new VideoSurface(this, PreviewState.FULL_SCREEN);
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup();
        mTabHost.getTabWidget().setVisibility(View.VISIBLE);

        mTabHost.addTab(mTabHost.newTabSpec("VRView").setIndicator("VRView").setContent(
            new TabContentFactory() {
                public View createTabContent(String arg0) {
                    return mVRView;
                }
            }));

        mTabHost.addTab(mTabHost.newTabSpec("Map").setIndicator("Map").setContent(
            new TabContentFactory() {
                public View createTabContent(String arg0) {
                    return new View(MainActivity.this.getApplicationContext());
                }
            }));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void surfaceCreated(SurfaceHolder arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onTabChanged(String arg0) {
        // TODO Auto-generated method stub
        
    }
}
package com.example.testtabhost;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.SurfaceHolder;
import android.widget.FrameLayout;
import android.widget.TextView;


public class VRView extends FrameLayout  {
    private static final String TAG = "VRView";

    public enum VRVPosition { 
        CENTER          {int gravity() {return Gravity.CENTER | Gravity.CENTER;}},
        RIGHT_TOP       {int gravity() {return Gravity.RIGHT | Gravity.TOP;}},
        RIGHT_BOTTOM    {int gravity() {return Gravity.RIGHT | Gravity.BOTTOM;}}, 
        LEFT_TOP        {int gravity() {return Gravity.LEFT | Gravity.TOP;}}, 
        LEFT_BOTTOM     {int gravity() {return Gravity.LEFT | Gravity.BOTTOM;}};
        abstract int gravity();
    }
    
    public enum PreviewState { NONE, TIMING, FULL_SCREEN }
    
    private TextView            mText;
    private VideoSurface        mSurface;
    private VRVPosition         mPosition;

    public VRView(Context context) {
        super(context);
    }

    public VRView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public VRView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    // this method should be called before view usage
    public void init(PreviewState state, VRVPosition position, OnClickListener clickListener,
            SurfaceHolder.Callback mSurfaceListener) {
        
        mPosition = position;
        // prepare surface
        mSurface = new VideoSurface(getContext(), state);
        mSurface.getHolder().addCallback(mSurfaceListener);
        LayoutParams parameters = new LayoutParams(1,1); 
        parameters.gravity = mPosition.gravity();
        addView(mSurface, parameters);
        // prepare button
        mText = new TextView(getContext());
        mText.setTextSize(20);
        //mText.setBackgroundResource(R.drawable.preview_text_bgr);
        mText.setText("Recording");
        mText.setTextColor(getResources().getColor(android.R.color.black));
        
        setOnClickListener(clickListener);
        parameters = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
        parameters.gravity = mPosition.gravity();
        addView(mText, parameters);
    }

    public SurfaceHolder getHolder() {
        System.out.println(TAG + "getHolder()");
        return mSurface.getHolder();
    }
}
package com.example.testtabhost;

import android.app.Service;
import android.content.Context;
import android.view.Display;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.WindowManager;
import android.widget.FrameLayout.LayoutParams;

import com.example.testtabhost.VRView.PreviewState;
import com.example.testtabhost.VRView.VRVPosition;

class VideoSurface extends SurfaceView {
    private static final String TAG = "VideoSurface";
    private static final int PREVIEW_TIMEOUT = 3000;

    private Runnable                mPreviewTask;
    private SurfaceHolder           mHolder;
    private PreviewState            mState;

    public VideoSurface(Context context) {
        this(context, PreviewState.NONE);
    }
    
    public VideoSurface(Context context, PreviewState state) {
        super(context);
        mState = state;
        // initialize surface holder
        mHolder =  getHolder();
        // deprecated setting, but required on Android versions prior to 3.0
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

   private void preparePreview(boolean show, final VRVPosition position) {
          LayoutParams parameters;
          Display display = ((WindowManager)getContext().getSystemService(Service.WINDOW_SERVICE)).getDefaultDisplay();
          if (show) {
              switch (mState) {
              case FULL_SCREEN:
                  parameters = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
                  parameters.gravity = position.gravity();
                  break;
              case TIMING:
                  mPreviewTask = new Runnable() {
                      @Override
                      public void run() {
                          mPreviewTask = null;
                          preparePreview(false, position);
                      }
                  };
                 parameters = new LayoutParams(display.getWidth()/2, display.getHeight()/2);
                 parameters.gravity = VRVPosition.CENTER.gravity();
                 postDelayed(mPreviewTask, PREVIEW_TIMEOUT);
                 break;
              default:
                  parameters = new LayoutParams(1,1);
                  parameters.gravity = position.gravity();
                  break;
              }
          } else {
              parameters = new LayoutParams(1,1); 
              parameters.gravity = position.gravity();
          }
          setLayoutParams(parameters);
      }

    public void startPreview(VRVPosition position) {
        preparePreview(true, position);
    }

     public void stopPreview(VRVPosition position) {
         if (mPreviewTask != null) {
              removeCallbacks(mPreviewTask);
              mPreviewTask = null;
          }
          preparePreview(false, position); 
      }
    }

Attachment: activity_main.xml
Description: XML document

Attachment: activity_main.xml
Description: XML document

Reply via email to