start time: 2016-1-19 21:30:41
in tomorrow night, I got two questions. one is callback. another is why conext need menus? I need some data. callback: a piece of code that gets called after a certain event has happend. like that

When something happens in my view I fire off an event that my activity is listening for:

// DECLARED IN (CUSTOM) VIEW

 private OnScoreSavedListener onScoreSavedListener; public interface OnScoreSavedListener { public void onScoreSaved(); } // ALLOWS YOU TO SET LISTENER && INVOKE THE OVERIDING METHOD  // FROM WITHIN ACTIVITY public void setOnScoreSavedListener(OnScoreSavedListener listener) { onScoreSavedListener = listener; }

// DECLARED IN ACTIVITY

 MyCustomView slider = (MyCustomView) view.findViewById(R.id.slider) slider.setOnScoreSavedListener(new OnScoreSavedListener() { @Override public void onScoreSaved() { Log.v("","EVENT FIRED"); } });
in simple way, what I understand is callback like a spy waiting for something happen then solve it.
let's check class window ,see how callback get work.
public abstract class

Window

extends Object
java.lang.Object
android.view.Window

Class Overview

Abstract base class for a top-level window look and behavior policy. An instance of this class should be used as the top-level view added to the window manager. It provides standard UI policies such as a background, title area, default key processing, etc.

The only existing implementation of this abstract class is android.view.PhoneWindow, which you should instantiate when needing a Window.

Summary

Nested Classes
interface Window.Callback API from a Window back to its caller.


top-level window , window manger , standard UI policies ? great, it's looks like some keys.
nested class ? in java definition : A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class.
like that OnScoreSavedListenernested in class activity.
afer that , some thing show before us.
XML Attributes
Attribute Name Related Method Description
android:windowAllowEnterTransitionOverlap setAllowEnterTransitionOverlap(boolean) Flag indicating whether this Window's transition should overlap with the exiting transition of the calling Activity.
android:windowAllowReturnTransitionOverlap setAllowReturnTransitionOverlap(boolean) Flag indicating whether this Window's transition should overlap with the exiting transition of the called Activity when the called Activity finishes.
android:windowContentTransitionManager setTransitionManager(TransitionManager) Reference to a TransitionManager XML resource defining the desired transitions between different window content.
android:windowEnterTransition setEnterTransition(Transition) Reference to a Transition XML resource defining the desired Transition used to move Views into the initial Window's content Scene.
android:windowExitTransition setExitTransition(Transition) Reference to a Transition XML resource defining the desired Transition used to move Views out of the Window's content Scene when launching a new Activity.
android:windowReenterTransition setReenterTransition(Transition) Reference to a Transition XML resource defining the desired Transition used to move Views in to the scene when returning from a previously-started Activity.
android:windowReturnTransition setReturnTransition(Transition) Reference to a Transition XML resource defining the desired Transition used to move Views out of the scene when the Window is preparing to close.
android:windowSharedElementEnterTransition setSharedElementEnterTransition(Transition) Reference to a Transition XML resource defining the desired Transition used to move shared elements transferred into the Window's initial content Scene.
android:windowSharedElementExitTransition setSharedElementExitTransition(Transition) Reference to a Transition XML resource defining the desired Transition used when starting a new Activity to move shared elements prior to transferring to the called Activity.
android:windowSharedElementReenterTransition setSharedElementReenterTransition(Transition) Reference to a Transition XML resource defining the desired Transition used for shared elements transferred back to a calling Activity.
android:windowSharedElementReturnTransition setSharedElementReturnTransition(Transition) Reference to a Transition XML resource defining the desired Transition used to move shared elements transferred back to a calling Activity.
android:windowSharedElementsUseOverlay setSharedElementsUseOverlay(boolean) Indicates whether or not shared elements should use an overlay during transitions.
android:windowTransitionBackgroundFadeDuration setTransitionBackgroundFadeDuration(long) The duration, in milliseconds, of the window background fade duration when transitioning into or away from an Activity when called with an Activity Transition.

