Hello Guys,
I want to use a View with SurfaceView as a Tab in TabHost. I had written a 
simple application and met a strange problem.

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 onPause() -> 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 handle clicks.

This problem does not appear if the same happened when the tab with Surface 
View is current. I did different to solve, but doesn't work. The code is 
quite simple and i don't want any extraordinary, but still strange problem 
is there.

May be someone can help us.

Thanks in advance.


public class MainActivity extends Activity implements OnTabChangeListener, 
SurfaceHolder.Callback {
        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());
                    }
                }));
        }
    ...
    //callbacks do nothing
    }

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

    public enum VRVPosition { 
        CENTER          {int gravity() {return Gravity.CENTER | 
Gravity.CENTER;}},
        ...
        abstract int gravity();
    }

    public enum PreviewState { NONE, TIMING, FULL_SCREEN }

    private TextView            mText;
    private VideoSurface        mSurface;
    private VRVPosition         mPosition;

    ...
   // Constructors

    // 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);
    }
}

And VideoSurface just extends SurfaceView 

 

-- 
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

Reply via email to