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.