) Windows class for Android

Source: Internet
Author: User
Windows for Android

By keis, 110 visits, network Abstract, favorites, Edit

Android's window class (1) the android GUI layer is not complex. Its complexity is similar to that of wgui, which is based on layout and dialog box. It is incomparable with large frameworks such as MFC and QT, and even the MiniGUI of feiman Wei Yongming is much more complicated than wgui. You may ask how to implement a browser with such a simple GUI? The reason is simple. The browser has its own GUI. The GUI of the android browser (WebKit) and the GUI of Android are used in the same set of GDI-skia, but the GUI layer is completely different and has its own system.
Unknown wn class, located in Code Tree frameworks \ base \ core \ Java \ Android \ view \ windowjava. Java file. Together with comments, this file contains more than one thousand lines. It summarizes the basic attributes and functions of the android window.
The window attributes are listed as follows:
Feature_options_panel = 0; the function is unknown. For more information, see the following description (default enabling)
Feature_no_title = 1; no title bar
Feature_progress = 2; display the loading progress on the title bar, for example, when a webview loads a webpage (Bar progress bar)
Feature_left_icon = 3; an icon is displayed on the left of the title bar.
Feature_right_icon = 4; an icon is displayed on the right of the title bar.
Feature_indeterminate_progress = 5; uncertain progress (circled wait icon)
Feature_context_menu = 6; context menu, equivalent to right-click menu on PC (enabled by default)
Feature_custom_title = 7; custom title bar, which cannot be used with other title bar attributes
Feature_opengl = 8; If OpenGL is enabled, 2D is processed by OpenGL (2d in OpenGL is a subset of 3D)
Progress_visibility_on =-1; The progress bar is visible.
Progress_visibility_off =-2; The progress bar is invisible.
Progress_indeterminate_on =-3; enable the uncertain Mode
Progress_indeterminate_off =-4; disable the uncertain Mode
Progress_start = 0; minimum value of the First progress bar
Progress_end = 10000; maximum value of the First progress bar
Progress_secondary_start = 20000; minimum value of the Second progress bar
Progress_secondary_end = 30000; maximum value of the Second progress bar
* Description: feature_options_panel indicates that when a user selects a menu, the window calls the onoptionsitemselected function to process the menu function. If the feature_options_panel option is not available, the menu will not respond? I have never tried it, and I cannot find it online.
Application Example:
1. Hide the title bar
Requestwindowfeature (window. feature_no_title );
2. display the progress bar on the title bar
Requestwindowfeature (window. feature_progress );
Setcontentview (R. layout. progressbar_1 );
Setprogressbarvisibility (true );
Final progressbar progresshorizontal = (progressbar) findviewbyid (R. Id. progress_horizontal );
Setprogress (progresshorizontal. getprogress () * 100 );
Setsecondaryprogress (progresshorizontal. getsecondaryprogress () * 100 );
3. Use custom title bars
Requestwindowfeature (window. feature_custom_title );
Setcontentview (R. layout. XXX );
Getwindow (). setfeatureint (window. feature_custom_title, R. layout. my_title_bar );
4. Clear the title bar, while the area is retained.
(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. display the title bar
... Setvisibility (view. Visible );
Other considerations
(1) requestwindowfeature () must be called before setcontentview;
(2) setting various feature features is exclusive. Once set, it cannot be changed to another type;
(3) When tabhost is used (derived from activitygroup), the activities in each tab are either no_title or custom_title, and cannot be set separately.

Windows for Android (2)

Apart from a lot of feature _ attributes, the remaining content of the window class is nothing more than two parts:
1. Define the callback interface, which contains a series of dispatchxxxx functions and a series of onxxxx functions for processing UI events;
2. define your own windowmanager-localwindowmanager. This mainly modifies the addview function and sets the title.
The callback interface includes the following functions:
Public Boolean dispatchkeyevent (keyeventevent );
Handle key events. At least, your code calls the superdispatchkeyevent function.
Public booleandispatchtouchevent (motionevent event );
Process touch events. At least, your code calls the superdispatchtouchevent function.
Public booleandispatchtrackballevent (motionevent event );
Process trackball events. At least, your code calls the superdispatchtrackballevent function.
Public booleandispatchpopulateaccessibilityevent (accessibilityeventevent );
Handle accessibility events (secondary events, such as focus changes and button clicks), and return true after processing is complete.
Create a view for the display panel
The return value is null. The default content (usually a menu) is created for you ).
The top-level view placed in the panel should be returned.
Public View oncreatepanelview (intfeatureid );
Initialize the Panel menu. If the oncreatepanelview function returns NULL, this function is called. To create a standard menu, you can add a menu item to it. This function is called only when the Panel is displayed for the first time. If false is returned, the Panel cannot be displayed.
Public Boolean oncreatepanelmenu (intfeatureid, menu );
This function is called before each panel window is displayed. True is returned, and false is not displayed.
Public Boolean onpreparepanel (intfeatureid, view, menu );
It is called when you open the panel menu. It is also called when the menu style is switched. For example, switch from the icon menu to the extended menu.
Returns true to allow the menu to be opened, and returns false to prevent the menu from being opened.
Public Boolean onmenuopened (intfeatureid, menu );
Select a menu item.
Public Boolean onmenuitemselected (intfeatureid, menuitem item );
The current window property is changed.
Public voidonwindowattributeschanged (windowmanager. layoutparamsattrs );
The view of the window is changed.
Public voidoncontentchanged ();
Window focus changes.
Public void onwindowfocuschanged (booleanhasfocus );
The window is appended to the window manager.
Public voidonattachedtowindow ();
The window is removed from the window manager.
Public voidondetachedfromwindow ();
Called when the Panel is closed.
If a subsequent panel is expanded (this panel makes room for subsequent panel), this function is not called.
Public void onpanelclosed (INT featureid, menu );
When the user presses the search button.
If the search interface is enabled, true is returned. If the search interface cannot be executed, false is returned.
Public booleanonsearchrequested ();
What does windowmanager do? It is not a "window manager". windowmanagerservice is the window manager. The name is Xuan Hu. In fact, windowmanager mainly manages a bunch of status words, among which layoutparams is the most commonly used.
The derived relationship is as follows:
ViewManager
|
----> Windowmanager
ViewManager has only three functions: addview, updateviewlayout, and removeview.
The layoutparams sub-classes of windowmanager are rich in content. In fact, the main content of windowmanager. Java is defined by this class. It is defined as follows:
Public static class layoutparams extendsviewgroup. layoutparams implementsparcelable
The derived relationship is as follows:
ViewManager. layoutparams
|
----> Windowmanager. layoutparams
The layoutparams of ViewManager mainly has two macros and two variables.
Two macros:
Fill_parent
Wrap_content
Two variables:
Width
Height
The layoutparams of windowmanager is rich. Let's break it down next time.
Windows for Android (III)