overlap transition move Views into the initial Window's content Scene move Views out of the Window's content Scene when launching a new Activity move shared elements starting a new Activity to move shared elements prior to transferring to the called Activity
what we all know about transition is like a procedure. all or not. so, move view or shared elements on window's context scene. that's key.
Constants
int DEFAULT_FEATURES This constant was deprecated in API level 22. usegetDefaultFeatures(android.content.Context)instead.
int FEATURE_ACTION_BAR Flag for enabling the Action Bar.
int FEATURE_ACTION_BAR_OVERLAY Flag for requesting an Action Bar that overlays window content.
int FEATURE_ACTION_MODE_OVERLAY Flag for specifying the behavior of action modes when an Action Bar is not present.
int FEATURE_ACTIVITY_TRANSITIONS Enables Activities to run Activity Transitions either through sending or receiving ActivityOptions bundle created withmakeSceneTransitionAnimation(android.app.Activity, android.util.Pair[])ormakeSceneTransitionAnimation(android.app.Activity, View, String).
int FEATURE_CONTENT_TRANSITIONS Flag for requesting that window content changes should be animated using a TransitionManager.
int FEATURE_CONTEXT_MENU Flag for the context menu.
int FEATURE_CUSTOM_TITLE Flag for custom title.
int FEATURE_INDETERMINATE_PROGRESS Flag for indeterminate progress
int FEATURE_LEFT_ICON Flag for having an icon on the left side of the title bar
int FEATURE_NO_TITLE Flag for the "no title" feature, turning off the title at the top of the screen.
int FEATURE_OPTIONS_PANEL Flag for the "options panel" feature.
int FEATURE_PROGRESS Flag for the progress indicator feature
int FEATURE_RIGHT_ICON Flag for having an icon on the right side of the title bar
int FEATURE_SWIPE_TO_DISMISS Flag for requesting a decoration-free window that is dismissed by swiping from the left.
int ID_ANDROID_CONTENT The ID that the main layout in the XML layout file should have.
String NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME The transitionName for the navigation bar background View when a custom background is used.
int PROGRESS_END Ending value for the (primary) progress
int PROGRESS_INDETERMINATE_OFF Flag for setting the progress bar's indeterminate mode off
int PROGRESS_INDETERMINATE_ON Flag for setting the progress bar's indeterminate mode on
int PROGRESS_SECONDARY_END Highest possible value for the secondary progress
int PROGRESS_SECONDARY_START Lowest possible value for the secondary progress
int PROGRESS_START Starting value for the (primary) progress
int PROGRESS_VISIBILITY_OFF Flag for setting the progress bar's visibility to GONE
int PROGRESS_VISIBILITY_ON Flag for setting the progress bar's visibility to VISIBLE
String STATUS_BAR_BACKGROUND_TRANSITION_NAME The transitionName for the status bar background View when a custom background is used.
Public Constructors

