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 |
Methods Summary |
---|
public boolean | dispatchHoverEvent(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 void | hide(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 boolean | isAssistantAvailable()
return ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
.getAssistIntent(mContext, false, UserHandle.USER_CURRENT) != null;
|
public boolean | isInContentArea(int x, int y)
return true;
|
public boolean | isShowing()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 void | maybeSwapSearchIcon()
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 void | onFinishInflate()
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 boolean | onTouchEvent(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 void | replaceDrawable(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 void | setBar(com.android.systemui.statusbar.BaseStatusBar bar)
mBar = bar;
|
public void | setHorizontal(boolean horizontal)
mHorizontal = horizontal;
mCircle.setHorizontal(horizontal);
|
public void | show(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 void | startAbortAnimation()
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 void | startAssistActivity()
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 void | startEnterAnimation()
mCircle.startEnterAnimation();
mScrim.setAlpha(0f);
mScrim.animate()
.alpha(1f)
.setDuration(300)
.setStartDelay(50)
.setInterpolator(PhoneStatusBar.ALPHA_IN)
.start();
|
private void | startExitAnimation()
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 void | vibrate()
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);
}
|