Add compass for #644
This commit is contained in:
@@ -14,6 +14,7 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -39,6 +40,9 @@ public class MainActivity extends ActionBarActivity {
|
||||
// The FPS label
|
||||
TextView mFpsTextView;
|
||||
|
||||
// The compass
|
||||
ImageView mCompassView;
|
||||
|
||||
//
|
||||
// Lifecycle events
|
||||
//
|
||||
@@ -53,9 +57,14 @@ public class MainActivity extends ActionBarActivity {
|
||||
setContentView(R.layout.activity_main);
|
||||
mMapFragment = (MapFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_map);
|
||||
mMapFragment.getMap().setOnFpsChangedListener(new MyOnFpsChangedListener());
|
||||
mMapFragment.getMap().setOnMapChangedListener(new MyOnMapChangedListener());
|
||||
|
||||
mFpsTextView = (TextView)findViewById(R.id.view_fps);
|
||||
mFpsTextView.setText("");
|
||||
|
||||
mCompassView = (ImageView)findViewById(R.id.view_compass);
|
||||
mCompassView.setOnClickListener(new CompassOnClickListener());
|
||||
|
||||
// Add a toolbar as the action bar
|
||||
Toolbar mainToolbar = (Toolbar)findViewById(R.id.toolbar_main);
|
||||
setSupportActionBar(mainToolbar);
|
||||
@@ -197,4 +206,22 @@ public class MainActivity extends ActionBarActivity {
|
||||
mFpsTextView.setText(getResources().getString(R.string.label_fps) + String.format(" %4.2f", fps));
|
||||
}
|
||||
}
|
||||
|
||||
// Called when map state changes
|
||||
public class MyOnMapChangedListener implements MapView.OnMapChangedListener {
|
||||
|
||||
@Override
|
||||
public void onMapChanged() {
|
||||
mCompassView.setRotation((float)mMapFragment.getMap().getDirection());
|
||||
}
|
||||
}
|
||||
|
||||
// Called when someone presses the compass
|
||||
public class CompassOnClickListener implements View.OnClickListener {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mMapFragment.getMap().resetNorth();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
android/java/app/src/main/res/drawable-mdpi/compass.png
Normal file
BIN
android/java/app/src/main/res/drawable-mdpi/compass.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
@@ -30,7 +30,16 @@
|
||||
tools:context="${packageName}.${activityClass}"
|
||||
tools:layout="@layout/fragment_main" />
|
||||
|
||||
<TextView
|
||||
<ImageView
|
||||
android:id="@+id/view_compass"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right|top"
|
||||
android:padding="10dp"
|
||||
android:contentDescription="Map compass. Click to reset the map rotation to North."
|
||||
android:src="@drawable/compass"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/view_fps"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user