Search in sources :

Example 81 with ActionMode

use of android.view.ActionMode in project android_frameworks_base by DirtyUnicorns.

the class DecorView method createStandaloneActionMode.

private ActionMode createStandaloneActionMode(ActionMode.Callback callback) {
    endOnGoingFadeAnimation();
    cleanupPrimaryActionMode();
    // cleanupPrimaryActionMode() invocation above.
    if (mPrimaryActionModeView == null || !mPrimaryActionModeView.isAttachedToWindow()) {
        if (mWindow.isFloating()) {
            // Use the action bar theme.
            final TypedValue outValue = new TypedValue();
            final Resources.Theme baseTheme = mContext.getTheme();
            baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
            final Context actionBarContext;
            if (outValue.resourceId != 0) {
                final Resources.Theme actionBarTheme = mContext.getResources().newTheme();
                actionBarTheme.setTo(baseTheme);
                actionBarTheme.applyStyle(outValue.resourceId, true);
                actionBarContext = new ContextThemeWrapper(mContext, 0);
                actionBarContext.getTheme().setTo(actionBarTheme);
            } else {
                actionBarContext = mContext;
            }
            mPrimaryActionModeView = new ActionBarContextView(actionBarContext);
            mPrimaryActionModePopup = new PopupWindow(actionBarContext, null, R.attr.actionModePopupWindowStyle);
            mPrimaryActionModePopup.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION);
            mPrimaryActionModePopup.setContentView(mPrimaryActionModeView);
            mPrimaryActionModePopup.setWidth(MATCH_PARENT);
            actionBarContext.getTheme().resolveAttribute(R.attr.actionBarSize, outValue, true);
            final int height = TypedValue.complexToDimensionPixelSize(outValue.data, actionBarContext.getResources().getDisplayMetrics());
            mPrimaryActionModeView.setContentHeight(height);
            mPrimaryActionModePopup.setHeight(WRAP_CONTENT);
            mShowPrimaryActionModePopup = new Runnable() {

                public void run() {
                    mPrimaryActionModePopup.showAtLocation(mPrimaryActionModeView.getApplicationWindowToken(), Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
                    endOnGoingFadeAnimation();
                    if (shouldAnimatePrimaryActionModeView()) {
                        mFadeAnim = ObjectAnimator.ofFloat(mPrimaryActionModeView, View.ALPHA, 0f, 1f);
                        mFadeAnim.addListener(new AnimatorListenerAdapter() {

                            @Override
                            public void onAnimationStart(Animator animation) {
                                mPrimaryActionModeView.setVisibility(VISIBLE);
                            }

                            @Override
                            public void onAnimationEnd(Animator animation) {
                                mPrimaryActionModeView.setAlpha(1f);
                                mFadeAnim = null;
                            }
                        });
                        mFadeAnim.start();
                    } else {
                        mPrimaryActionModeView.setAlpha(1f);
                        mPrimaryActionModeView.setVisibility(VISIBLE);
                    }
                }
            };
        } else {
            ViewStub stub = (ViewStub) findViewById(R.id.action_mode_bar_stub);
            if (stub != null) {
                mPrimaryActionModeView = (ActionBarContextView) stub.inflate();
                mPrimaryActionModePopup = null;
            }
        }
    }
    if (mPrimaryActionModeView != null) {
        mPrimaryActionModeView.killMode();
        ActionMode mode = new StandaloneActionMode(mPrimaryActionModeView.getContext(), mPrimaryActionModeView, callback, mPrimaryActionModePopup == null);
        return mode;
    }
    return null;
}
Also used : Context(android.content.Context) PopupWindow(android.widget.PopupWindow) Paint(android.graphics.Paint) StandaloneActionMode(com.android.internal.view.StandaloneActionMode) ViewStub(android.view.ViewStub) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ContextThemeWrapper(android.view.ContextThemeWrapper) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ActionMode(android.view.ActionMode) StandaloneActionMode(com.android.internal.view.StandaloneActionMode) FloatingActionMode(com.android.internal.view.FloatingActionMode) ActionBarContextView(com.android.internal.widget.ActionBarContextView) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 82 with ActionMode

