Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit abc13309 authored by Samuel Cheung's avatar Samuel Cheung Committed by Josh Guilfoyle
Browse files

resolve bug: Carousel - switching between items causes activities to pause and resume several times

parent 56f13367
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -156964,6 +156964,19 @@
<parameter name="isInTouchMode" type="boolean">
</parameter>
</method>
<method name="removeViewFromLayout"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="protected"
>
<parameter name="mLaunchedView" type="android.view.View">
</parameter>
</method>
<method name="setCurrentTab"
 return="void"
 abstract="false"
+20 −5
Original line number Diff line number Diff line
@@ -289,8 +289,10 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");

    @Override
    public void dispatchWindowFocusChanged(boolean hasFocus) {
        if (mCurrentView != null) {
            mCurrentView.dispatchWindowFocusChanged(hasFocus);
        }
    }

    public void setCurrentTab(int index) {
        if (index < 0 || index >= mTabSpecs.size()) {
@@ -316,6 +318,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
        // tab content
        mCurrentView = spec.mContentStrategy.getContentView();

        if (mCurrentView != null) {
        if (mCurrentView.getParent() == null) {
            mTabContent
                    .addView(
@@ -330,6 +333,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
            // give the current tab content view a shot
            mCurrentView.requestFocus();
        }
        }
        
        //mTabContent.requestFocus(View.FOCUS_FORWARD);
        invokeOnTabChangeListener();
@@ -664,6 +668,10 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
        }

        public View getContentView() {
            
//            if (!mCloseView)
//                return null;
            
            if (mLocalActivityManager == null) {
                throw new IllegalStateException("Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?");
            }
@@ -696,9 +704,16 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
            if (mLaunchedView != null) {
                if (mCloseView) {
                    mLaunchedView.setVisibility(View.GONE);
                } else {
                    removeViewFromLayout(mLaunchedView);
                }
            }
        }

       
    }

    protected void removeViewFromLayout(View mLaunchedView) {
        
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ public class Carousel extends TabHost implements OnGestureListener {
		}

		if (mCarouselTabContentLayout != null) {
		    mCarouselTabContentLayout.setTabHost(this);
			mCarouselTabContentLayout.setAdapter(new CarouselViewAdapter());
		}
	}
@@ -166,7 +167,7 @@ public class Carousel extends TabHost implements OnGestureListener {
				return false;
			}
			
			mCarouselTabContentLayout.setSelection(newSelectedPosition);
			mCarouselTabContentLayout.setSelection(newSelectedPosition, true, true);
			mTabWidget.setFilmstripSelection(newSelectedPosition);
			
			return true;
@@ -220,4 +221,9 @@ public class Carousel extends TabHost implements OnGestureListener {
            
            mCarouselTabContentLayout.setSelection(index, false);
        }
		
		// Call carousel tab layout to remove view
		protected void removeViewFromLayout(View aView) {
		    mCarouselTabContentLayout.removeViewFromLayout(aView);
		}
}
+29 −19
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.view.ViewParent;
import android.widget.AbsoluteLayout;
import android.widget.Adapter;
import android.widget.Scroller;
import android.widget.TabHost;

public class CarouselLayout extends AbsoluteLayout {

@@ -68,6 +69,8 @@ public class CarouselLayout extends AbsoluteLayout {
    private int mSelectedPosition = INVALID_POSITION;
    private Adapter mAdapter;
    private int mScrollDuration = 0;
    private TabHost mTabHost;
    
    private ScrollerRunnable mScrollerRunnable = new ScrollerRunnable();

    public CarouselLayout(Context context) {
@@ -127,33 +130,28 @@ public class CarouselLayout extends AbsoluteLayout {
    private void removeOldSelectedView() {
        if (INVALID_POSITION == mOldSelectedPosition) return;

        View theOldSelectedView = mAdapter.getView(mOldSelectedPosition, null, this);
        removeView(theOldSelectedView);
        mOldSelectedPosition = INVALID_POSITION;
    }
    
    public void removeViewFromLayout(View aView) {
        removeView(aView);
    }
    
    
    private void snapToCurrentSelection() {
        mScrollerRunnable.stop();
        removeOldSelectedView();
        if (INVALID_POSITION != mSelectedPosition) {
            View theSelectedView = mAdapter.getView(mSelectedPosition, null, this);
            theSelectedView.setLayoutParams(new AbsoluteLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                                                                            ViewGroup.LayoutParams.FILL_PARENT, 0, 0));
            requestLayout();
            theSelectedView.setFocusable(true);
            theSelectedView.setFocusableInTouchMode(true);
            ((ViewGroup) theSelectedView).setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
            
            // Do not request focus in order to keep the focus in Gallery when it has the focus
            //theSelectedView.requestFocus();
        }
    }
    
    public void setSelection(int position) {
        setSelection(position, false);
        setSelection(position, false, false);
    }
    
    public void setTabHost(TabHost aTabHost) {
        mTabHost = aTabHost;
    }
    
    public void setSelection(int position, boolean animate) {
    public void setSelection(int position, boolean animate, boolean startActivity) {
        if (position == mSelectedPosition) return;
        
        snapToCurrentSelection();
@@ -161,7 +159,16 @@ public class CarouselLayout extends AbsoluteLayout {
        mSelectedPosition = position;
        if (INVALID_POSITION != mSelectedPosition) {
            int xView = 0;
            View theSelectedView = mAdapter.getView(mSelectedPosition, null, this);
            
            View theSelectedView = null;
            
            if (startActivity) {
                theSelectedView = mAdapter.getView(mSelectedPosition, null, this);
            } else {
                theSelectedView = mTabHost.getCurrentView();
            }
           
            
            if (animate && (INVALID_POSITION != mOldSelectedPosition)) {
                xView = (mSelectedPosition > mOldSelectedPosition) ? getWidth() : -getWidth();
                mScrollerRunnable.scrollBy(-xView, mScrollDuration);
@@ -182,6 +189,9 @@ public class CarouselLayout extends AbsoluteLayout {
            addView(theSelectedView,
                    new AbsoluteLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                                                    ViewGroup.LayoutParams.FILL_PARENT, xView, 0));
                                                    
                 
        
        } else {
           removeOldSelectedView();
       }
+13 −2
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import android.view.KeyEvent;
import android.view.View;
import android.widget.Adapter;
import android.widget.FrameLayout;
import android.widget.TabHost;

import com.android.internal.R;

@@ -54,13 +55,17 @@ public class CarouselTabContentLayout extends FrameLayout {
	}
	
	public void setSelection(int position, boolean animate) {
		mCarouselLayout.setSelection(position, animate);
		mCarouselLayout.setSelection(position, animate, false);
    }
	
	public void setAdapter(Adapter adapter) {
		mCarouselLayout.setAdapter(adapter);
	}
	
	public void setTabHost(TabHost aTabHost) {
	    mCarouselLayout.setTabHost(aTabHost);
	}

	@Override
	public void addView(View child, int width, int height) {
		// Do nothing
@@ -128,9 +133,15 @@ public class CarouselTabContentLayout extends FrameLayout {
	}
	
	public void setSelection(int position) {
		mCarouselLayout.setSelection(position, true);
		mCarouselLayout.setSelection(position, true, false);
	}
	
	public void setSelection(int position, boolean animate, boolean startActivity) {
        mCarouselLayout.setSelection(position, animate, startActivity);
    }
	
	protected void removeViewFromLayout(View aView) {
	    mCarouselLayout.removeViewFromLayout(aView);
    }
	
}