| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.widget; |
| 18 |
|
| 19 |
import android.content.BroadcastReceiver; |
| 20 |
import android.content.Context; |
| 21 |
import android.content.Intent; |
| 22 |
import android.content.IntentFilter; |
| 23 |
import android.graphics.PixelFormat; |
| 24 |
import android.graphics.Rect; |
| 25 |
import android.os.Handler; |
| 26 |
import android.os.Message; |
| 27 |
import android.util.Log; |
| 28 |
import android.view.Gravity; |
| 29 |
import android.view.KeyEvent; |
| 30 |
import android.view.LayoutInflater; |
| 31 |
import android.view.MotionEvent; |
| 32 |
import android.view.View; |
| 33 |
import android.view.View.OnClickListener; |
| 34 |
import android.view.ViewConfiguration; |
| 35 |
import android.view.ViewGroup; |
| 36 |
import android.view.ViewRootImpl; |
| 37 |
import android.view.WindowManager; |
| 38 |
import android.view.WindowManager.LayoutParams; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
@Deprecated |
| 76 |
public class ZoomButtonsController implements View.OnTouchListener { |
| 77 |
|
| 78 |
private static final String TAG = "ZoomButtonsController"; |
| 79 |
|
| 80 |
private static final int ZOOM_CONTROLS_TIMEOUT = |
| 81 |
(int) ViewConfiguration.getZoomControlsTimeout(); |
| 82 |
|
| 83 |
private static final int ZOOM_CONTROLS_TOUCH_PADDING = 20; |
| 84 |
private int mTouchPaddingScaledSq; |
| 85 |
|
| 86 |
private final Context mContext; |
| 87 |
private final WindowManager mWindowManager; |
| 88 |
private boolean mAutoDismissControls = true; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
private final View mOwnerView; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
private final int[] mOwnerViewRawLocation = new int[2]; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
private final FrameLayout mContainer; |
| 105 |
private LayoutParams mContainerLayoutParams; |
| 106 |
private final int[] mContainerRawLocation = new int[2]; |
| 107 |
|
| 108 |
private ZoomControls mControls; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
private View mTouchTargetView; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
private final int[] mTouchTargetWindowLocation = new int[2]; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
private boolean mReleaseTouchListenerOnUp; |
| 129 |
|
| 130 |
|
| 131 |
private boolean mIsVisible; |
| 132 |
|
| 133 |
private final Rect mTempRect = new Rect(); |
| 134 |
private final int[] mTempIntArray = new int[2]; |
| 135 |
|
| 136 |
private OnZoomListener mCallback; |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
private Runnable mPostedVisibleInitializer; |
| 145 |
|
| 146 |
private final IntentFilter mConfigurationChangedFilter = |
| 147 |
new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED); |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
private final BroadcastReceiver mConfigurationChangedReceiver = new BroadcastReceiver() { |
| 153 |
@Override |
| 154 |
public void onReceive(Context context, Intent intent) { |
| 155 |
if (!mIsVisible) return; |
| 156 |
|
| 157 |
mHandler.removeMessages(MSG_POST_CONFIGURATION_CHANGED); |
| 158 |
mHandler.sendEmptyMessage(MSG_POST_CONFIGURATION_CHANGED); |
| 159 |
} |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
private static final int MSG_POST_CONFIGURATION_CHANGED = 2; |
| 164 |
|
| 165 |
private static final int MSG_DISMISS_ZOOM_CONTROLS = 3; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
private static final int MSG_POST_SET_VISIBLE = 4; |
| 171 |
|
| 172 |
private final Handler mHandler = new Handler() { |
| 173 |
@Override |
| 174 |
public void handleMessage(Message msg) { |
| 175 |
switch (msg.what) { |
| 176 |
case MSG_POST_CONFIGURATION_CHANGED: |
| 177 |
onPostConfigurationChanged(); |
| 178 |
break; |
| 179 |
|
| 180 |
case MSG_DISMISS_ZOOM_CONTROLS: |
| 181 |
setVisible(false); |
| 182 |
break; |
| 183 |
|
| 184 |
case MSG_POST_SET_VISIBLE: |
| 185 |
if (mOwnerView.getWindowToken() == null) { |
| 186 |
|
| 187 |
Log.e(TAG, |
| 188 |
"Cannot make the zoom controller visible if the owner view is " + |
| 189 |
"not attached to a window."); |
| 190 |
} else { |
| 191 |
setVisible(true); |
| 192 |
} |
| 193 |
break; |
| 194 |
} |
| 195 |
|
| 196 |
} |
| 197 |
}; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
public ZoomButtonsController(View ownerView) { |
| 206 |
mContext = ownerView.getContext(); |
| 207 |
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
| 208 |
mOwnerView = ownerView; |
| 209 |
|
| 210 |
mTouchPaddingScaledSq = (int) |
| 211 |
(ZOOM_CONTROLS_TOUCH_PADDING * mContext.getResources().getDisplayMetrics().density); |
| 212 |
mTouchPaddingScaledSq *= mTouchPaddingScaledSq; |
| 213 |
|
| 214 |
mContainer = createContainer(); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
public void setZoomInEnabled(boolean enabled) { |
| 223 |
mControls.setIsZoomInEnabled(enabled); |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
public void setZoomOutEnabled(boolean enabled) { |
| 232 |
mControls.setIsZoomOutEnabled(enabled); |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
public void setZoomSpeed(long speed) { |
| 241 |
mControls.setZoomSpeed(speed); |
| 242 |
} |
| 243 |
|
| 244 |
private FrameLayout createContainer() { |
| 245 |
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); |
| 246 |
|
| 247 |
lp.gravity = Gravity.TOP | Gravity.START; |
| 248 |
lp.flags = LayoutParams.FLAG_NOT_TOUCHABLE | |
| 249 |
LayoutParams.FLAG_NOT_FOCUSABLE | |
| 250 |
LayoutParams.FLAG_LAYOUT_NO_LIMITS | |
| 251 |
LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 252 |
lp.height = LayoutParams.WRAP_CONTENT; |
| 253 |
lp.width = LayoutParams.MATCH_PARENT; |
| 254 |
lp.type = LayoutParams.TYPE_APPLICATION_PANEL; |
| 255 |
lp.format = PixelFormat.TRANSLUCENT; |
| 256 |
lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; |
| 257 |
mContainerLayoutParams = lp; |
| 258 |
|
| 259 |
FrameLayout container = new Container(mContext); |
| 260 |
container.setLayoutParams(lp); |
| 261 |
container.setMeasureAllChildren(true); |
| 262 |
|
| 263 |
LayoutInflater inflater = (LayoutInflater) mContext |
| 264 |
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 265 |
inflater.inflate(com.android.internal.R.layout.zoom_container, container); |
| 266 |
|
| 267 |
mControls = container.findViewById(com.android.internal.R.id.zoomControls); |
| 268 |
mControls.setOnZoomInClickListener(new OnClickListener() { |
| 269 |
public void onClick(View v) { |
| 270 |
dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT); |
| 271 |
if (mCallback != null) mCallback.onZoom(true); |
| 272 |
} |
| 273 |
}); |
| 274 |
mControls.setOnZoomOutClickListener(new OnClickListener() { |
| 275 |
public void onClick(View v) { |
| 276 |
dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT); |
| 277 |
if (mCallback != null) mCallback.onZoom(false); |
| 278 |
} |
| 279 |
}); |
| 280 |
|
| 281 |
return container; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
public void setOnZoomListener(OnZoomListener listener) { |
| 290 |
mCallback = listener; |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
public void setFocusable(boolean focusable) { |
| 301 |
int oldFlags = mContainerLayoutParams.flags; |
| 302 |
if (focusable) { |
| 303 |
mContainerLayoutParams.flags &= ~LayoutParams.FLAG_NOT_FOCUSABLE; |
| 304 |
} else { |
| 305 |
mContainerLayoutParams.flags |= LayoutParams.FLAG_NOT_FOCUSABLE; |
| 306 |
} |
| 307 |
|
| 308 |
if ((mContainerLayoutParams.flags != oldFlags) && mIsVisible) { |
| 309 |
mWindowManager.updateViewLayout(mContainer, mContainerLayoutParams); |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
public boolean isAutoDismissed() { |
| 319 |
return mAutoDismissControls; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
public void setAutoDismissed(boolean autoDismiss) { |
| 327 |
if (mAutoDismissControls == autoDismiss) return; |
| 328 |
mAutoDismissControls = autoDismiss; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
public boolean isVisible() { |
| 337 |
return mIsVisible; |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
public void setVisible(boolean visible) { |
| 346 |
|
| 347 |
if (visible) { |
| 348 |
if (mOwnerView.getWindowToken() == null) { |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
if (!mHandler.hasMessages(MSG_POST_SET_VISIBLE)) { |
| 355 |
mHandler.sendEmptyMessage(MSG_POST_SET_VISIBLE); |
| 356 |
} |
| 357 |
return; |
| 358 |
} |
| 359 |
|
| 360 |
dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT); |
| 361 |
} |
| 362 |
|
| 363 |
if (mIsVisible == visible) { |
| 364 |
return; |
| 365 |
} |
| 366 |
mIsVisible = visible; |
| 367 |
|
| 368 |
if (visible) { |
| 369 |
if (mContainerLayoutParams.token == null) { |
| 370 |
mContainerLayoutParams.token = mOwnerView.getWindowToken(); |
| 371 |
} |
| 372 |
|
| 373 |
mWindowManager.addView(mContainer, mContainerLayoutParams); |
| 374 |
|
| 375 |
if (mPostedVisibleInitializer == null) { |
| 376 |
mPostedVisibleInitializer = new Runnable() { |
| 377 |
public void run() { |
| 378 |
refreshPositioningVariables(); |
| 379 |
|
| 380 |
if (mCallback != null) { |
| 381 |
mCallback.onVisibilityChanged(true); |
| 382 |
} |
| 383 |
} |
| 384 |
}; |
| 385 |
} |
| 386 |
|
| 387 |
mHandler.post(mPostedVisibleInitializer); |
| 388 |
|
| 389 |
|
| 390 |
mContext.registerReceiver(mConfigurationChangedReceiver, mConfigurationChangedFilter); |
| 391 |
|
| 392 |
|
| 393 |
mOwnerView.setOnTouchListener(this); |
| 394 |
mReleaseTouchListenerOnUp = false; |
| 395 |
|
| 396 |
} else { |
| 397 |
|
| 398 |
if (mTouchTargetView != null) { |
| 399 |
|
| 400 |
|
| 401 |
mReleaseTouchListenerOnUp = true; |
| 402 |
} else { |
| 403 |
mOwnerView.setOnTouchListener(null); |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
mContext.unregisterReceiver(mConfigurationChangedReceiver); |
| 408 |
|
| 409 |
mWindowManager.removeViewImmediate(mContainer); |
| 410 |
mHandler.removeCallbacks(mPostedVisibleInitializer); |
| 411 |
|
| 412 |
if (mCallback != null) { |
| 413 |
mCallback.onVisibilityChanged(false); |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
public ViewGroup getContainer() { |
| 429 |
return mContainer; |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
public View getZoomControls() { |
| 438 |
return mControls; |
| 439 |
} |
| 440 |
|
| 441 |
private void dismissControlsDelayed(int delay) { |
| 442 |
if (mAutoDismissControls) { |
| 443 |
mHandler.removeMessages(MSG_DISMISS_ZOOM_CONTROLS); |
| 444 |
mHandler.sendEmptyMessageDelayed(MSG_DISMISS_ZOOM_CONTROLS, delay); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
private void refreshPositioningVariables() { |
| 449 |
|
| 450 |
if (mOwnerView.getWindowToken() == null) return; |
| 451 |
|
| 452 |
|
| 453 |
int ownerHeight = mOwnerView.getHeight(); |
| 454 |
int ownerWidth = mOwnerView.getWidth(); |
| 455 |
|
| 456 |
int containerOwnerYOffset = ownerHeight - mContainer.getHeight(); |
| 457 |
|
| 458 |
|
| 459 |
mOwnerView.getLocationOnScreen(mOwnerViewRawLocation); |
| 460 |
mContainerRawLocation[0] = mOwnerViewRawLocation[0]; |
| 461 |
mContainerRawLocation[1] = mOwnerViewRawLocation[1] + containerOwnerYOffset; |
| 462 |
|
| 463 |
int[] ownerViewWindowLoc = mTempIntArray; |
| 464 |
mOwnerView.getLocationInWindow(ownerViewWindowLoc); |
| 465 |
|
| 466 |
|
| 467 |
mContainerLayoutParams.x = ownerViewWindowLoc[0]; |
| 468 |
mContainerLayoutParams.width = ownerWidth; |
| 469 |
mContainerLayoutParams.y = ownerViewWindowLoc[1] + containerOwnerYOffset; |
| 470 |
if (mIsVisible) { |
| 471 |
mWindowManager.updateViewLayout(mContainer, mContainerLayoutParams); |
| 472 |
} |
| 473 |
|
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
private boolean onContainerKey(KeyEvent event) { |
| 478 |
int keyCode = event.getKeyCode(); |
| 479 |
if (isInterestingKey(keyCode)) { |
| 480 |
|
| 481 |
if (keyCode == KeyEvent.KEYCODE_BACK) { |
| 482 |
if (event.getAction() == KeyEvent.ACTION_DOWN |
| 483 |
&& event.getRepeatCount() == 0) { |
| 484 |
if (mOwnerView != null) { |
| 485 |
KeyEvent.DispatcherState ds = mOwnerView.getKeyDispatcherState(); |
| 486 |
if (ds != null) { |
| 487 |
ds.startTracking(event, this); |
| 488 |
} |
| 489 |
} |
| 490 |
return true; |
| 491 |
} else if (event.getAction() == KeyEvent.ACTION_UP |
| 492 |
&& event.isTracking() && !event.isCanceled()) { |
| 493 |
setVisible(false); |
| 494 |
return true; |
| 495 |
} |
| 496 |
|
| 497 |
} else { |
| 498 |
dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT); |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
return false; |
| 503 |
|
| 504 |
} else { |
| 505 |
|
| 506 |
ViewRootImpl viewRoot = mOwnerView.getViewRootImpl(); |
| 507 |
if (viewRoot != null) { |
| 508 |
viewRoot.dispatchInputEvent(event); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
return true; |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
private boolean isInterestingKey(int keyCode) { |
| 517 |
switch (keyCode) { |
| 518 |
case KeyEvent.KEYCODE_DPAD_CENTER: |
| 519 |
case KeyEvent.KEYCODE_DPAD_UP: |
| 520 |
case KeyEvent.KEYCODE_DPAD_DOWN: |
| 521 |
case KeyEvent.KEYCODE_DPAD_LEFT: |
| 522 |
case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 523 |
case KeyEvent.KEYCODE_ENTER: |
| 524 |
case KeyEvent.KEYCODE_BACK: |
| 525 |
return true; |
| 526 |
default: |
| 527 |
return false; |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
public boolean onTouch(View v, MotionEvent event) { |
| 536 |
int action = event.getAction(); |
| 537 |
|
| 538 |
if (event.getPointerCount() > 1) { |
| 539 |
|
| 540 |
return false; |
| 541 |
} |
| 542 |
|
| 543 |
if (mReleaseTouchListenerOnUp) { |
| 544 |
|
| 545 |
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { |
| 546 |
mOwnerView.setOnTouchListener(null); |
| 547 |
setTouchTargetView(null); |
| 548 |
mReleaseTouchListenerOnUp = false; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
return true; |
| 553 |
} |
| 554 |
|
| 555 |
dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT); |
| 556 |
|
| 557 |
View targetView = mTouchTargetView; |
| 558 |
|
| 559 |
switch (action) { |
| 560 |
case MotionEvent.ACTION_DOWN: |
| 561 |
targetView = findViewForTouch((int) event.getRawX(), (int) event.getRawY()); |
| 562 |
setTouchTargetView(targetView); |
| 563 |
break; |
| 564 |
|
| 565 |
case MotionEvent.ACTION_UP: |
| 566 |
case MotionEvent.ACTION_CANCEL: |
| 567 |
setTouchTargetView(null); |
| 568 |
break; |
| 569 |
} |
| 570 |
|
| 571 |
if (targetView != null) { |
| 572 |
|
| 573 |
int targetViewRawX = mContainerRawLocation[0] + mTouchTargetWindowLocation[0]; |
| 574 |
int targetViewRawY = mContainerRawLocation[1] + mTouchTargetWindowLocation[1]; |
| 575 |
|
| 576 |
MotionEvent containerEvent = MotionEvent.obtain(event); |
| 577 |
|
| 578 |
|
| 579 |
containerEvent.offsetLocation(mOwnerViewRawLocation[0] - targetViewRawX, |
| 580 |
mOwnerViewRawLocation[1] - targetViewRawY); |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
float containerX = containerEvent.getX(); |
| 585 |
float containerY = containerEvent.getY(); |
| 586 |
if (containerX < 0 && containerX > -ZOOM_CONTROLS_TOUCH_PADDING) { |
| 587 |
containerEvent.offsetLocation(-containerX, 0); |
| 588 |
} |
| 589 |
if (containerY < 0 && containerY > -ZOOM_CONTROLS_TOUCH_PADDING) { |
| 590 |
containerEvent.offsetLocation(0, -containerY); |
| 591 |
} |
| 592 |
boolean retValue = targetView.dispatchTouchEvent(containerEvent); |
| 593 |
containerEvent.recycle(); |
| 594 |
return retValue; |
| 595 |
|
| 596 |
} else { |
| 597 |
return false; |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
private void setTouchTargetView(View view) { |
| 602 |
mTouchTargetView = view; |
| 603 |
if (view != null) { |
| 604 |
view.getLocationInWindow(mTouchTargetWindowLocation); |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
private View findViewForTouch(int rawX, int rawY) { |
| 616 |
|
| 617 |
int containerCoordsX = rawX - mContainerRawLocation[0]; |
| 618 |
int containerCoordsY = rawY - mContainerRawLocation[1]; |
| 619 |
Rect frame = mTempRect; |
| 620 |
|
| 621 |
View closestChild = null; |
| 622 |
int closestChildDistanceSq = Integer.MAX_VALUE; |
| 623 |
|
| 624 |
for (int i = mContainer.getChildCount() - 1; i >= 0; i--) { |
| 625 |
View child = mContainer.getChildAt(i); |
| 626 |
if (child.getVisibility() != View.VISIBLE) { |
| 627 |
continue; |
| 628 |
} |
| 629 |
|
| 630 |
child.getHitRect(frame); |
| 631 |
if (frame.contains(containerCoordsX, containerCoordsY)) { |
| 632 |
return child; |
| 633 |
} |
| 634 |
|
| 635 |
int distanceX; |
| 636 |
if (containerCoordsX >= frame.left && containerCoordsX <= frame.right) { |
| 637 |
distanceX = 0; |
| 638 |
} else { |
| 639 |
distanceX = Math.min(Math.abs(frame.left - containerCoordsX), |
| 640 |
Math.abs(containerCoordsX - frame.right)); |
| 641 |
} |
| 642 |
int distanceY; |
| 643 |
if (containerCoordsY >= frame.top && containerCoordsY <= frame.bottom) { |
| 644 |
distanceY = 0; |
| 645 |
} else { |
| 646 |
distanceY = Math.min(Math.abs(frame.top - containerCoordsY), |
| 647 |
Math.abs(containerCoordsY - frame.bottom)); |
| 648 |
} |
| 649 |
int distanceSq = distanceX * distanceX + distanceY * distanceY; |
| 650 |
|
| 651 |
if ((distanceSq < mTouchPaddingScaledSq) && |
| 652 |
(distanceSq < closestChildDistanceSq)) { |
| 653 |
closestChild = child; |
| 654 |
closestChildDistanceSq = distanceSq; |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
return closestChild; |
| 659 |
} |
| 660 |
|
| 661 |
private void onPostConfigurationChanged() { |
| 662 |
dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT); |
| 663 |
refreshPositioningVariables(); |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
public interface OnZoomListener { |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
void onVisibilityChanged(boolean visible); |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
void onZoom(boolean zoomIn); |
| 685 |
} |
| 686 |
|
| 687 |
private class Container extends FrameLayout { |
| 688 |
public Container(Context context) { |
| 689 |
super(context); |
| 690 |
} |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
@Override |
| 699 |
public boolean dispatchKeyEvent(KeyEvent event) { |
| 700 |
return onContainerKey(event) ? true : super.dispatchKeyEvent(event); |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
} |