FileDocCategorySizeDatePackage
SearchPanelView.javaAPI DocAndroid 5.1 API12684Thu Mar 12 22:22:42 GMT 2015com.android.systemui

SearchPanelView

public class SearchPanelView extends android.widget.FrameLayout implements com.android.systemui.statusbar.StatusBarPanel

Fields Summary
private static final String
TAG
private static final String
ASSIST_ICON_METADATA_NAME
private static final android.media.AudioAttributes
VIBRATION_ATTRIBUTES
private final android.content.Context
mContext
private com.android.systemui.statusbar.BaseStatusBar
mBar
private SearchPanelCircleView
mCircle
private android.widget.ImageView
mLogo
private android.view.View
mScrim
private int
mThreshold
private boolean
mHorizontal
private boolean
mLaunching
private boolean
mDragging
private boolean
mDraggedFarEnough
private float
mStartTouch
private float
mStartDrag
private boolean
mLaunchPending
Constructors Summary
public SearchPanelView(android.content.Context context, android.util.AttributeSet attrs)


         
        this(context, attrs, 0);
    
public SearchPanelView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
        mContext = context;
        mThreshold = context.getResources().getDimensionPixelSize(R.dimen.search_panel_threshold);
    
Methods Summary
public booleandispatchHoverEvent(android.view.MotionEvent event)

        // Ignore hover events outside of this panel bounds since such events
        // generate spurious accessibility events with the panel content when
        // tapping outside of it, thus confusing the user.
        final int x = (int) event.getX();
        final int y = (int) event.getY();
        if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
            return super.dispatchHoverEvent(event);
        }
        return true;
    
public voidhide(boolean animate)

        if (mBar != null) {
            // This will indirectly cause show(false, ...) to get called
            mBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
        } else {
            if (animate) {
                startAbortAnimation();
            } else {
                setVisibility(View.INVISIBLE);
            }
        }
    
public booleanisAssistantAvailable()

        return ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
                .getAssistIntent(mContext, false, UserHandle.USER_CURRENT) != null;
    
public booleanisInContentArea(int x, int y)

        return true;
    
public booleanisShowing()
Whether the panel is showing, or, if it's animating, whether it will be when the animation is done.

        return getVisibility() == View.VISIBLE && !mCircle.isAnimatingOut();
    
private voidmaybeSwapSearchIcon()

        Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
                .getAssistIntent(mContext, false, UserHandle.USER_CURRENT);
        if (intent != null) {
            ComponentName component = intent.getComponent();
            replaceDrawable(mLogo, component, ASSIST_ICON_METADATA_NAME);
        } else {
            mLogo.setImageDrawable(null);
        }
    
protected voidonFinishInflate()

        super.onFinishInflate();
        mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mCircle = (SearchPanelCircleView) findViewById(R.id.search_panel_circle);
        mLogo = (ImageView) findViewById(R.id.search_logo);
        mScrim = findViewById(R.id.search_panel_scrim);
    
public booleanonTouchEvent(android.view.MotionEvent event)

        if (mLaunching || mLaunchPending) {
            return false;
        }
        int action = event.getActionMasked();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                mStartTouch = mHorizontal ? event.getX() : event.getY();
                mDragging = false;
                mDraggedFarEnough = false;
                mCircle.reset();
                break;
            case MotionEvent.ACTION_MOVE:
                float currentTouch = mHorizontal ? event.getX() : event.getY();
                if (getVisibility() == View.VISIBLE && !mDragging &&
                        (!mCircle.isAnimationRunning(true /* enterAnimation */)
                                || Math.abs(mStartTouch - currentTouch) > mThreshold)) {
                    mStartDrag = currentTouch;
                    mDragging = true;
                }
                if (mDragging) {
                    float offset = Math.max(mStartDrag - currentTouch, 0.0f);
                    mCircle.setDragDistance(offset);
                    mDraggedFarEnough = Math.abs(mStartTouch - currentTouch) > mThreshold;
                    mCircle.setDraggedFarEnough(mDraggedFarEnough);
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                if (mDraggedFarEnough) {
                    if (mCircle.isAnimationRunning(true  /* enterAnimation */)) {
                        mLaunchPending = true;
                        mCircle.setAnimatingOut(true);
                        mCircle.performOnAnimationFinished(new Runnable() {
                            @Override
                            public void run() {
                                startExitAnimation();
                            }
                        });
                    } else {
                        startExitAnimation();
                    }
                } else {
                    startAbortAnimation();
                }
                break;
        }
        return true;
    