Window( Context context)
OH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! OMG!!!!????? Action Bar context menu custom title indeterminate progress an icon on the left/right side of the title bar main layout secondary progress? progress bar's VISIBLE/GONE
let me calm down. just calm down. what I found ? why context must have a menu. It's not more than menu, and Action Bar, title, progress. I think I figure out the second problem.
Look out, class window extends java.lang.Object. Object is basic. let's check its methds.
Public Methods
abstract void addContentView( View view, ViewGroup.LayoutParams params) Variation on setContentView(View, android.view.ViewGroup.LayoutParams) to add an additional content view to the screen.
void addFlags(int flags) Convenience function to set the flag bits as specified in flags, as per setFlags(int, int).
void clearFlags(int flags) Convenience function to clear the flag bits as specified in flags, as per setFlags(int, int).
abstract void closeAllPanels()
abstract void closePanel(int featureId)
View findViewById(int id) Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).
boolean getAllowEnterTransitionOverlap() Returns how the transition set in setEnterTransition(android.transition.Transition) overlaps with the exit transition of the calling Activity.
boolean getAllowReturnTransitionOverlap() Returns how the transition set in setExitTransition(android.transition.Transition) overlaps with the exit transition of the called Activity when reentering after if finishes.
final WindowManager.LayoutParams getAttributes() Retrieve the current window attributes associated with this panel.
final Window.Callback getCallback() Return the current Callback interface for this window.
final Window getContainer() Return the container for this Window.
Scene getContentScene() Retrieve the Scene representing this window's current content.
final Context getContext() Return the Context this window policy is running in, for retrieving resources and other information.
abstract View getCurrentFocus() Return the view in this Window that currently has focus, or null if there are none.
abstract View getDecorView() Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that), which can be added as a window to the window manager.
static int getDefaultFeatures( Context context) Return the feature bits set by default on a window.
Transition getEnterTransition() Returns the transition used to move Views into the initial scene.
Transition getExitTransition() Returns the Transition that will be used to move Views out of the scene when starting a new Activity.
abstract LayoutInflater getLayoutInflater() Quick access to the LayoutInflater instance that this Window retrieved from its Context.
MediaController getMediaController() Gets the MediaController that was previously set.
abstract int getNavigationBarColor()
Transition getReenterTransition() Returns the Transition that will be used to move Views in to the scene when returning from a previously-started Activity.
Transition getReturnTransition() Returns he Transition that will be used to move Views out of the scene when the Window is preparing to close, for example after a call to finishAfterTransition().
Transition getSharedElementEnterTransition() Returns the Transition that will be used for shared elements transferred into the content Scene.
Transition getSharedElementExitTransition() Returns the Transition to use for shared elements in the launching Window prior to transferring to the launched Activity's Window.
Transition getSharedElementReenterTransition() Returns the Transition that will be used for shared elements reentering from a started Activity after it has returned the shared element to it start location.
Transition getSharedElementReturnTransition() Returns the Transition that will be used for shared elements transferred back to a calling Activity.
boolean getSharedElementsUseOverlay() Returns true when shared elements should use an Overlay during shared element transitions or falsewhen they should animate as part of the normal View hierarchy.
abstract int getStatusBarColor()
long getTransitionBackgroundFadeDuration() Returns the duration, in milliseconds, of the window background fade when transitioning into or away from an Activity when called with an Activity Transition.
TransitionManager getTransitionManager() Retrieve the TransitionManager responsible for for default transitions in this window.
abstract int getVolumeControlStream()
WindowManager getWindowManager() Return the window manager allowing this Window to display its own windows.
final TypedArray getWindowStyle() Return the Window attributes from this window's theme.
final boolean hasChildren()
boolean hasFeature(int feature) Query for the availability of a certain feature.
void injectInputEvent( InputEvent event) Inject an event to window locally.
abstract void invalidatePanelMenu(int featureId)
final boolean isActive()
abstract boolean isFloating() Return whether this window is being displayed with a floating style (based on the windowIsFloatingattribute in the style/theme).
abstract boolean isShortcutKey(int keyCode, KeyEvent event) Is a keypress one of the defined shortcut keys for this window.
final void makeActive()
abstract void onConfigurationChanged( Configuration newConfig) Should be called when the configuration is changed.
abstract void openPanel(int featureId, KeyEvent event)
abstract View peekDecorView() Retrieve the current decor view, but only if it has already been created; otherwise returns null.
abstract boolean performContextMenuIdentifierAction(int id, int flags)
abstract boolean performPanelIdentifierAction(int featureId, int id, int flags)
abstract boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags)
boolean requestFeature(int featureId) Enable extended screen features.
abstract void restoreHierarchyState( Bundle savedInstanceState)
abstract Bundle saveHierarchyState()
void setAllowEnterTransitionOverlap(boolean allow) Controls how the transition set in setEnterTransition(android.transition.Transition) overlaps with the exit transition of the calling Activity.
void setAllowReturnTransitionOverlap(boolean allow) Controls how the transition set in setExitTransition(android.transition.Transition) overlaps with the exit transition of the called Activity when reentering after if finishes.
void setAttributes( WindowManager.LayoutParams a) Specify custom window attributes.
abstract void setBackgroundDrawable( Drawable drawable) Change the background of this window to a custom Drawable.
void setBackgroundDrawableResource(int resId) Change the background of this window to a Drawable resource.
void setCallback( Window.Callback callback) Set the Callback interface for this window, used to intercept key events and other dynamic operations in the window.
abstract void setChildDrawable(int featureId, Drawable drawable)
abstract void setChildInt(int featureId, int value)
void setClipToOutline(boolean clipToOutline) Sets whether window content should be clipped to the outline of the window background.
void setContainer( Window container) Set the container for this window.
abstract void setContentView(int layoutResID) Convenience for setContentView(View, android.view.ViewGroup.LayoutParams) to set the screen content from a layout resource.
abstract void setContentView( View view) Convenience for setContentView(View, android.view.ViewGroup.LayoutParams) set the screen content to an explicit view.
abstract void setContentView( View view, ViewGroup.LayoutParams params) Set the screen content to an explicit view.
void setDimAmount(float amount) Set the amount of dim behind the window when using FLAG_DIM_BEHIND.
void setElevation(float elevation) Sets the window elevation.
void setEnterTransition( Transition transition) Sets the Transition that will be used to move Views into the initial scene.
void setExitTransition( Transition transition) Sets the Transition that will be used to move Views out of the scene when starting a new Activity.
abstract void setFeatureDrawable(int featureId, Drawable drawable) Set an explicit Drawable value for feature of this window.
abstract void setFeatureDrawableAlpha(int featureId, int alpha) Set a custom alpha value for the given drawable feature, controlling how much the background is visible through it.
abstract void setFeatureDrawableResource(int featureId, int resId) Set the value for a drawable feature of this window, from a resource identifier.
abstract void setFeatureDrawableUri(int featureId, Uri uri) Set the value for a drawable feature of this window, from a URI.
abstract void setFeatureInt(int featureId, int value) Set the integer value for a feature.
void setFlags(int flags, int mask) Set the flags of the window, as per the WindowManager.LayoutParams flags.
void setFormat(int format) Set the format of window, as per the PixelFormat types.
void setGravity(int gravity) Set the gravity of the window, as per the Gravity constants.
void setIcon(int resId) Set the primary icon for this window.
void setLayout(int width, int height) Set the width and height layout parameters of the window.
void setLocalFocus(boolean hasFocus, boolean inTouchMode) Set focus locally.
void setLogo(int resId) Set the logo for this window.
void setMediaController( MediaController controller) Sets a MediaController to send media keys and volume changes to.
abstract void setNavigationBarColor(int color) Sets the color of the navigation bar to .
void setReenterTransition( Transition transition) Sets the Transition that will be used to move Views in to the scene when returning from a previously-started Activity.
void setReturnTransition( Transition transition) Sets the Transition that will be used to move Views out of the scene when the Window is preparing to close, for example after a call to finishAfterTransition().
void setSharedElementEnterTransition( Transition transition) Sets the Transition that will be used for shared elements transferred into the content Scene.
void setSharedElementExitTransition( Transition transition) Sets the Transition that will be used for shared elements after starting a new Activity before the shared elements are transferred to the called Activity.
void setSharedElementReenterTransition( Transition transition) Sets the Transition that will be used for shared elements reentering from a started Activity after it has returned the shared element to it start location.
void setSharedElementReturnTransition( Transition transition) Sets the Transition that will be used for shared elements transferred back to a calling Activity.
void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) Sets whether or not shared elements should use an Overlay during shared element transitions.
void setSoftInputMode(int mode) Specify an explicit soft input mode to use for the window, as per WindowManager.LayoutParams.softInputMode.
abstract void setStatusBarColor(int color) Sets the color of the status bar to color.
abstract void setTitle( CharSequence title)
abstract void setTitleColor(int textColor)
void setTransitionBackgroundFadeDuration(long fadeDurationMillis) Sets the duration, in milliseconds, of the window background fade when transitioning into or away from an Activity when called with an Activity Transition.
void setTransitionManager( TransitionManager tm) Set the TransitionManager to use for default transitions in this window.
void setType(int type) Set the type of the window, as per the WindowManager.LayoutParams types.
void setUiOptions(int uiOptions) Set extra options that will influence the UI for this window.
void setUiOptions(int uiOptions, int mask) Set extra options that will influence the UI for this window.
abstract void setVolumeControlStream(int streamType)
void setWindowAnimations(int resId) Specify custom animations to use for the window, as per WindowManager.LayoutParams.windowAnimations.
void setWindowManager( WindowManager wm, IBinder appToken, String appName) Set the window manager for use by this Window to, for example, display panels.
void setWindowManager( WindowManager wm, IBinder appToken, String appName, boolean hardwareAccelerated) Set the window manager for use by this Window to, for example, display panels.
abstract boolean superDispatchGenericMotionEvent( MotionEvent event) Used by custom windows, such as Dialog, to pass the generic motion event further down the view hierarchy.
abstract boolean superDispatchKeyEvent( KeyEvent event) Used by custom windows, such as Dialog, to pass the key press event further down the view hierarchy.
abstract boolean superDispatchKeyShortcutEvent( KeyEvent event) Used by custom windows, such as Dialog, to pass the key shortcut press event further down the view hierarchy.
abstract boolean superDispatchTouchEvent( MotionEvent event) Used by custom windows, such as Dialog, to pass the touch screen event further down the view hierarchy.
abstract boolean superDispatchTrackballEvent( MotionEvent event) Used by custom windows, such as Dialog, to pass the trackball event further down the view hierarchy.
abstract void takeInputQueue( InputQueue.Callback callback) Take ownership of this window's InputQueue.
abstract void takeKeyEvents(boolean get) Request that key events come to this activity.
abstract void takeSurface( SurfaceHolder.Callback2 callback) Take ownership of this window's surface.
abstract void togglePanel(int featureId, KeyEvent event)
Protected Methods
final int getFeatures() Return the feature bits that are enabled.
final int getForcedWindowFlags() Return the window flags that have been explicitly set by the client, so will not be modified by getDecorView().
final int getLocalFeatures() Return the feature bits that are being implemented by this Window.
final boolean hasSoftInputMode() Has the app specified their own soft input mode?
abstract void onActive()
void setDefaultWindowFormat(int format) Set the default format of window, as per the PixelFormat types.

