Skip to content

Commit

Permalink
mapbox#1856 - Adding Location FAB to TestApp with color toggle to sho…
Browse files Browse the repository at this point in the history
…w state
  • Loading branch information
bleege committed Aug 10, 2015
1 parent daa42fc commit d6d0dc9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.PointF;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class MainActivity extends AppCompatActivity {
private ArrayAdapter mSatelliteClassAdapter;

// Used for GPS
private MenuItem mGpsMenuItem;
private FloatingActionButton locationFAB;

// Used for Annotations
private boolean mIsAnnotationsOn = false;
Expand Down Expand Up @@ -143,6 +144,16 @@ public boolean onTouch(View v, MotionEvent event) {

mMapFrameLayout = (FrameLayout) findViewById(R.id.layout_map);

locationFAB = (FloatingActionButton)findViewById(R.id.locationFAB);
locationFAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toggle GPS position updates
toggleGps(!mapView.isMyLocationEnabled());
updateMap();
}
});

/*
// Add the spinner to select class styles
mClassSpinner = (Spinner) findViewById(R.id.spinner_class);
Expand Down Expand Up @@ -220,22 +231,6 @@ public void onLowMemory() {
// Other events
//

/*
// Adds items to the action bar menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
mGpsMenuItem = menu.findItem(R.id.action_gps);
if (mapView.isMyLocationEnabled()) {
mGpsMenuItem.setIcon(R.drawable.ic_action_location_found);
} else {
mGpsMenuItem.setIcon(R.drawable.ic_action_location_searching);
}
return super.onCreateOptionsMenu(menu);
}
*/

// Called when pressing action bar items
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Expand Down Expand Up @@ -340,16 +335,12 @@ private void toggleGps(boolean enableGps) {
if (enableGps) {
if (!mapView.isMyLocationEnabled()) {
mapView.setMyLocationEnabled(enableGps);
if (mGpsMenuItem != null) {
mGpsMenuItem.setIcon(R.drawable.ic_action_location_found);
}
locationFAB.setColorFilter(getResources().getColor(R.color.primary));
}
} else {
if (mapView.isMyLocationEnabled()) {
mapView.setMyLocationEnabled(enableGps);
if (mGpsMenuItem != null) {
mGpsMenuItem.setIcon(R.drawable.ic_action_location_searching);
}
locationFAB.setColorFilter(Color.TRANSPARENT);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@
</FrameLayout>


<!--
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
/>
-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/locationFAB"
android:src="@drawable/ic_my_location_white_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
/>

</android.support.design.widget.CoordinatorLayout>

Expand Down

0 comments on commit d6d0dc9

Please sign in to comment.