public voidreplaceDrawable(android.widget.ImageView v, android.content.ComponentName component, java.lang.String name)

        if (component != null) {
            try {
                PackageManager packageManager = mContext.getPackageManager();
                // Look for the search icon specified in the activity meta-data
                Bundle metaData = packageManager.getActivityInfo(
                        component, PackageManager.GET_META_DATA).metaData;
                if (metaData != null) {
                    int iconResId = metaData.getInt(name);
                    if (iconResId != 0) {
                        Resources res = packageManager.getResourcesForActivity(component);
                        v.setImageDrawable(res.getDrawable(iconResId));
                        return;
                    }
                }
            } catch (PackageManager.NameNotFoundException e) {
                Log.w(TAG, "Failed to swap drawable; "
                        + component.flattenToShortString() + " not found", e);
            } catch (Resources.NotFoundException nfe) {
                Log.w(TAG, "Failed to swap drawable from "
                        + component.flattenToShortString(), nfe);
            }
        }
        v.setImageDrawable(null);
    
public voidsetBar(com.android.systemui.statusbar.BaseStatusBar bar)

        mBar = bar;
    
public voidsetHorizontal(boolean horizontal)

        mHorizontal = horizontal;
        mCircle.setHorizontal(horizontal);
    
public voidshow(boolean show, boolean animate)

        if (show) {
            maybeSwapSearchIcon();
            if (getVisibility() != View.VISIBLE) {
                setVisibility(View.VISIBLE);
                vibrate();
                if (animate) {
                    startEnterAnimation();
                } else {
                    mScrim.setAlpha(1f);
                }
            }
            setFocusable(true);
            setFocusableInTouchMode(true);
            requestFocus();
        } else {
            if (animate) {
                startAbortAnimation();
            } else {
                setVisibility(View.INVISIBLE);
            }
        }
    
private voidstartAbortAnimation()

        mCircle.startAbortAnimation(new Runnable() {
                    @Override
                    public void run() {
                        mCircle.setAnimatingOut(false);
                        setVisibility(View.INVISIBLE);
                    }
                });
        mCircle.setAnimatingOut(true);
        mScrim.animate()
                .alpha(0f)
                .setDuration(300)
                .setStartDelay(0)
                .setInterpolator(PhoneStatusBar.ALPHA_OUT);
    
private voidstartAssistActivity()

        if (!mBar.isDeviceProvisioned()) return;

        // Close Recent Apps if needed
        mBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL);

        final Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
                .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
        if (intent == null) return;

        try {
            final ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext,
                    R.anim.search_launch_enter, R.anim.search_launch_exit);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            AsyncTask.execute(new Runnable() {
                @Override
                public void run() {
                    mContext.startActivityAsUser(intent, opts.toBundle(),
                            new UserHandle(UserHandle.USER_CURRENT));
                }
            });
        } catch (ActivityNotFoundException e) {
            Log.w(TAG, "Activity not found for " + intent.getAction());
        }
    
private voidstartEnterAnimation()

        mCircle.startEnterAnimation();
        mScrim.setAlpha(0f);
        mScrim.animate()
                .alpha(1f)
                .setDuration(300)
                .setStartDelay(50)
                .setInterpolator(PhoneStatusBar.ALPHA_IN)
                .start();

    
private voidstartExitAnimation()

        mLaunchPending = false;
        if (mLaunching || getVisibility() != View.VISIBLE) {
            return;
        }
        mLaunching = true;
        startAssistActivity();
        vibrate();
        mCircle.setAnimatingOut(true);
        mCircle.startExitAnimation(new Runnable() {
                    @Override
                    public void run() {
                        mLaunching = false;
                        mCircle.setAnimatingOut(false);
                        setVisibility(View.INVISIBLE);
                    }
                });
        mScrim.animate()
                .alpha(0f)
                .setDuration(300)
                .setStartDelay(0)
                .setInterpolator(PhoneStatusBar.ALPHA_OUT);
    
private voidvibrate()

        Context context = getContext();
        if (Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.HAPTIC_FEEDBACK_ENABLED, 1, UserHandle.USER_CURRENT) != 0) {
            Resources res = context.getResources();
            Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            vibrator.vibrate(res.getInteger(R.integer.config_search_panel_view_vibration_duration),
                    VIBRATION_ATTRIBUTES);
        }