Sample Apps by Android Team, Alibaba Android

Source: Internet
Author: User

Sample Apps by Android Team, Alibaba Android

Sample Apps by Android Team code download: http://pan.baidu.com/s/1eSNmdUE, code source address: https://code.google.com/archive/p/apps-for-android/

Note: the code is not a project that can be run directly. You need to create a new project and copy the relevant files to the project.

This is the Learning Record of the Amazed project code.

1. Create a custom View

@. In onSizeChanged, compare the parameter w (width) with h (height) to determine whether the mobile phone is in Landscape or Portrait ).

@. Draw a custom View Interface in onDraw.

@. Canvas and Paint are required to draw the interface:

1. Cnavas: used to control what to draw, such as drawLine, drawRect, and drawBitmap ).

2. Paint: used to control how to draw and how to control the style. For example, set the color to red or set the font to setTypeface ).

@: Call the View method invalidate () to trigger onDraw.

Ii. accelerometer

@: GetSystemService (Context. SENSOR_SERVICE) of the Activity method to obtain the SensorManager instance (for example, mSensorManager ).

@, Implements the SensorListener interface, and creates an instance (for example, mSensorAccelerometer ).

@, Note: In the current Android version, the SensorListener interface has been replaced by the SensorEventListener interface.

@. Use mSensorManager. registerListener (mSensorAccelerometer, SensorManager. SENSOR_ACCELEROMETER, SensorManager. SENSOR_DELAY_GAME) to register the accelerometer sensor.

@, Cancel accelerometer sensor Registration through mSensorManager. unregisterListener (msensjavascelerometer. (In this way, the pause effect can be achieved .)

@, Note: the sensor coordinate system is based on the origin in the lower left corner of the screen, the X axis along the screen to the right, the Y axis along the screen up, the Z axis vertical screen up. The second value of SensorListener. onSensorChanged corresponds to the acceleration on the X, Y, and Z axes respectively. This acceleration includes the components of the gravity acceleration on each axis. For example, when the mobile phone is flat, the acceleration of gravity is in the Z direction, but opposite to the Z direction, so values [2] =-g (g stands for the acceleration of gravity ).

 

Iii. assets

1. The main/assets/directory is used to place files that do not change due to device configuration changes. For example, the data set for the game level.

2. Get the AssetsManager instance through the getAssets method of the Activity, and use the AssetsManager instance to call the open Method to read the files in the assets Directory.

 

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.