Introduction to horizontal and vertical screen switching knowledge in j2-based Programming

Source: Internet
Author: User

Introduction to horizontal and vertical screen switching knowledge in j2-based Programming

Chen yuefeng, Java Studio

From: http://blog.csdn.net/mailbomb

Note: Please indicate the source for reprinting.

 

As mobile phone functions become more and more abundant and mobile phones support horizontal and vertical screen switching, mobile phone software development must also handle this function. The following is a summary of the knowledge about horizontal/portrait screen (screen rotation) Switching when using the j2_based Technology for programming.

1. How to determine whether the screen is switched

The switching between the portrait and landscape screens is automatically completed by the mobile phone system. Only such switching can be detected in the j2_m2. there are two methods to determine the switching between the portrait and landscape screens:

A) Check each time in the thread (polling Mode)

In this way, the screen width and height are obtained at a certain interval in the program thread, and then the width and height are determined to change, if the width and height are different from the existing width and height, you only need to set the width and height to landscape or landscape. Execute the logic code when you determine whether to switch between the horizontal and vertical screens.

This method is used because every thread loop needs to be detected, so the execution efficiency is not high. However, some screen-changing mobile phones do not support sizechanged callback, so this method has the highest versatility, is a frequently used method.

B) sizechanged method (interrupt mode)

This method means that if the screen-to-screen mobile phone supports relatively standard MIDP, The sizechanged method in the canvas class will be automatically called when the screen-to-screen switching is performed, in this way, you need to override this method in the subclass of canvas, and write the logic processing code for horizontal and vertical screen switching in this method.

This method is automatically called by the system, so the execution efficiency is very good. However, due to the non-standard implementation of some mobile phones, there is no first method with high universality.

Note: The advanced user interface automatically switches without writing and processing code.

2. How to Handle horizontal and vertical screen Switching

After detecting switching between the portrait and landscape screens, you need to handle switching between the landscape and landscape screens. There are two ways to handle this:

A) simple tips

This method only implements the logic in one screen mode, and displays the prompt in another screen mode. For example, if you only implement the portrait mode, only the prompt "Please use this program in portrait mode" appears in Landscape mode ".

In this way, the program implementation is relatively simple. You only need to implement a set of interfaces, which is suitable for simple programs.

B) implement two sets of UI Methods

This processing method refers to implementing two sets of interfaces in a program: one set of horizontal screens and one set of vertical screens. You can set a screentype parameter in the program. In the program plotting method, you can determine whether the screen is a horizontal screen or a vertical screen based on this parameter, and then execute different drawing code.

In this way, the program implementation is friendly, but the workload of program development and testing is a little larger, and the data transformation during horizontal and vertical screen switching is also troublesome.

3. Other Instructions

Some knowledge will help you implement some practical functions when switching between landscape and landscape screens:

A) Disable horizontal and vertical screen switching on the Nokia mobile phone:

In s60 5th and later versions, you can specify the screen type when running the program by specifying the following attributes in the Jad or manifest file:

Portrait screen: Nokia-MIDlet-app-orientation: Portrait

Horizontal screen: Nokia-MIDlet-app-orientation: Landscape

 

 

I hope you can actively correct, communicate, and improve your shortcomings!

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.