Adding Compass Utility in Travel-Mate Android App

in #utopian-io6 years ago (edited)

Repository

Github

Project

The app provides users with various features from choosing the correct destination to making all the bookings and to easily organising the trip. The app provides solutions for every possible problem a traveller might face during the course of his or her entire journey.

New Features

Feature - 411

What feature(s) did you add?

App has some cool features for travellers like weather info, checklist etc. There was a open issue on adding compass utility. Have implemented the compass in utilities section of the App.

How did you implement it/them?

-The smartphones have a small magnetometer built in, which can measure the Earth’s magnetic field. This information is combined with an accelerator that acquires information regarding the phone’s position in space.


@Override
public void onSensorChanged(SensorEvent event) {
final float alpha = 0.97f;

synchronized (this) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

mGravity[0] = alpha * mGravity[0] + (1 - alpha)
* event.values[0];
mGravity[1] = alpha * mGravity[1] + (1 - alpha)
* event.values[1];
mGravity[2] = alpha * mGravity[2] + (1 - alpha)
* event.values[2];
}

if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
// mGeomagnetic = event.values;

mGeomagnetic[0] = alpha * mGeomagnetic[0] + (1 - alpha)
* event.values[0];
mGeomagnetic[1] = alpha * mGeomagnetic[1] + (1 - alpha)
* event.values[1];
mGeomagnetic[2] = alpha * mGeomagnetic[2] + (1 - alpha)
* event.values[2];
// Log.e(TAG, Float.toString(event.values[0]));

}

boolean success = SensorManager.getRotationMatrix(mR, mI, mGravity,
mGeomagnetic);
if (success) {
float[] orientation = new float[3];
SensorManager.getOrientation(mR, orientation);
// Log.d(TAG, "azimuth (rad): " + azimuth);
mAzimuth = (float) Math.toDegrees(orientation[0]); // orientation
mAzimuth = (mAzimuth + mAzimuthFix + 360) % 360;
// Log.d(TAG, "azimuth (deg): " + azimuth);
if (mListener != null) {
mListener.onNewAzimuth(mAzimuth);
}
}
}

/**
* setup compass
*/
private void setupCompass() {
mCompass = new Compass(this);
Compass.CompassListener cl = new Compass.CompassListener() {
@Override
public void onNewAzimuth(float azimuth) {
adjustArrow(azimuth);
}
};
mCompass.setListener(cl);
}
/**
* adjuts arrow
** @param azimuth azimuth
*/
private void adjustArrow(float azimuth) {
Log.d(TAG, "will set rotation from " + mCurrentAzimuth + " to "
+ azimuth);
Animation an = new RotateAnimation(-mCurrentAzimuth, -azimuth,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mCurrentAzimuth = azimuth;
an.setDuration(500);
an.setRepeatCount(0);
an.setFillAfter(true);
mArrowView.startAnimation(an);
}

Drawables used Compass_dial and compass_hand

Pull Request

GitHub Account

https://github.com/santoshhiremani/

Sort:  

Hi, @hiremani. Your account has been excluded from Utopian rewards and therefore this contribution post will not be reviewed. You can contact us at https://support.utopian.io/ if you have any further questions.

Congratulations @hiremani! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

$0.8365533053797927
Upvote ibar's comment to Support!
Get list of coin ids here and you will use id names with commands to make it work.

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.032
BTC 62521.03
ETH 3025.04
USDT 1.00
SBD 3.97