use of android.view.ActionMode in project android_frameworks_base by DirtyUnicorns.

the class WindowDecorActionBarTest method testStartActionModeFinishesPreviousMode.

@UiThreadTest
public void testStartActionModeFinishesPreviousMode() {
    ActionMode mode1 = mWindowDecorActionBar.startActionMode(mCallback);
    ActionMode mode2 = mWindowDecorActionBar.startActionMode(new MockActionModeCallback());
    assertNotNull(mode1);
    assertNotNull(mode2);
    assertTrue(mCallback.mIsDestroyActionModeCalled);
}
Also used : ActionMode(android.view.ActionMode) UiThreadTest(android.test.UiThreadTest)

Example 83 with ActionMode

use of android.view.ActionMode in project android_frameworks_base by DirtyUnicorns.

the class PhoneWindowActionModeTest method testStartActionModeWithCallback.

public void testStartActionModeWithCallback() {
    mWindowCallback.mShouldReturnOwnActionMode = true;
    ActionMode mode = mPhoneWindow.getDecorView().startActionMode(mActionModeCallback, ActionMode.TYPE_FLOATING);
    assertEquals(mWindowCallback.mLastCreatedActionMode, mode);
}
Also used : ActionMode(android.view.ActionMode)

Example 84 with ActionMode

use of android.view.ActionMode in project android_frameworks_base by DirtyUnicorns.

the class PhoneWindowActionModeTest method testStartActionModePrimaryFinishesPreviousMode.

public void testStartActionModePrimaryFinishesPreviousMode() {
    // Use custom callback to control the provided ActionMode.
    mWindowCallback.mShouldReturnOwnActionMode = true;
    ActionMode mode1 = mPhoneWindow.getDecorView().startActionMode(mActionModeCallback, ActionMode.TYPE_PRIMARY);
    ActionMode mode2 = mPhoneWindow.getDecorView().startActionMode(mActionModeCallback, ActionMode.TYPE_PRIMARY);
    assertTrue(mode1 instanceof MockActionMode);
    assertTrue(((MockActionMode) mode1).mIsFinished);
    assertNotNull(mode2);
}
Also used : ActionMode(android.view.ActionMode)

Example 85 with ActionMode

use of android.view.ActionMode in project android_frameworks_base by DirtyUnicorns.

the class PhoneWindowActionModeTest method testStartActionModePreservesPreviousModeOfDifferentType2.

public void testStartActionModePreservesPreviousModeOfDifferentType2() {
    // Use custom callback to control the provided ActionMode.
    mWindowCallback.mShouldReturnOwnActionMode = true;
    ActionMode mode1 = mPhoneWindow.getDecorView().startActionMode(mActionModeCallback, ActionMode.TYPE_PRIMARY);
    ActionMode mode2 = mPhoneWindow.getDecorView().startActionMode(mActionModeCallback, ActionMode.TYPE_FLOATING);
    assertTrue(mode1 instanceof MockActionMode);
    assertFalse(((MockActionMode) mode1).mIsFinished);
    assertNotNull(mode2);
}
Also used : ActionMode(android.view.ActionMode)

Aggregations

ActionMode (android.view.ActionMode)99 UiThreadTest (android.test.UiThreadTest)30 FloatingActionMode (com.android.internal.view.FloatingActionMode)15 StandaloneActionMode (com.android.internal.view.StandaloneActionMode)10 Menu (android.view.Menu)9 MenuItem (android.view.MenuItem)9 Animator (android.animation.Animator)6 Context (android.content.Context)6 Paint (android.graphics.Paint)6 View (android.view.View)6 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)5 ObjectAnimator (android.animation.ObjectAnimator)5 Resources (android.content.res.Resources)5 TypedValue (android.util.TypedValue)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 ViewStub (android.view.ViewStub)5 PopupWindow (android.widget.PopupWindow)5 ActionBarContextView (com.android.internal.widget.ActionBarContextView)5 MenuInflater (android.view.MenuInflater)4 AdapterView (android.widget.AdapterView)3