View的事件分发二
来源:互联网 发布:xpath语法和数据库 编辑:程序博客网 时间:2024/06/13 09:03
前面说到View的事件分发是从Activity开始的,那是什么传给我们的Activity的呢。
首先我们知道activity只有在onResume后才能点击对吧。
那我们看它的代码,看它和窗口的关系
我们知道Activity里有它实现了一个接口window.Callback
public class Activity extends ContextThemeWrapper implements LayoutInflater.Factory2, Window.Callback, KeyEvent.Callback, OnCreateContextMenuListener, ComponentCallbacks2
public interface Callback { /** * Called to process key events. At the very least your * implementation must call * {@link android.view.Window#superDispatchKeyEvent} to do the * standard key processing. * * @param event The key event. * * @return boolean Return true if this event was consumed. */ public boolean dispatchKeyEvent(KeyEvent event); //事件分发 /** * Called to process a key shortcut event. * At the very least your implementation must call * {@link android.view.Window#superDispatchKeyShortcutEvent} to do the * standard key shortcut processing. * * @param event The key shortcut event. * @return True if this event was consumed. */ public boolean dispatchKeyShortcutEvent(KeyEvent event); /** * Called to process touch screen events. At the very least your * implementation must call * {@link android.view.Window#superDispatchTouchEvent} to do the * standard touch screen processing. * * @param event The touch screen event. * * @return boolean Return true if this event was consumed. */ public boolean dispatchTouchEvent(MotionEvent event); /** * Called to process trackball events. At the very least your * implementation must call * {@link android.view.Window#superDispatchTrackballEvent} to do the * standard trackball processing. * * @param event The trackball event. * * @return boolean Return true if this event was consumed. */ public boolean dispatchTrackballEvent(MotionEvent event); /** * Called to process generic motion events. At the very least your * implementation must call * {@link android.view.Window#superDispatchGenericMotionEvent} to do the * standard processing. * * @param event The generic motion event. * * @return boolean Return true if this event was consumed. */ public boolean dispatchGenericMotionEvent(MotionEvent event); /** * Called to process population of {@link AccessibilityEvent}s. * * @param event The event. * * @return boolean Return true if event population was completed. */ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event); /** * Instantiate the view to display in the panel for 'featureId'. * You can return null, in which case the default content (typically * a menu) will be created for you. * * @param featureId Which panel is being created. * * @return view The top-level view to place in the panel. * * @see #onPreparePanel */ @Nullable public View onCreatePanelView(int featureId); /** * Initialize the contents of the menu for panel 'featureId'. This is * called if onCreatePanelView() returns null, giving you a standard * menu in which you can place your items. It is only called once for * the panel, the first time it is shown. * * <p>You can safely hold on to <var>menu</var> (and any items created * from it), making modifications to it as desired, until the next * time onCreatePanelMenu() is called for this feature. * * @param featureId The panel being created. * @param menu The menu inside the panel. * * @return boolean You must return true for the panel to be displayed; * if you return false it will not be shown. */ public boolean onCreatePanelMenu(int featureId, Menu menu); /** * Prepare a panel to be displayed. This is called right before the * panel window is shown, every time it is shown. * * @param featureId The panel that is being displayed. * @param view The View that was returned by onCreatePanelView(). * @param menu If onCreatePanelView() returned null, this is the Menu * being displayed in the panel. * * @return boolean You must return true for the panel to be displayed; * if you return false it will not be shown. * * @see #onCreatePanelView */ public boolean onPreparePanel(int featureId, View view, Menu menu); /** * Called when a panel's menu is opened by the user. This may also be * called when the menu is changing from one type to another (for * example, from the icon menu to the expanded menu). * * @param featureId The panel that the menu is in. * @param menu The menu that is opened. * @return Return true to allow the menu to open, or false to prevent * the menu from opening. */ public boolean onMenuOpened(int featureId, Menu menu); /** * Called when a panel's menu item has been selected by the user. * * @param featureId The panel that the menu is in. * @param item The menu item that was selected. * * @return boolean Return true to finish processing of selection, or * false to perform the normal menu handling (calling its * Runnable or sending a Message to its target Handler). */ public boolean onMenuItemSelected(int featureId, MenuItem item); /** * This is called whenever the current window attributes change. * */ public void onWindowAttributesChanged(WindowManager.LayoutParams attrs); /** * This hook is called whenever the content view of the screen changes * (due to a call to * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams) * Window.setContentView} or * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams) * Window.addContentView}). */ public void onContentChanged(); /** * This hook is called whenever the window focus changes. See * {@link View#onWindowFocusChanged(boolean) * View.onWindowFocusChangedNotLocked(boolean)} for more information. * * @param hasFocus Whether the window now has focus. */ public void onWindowFocusChanged(boolean hasFocus); /** * Called when the window has been attached to the window manager. * See {@link View#onAttachedToWindow() View.onAttachedToWindow()} * for more information. */ public void onAttachedToWindow(); /** * Called when the window has been attached to the window manager. * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()} * for more information. */ public void onDetachedFromWindow(); /** * Called when a panel is being closed. If another logical subsequent * panel is being opened (and this panel is being closed to make room for the subsequent * panel), this method will NOT be called. * * @param featureId The panel that is being displayed. * @param menu If onCreatePanelView() returned null, this is the Menu * being displayed in the panel. */ public void onPanelClosed(int featureId, Menu menu); /** * Called when the user signals the desire to start a search. * * @return true if search launched, false if activity refuses (blocks) * * @see android.app.Activity#onSearchRequested() */ public boolean onSearchRequested(); /** * Called when an action mode is being started for this window. Gives the * callback an opportunity to handle the action mode in its own unique and * beautiful way. If this method returns null the system can choose a way * to present the mode or choose not to start the mode at all. * * @param callback Callback to control the lifecycle of this action mode * @return The ActionMode that was started, or null if the system should present it */ @Nullable public ActionMode onWindowStartingActionMode(ActionMode.Callback callback); /** * Called when an action mode has been started. The appropriate mode callback * method will have already been invoked. * * @param mode The new mode that has just been started. */ public void onActionModeStarted(ActionMode mode); /** * Called when an action mode has been finished. The appropriate mode callback * method will have already been invoked. * * @param mode The mode that was just finished. */ public void onActionModeFinished(ActionMode mode); }里面有很多我们耳熟能详的方法,如onWindowsfocusChanged,看到了没,还有我们的onDispatchTouchEvent吧。接口被定义在window里,说明肯定是类似phonewindow的那种对象来回调activity.
mWindow = PolicyManager.makeNewWindow(this);mWindow.setCallback(this);Activity的attach方法里出现了如上代码。
总结几点View分发一的文章得出的结论,
由于onIntercept里可以根据事件而返回。
1.当父容器拦截了down事件后,mfirstTouch为空,所以就以父容器拦截整个事件结束,
2.当父容器不拦截down事件,子容器如果消耗掉的down事件的化,此时mFirstTouch不为空还是进入语句,这个事件的move和up还是得经过父容器的拦截器,它的事件还是可能被父容器拦截
3.当父容器不拦截down事件,子容器也不去消耗,这个事件就是以父容器上传给activity而结束。
上面情况是不考虑一个标志,这个标志称为不准拦截标志。
0 0
- View的事件分发二
- View的事件分发机制二--事件分发规则
- View的事件分发
- View的事件分发
- view的分发事件
- View的事件分发
- View的事件分发
- View的事件分发
- View的事件分发
- View及ViewGroup的事件分发及传递(二)
- View及ViewGroup的事件分发及传递(二)
- View及ViewGroup的事件分发及传递(二)
- Android知识整理<二>View的事件分发机制
- View及ViewGroup的事件分发及传递(二)
- Android自定义View的事件分发机制(二)
- Android事件分发详解(二)——View的事件分发
- Android——View的事件体系(二)View的事件分发机制
- 关于View的事件分发
- Eclipse工程之间设置依赖关系
- Android OTA升级
- Eclipse 保存修改文件时编译整个项目问题
- HttpURLConnection用法详解
- Dandelion - Eclipse Lisp Plugin
- View的事件分发二
- LeetCode刷题系列(九)Dynamic Programming(2)Longest Subxxxx
- 获取汉字拼音
- 【Leetcode】之Sort Colors
- 理解ImageLoader的原理
- 之前好好的 JLink SWD can not enter debug mode
- 写论文时,给目录和正文分别设置从1开始的页码
- Java/Android对象的四中引用类型 (对象的强、软、弱和虚引用)
- 九度OJ 1096 日期差值(经典)