Permalink
Browse files

-fixing bits of the rotated image view

  • Loading branch information...
1 parent 6afa4ab commit d292dc9c0e6af5197f514320a0bf7e35711539d9 @akshaydashrath akshaydashrath committed Jul 13, 2012
@@ -1,59 +1,55 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.novoda.example.compass"
- android:versionCode="1"
- android:versionName="1.0" >
+ package="com.novoda.example.compass" android:versionCode="1"
+ android:versionName="1.0">
- <uses-sdk
- android:minSdkVersion="9"
- android:targetSdkVersion="15" />
+ <uses-sdk 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"/>
-
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/Theme.Sherlock.Light" android:name="NovoCompass">
- <activity
- android:name=".activities.CompassActivity"
- android:label="@string/title_activity_compass" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
-
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
-
- <!-- Receivers -->
-
- <receiver android:name="com.novoda.location.receiver.LocationChanged" >
- <intent-filter>
- <action android:name="com.novoda.location.ACTIVE_LOCATION_UPDATE_ACTION" />
- </intent-filter>
- </receiver>
-
- <receiver android:name="com.novoda.location.receiver.PassiveLocationChanged" />
-
- <receiver
- android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLostConnectivity"
- enabled="false" >
- <intent-filter>
- <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
- </intent-filter>
- </receiver>
-
- <receiver android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLowBattery" >
- <intent-filter>
- <action android:name="android.intent.action.BATTERY_LOW" />
- <action android:name="android.intent.action.BATTERY_OKAY" />
- </intent-filter>
- </receiver>
-
- <receiver android:name="com.novoda.location.receiver.RestorePassiveListenerBoot" >
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
-
- </application>
+ <activity android:name=".activities.CompassActivity"
+ android:screenOrientation="portrait" android:label="@string/title_activity_compass">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <!-- Receivers -->
+
+ <receiver android:name="com.novoda.location.receiver.LocationChanged">
+ <intent-filter>
+ <action android:name="com.novoda.location.ACTIVE_LOCATION_UPDATE_ACTION" />
+ </intent-filter>
+ </receiver>
+
+ <receiver android:name="com.novoda.location.receiver.PassiveLocationChanged" />
+
+ <receiver
+ android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLostConnectivity"
+ enabled="false">
+ <intent-filter>
+ <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
+ </intent-filter>
+ </receiver>
+
+ <receiver
+ android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLowBattery">
+ <intent-filter>
+ <action android:name="android.intent.action.BATTERY_LOW" />
+ <action android:name="android.intent.action.BATTERY_OKAY" />
+ </intent-filter>
+ </receiver>
+
+ <receiver android:name="com.novoda.location.receiver.RestorePassiveListenerBoot">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ </intent-filter>
+ </receiver>
+
+ </application>
</manifest>
@@ -1,16 +1,14 @@
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+ android:layout_height="match_parent" android:orientation="vertical">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- 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" />
+ <TextView android:layout_width="match_parent"
+ android:layout_height="match_parent" android:id="@android:id/text1"
+ android:padding="@dimen/padding_medium" android:layout_weight="10" />
-</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>
@@ -1,68 +0,0 @@
-package com.novoda.example.compass;
-
-import utils.RotatedImageView;
-
-import android.app.Activity;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Matrix;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.View.OnTouchListener;
-import android.widget.ImageView;
-
-public class ImageActivity extends Activity implements OnTouchListener{
-
- private ImageView image;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- RotatedImageView view = new RotatedImageView(this);
- view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT));
-
- setContentView(view);
-
-// setContentView(R.layout.activity_image);
-// loadImage();
- }
-
- private void loadImage(){
- image = (ImageView) findViewById(R.id.backgroundimage);
- image.setOnTouchListener(this);
- }
-
- @Override
- public boolean onTouch(View v, MotionEvent event) {
-
- double r = Math.atan2(event.getX() - image.getWidth() / 2, image.getHeight() / 2 - event.getY());
- int rotation = (int) Math.toDegrees(r);
-
- if (event.getAction() == MotionEvent.ACTION_MOVE)
- {
- updateRotation(rotation);
- }
-
- return true;
- }
-
- private void updateRotation(double rot)
- {
- float newRot = new Float(rot);
-
- Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.floorplan);
-
- Matrix matrix = new Matrix();
- matrix.postRotate(newRot - 50);
-
- Bitmap redrawnBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
- image.setImageBitmap(redrawnBitmap);
- }
-
-
-
-}
@@ -3,6 +3,7 @@
import com.actionbarsherlock.view.Menu;
import com.novoda.example.compass.R;
import com.novoda.example.compass.utils.CompassUtils;
+import com.novoda.example.compass.view.RotatedImageView;
import android.hardware.SensorEvent;
import android.os.Bundle;
@@ -12,11 +13,13 @@
public class CompassActivity extends BasicSensorActivity {
private boolean isCompassEnabled;
+ private RotatedImageView image;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compass);
+ image = (RotatedImageView) findViewById(R.id.image);
isCompassEnabled = false;
refreshText();
}
@@ -26,13 +29,22 @@ private void refreshText() {
+ " Rotation in degress " + getRotation()) : "Compass disabled";
updateText(text);
}
+
+ private void refreshImageRotation() {
+ if (isCompassEnabled){
+ image.updateCompassDegrees(getRotation());
+ }
+ }
@Override
public void onSensorChanged(SensorEvent evt) {
super.onSensorChanged(evt);
refreshText();
+ refreshImageRotation();
}
+
+
private void updateText(String textString) {
TextView text = (TextView) findViewById(android.R.id.text1);
text.setText(textString);
@@ -49,6 +61,7 @@ public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_enable_compass_rotation:
isCompassEnabled = !isCompassEnabled;
+ image.setCompassActivated(isCompassEnabled, getRotation());
String text = isCompassEnabled ? "Compass rotation has been enabled!"
: "Compass rotation has been disabled";
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
@@ -8,16 +8,13 @@
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
-import android.hardware.Sensor;
-import android.hardware.SensorEvent;
-import android.hardware.SensorEventListener;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
-public class RotatedImageView extends View implements SensorEventListener {
+public class RotatedImageView extends View {
private static final int INVALID_POINTER_ID = -1;
@@ -341,17 +338,6 @@ public void setCompassActivated(boolean activated, float originalDegrees) {
public void updateCompassDegrees(float 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();
}

0 comments on commit d292dc9

Please sign in to comment.