(Go) android window class

Source: Internet
Author: User
Tags class definition

Window class for Android 2011-03-25 10:02 by Keis, visits, net pick, collection, compilation

Android's window class (a) the GUI layer of Android is not complicated. Its complexity is similar to Wgui such as the layout and dialog-based GUI, and MFC, QT and other large frameworks are not comparable, and even fly diffuse Wei Yongming Minigui more complex than it. You might ask, how does a simple GUI implement a browser? The reason is simple, the browser has its own set of GUI. The GUI of Android browser (WebKit) and the GUI of Android are practical with the same set of Gdi--skia, but the GUI layer is completely different from the design, respectively, into the system.
The Windown class, located in the code tree Frameworks\base\core\java\android\view\windowjava.java file. Together with a note, this file totals more than 1000 lines, outlining the basic properties and basic features of the android window.
The Window property is listed as follows:
Feature_options_panel = 0; function is unknown, see the following instructions (default enable)
Feature_no_title = 1; No title bar
Feature_progress = 2; Show loading progress on the title bar, such as WebView loading a Web page (Bar progress bar)
Feature_left_icon = 3; Show an icon to the left of the title bar
Feature_right_icon = 4; Show an icon to the right of the title bar
feature_indeterminate_progress = 5; Indeterminate Progress (circle-like wait icon)
Feature_context_menu = 6; Context menu, equivalent to the right-click menu on the PC (enabled by default)
Feature_custom_title = 7; Custom title bar, this property cannot be combined with other title bar properties
Feature_opengl = 8; If OpenGL is turned on, then 2D will be processed by OpenGL (2D in OpenGL is a subset of 3D)
progress_visibility_on =-1; progress bar Visible
Progress_visibility_off =-2; The progress bar is not visible
progress_indeterminate_on =-3; Turn on the indeterminate mode
Progress_indeterminate_off =-4; Turn off indeterminate 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; The maximum value of the second progress bar
* Description: Feature_options_panel means: When the user selects the menu, the window calls the Onoptionsitemselected function to handle the menu function. If there is no feature_options_panel option, then the menu will not respond? I haven't tried it and I haven't found it online.
Examples of applications:
1. Hide the title bar
Requestwindowfeature (Window.feature_no_title);
2. Display the progress bar in 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 the custom title bar
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 content, and 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. Display the title bar
... setvisibility (view.visible);
Other precautions
(1) requestwindowfeature () to be called before Setcontentview ();
(2) Set various feature, IS has the exclusive nature, once set, the subsequent cannot change the other type;
(3) When using Tabhost (derived from Activitygroup), the activity in each tab is either No_title or Custom_title and cannot be set separately.