The layoutparams subclass of windowmanager can be described by the word "rich content.

If the gravity attribute is ignored, it indicates the absolute X position of the window.
What is the gravity attribute? Simply put, it is how the window is docked.
After gravity. Left or gravity. Right is set, the X value indicates the distance to a specific edge.
Public intx;
If the gravity attribute is ignored, it indicates the absolute y position of the window.
After gravity. Top or gravity. Bottom is set, the Y value indicates the distance to a specific edge.
Public inty;
Vertically, how much extra space (pixels) is reserved for the associated view ). If it is 0, the view cannot be stretched.
In other cases, the Extended Space (pixels) is evenly distributed by widgets.
Public floathorizontalweight;
Public floatverticalweight;
Window Type . There are three main types:
Applicationwindows: The value is between first_application_window and last_application_window.
Is a common, top-level application Program Window. You must set the token of the activity.
Sub_windows: The value is between first_sub_window and last_sub_window.
Associated with the top-level window, the token must be set as the token of the host window to which it is attached.
Systemwindows: The value is between first_system_window and last_system_window.
Used for specific system functions. It cannot be used in applications and requires special permissions.
Public inttype;
The value of type is defined below:
Application Window .
Public staticfinal int first_application_window = 1;
The "base" Window of all program windows, and other application windows are displayed on it.
Public staticfinal int type_base_application = 1;
Common functions and procedures. The token must be set as the activity token to indicate who the window belongs.
Public staticfinal int type_application = 2;
The window displayed when the application starts. The application itself does not use this type.
It is used for the system to display some information until the application can open its own window.
Public staticfinal int type_application_starting = 3;
The application window ends.
Public staticfinal int last_application_window = 99;
Subwindow . The Z-order and coordinate spaces of subwindows depend on their host windows.
Public staticfinal int first_sub_window = 1000;
The panel window is displayed on the upper layer of the host window.
Public staticfinal int type_application_panel = first_sub_window;
Media window, such as video. Displayed at the lower layer of the host window.
Public staticfinal int type_application_media = first_sub_window + 1;
The Child Panel of the application window. Displayed on the upper layer of all panel windows. (The more "sub", the closer the GUI is)
Public staticfinal int type_application_sub_panel = first_sub_window + 2;
Dialog box. Similar to a panel window, draw a window similar to a top-level window, rather than a child window of the host.
Public staticfinal int type_application_attached_dialog = first_sub_window + 3;
Media information. The display must be transparent (translucent) between the media layer and the program window. (For example, show subtitles)
Public staticfinal int type_application_media_overlay = first_sub_window + 4;
The child window ends.
Public staticfinal int last_sub_window = 1999;
System window . Non-application creation.
Public staticfinal int first_system_window = 2000;
Status Bar. There can be only one status bar; it is located at the top of the screen, and other windows are located below it.
Public staticfinal int type_status_bar = first_system_window;
Search bar. There can be only one search bar; it is located above the screen.
Public staticfinal int type_search_bar = first_system_window + 1;
Phone window. It is used for telephone interaction (especially incoming calls ). It is placed above all applications and under the status bar.
Public staticfinal int type_phone = first_system_window + 2;
System prompt. It always appears in the application window.
Public staticfinal int type_system_alert = first_system_window + 3;
Screen lock window.
Public staticfinal int type_keyguard = first_system_window + 4;
Information Window. Display toast.
Public staticfinal int type_toast = first_system_window + 5;
System top-level window. It is displayed on top of everything else. This window cannot obtain the input focus; otherwise, the screen lock will be affected.
Public staticfinal int type_system_overlay = first_system_window + 6;
The phone number is preferred. It is displayed when the screen is locked. This window cannot obtain the input focus; otherwise, the screen lock will be affected.
Public staticfinal int type_priority_phone = first_system_window + 7;
System dialog box. (For example, the volume adjustment box ).
Public staticfinal int type_system_dialog = first_system_window + 8;
The dialog box displayed when the screen is locked.
Public staticfinal int type_keyguard_dialog = first_system_window + 9;
The system internal error message is displayed on top of all content.
Public staticfinal int type_system_error = first_system_window + 10;
The internal input method window is displayed on the normal UI. Applications can be laid out again to avoid being overwritten by this window.
Public staticfinal int type_input_method = first_system_window + 11;
The internal input method dialog box is displayed on top of the current input method window.
Public staticfinal int type_input_method_dialog = first_system_window + 12;
Wallpaper window.
Public staticfinal int type_wallpaper = first_system_window + 13;
Slide Panel of the status bar.
Public staticfinal int type_status_bar_panel = first_system_window + 14;
The system window ends.
Public staticfinal int last_system_window = 2999;
SpecifiesMemory buffer type . The default value is normal.
Public intmemorytype;
The window buffer is in the primary memory.
Public staticfinal int memory_type_normal = 0;
The window buffer is located in the memory area that can be accessed by DMA or hardware acceleration.
Public staticfinal int memory_type_hardware = 1;
The window buffer is located in the area that can be accessed by the graphic accelerator.
Public staticfinal int memory_type_gpu = 2;
The window buffer does not have its own buffer and cannot be locked. The buffer is provided by the local method.
Public staticfinal int memory_type_push_buffers = 3;
Behavior option/flag The default value is none.
Public intflags;
The content after the window is dimmed.
Public staticfinal int flag_dim_behind = 0x00000002;
The content after the window is blurred.
Public staticfinal int flag_blur_behind = 0x00000004;

