Create Compass app in Sketchware

 To create a Compass app in Sketchware, follow the steps given below.

1. In View area add an ImageView imageview1. Set image of a Compass as it's image. Make sure that North is towards the top.


2. Create a Gyroscope component gyro and another Gyroscope component gyroMagnet.


3. Create a More block extra and put following code in it.

}

private float[] floatGravity = new float[3];

private float[] floatGeoMagnetic = new float[3];

private float[] floatOrientation = new float[3];

private float[] floatRotationMatrix = new float[9];

{


4. In onCreate event use blocks

Gyroscope gyro sensor stop,

and Gyroscope gyroMagnet sensor stop.

After that put following code in an add source directly block:

gyro.registerListener(_gyro_sensor_listener, gyro.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_NORMAL);

gyro.registerListener(_gyroMagnet_sensor_listener, gyro.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),SensorManager.SENSOR_DELAY_NORMAL);



5. In onPause event use blocks

Gyroscope gyro sensor stop,

and Gyroscope gyroMagnet sensor stop.


6. In onResume event put following code in an add source directly block:

gyro.registerListener(_gyro_sensor_listener, gyro.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_NORMAL);

gyro.registerListener(_gyroMagnet_sensor_listener, gyro.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),SensorManager.SENSOR_DELAY_NORMAL);


7. In gyro: onSensorChanged event use an add source directly block and put following code:

floatGravity = _param1.values;

SensorManager.getRotationMatrix(floatRotationMatrix, null, floatGravity, floatGeoMagnetic);

SensorManager.getOrientation(floatRotationMatrix, floatOrientation);

imageview1.setRotation((float) (-floatOrientation[0]*180/3.14159265359));



8. In gyroMagnet: onSensorChanged event use an add source directly block and put following code:

floatGeoMagnetic = _param1.values;

SensorManager.getRotationMatrix(floatRotationMatrix, null, floatGravity, floatGeoMagnetic);

SensorManager.getOrientation(floatRotationMatrix, floatOrientation);

imageview1.setRotation((float) (-floatOrientation[0]*180/3.14159265359));



9. Save and run the project. You will see the top of image rotate to the North direction.



Comments

  1. Nice blog . I have also been making tutorials related to Sketchware. In my Sketchware Interface video I have explaines each and every part of the Sketchware app itself. Do check my channel to learn more about sketchware.
    My channel link - https://youtube.com/channel/UCOUL_rPb3vQZoQ_ENC9lB3w

    Thanks Sanjeev sir. I have learnt about sketchware by watching your videos . So Thanks a lot.

    ReplyDelete
  2. Great Work Sir

    kindly solve my problem .
    i created a pdf reader and wanted to be it as default App.
    i got success to do so when i view a pdf file from Myfiles.

    But when i tried to open a pdf in whatsapp error occurred.
    Because here Uri like

    content //com.whatsapp.provider.media/item/9231

    is received instead of Real Path.

    kindly explain how can this URi is converted into Real Path ?

    ReplyDelete
  3. I am also interested android apps development. & I have Coded several app from Android Aide.

    My Blog - Ashu4Tech.com (A4T)

    ReplyDelete
  4. Hello Sir
    Do you know how to turn off Anti-Alisasing of an imageview.
    An example I have a car pixel art, and its parameters is 24 x 36 pixels.
    But when i load the image in the app, the anti-aliasing is blurred off the image.
    I want to see the picture like this:
    https://i.stack.imgur.com/UnUzg.png

    But this is how the app shows the picture:
    https://drive.google.com/file/d/1xhbZIwlxU0JvnBiqsQF0ipaGY6aSw3MU/view?usp=sharing

    Is there any way to turn off this terrible function.

    Thanks, and have a nice day ;)

    ReplyDelete

Post a Comment

Popular posts from this blog

Create Music Player app in Sketchware

A Flash Light App in Sketchware

Admob rewarded video Ads in Sketchware

Simple car racing android game in Sketchware

Firebase auth in Sketchware for Login Activity