. Android's default classification 2011-01-19 13:33:32 Window class to read 514 comments 0 Font Size: medium and small subscription.
Android's Window class (a) Android's GUI layer is not complicated. The complexity of such similar WGUI layout and dialog-based GUI, and MFC, QT and other large frame are not comparable, or even the MiniGUI Feynman Wei Yongming than it is complex. You may ask how such a simple GUI browser it? The reason is simple, the browser has its own GUI. Android browser (WebKit) the GUI and the same set of Android's GUI utility GDI - Skia, but the GUI layer is completely different design, are self-contained.
Windown class, located in the code tree frameworks \ base \ core \ java \ android \ view \ Windowjava.java file. Together with the notes, a total of more than a thousand lines of this document, which outlines the basic properties of Android windows and basic functions.
Window attributes are listed below:
FEATURE_OPTIONS_PANEL = 0; function is unknown, see the description below (default enabled)
FEATURE_NO_TITLE = 1; no title bar
FEATURE_PROGRESS = 2; in the title bar shows the loading progress, such as when the page loads webview (strip progress bar)
FEATURE_LEFT_ICON = 3; in the title bar displays an icon on the left
FEATURE_RIGHT_ICON = 4; in the title bar displays an icon on the right
FEATURE_INDETERMINATE_PROGRESS = 5; uncertain progress (circle-like waiting icon)
FEATURE_CONTEXT_MENU = 6; the context menu, right-click menu on a PC equivalent (default enabled)
FEATURE_CUSTOM_TITLE = 7; custom title bar, the property can not be combined with other properties of the title bar
FEATURE_OPENGL = 8; If you open the OpenGL, OpenGL will then deal with 2D (OpenGL 3D in 2D is a subset of)
PROGRESS_VISIBILITY_ON = -1; progress bar shows
PROGRESS_VISIBILITY_OFF = -2; progress bar is not visible
PROGRESS_INDETERMINATE_ON = -3; open the uncertain model
PROGRESS_INDETERMINATE_OFF = -4; off uncertainty model
PROGRESS_START = 0; the first progress bar's minimum value
PROGRESS_END = 10000; the maximum value of the first progress bar
PROGRESS_SECONDARY_START = 20000; the minimum value of the second progress bar
PROGRESS_SECONDARY_END = 30000; the maximum value of the second progress bar
* Note: FEATURE_OPTIONS_PANEL probably meant is: when the user selected the menu, the window will call onOptionsItemSelected function to handle the menu functions. If you do not FEATURE_OPTIONS_PANEL option, then the menu will not respond to it? Never tried, did not find online.
1, hide the title bar
2, in the title bar displays the progress bar
final ProgressBar progressHorizontal = (ProgressBar) findViewById (R.id.progress_horizontal);
setProgress (progressHorizontal.getProgress () * 100);
setSecondaryProgress (progressHorizontal.getSecondaryProgress () * 100);
3, using a custom title bar
getWindow (). setFeatureInt (Window.FEATURE_CUSTOM_TITLE, R.layout.my_title_bar);
4, clear the contents of the title bar, while the area is reserved
((ViewGroup) getWindow (). FindViewById (com.android.internal.R.id.title_container)). RemoveAllViews ();
5, hide the title bar
((ViewGroup) getWindow ().
findViewById (com.android.internal.R.id.title_container)). setVisibility (View.GONE);
6, show the title bar
... SetVisibility (View.VISIBLE);
(1) requestWindowFeature () to setContentView () before calling;
(2) set the various Feature, is a exclusive, once set, can not be changed for other types of follow-up;
(3) When using TabHost (derived from the ActivityGroup), the various Tab in the Activity, or are NO_TITLE, or are CUSTOM_TITLE, can not be set separately.
Android's Window class (b)
Window class to remove a lot of FEATURE_ attributes, is nothing less than the rest of the contents of two parts:
First, the definition of Callback interface, which contains a series of dispatchXxxx function and a series of onXxxx functions for handling UI events;
Second, define your own WindowManager - LocalWindowManager. The main changes the addView function, set the title.
Callback interface contains the following functions:
public boolean dispatchKeyEvent (KeyEventevent);
Key event handling. At a minimum, your code to call superDispatchKeyEvent function.
public booleandispatchTouchEvent (MotionEvent event);
Processing touch event. At a minimum, your code to call superDispatchTouchEvent function.
public booleandispatchTrackballEvent (MotionEvent event);
Handle trackball events. At a minimum, your code to call superDispatchTrackballEvent function.
public booleandispatchPopulateAccessibilityEvent (AccessibilityEventevent);
Accessibility event processing (ancillary events, such as focus changes, the button is clicked, etc.), processing is complete, return true.
Create a display panel of the view
Returns null, you will create a default content (usually a menu).
Back to the top panel should be placed on view.
public View onCreatePanelView (intfeatureId);
Initialization panel menu, the function returns null if onCreatePanelView will call this function, create a standard menu, you can add menu items to it. Only when the panel displays the time of the first call this function. If it returns false, panel will not be displayed.
public boolean onCreatePanelMenu (intfeatureId, Menu menu);
Each panel shows the window before any call to this function. Should return true, if the return false will not be displayed.
public boolean onPreparePanel (intfeatureId, View view, Menu menu);
When the user opens the panel's menu is called. When switching the menu style will be called. For example, from the icon menu to switch to the extended menu.
Returns true to allow the menu to open, false to stop the menu opens.
public boolean onMenuOpened (intfeatureId, Menu menu);
Users select the menu item.
public boolean onMenuItemSelected (intfeatureId, MenuItem item);
The current window attributes change.
public voidonWindowAttributesChanged (WindowManager.LayoutParamsattrs);
Change the window view.
public voidonContentChanged ();
Window focus changes.
public void onWindowFocusChanged (booleanhasFocus);
Window attached to the window manager.
public voidonAttachedToWindow ();
Window on the removal from the window manager.
public voidonDetachedFromWindow ();
panel to be called off.
If a follow-up of the panel will start (this panel to make room for follow-up panel), then do not call this function.
public void onPanelClosed (int featureId, Menu menu);
When the user presses the search button.
If you start the search interface returns true, if it can not execute it returns false.
public booleanonSearchRequested ();
WindowManager doing? It is not a "window manager", WindowManagerService is the window manager. Name of Xuan Hu, in fact, a bunch of key management state WindowManager word, and words in these states, the most commonly used is LayoutParams.
Derived relationship is as follows:
ViewManager only three functions: addView, updateViewLayout, removeView.
The subclass LayoutParams WindowManager the very rich. In fact WindowManager.java the main content is constituted by this class definition. It is defined as follows:
public static class LayoutParams extendsViewGroup.LayoutParams implementsParcelable
Derived relationship is as follows:
There are two main LayoutParams ViewManager the macro, the two variables.
LayoutParams WindowManager the relatively rich, we will go next time decomposition.
Android's Window class (c)
The LayoutParams WindowManager subclass, can be "rich" to describe the word.
If you ignore the gravity attribute it to represent the absolute X position.
What is the gravity attributes? In short, is the window to stop.
When the set after Gravity.LEFT or Gravity.RIGHT, x value for that edge to a specific distance.
If you ignore the gravity attribute it to represent the absolute Y position.
When the set after Gravity.TOP or Gravity.BOTTOM, y value to a particular edge to that distance.
In the vertical, the associated view for the expansion of space reserved for how much (in pixels). If it is 0, then this view can not be stretched.
Other cases, the expansion of space (pixels) will be shared equally by the widget.
Window type. There are 3 main types:
Applicationwindows: FIRST_APPLICATION_WINDOW and LAST_APPLICATION_WINDOW value in between.
Is the usual, top-level application window. Activity token must be set to the token.
Sub_windows: FIRST_SUB_WINDOW and LAST_SUB_WINDOW value in between.
Associated with the top-level window, token must be set to which it is attached to the host window token.
Systemwindows: FIRST_SYSTEM_WINDOW and LAST_SYSTEM_WINDOW value in between.
For specific system functions. It can not be used for applications that use need special permissions.
The following type values are defined:
public staticfinal int FIRST_APPLICATION_WINDOW = 1;
All the program window "base" window, the other application windows are displayed on it.
public staticfinal int TYPE_BASE_APPLICATION = 1;
Normal function of the program window to be yo. token must be set to Activity of the token, to point out that the window is who.
public staticfinal int TYPE_APPLICATION = 2;
When the application starts for the display window. Do not use this type of application itself.
It is used to allow the system to display more information, until the application can open their windows.
public staticfinal int TYPE_APPLICATION_STARTING = 3;
The end of the application window.
public staticfinal int LAST_APPLICATION_WINDOW = 99;
Child window. Z order and child window coordinate space are dependent on their host window.
public staticfinal int FIRST_SUB_WINDOW = 1000;
Panel window, shown in the upper window the host.
public staticfinal int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW;
Media window, such as video. The lower window displays the host.
public staticfinal int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW +1;
Sub-panel of the application window. All panels shown in the upper window. (GUI's general rule, the more "child," the more upper)
public staticfinal int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW +2;
Dialog box. Similar to the panel window, similar to top-level window to draw, not the host of the child window.
public staticfinal int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW +3;
Media Information. Display window in the media layer and between the need to implement transparent (translucent) effect. (Such as displaying subtitles)
public staticfinal int TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW +4;
The end of the child window.
public staticfinal int LAST_SUB_WINDOW = 1999;
System window. Non-application to create.
public staticfinal int FIRST_SYSTEM_WINDOW = 2000;
Status bar. Can only have a status bar; It is located in top of the screen, other windows are located beneath it.
public staticfinal int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW;
Search bar. Can only have a search bar; it is located in top of the screen.
public staticfinal int TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW +1;
Phone window. It is used for telephone interaction (especially incoming). It is placed on top of all applications, the status bar below.
public staticfinal int TYPE_PHONE = FIRST_SYSTEM_WINDOW +2;
Prompted. It appears in the application window always on top.
public staticfinal int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW +3;
Lock screen window.
public staticfinal int TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW +4;
Information window. Used to display the toast.
public staticfinal int TYPE_TOAST = FIRST_SYSTEM_WINDOW +5;
System top-level window. All other content displayed on top of. This window can not get the input focus, or affect the lock screen.
public staticfinal int TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW +6;
Call first, when the lock screen is displayed. This window can not get the input focus, or affect the lock screen.
public staticfinal int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW +7;
System dialog box. (Such as volume control box).
public staticfinal int TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW +8;
Lock screen displayed when the dialog box.
public staticfinal int TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW +9;
Internal system error, displayed on top of everything.
public staticfinal int TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW +10;
Internal input window, displayed on top of regular UI. Re-layout of the application window to avoid being overwritten.
public staticfinal int TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW +11;
Internal input dialog box displays the current input method windows.
public staticfinal int TYPE_INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW +12;
public staticfinal int TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW +13;
Status bar sliding panel.
public staticfinal int TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW +14;
The end of the system window.
public staticfinal int LAST_SYSTEM_WINDOW = 2999;
Pointed out that the memory buffer used by the window type. The default is NORMAL.
Window located in the main memory buffer.
public staticfinal int MEMORY_TYPE_NORMAL = 0;
DMA buffer in the window can be accessed or hardware accelerated memory.
public staticfinal int MEMORY_TYPE_HARDWARE = 1;
Window graphics accelerator buffer can be visited in the area.
public staticfinal int MEMORY_TYPE_GPU = 2;
The window does not have its own buffer cache and can not be locked. Buffer provided by the local method.
public staticfinal int MEMORY_TYPE_PUSH_BUFFERS = 3;
Behavioral options / flags, the default is none
The contents of the window after dark.
public staticfinal int FLAG_DIM_BEHIND = 0x00000002;
After the contents of the window blur.
public staticfinal int FLAG_BLUR_BEHIND = 0x00000004;
Allowed to receive focus.
Can not get key input focus, so it can not be sent to the key or button event. Time will be sent to those who follow it can get the focus window. This option will set FLAG_NOT_TOUCH_MODAL options. Setting this option means that the window can not interact with the soft-input method, so it's Z order activities independent of any input method (in other words, it can be full screen, if necessary, covering the input window). To modify this behavior, refer to FLAG_ALT_FOCUSALBE_IM options.
public staticfinal int FLAG_NOT_FOCUSABLE = 0x00000008;
Do not accept the touch screen events.
public staticfinal int FLAG_NOT_TOUCHABLE = 0x00000010;
When the window can get the focus (not set FLAG_NOT_FOCUSALBE option), the still point outside the window device events (mouse, touch screen) sent to the back of the window treatment. Otherwise it will keep all the points device events, and whether they are not in the window range.
public staticfinal int FLAG_NOT_TOUCH_MODAL = 0x00000020;
If you set this flag, when the device is suspended, click the touch screen, the device will receive the first touch event.
The first touch event is usually consumed by the system, users will not see what response they click the screen.
public staticfinal int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040;
When this window is visible for the user to maintain equipment normally open, and keep the brightness constant.
public staticfinal int FLAG_KEEP_SCREEN_ON = 0x00000080;
Window fill the screen, ignoring the decoration around the border (such as the status bar.) This window must take into account the content of decorative borders.
public staticfinal int FLAG_LAYOUT_IN_SCREEN = 0x00000100;
Allows the window to expand beyond the screen.
public staticfinal int FLAG_LAYOUT_NO_LIMITS = 0x00000200;
Window is displayed, the screen hides all decorations (such as the status bar). Make the window occupy the entire display area.
public staticfinal int FLAG_FULLSCREEN = 0x00000400;
This option will cover FLAG_FULLSCREEN option, and force the screen decoration (such as the status bar) pops up.
public staticfinal int FLAG_FORCE_NOT_FULLSCREEN = 0x00000800;
Jitter. Refers to the semi-transparent display method. Also known as the "point through." Poor graphics device often used "point through" alternative Alpha blending.
public staticfinal int FLAG_DITHER = 0x00001000;
Does not allow screenshots.
public staticfinal int FLAG_SECURE = 0x00002000;
A special pattern, layout parameters used to indicate the ratio.
public staticfinal int FLAG_SCALED = 0x00004000;
When the screen may be affixed to her face, this option prevents the misoperation caused by cheek on the screen.
public staticfinal int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000;
When requesting the layout, your window may appear in the status bar above or below, resulting in occlusion. When setting this option, the window manager will ensure that the window contents are not decoration (the status bar) covered.
public staticfinal int FLAG_LAYOUT_INSET_DECOR = 0x00010000;
Reverse FLAG_NOT_FOCUSABLE options.
If both the FLAG_NOT_FOCUSABLE options and this option, the window will be able to interact with the input method that allows input method window cover;
If FLAG_NOT_FOCUSABLE not set and this option is set, the window is not interacting with the input method, you can cover the input method window.
public staticfinal int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
If you set the FLAG_NOT_TOUCH_MODAL, then when the touch event took place in the window of foreign affairs, you can set this flag to receive a MotionEvent.ACTION_OUTSIDE event. Note that you will not receive the full down / move / up events, only the first down when the event can receive ACTION_OUTSIDE.
public staticfinal int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000;
When the screen is locked, the window can be seen. This makes the priority application window lock screen interface. Can light up the screen with FLAG_KEEP_SCREEN_ON option and displayed before the lock screen interface. Option can be used directly to lift the non-locking FLAG_DISMISS_KEYGUARD the lock-screen state. This option is only for the most top-level full-screen window.
public staticfinal int FLAG_SHOW_WHEN_LOCKED = 0x00080000;
Request system wallpaper displayed on the back of your window. Window must be translucent.
public staticfinal int FLAG_SHOW_WALLPAPER = 0x00100000;
Once the window is displayed, the system will light up the screen, as users wake up the device so.
public staticfinal int FLAG_TURN_SCREEN_ON = 0x00200000;
Unlock screen. Only the lock-screen interface is not encrypted can be unlocked. If the lock-screen interface is encrypted, then the user can see the window after unlock, unless set FLAG_SHOW_WHEN_LOCKED options.
public staticfinal int FLAG_DISMISS_KEYGUARD = 0x00400000;
Lock screen interface fade out, to continue to run the animation.
public staticfinal int FLAG_KEEP_SURFACE_WHILE_ANIMATING = 0x10000000;
Display window to its original size. Used to run the program in compatibility mode.
public staticfinal int FLAG_COMPATIBLE_WINDOW = 0x20000000;
For the system dialog box. Setting this option window unconditional focus.
public staticfinal int FLAG_SYSTEM_ERROR = 0x40000000;
Soft-input mode options:
The following options and input patterns:
Soft input area is visible.
public staticfinal int SOFT_INPUT_MASK_STATE = 0x0f;
public staticfinal int SOFT_INPUT_STATE_UNSPECIFIED = 0;
Do not modify the state of the soft input area.
public staticfinal int SOFT_INPUT_STATE_UNCHANGED = 1;
Hide the input area (when the user into the window.)
public staticfinal int SOFT_INPUT_STATE_HIDDEN = 2;
When the window has focus, hide the input area.
public staticfinal int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
Display input area (when the user into the window.)
public staticfinal int SOFT_INPUT_STATE_VISIBLE = 4;
When the window gets the focus, the display input area.
public staticfinal int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
Window should take the initiative to adjust to the soft input window.
public staticfinal int SOFT_INPUT_MASK_ADJUST = 0xf0;
The state is not specified, the system will try to select a window to input the content of style.
public staticfinal int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
When the input is displayed, allowing the window to recalculate the size of the input content is not covered.
Can not be mixed with SOFT_INPUT_ADJUSP_PAN; if the two are not set, the system will automatically set according to the contents of one of the options window.
public staticfinal int SOFT_INPUT_ADJUST_RESIZE = 0x10;
Input shift display window. It does not deal with size changes can move the window frame to ensure that the input focus visible.
Can not be mixed with SOFT_INPUT_ADJUST_RESIZE; if the two are not set, the system will automatically set according to the contents of one of the options window.
public staticfinal int SOFT_INPUT_ADJUST_PAN = 0x20;
When the user switch to this window, set automatically by the system, so you do not set it.
When the window displays of the flag is automatically cleared after.
public staticfinal int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
The level of margins, the distance between the container and the widget, representing the percentage of the width of the container.
The desired bitmap format. The default is opaque. Reference android.graphics.PixelFormat.
Animation settings used by the window. It must be a system resources than the application of resources, because the window manager can not access the application.
Value of the entire window translucent and 1.0 means transparent and 0.0 means fully transparent.
public floatalpha = 1.0f;
When FLAG_DIM_BEHIND set to take effect. This variable indicates the degree of dimming rear window.
1.0 means fully opaque, 0.0 is not dimmed.
public floatdimAmount = 1.0f;
Used to cover the user to set the screen brightness. Said the application user settings screen brightness.
Adjusted from 0 to 1, the brightest light from the dark to change.
public floatscreenBrightness =-1.0f;
public IBindertoken = null;
This window is where the package name.
public StringpackageName = null;
Screen orientation, see android.content.pm.ActivityInfo # screenOrientation.
public intscreenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The following defines a variety of "CHANGE" message is used for the copyFrom function.
public staticfinal int LAYOUT_CHANGED = 1 <<0;
public staticfinal int TYPE_CHANGED = 1 <<1;
public staticfinal int FLAGS_CHANGED = 1 <<2;
public staticfinal int FORMAT_CHANGED = 1 <<3;
public staticfinal int ANIMATION_CHANGED = 1 <<4;
public staticfinal int DIM_AMOUNT_CHANGED = 1 <<5;
public staticfinal int TITLE_CHANGED = 1 <<6;
public staticfinal int ALPHA_CHANGED = 1 <<7;
public staticfinal int MEMORY_TYPE_CHANGED = 1 <<8;
public staticfinal int SOFT_INPUT_MODE_CHANGED = 1 <<9;
public staticfinal int SCREEN_ORIENTATION_CHANGED = 1 <<10;
public staticfinal int SCREEN_BRIGHTNESS_CHANGED = 1 <<11;
In compatibility mode, backup / recovery parameters used by the internal buffer.
private int  mCompatibilityParamsBackup = null;