Re: [android-developers] Android Compass help

2012-06-27 Thread sajjan androiddeveloper
You have compass application already in android sample code.Have a look on
that

On Sun, Jun 24, 2012 at 2:52 AM, axesh ajmera ajmeraax...@gmail.com wrote:

 Hi Guys,
  I need your help on developing an android compass
 application.Here is the source code...I want to know if i am using correct
 algorithm and sensors for developing the app and secondly I am unable to
 understand why my compass jitters so much

 package com.android.compass.example

 import android.app.Activity;
 import android.hardware.Sensor;
 import android.hardware.SensorEvent;
 import android.hardware.SensorEventListener;
 import android.hardware.SensorManager;
 import android.os.Bundle;

 public class CompassExample4Activity extends Activity implements
 SensorEventListener{
  private SensorManager mSensorManager;
 CompassView mCompassView;
 Sensor accelerometer;
 Sensor magnetometer;
 float azimut;
 float[] mGravity;
 float[] mGeomagnetic;
 static final float ALPHA = 0.2f;
 double SmoothFactorCompass = 0.5;
 double SmoothThresholdCompass = 30.0;
 double oldCompass = 0.0;
 int oldCompass2 = 0;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 mCompassView = new CompassView(this);
 //this.setRequestedOrientation(0);
 setContentView(mCompassView);

 mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
 accelerometer =
 mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
 magnetometer =
 mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
 }

 @Override
 public void onResume() {
 super.onResume();
 mSensorManager.registerListener(this, accelerometer,
 SensorManager.SENSOR_DELAY_UI);
 mSensorManager.registerListener(this, magnetometer,
 SensorManager.SENSOR_DELAY_UI);
 }
 @Override
 public void onPause() {
 super.onPause();
 mSensorManager.unregisterListener(this);
 }

 @Override
 public void onAccuracyChanged(Sensor sensor, int accuracy) {
 // TODO Auto-generated method stub
  }

 @Override
 public void onSensorChanged(SensorEvent event) {
 // TODO Auto-generated method stub
 if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
   mGravity = lowPass(event.values, mGravity);
 if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
   mGeomagnetic = lowPass(event.values, mGeomagnetic);

 if (mGravity != null  mGeomagnetic != null) {
   float R[] = new float[9];
   float I[] = new float[9];
   boolean success = SensorManager.getRotationMatrix(R, I, mGravity,
 mGeomagnetic);
   // Correct if screen is in Landscape
   SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X,
 SensorManager.AXIS_Z, R);

   if (success) {
 float orientation[] = new float[3];
 SensorManager.getOrientation(R, orientation);
 float azimut = orientation[0]; // orientation contains: azimut,
 pitch and roll
 //float azimuth = (float)
 Math.round((Math.toDegrees(orientation[0]))*7)/7;
 //azimuth = ( azimuth + 360)%360;


  
 mCompassView.updateDirection((float)smoothnessFunction(azimut*360/(2*3.14159f)));
 //mCompassView.updateDirection(azimuth);
   }
  }
 }
  protected float[] lowPass( float[] input, float[] output ) {
 if ( output == null ) return input;

 for ( int i=0; iinput.length; i++ ) {
 output[i] = output[i] + ALPHA * (input[i] - output[i]);
 }
 return output;
 }
  public double smoothnessFunction( double newCompass) {
  if (Math.abs(newCompass - oldCompass)  180) {
 if (Math.abs(newCompass - oldCompass)  SmoothThresholdCompass) {
 oldCompass = newCompass;
 }
 else {
 oldCompass = oldCompass + SmoothFactorCompass * (newCompass -
 oldCompass);
 }
 } else {
 if (360.0 - Math.abs(newCompass - oldCompass) 
 SmoothThresholdCompass) {
 oldCompass = newCompass;
 } else {
 if (oldCompass  newCompass) {
 oldCompass = (oldCompass + SmoothFactorCompass * ((360 +
 newCompass - oldCompass) % 360) + 360) % 360;
 } else {
 oldCompass = (oldCompass - SmoothFactorCompass * ((360 -
 newCompass + oldCompass) % 360) + 360) % 360;
 }
 }
 }
 return oldCompass;
 }
  public int smoothnessFunction2(double newCompass){
 if ((int)newCompass % 360 != oldCompass2) {
 oldCompass2 = (int) newCompass;
 }
 return oldCompass2;
 }
 }

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send 

Re: [android-developers] button

2012-06-21 Thread sajjan androiddeveloper
Use selector that will be easy for you

On Thu, Jun 21, 2012 at 3:22 PM, bob b...@coolfone.comze.com wrote:

 Are you talking about using this?

 void setOnTouchListener(View.OnTouchListener l)


 On Wednesday, June 20, 2012 10:34:42 AM UTC-5, Kristopher Micinski wrote:

 Sure, in the onPressed event, change the image, when it's not pressed,
 change it back.?

 kris

 On Wed, Jun 20, 2012 at 11:32 AM, bob b...@coolfone.comze.com wrote:
  I'm trying to make a button that uses two different images - one for
 when it
  is pressed, and one for when it's not.
 
 
  Anyone know an easy way to do this?
 
 
  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@**
 googlegroups.com android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+**unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/**group/android-developers?hl=enhttp://groups.google.com/group/android-developers?hl=en

  --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: About Phone GAP

2011-12-01 Thread sajjan androiddeveloper
Unfortunately ,If you need same code to be working on multiple
platforms(iPhone and Blackberry) no other way now..

On Thu, Dec 1, 2011 at 10:30 AM, Mukesh Srivastav mukicha...@gmail.comwrote:

 JQuery,PhoneGAP,Snecha are all Same Web-Development tools.


 I suspect, one day, Mobile companies would HIRE Web-Developes who are good
 at HTML and CSS and will ask to work on PhoneGAP or Jquery


 -*Mukesh*

 On Thu, Dec 1, 2011 at 3:53 PM, Alessandro Pellizzari a...@amiran.itwrote:

 Il Thu, 01 Dec 2011 14:59:16 +0530, Mukesh Srivastav ha scritto:

  I just wanted to check how many Android/iPhone Developers would really
  likes it work on PhoneGAP which is like Developing Web-programming
 usinge
  HTML/Javascript and CSS.

 The primary field I work in is HTML+CSS+JS (+PHP). I do it 8-12 hours a
 day, 6 or 7 days a week. :)

 I still find it quite hard to adapt a web interface for a mobile device.
 It is much easier to use Android Activities instead of juggling DOM
 pieces thru Javascript.

 Maybe with PhoneGAP, Sencha and jQueryMobile it is/will be easier.
 But performance is (still) much poorer.

 Bye.


 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




 --
 Warm Regards,
 *Mukesh Kumar*,
 Android Consultant/Freelancer,
 India,Hyderabad.

  --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en