here I make a conclusion, amazing found.
add an additional content view to the screen findViewById(int id) Retrieve the current window attributesassociated with this panel container for this Window Return the Context this window policy is running in Return the view in this Window that currently has focus Returns the transitionused to move Views into the initial scene(do not know what's use to ) Quick access LayoutInflater instance Gets the MediaController Return the window managerallowing this Window to display Return the Window attributesfrom this window's theme isActive() Specify custom window attributes Change the backgroundof this window Set the Callback interface setContentView(int layoutResID) setElevation(float elevation) (>=android 6.0) setGravity(int gravity) superDispatchKeyEvent(KeyEvent event) superDispatchTouchEvent(MotionEvent event)
Window is wonderful ! I want to read its code. so I fix two problem. task is finish. here are another question. fist : class window is a basic. Activiy , Dialog and other panel base on it. I wan to know how window control OS resources. android is base on Linux. how her work? second : what is class contex ? like a container, a panel. I can feel it's like a browser which is loading javascript code or html code. Let's check tommorrow night.
I'm fish, I'm on. ----jack chen

更多相关文章

  1. Android(安卓)EditText 密码框默认是小圆点 怎么改成其它的(*)?
  2. ch08 Android(安卓)Intent
  3. Android之SharedPreference轻量级数据存储
  4. Android全局捕获异常
  5. android开发常用小知识点整理
  6. Android禁止Menu菜单键长按,(Android菜单形式)
  7. Android(安卓)禁止下拉状态栏和底部导航栏的控制
  8. Android(安卓)自定义CheckBox 样式
  9. 在Android(安卓)Studio上进行OpenCV3.1开发环境的配置

随机推荐

  1. Android中ExpandableListView的使用
  2. Android(安卓)原生 MediaPlayer 和 Media
  3. Android(安卓)图片的浏览、缩放、拖动和
  4. android-screenshot-library - Library f
  5. android部署运行已有项目小结
  6. android 启动页面
  7. Android(安卓)apk打包流程,AAPT打包,apk瘦
  8. Android(安卓)StageFrightMediaScanner源
  9. adb命令
  10. Android中文API(130) —— Html