Android's window class (ii) The window class removes a large number of feature_ attributes, leaving nothing more than two things:
Define the callback interface, which contains a series of dispatchxxxx functions and a series of onxxxx functions for handling UI events;
Second, the definition of their own windowmanager--localwindowmanager. The main modified AddView function, set the title.
The callback interface contains the following functions:
public boolean dispatchkeyevent (keyeventevent);
Handles the key event. At the very least, your code will call the Superdispatchkeyevent function.
Public Booleandispatchtouchevent (Motionevent event);
Handle Touch events. At the very least, your code will call the Superdispatchtouchevent function.
Public Booleandispatchtrackballevent (Motionevent event);
Handles the Trackball event. At the very least, your code will call the Superdispatchtrackballevent function.
Public booleandispatchpopulateaccessibilityevent (accessibilityeventevent);
Handles accessibility events (auxiliary events, such as focus changes, button clicks, etc.), and returns true after processing is complete.
Create a view that displays a panel
You can return null, which will create a default content (usually a menu) for you.
You should return to the top-level view where the panel is placed.
Public View Oncreatepanelview (Intfeatureid);
Initializes the Panel menu, and if the Oncreatepanelview function returns NULL, this function is called, creating a standard menu that you can add to the menu item. This function is called only when the panel first displays. If the return false,panel will not be displayed.
public boolean Oncreatepanelmenu (Intfeatureid, menu menu);
This function is called before each panel window is displayed. Should return true if the return false will not be displayed.
public boolean Onpreparepanel (Intfeatureid, View view, menu menu);
Called when the user opens the Panel's menu. It is also called when the menu style is toggled. For example, switch from the icon menu to the extended menu.
Returns True to allow the menu to open and return False to prevent the menu from opening.
public boolean onmenuopened (Intfeatureid, menu menu);
The user selects the menu item.
public boolean onmenuitemselected (Intfeatureid, MenuItem item);
The current Window property is changed.
Public voidonwindowattributeschanged (WINDOWMANAGER.LAYOUTPARAMSATTRS);
The view of the window has changed.
public voidoncontentchanged ();
Window focus changes.
public void onwindowfocuschanged (Booleanhasfocus);
window is attached to the window manager.
public Voidonattachedtowindow ();
window is removed from the window manager.
public Voidondetachedfromwindow ();
Called when the panel is closed.
This function is not called if a subsequent panel expands (this panel frees up space for subsequent panel).
public void onpanelclosed (int featureid,menu Menu);
When the user presses the search button.
Returns true if the search interface is started, or false if it cannot be executed.
public booleanonsearchrequested ();
What's WindowManager doing? It is not a "window manager", Windowmanagerservice is the window manager. The name is called the iffy, and in fact WindowManager mainly manages a bunch of state words, and these state words, the most commonly used is layoutparams.
The derived relationship is as follows:
Viewmanager
|
---->windowmanager
Viewmanager has only three functions: Addview,updateviewlayout,removeview.
And WindowManager's Layoutparams sub-category content is very rich. In fact, the main content of Windowmanager.java is composed of this class definition. It is defined as follows:
public static class Layoutparams Extendsviewgroup.layoutparams implementsparcelable
The derived relationship is as follows:
Viewmanager.layoutparams
|
---->windowmanager.layoutparams
Viewmanager's layoutparams consists of two macros and two variables.
Two macros:
Fill_parent
Wrap_content
Two variables:
Width
Height
WindowManager's layoutparams is more rich, we tell. android window Class (iii)

The Layoutparams subclass of WindowManager can be described by the term "content rich".

