Skip to content

Commit

Permalink
-fixing bits of the rotated image view
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaydashrath committed Jul 13, 2012
1 parent 6afa4ab commit d292dc9
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 151 deletions.
104 changes: 50 additions & 54 deletions CompassExample/AndroidManifest.xml
@@ -1,59 +1,55 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.novoda.example.compass" package="com.novoda.example.compass" android:versionCode="1"
android:versionCode="1" android:versionName="1.0">
android:versionName="1.0" >


<uses-sdk <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="15" />
android:minSdkVersion="9"
android:targetSdkVersion="15" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:theme="@style/Theme.Sherlock.Light"
android:name="NovoCompass">


<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <activity android:name=".activities.CompassActivity"

android:screenOrientation="portrait" android:label="@string/title_activity_compass">
<application <intent-filter>
android:icon="@drawable/ic_launcher" <action android:name="android.intent.action.MAIN" />
android:label="@string/app_name" <category android:name="android.intent.category.LAUNCHER" />
android:theme="@style/Theme.Sherlock.Light" android:name="NovoCompass"> </intent-filter>
<activity </activity>
android:name=".activities.CompassActivity"
android:label="@string/title_activity_compass" > <!-- Receivers -->
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <receiver android:name="com.novoda.location.receiver.LocationChanged">

<intent-filter>
<category android:name="android.intent.category.LAUNCHER" /> <action android:name="com.novoda.location.ACTIVE_LOCATION_UPDATE_ACTION" />
</intent-filter> </intent-filter>
</activity> </receiver>


<!-- Receivers --> <receiver android:name="com.novoda.location.receiver.PassiveLocationChanged" />


<receiver android:name="com.novoda.location.receiver.LocationChanged" > <receiver
<intent-filter> android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLostConnectivity"
<action android:name="com.novoda.location.ACTIVE_LOCATION_UPDATE_ACTION" /> enabled="false">
</intent-filter> <intent-filter>
</receiver> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />

</intent-filter>
<receiver android:name="com.novoda.location.receiver.PassiveLocationChanged" /> </receiver>


<receiver <receiver
android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLostConnectivity" android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLowBattery">
enabled="false" > <intent-filter>
<intent-filter> <action android:name="android.intent.action.BATTERY_LOW" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <action android:name="android.intent.action.BATTERY_OKAY" />
</intent-filter> </intent-filter>
</receiver> </receiver>


<receiver android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLowBattery" > <receiver android:name="com.novoda.location.receiver.RestorePassiveListenerBoot">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BATTERY_LOW" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.BATTERY_OKAY" /> </intent-filter>
</intent-filter> </receiver>
</receiver>

</application>
<receiver android:name="com.novoda.location.receiver.RestorePassiveListenerBoot" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

</application>


</manifest> </manifest>
26 changes: 12 additions & 14 deletions CompassExample/res/layout/activity_compass.xml
@@ -1,16 +1,14 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
android:layout_height="match_parent" >


<TextView <TextView android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@android:id/text1"
android:layout_height="wrap_content" android:padding="@dimen/padding_medium" android:layout_weight="10" />
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="@android:id/text1"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".CompassActivity" />


</RelativeLayout> <com.novoda.example.compass.view.RotatedImageView
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:id="@+id/image" />


</LinearLayout>
68 changes: 0 additions & 68 deletions CompassExample/src/com/novoda/example/compass/ImageActivity.java

This file was deleted.

Expand Up @@ -3,6 +3,7 @@
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.novoda.example.compass.R; import com.novoda.example.compass.R;
import com.novoda.example.compass.utils.CompassUtils; import com.novoda.example.compass.utils.CompassUtils;
import com.novoda.example.compass.view.RotatedImageView;


import android.hardware.SensorEvent; import android.hardware.SensorEvent;
import android.os.Bundle; import android.os.Bundle;
Expand All @@ -12,11 +13,13 @@
public class CompassActivity extends BasicSensorActivity { public class CompassActivity extends BasicSensorActivity {


private boolean isCompassEnabled; private boolean isCompassEnabled;
private RotatedImageView image;


@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compass); setContentView(R.layout.activity_compass);
image = (RotatedImageView) findViewById(R.id.image);
isCompassEnabled = false; isCompassEnabled = false;
refreshText(); refreshText();
} }
Expand All @@ -26,13 +29,22 @@ private void refreshText() {
+ " Rotation in degress " + getRotation()) : "Compass disabled"; + " Rotation in degress " + getRotation()) : "Compass disabled";
updateText(text); updateText(text);
} }

private void refreshImageRotation() {
if (isCompassEnabled){
image.updateCompassDegrees(getRotation());
}
}


@Override @Override
public void onSensorChanged(SensorEvent evt) { public void onSensorChanged(SensorEvent evt) {
super.onSensorChanged(evt); super.onSensorChanged(evt);
refreshText(); refreshText();
refreshImageRotation();
} }




private void updateText(String textString) { private void updateText(String textString) {
TextView text = (TextView) findViewById(android.R.id.text1); TextView text = (TextView) findViewById(android.R.id.text1);
text.setText(textString); text.setText(textString);
Expand All @@ -49,6 +61,7 @@ public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_enable_compass_rotation: case R.id.menu_enable_compass_rotation:
isCompassEnabled = !isCompassEnabled; isCompassEnabled = !isCompassEnabled;
image.setCompassActivated(isCompassEnabled, getRotation());
String text = isCompassEnabled ? "Compass rotation has been enabled!" String text = isCompassEnabled ? "Compass rotation has been enabled!"
: "Compass rotation has been disabled"; : "Compass rotation has been disabled";
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
Expand Down
Expand Up @@ -8,16 +8,13 @@
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.ScaleGestureDetector; import android.view.ScaleGestureDetector;
import android.view.View; import android.view.View;


public class RotatedImageView extends View implements SensorEventListener { public class RotatedImageView extends View {


private static final int INVALID_POINTER_ID = -1; private static final int INVALID_POINTER_ID = -1;


Expand Down Expand Up @@ -341,17 +338,6 @@ public void setCompassActivated(boolean activated, float originalDegrees) {


public void updateCompassDegrees(float degrees) { public void updateCompassDegrees(float degrees) {
compass_degrees = -degrees; compass_degrees = -degrees;
}

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

}

@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
invalidate(); invalidate();
} }


Expand Down

0 comments on commit d292dc9

Please sign in to comment.