Do not get focus.
You cannot obtain the key input focus, so you cannot send a key or button event to it. The time that will be sent to the window after which the focus can be obtained. This option also sets the flag_not_touch_modal option. Setting this option means that the window cannot interact with the soft input method, so its Z-order is independent of any active input method (in other words, it can be displayed in full screen, if needed, can overwrite the input method window ). To modify this line, see the flag_alt_focusalbe_im option.
Public staticfinal int flag_not_focusable = 0x00000008;
Do not accept touch screen events.
Public staticfinal int flag_not_touchable = 0x00000010;
When the window can get the focus (the flag_not_focusalbe option is not set), the point device event (mouse, touch screen) outside the window is still sent to the subsequent window for processing. Otherwise, it excludes all vertex device events, regardless of whether they occur within the window range.
Public staticfinal int flag_not_touch_modal = 0x00000020;
If this flag is set, when the device sleep, click the touch screen and the device will receive this first touch event.
Usually, the first touch event is consumed by the system, and the user will not see the response of their clicking on the screen.
Public staticfinal int flag_touchable_when_waking = 0x00000040;
When this window is visible to the user, keep the device open and keep the brightness unchanged.
Public staticfinal int flag_keep_screen_on = 0x00000080;
The window occupies the entire screen, ignoring the surrounding decorative border (such as the status bar ). This window should take into account the content of the decorative border.
Public staticfinal int flag_layout_in_screen = 0x00000100;
The window can be extended out of the screen.
Public staticfinal int flag_layout_no_limits = 0x00000200;
Hide all screen decorations (such as status bars) when the window is displayed ). Make the window occupy the entire display area.
Public staticfinal int flag_fullscreen = 0x00000400;
This option overwrites the flag_fullscreen option and forces the screen Decoration (such as status bar) to pop up.
Public staticfinal int flag_force_not_fullscreen = 0x00000800;
Jitter. It refers to the display method of translucent. It is also called "Point-through ". Devices with poor image processing often use dot-passthrough instead of Alpha mixing.
Public staticfinal int flag_dither = 0x00001000;
Screen is not allowed.
Public staticfinal int flag_secure = 0x00002000;
The layout parameter is used to indicate the display ratio.
Public staticfinal int flag_scaled = 0x00004000;
This option prevents cheek misoperation on the screen when the screen may have a face.
Public staticfinal int flag_ignore_cheek_presses = 0x00008000;
When the request is laid out, your window may appear above or below the status bar, thus blocking. When this option is set, the window manager ensures that the window content is not covered by the decoration bar (status bar.
Public staticfinal int flag_layout_inset_decor = 0x00010000;
Reverse the flag_not_focusable option.
If both the flag_not_focusable option and the current option are set, the window can interact with the input method and allow the input method window to overwrite;
If this option is not set for flag_not_focusable, the window cannot interact with the input method, and the input method window can be overwritten.
Public staticfinal int flag_alt_focusable_im = 0x00020000;
If you have set flag_not_touch_modal, when a touch screen event occurs outside the window, you can receive a motionevent. action_outside event by setting this flag. Note that you will not receive the complete down/move/Up event. You can only receive action_outside when you first go down the event.
Public staticfinal int flag_watch_outside_touch = 0x00040000;
When the screen lock is set, the window is displayed. This gives the application window priority over the screen lock interface. You can use the flag_keep_screen_on option to light up the screen and display it directly before the screen lock. You can use the flag_dismiss_keyguard option to directly unlock the unlocked screen. This option is only used for the top-level full screen window.
Public staticfinal int flag_show_when_locked = 0x00080000;
The request system wallpaper is displayed behind your window. The window must be translucent.
Public staticfinal int flag_show_wallpaper = 0x00100000;
Once the window is displayed, the system will light up the screen, just as the user wakes up the device.
Public staticfinal int flag_turn_screen_on = 0x00200000;
Unlock the screen. Only the screen lock interface is not encrypted can be unlocked. If the screen lock is encrypted, you can see the screen only after unlocking it, unless the flag_show_when_locked option is set.
Public staticfinal int flag_dismiss_keyguard = 0x00400000;
When the screen lock interface fades out, it continues to run its animation.
Public staticfinal int flag_keep_surface_while_animating = 0x10000000;
Display the window in the original size. It is used to run programs in compatible mode.
Public staticfinal int flag_compatible_window = 0x20000000;
Used in the system dialog box. The window for setting this option will obtain the focus unconditionally.
Public staticfinal int flag_system_error = 0x40000000;

Soft input mode Option:
Public intsoftinputmode;
The following options are related to the input mode:
Whether the soft input area is visible.
Public staticfinal int soft_input_mask_state = 0x0f;
The status is not specified.
Public staticfinal int soft_input_state_unspecified = 0;
Do not modify the status of the soft input area.
Public staticfinal int soft_input_state_unchanged = 1;
Hide the Input Method Area (when the user enters the window ).
Public staticfinal int soft_input_state_hidden = 2;
When the window gets focus, the input method area is hidden.
Public staticfinal int soft_input_state_always_hidden = 3;
Display the Input Method Area (when the user enters the window ).
Public staticfinal int soft_input_state_visible = 4;
When the window gets focus, the input method area is displayed.
Public staticfinal int soft_input_state_always_visible = 5;
The window should be adjusted to adapt to the soft input window.
Public staticfinal int soft_input_mask_adjust = 0xf0;
If the status is not specified, the system will try to select an input method style based on the window content.
Public staticfinal int soft_input_adjust_unspecified = 0x00;
When the input method is displayed, the window size can be re-calculated so that the content is not overwritten by the input method.
It cannot be used together with soft_input_adjusp_pan. If neither of them is set, the system automatically sets an option based on the window content.
Public staticfinal int soft_input_adjust_resize = 0x10;
Translation window when the input method is displayed. It does not need to handle size changes. The frame can move the window to ensure that the input focus is visible.
It cannot be used together with soft_input_adjust_resize. If neither of them is set, the system automatically sets an option based on the window content.
Public staticfinal int soft_input_adjust_pan = 0x20;
When you go to this window, it is automatically set by the system, so do not set it.
This flag is automatically cleared when the window is displayed.
Public staticfinal int soft_input_is_forward_navigation = 0x100;
Gravity settings
Public intgravity;
Horizontal margin, the distance between the container and the widget, percentage of the container width.
Public floathorizontalmargin;

Vertical margin.
Public floatverticalmargin;
The expected bitmap format. The default value is opacity. See Android. Graphics. pixelformat.
Public intformat;
Animation settings used in the window. It must be a system resource rather than an application resource because the window manager cannot access the application.
Public intwindowanimations;
The translucent value of the entire window. The value 1.0 indicates opacity, and the value 0.0 indicates full transparency.
Public floatalpha = 1.0f;
It takes effect after flag_dim_behind is set. This variable indicates the degree to which the subsequent window is dimmed.
1.0 indicates that the image is completely opaque, and 0.0 indicates that the image is not dimmed.
Public floatdimamount = 1.0f;

It is used to overwrite the screen brightness set by the user. The screen brightness set by the Application User.
The brightness changes from 0 to 1.
Public floatscreenbrightness =-1.0f;
The identifier of the window.
Public ibindertoken = NULL;
The package name of the window.
Public stringpackagename = NULL;
For more information about the screen direction, see Android. content. PM. activityinfo # screenorientation.
Public intscreenorientation = activityinfo. screen_orientation_unspecified;

various "change" information is defined below, which is used by 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 partition = 1 <9;
Public staticfinal int screen_orientation_changed = 1 <10;
Public staticfinal int screen_brightness_changed = 1 <11;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.