If the Gravity property is omitted, it represents the absolute x position of the window.
What is the gravity attribute? Simply put, it's how the window docks.
When Gravity.left or Gravity.right is set, the X value represents the distance to a particular edge.
Public intx;
If the Gravity property is omitted, it represents the absolute y position of the window.
When Gravity.top or Gravity.bottom is set, the Y value represents the distance to a particular edge.
Public inty;
In portrait, How much space (in pixels) is reserved for the associated view. If it is 0, then this view cannot be stretched.
In other cases, the expansion space (pixels) will be evenly divided by the widget.
Public floathorizontalweight;
Public floatverticalweight;
window Type。 There are 3 main types of:
Applicationwindows: The value is between First_application_window and Last_application_window.
Is the usual, top-level application window. Token must be set as activity token.
Sub_windows: The value is between First_sub_window and Last_sub_window.
associated with the top-level window, token must be set to 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 is not available for applications and requires special permissions when used.
Public inttype;
The following defines the value of the type:
application window
public staticfinal int first_application_window = 1;
The "Base" window of all program windows, the other application windows are displayed above it.
public staticfinal int type_base_application = 1;
Normal should yo function program window. Token must be set to the activity token to indicate who the window belongs to.
public staticfinal int type_application = 2;
Used for Windows that are displayed when the application starts. The app itself does not use this type.
It is used to let the system 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;
child window。 The z-order and coordinate space of the child windows are dependent on their host window.
public staticfinal int first_sub_window = 1000;
A panel window that appears on top of the host window.
public staticfinal int Type_application_panel =first_sub_window;
Media window, such as video. Appears below the host window.
public staticfinal int Type_application_media =first_sub_window+1;
The sub-panel of the application window. Appears on top of all panel windows. (The general rule of the GUI, the more "son" more up)
public staticfinal int Type_application_sub_panel =first_sub_window+2;
dialog box. Similar to a panel window, drawing is similar to a top-level window, not a child window of the host.
public staticfinal int Type_application_attached_dialog =first_sub_window+3;
Media information. Appears between the media layer and the program window, and you need to implement transparent (translucent) effects. (e.g. display 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 only be one status bar; it is at the top of the screen, and the other windows are underneath it.
public staticfinal int Type_status_bar =first_system_window;
Search bar. There can be only one search bar, which is located above the screen.
public staticfinal int Type_search_bar =first_system_window+1;
Phone window. It is used for telephone interactions (especially inbound). It is placed above all applications, under the status bar.
public staticfinal int Type_phone =first_system_window+2;
System prompts. It always appears on top of the application window.
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 toast.
public staticfinal int Type_toast =first_system_window+5;
The top-level window of the system. is displayed on top of all other content. This window cannot get input focus, otherwise it affects the lock screen.
public staticfinal int type_system_overlay = first_system_window+6;
The phone takes precedence when the lock screen is displayed. This window cannot get input focus, otherwise it affects the lock screen.
public staticfinal int type_priority_phone = first_system_window+7;
System dialog box. (such as the volume adjustment box).
public staticfinal int type_system_dialog = first_system_window+8;
The dialog box that appears when you lock the screen.
public staticfinal int type_keyguard_dialog = first_system_window+9;
System internal error message, displayed on all content.
public staticfinal int type_system_error = first_system_window+10;
The internal Input Method window is displayed on top of the normal UI. The application can be re-laid out to avoid being overwritten by this window.
public staticfinal int type_input_method = first_system_window+11;
The internal Input Method dialog box appears above 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;
Indicates that the window is usedMemory Buffer Type。 The default is normal.
Public intmemorytype;
The window buffer is located in main memory.
public staticfinal int memory_type_normal = 0;
The window buffer is located in a memory area that can be accessed by DMA or hardware acceleration.
public staticfinal int memory_type_hardware = 1;
The window buffer is located in an area that can be accessed by the graphics accelerator.
public staticfinal int MEMORY_TYPE_GPU = 2;
The window buffer does not have its own buffer and cannot be locked. Buffers are provided by local methods.
public staticfinal int memory_type_push_buffers = 3;
behavior Options/Flags, the default is None
Public intflags;
The content after the window is dimmed.
public staticfinal int flag_dim_behind = 0x00000002;
The content after the window becomes blurred.
public staticfinal int flag_blur_behind = 0x00000004;

Don't get the spotlight.
You cannot get key input focus, so you cannot send a button or button event to it. Those times will be sent to the window behind it to get the focus. 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 and can overwrite the IME window if needed). To modify this behavior, refer to the FLAG_ALT_FOCUSALBE_IM option.
public staticfinal int flag_not_focusable = 0x00000008;
Touch screen events are not accepted.
public staticfinal int flag_not_touchable = 0x00000010;
When the window can get focus (without setting the FLAG_NOT_FOCUSALBE option), the Point device events (mouse, touch screen) that are outside the window range are still sent to the subsequent window processing. Otherwise it will monopolize all point 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 sleeps, tap on the touchscreen 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 what happens when they click on the screen.
public staticfinal int flag_touchable_when_waking = 0x00000040;
When this window is visible to the user, keep the device normally open and keep the brightness constant.
public staticfinal int flag_keep_screen_on = 0x00000080;
The window fills the entire screen, ignoring the surrounding decorative borders (such as the status bar). This window takes into account the contents of the decorative border.
public staticfinal int Flag_layout_in_screen =0x00000100;
Allow the window to extend beyond the screen.
public staticfinal int Flag_layout_no_limits =0x00000200;
When the window is displayed, hide all of the screen decorations (such as the status bar). Causes the window to occupy the entire display area.
public staticfinal int flag_fullscreen = 0x00000400;
This option overrides the Flag_fullscreen option and forces the screen decorations (such as the status bar) to pop up.
public staticfinal int Flag_force_not_fullscreen =0x00000800;
Jitter. Refers to the method of displaying translucent. Also known as "point through". Devices with poor graphics tend to use "point through" instead of alpha blending.
public staticfinal int flag_dither = 0x00001000;
Screen is not allowed.
public staticfinal int flag_secure = 0x00002000;
A special mode in which layout parameters are used to indicate the scale of the display.
public staticfinal int flag_scaled = 0x00004000;
This option prevents the cheek from operating incorrectly on the screen when the screen is likely to have a face attached.
public staticfinal int flag_ignore_cheek_presses = 0x00008000;
When you request a layout, your window may appear above or below the status bar, causing occlusion. When this option is set, the window manager ensures that the contents of the window are not covered by the trim bar (status bar).
public staticfinal int flag_layout_inset_decor = 0x00010000;
Reverses the flag_not_focusable option.
If both the flag_not_focusable option and this option are set, the window will be able to interact with the IME, allowing the IME window to be overwritten;
If the flag_not_focusable is not set and the option is set, the window cannot interact with the IME and can overwrite the IME window.
public staticfinal int flag_alt_focusable_im = 0x00020000;
If you set the Flag_not_touch_modal, then when the touchscreen event occurs outside the window, you can receive a Motionevent.action_outside event by setting this flag. Note that you will not receive the full Down/move/up event, only the first down event can receive action_outside.
public staticfinal int flag_watch_outside_touch = 0x00040000;
When the screen is locked, the window can be seen. This allows the application window to take precedence over the lock screen. The screen can be lit with the flag_keep_screen_on option and displayed directly before the lock screen. Unlocked lock screen status can be lifted directly using the Flag_dismiss_keyguard option. This option is only available for the topmost 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;
Unlocks the lock screen. Only the lock screen interface is not encrypted to unlock. If the lock screen is encrypted, the user will not see the window until the flag_show_when_locked option is set.
public staticfinal int flag_dismiss_keyguard = 0x00400000;
When the lock screen fades out, it continues to run its animation.
public staticfinal int flag_keep_surface_while_animating =0x10000000;
Displays the window in its original size. Used to run the program in compatibility mode.
public staticfinal int flag_compatible_window = 0x20000000;
for system dialog boxes. The window that sets this option will receive the focus unconditionally.
public staticfinal int flag_system_error = 0x40000000;

Soft IME ModeOptions:
Public Intsoftinputmode;
The following options are related to IME mode:
Whether the soft-input area is visible.
public staticfinal int soft_input_mask_state = 0x0f;
No state was specified.
public staticfinal int soft_input_state_unspecified = 0;
Do not modify the state of the soft input region.
public staticfinal int soft_input_state_unchanged = 1;
Hides the input region (when the user enters the window).
public staticfinal int soft_input_state_hidden = 2;
Hides the input region when the window receives focus.
public staticfinal int soft_input_state_always_hidden = 3;
Displays the input region (when the user enters the window).
public staticfinal int soft_input_state_visible = 4;
Displays the input region when the window receives focus.
public staticfinal int soft_input_state_always_visible = 5;
The window should be actively adjusted to fit the soft input window.
public staticfinal int soft_input_mask_adjust = 0xf0;
If no state is specified, the system attempts to select an input method style based on the contents of the window.
public staticfinal int soft_input_adjust_unspecified = 0x00;
When the input method is displayed, the window is allowed to recalculate dimensions so that the content is not overwritten by the input method.
Cannot be mixed with soft_input_adjusp_pan; if none of the two are set, an option is automatically set according to the contents of the window.
public staticfinal int soft_input_adjust_resize = 0x10;
The IME displays when the Panning window is displayed. It does not need to handle dimensional changes, and the framework can move the window to ensure that the input focus is visible.
Cannot be mixed with soft_input_adjust_resize; if none of the two are set, an option is automatically set according to the contents of the window.
public staticfinal int soft_input_adjust_pan = 0x20;
When the user goes to this window, it is set automatically by the system, so you do not set it.
The flag is automatically cleared when the window is displayed.
public staticfinal int soft_input_is_forward_navigation = 0x100;
Gravity Settings
Public intgravity;
The horizontal margin, the distance between the container and the widget, which is the percentage of the container width.
Public floathorizontalmargin;

longitudinal margins.
Public floatverticalmargin;
The desired bitmap format. The default is opaque. Refer to Android.graphics.PixelFormat.
Public Intformat;
The animation settings used by the window. It must be a system resource, not an application resource, because the window manager cannot access the application.
Public intwindowanimations;
The translucent value of the entire window, 1.0 for opacity, and 0.0 for full transparency.
Public Floatalpha = 1.0f;
Takes effect when Flag_dim_behind is set. The variable indicates the degree to which the subsequent window darkens.
1.0 means completely opaque, and 0.0 means no darkening.
Public floatdimamount = 1.0f;

The screen brightness used to override user settings. Represents the screen brightness of the app user settings.
Adjusts the brightness from 0 to 1 to change from dark to brightest.
Public floatscreenbrightness = -1.0f;
The identifier for the window.
public ibindertoken = null;
The package name in which this window resides.
public stringpackagename = null;
Screen orientation, see android.content.pm.activityinfo#screenorientation.
Public Intscreenorientation =activityinfo.screen_orientation_unspecified;

The following defines the various "change" information that 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 soft_input_mode_changed =1<<9;
public staticfinal int screen_orientation_changed =1<<10;
public staticfinal int screen_brightness_changed =1<<11;

(Go) android window class

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.