fixups for Share location merger

* use data binder
* introduced styled button
* fixed snackbar showing above button bar
This commit is contained in:
Daniel Gultsch 2018-04-21 18:25:40 +02:00
parent ee855ab560
commit 4599e477b4
7 changed files with 154 additions and 153 deletions

View File

@ -50,7 +50,7 @@ public abstract class LocationActivity extends ActionBarActivity implements Loca
protected static final String KEY_ZOOM_LEVEL = "zoom"; protected static final String KEY_ZOOM_LEVEL = "zoom";
protected Location myLoc = null; protected Location myLoc = null;
protected MapView map = null; private MapView map = null;
protected IMapController mapController = null; protected IMapController mapController = null;
protected Bitmap marker_icon; protected Bitmap marker_icon;
@ -137,9 +137,8 @@ public abstract class LocationActivity extends ActionBarActivity implements Loca
} }
} }
protected void setupMapView(final GeoPoint pos) { protected void setupMapView(MapView mapView, final GeoPoint pos) {
// Get map view and configure it. map = mapView;
map = findViewById(R.id.map);
map.setTileSource(tileSource()); map.setTileSource(tileSource());
map.setBuiltInZoomControls(false); map.setBuiltInZoomControls(false);
map.setMultiTouchControls(true); map.setMultiTouchControls(true);

View File

@ -3,22 +3,22 @@ package eu.siacs.conversations.ui;
import android.Manifest; import android.Manifest;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.location.Location; import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import android.widget.Button;
import org.osmdroid.api.IGeoPoint; import org.osmdroid.api.IGeoPoint;
import org.osmdroid.util.GeoPoint; import org.osmdroid.util.GeoPoint;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityShareLocationBinding;
import eu.siacs.conversations.ui.util.LocationHelper; import eu.siacs.conversations.ui.util.LocationHelper;
import eu.siacs.conversations.ui.widget.Marker; import eu.siacs.conversations.ui.widget.Marker;
import eu.siacs.conversations.ui.widget.MyLocation; import eu.siacs.conversations.ui.widget.MyLocation;
@ -26,6 +26,7 @@ import eu.siacs.conversations.ui.widget.MyLocation;
public class ShareLocationActivity extends LocationActivity implements LocationListener { public class ShareLocationActivity extends LocationActivity implements LocationListener {
private Snackbar snackBar; private Snackbar snackBar;
private ActivityShareLocationBinding binding;
private boolean marker_fixed_to_loc = false; private boolean marker_fixed_to_loc = false;
private static final String KEY_FIXED_TO_LOC = "fixed_to_loc"; private static final String KEY_FIXED_TO_LOC = "fixed_to_loc";
private Boolean noAskAgain = false; private Boolean noAskAgain = false;
@ -50,59 +51,48 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share_location); this.binding = DataBindingUtil.setContentView(this,R.layout.activity_share_location);
setSupportActionBar(findViewById(R.id.toolbar)); setSupportActionBar((Toolbar) binding.toolbar);
configureActionBar(getSupportActionBar()); configureActionBar(getSupportActionBar());
setupMapView(Config.Map.INITIAL_POS); setupMapView(binding.map, Config.Map.INITIAL_POS);
// Setup the cancel button this.binding.cancelButton.setOnClickListener(view -> {
final Button cancelButton = findViewById(R.id.cancel_button);
cancelButton.setOnClickListener(view -> {
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();
}); });
final CoordinatorLayout snackBarCoordinator = findViewById(R.id.snackbarCoordinator); this.snackBar = Snackbar.make(this.binding.snackbarCoordinator, R.string.location_disabled, Snackbar.LENGTH_INDEFINITE);
if (snackBarCoordinator != null) { this.snackBar.setAction(R.string.enable, view -> {
this.snackBar = Snackbar.make(snackBarCoordinator, R.string.location_disabled, Snackbar.LENGTH_INDEFINITE); if (isLocationEnabledAndAllowed()) {
snackBar.setAction(R.string.enable, view -> { updateUi();
if (isLocationEnabledAndAllowed()) { } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasLocationPermissions()) {
updateUi(); requestPermissions(REQUEST_CODE_SNACKBAR_PRESSED);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasLocationPermissions()) { } else if (!isLocationEnabled()) {
requestPermissions(REQUEST_CODE_SNACKBAR_PRESSED); startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
} else if (!isLocationEnabled()) { }
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); });
}
});
}
// Setup the share button this.binding.shareButton.setOnClickListener(view -> {
final Button shareButton = findViewById(R.id.share_button); final Intent result = new Intent();
if (shareButton != null) {
shareButton.setOnClickListener(view -> {
final Intent result = new Intent();
if (marker_fixed_to_loc && myLoc != null) { if (marker_fixed_to_loc && myLoc != null) {
result.putExtra("latitude", myLoc.getLatitude()); result.putExtra("latitude", myLoc.getLatitude());
result.putExtra("longitude", myLoc.getLongitude()); result.putExtra("longitude", myLoc.getLongitude());
result.putExtra("altitude", myLoc.getAltitude()); result.putExtra("altitude", myLoc.getAltitude());
result.putExtra("accuracy", (int) myLoc.getAccuracy()); result.putExtra("accuracy", (int) myLoc.getAccuracy());
} else { } else {
final IGeoPoint markerPoint = map.getMapCenter(); final IGeoPoint markerPoint = this.binding.map.getMapCenter();
result.putExtra("latitude", markerPoint.getLatitude()); result.putExtra("latitude", markerPoint.getLatitude());
result.putExtra("longitude", markerPoint.getLongitude()); result.putExtra("longitude", markerPoint.getLongitude());
} }
setResult(RESULT_OK, result); setResult(RESULT_OK, result);
finish(); finish();
}); });
}
this.marker_fixed_to_loc = isLocationEnabledAndAllowed(); this.marker_fixed_to_loc = isLocationEnabledAndAllowed();
// Setup the fab button this.binding.fab.setOnClickListener(view -> {
final FloatingActionButton toggleFixedMarkerButton = findViewById(R.id.fab);
toggleFixedMarkerButton.setOnClickListener(view -> {
if (!marker_fixed_to_loc) { if (!marker_fixed_to_loc) {
if (!isLocationEnabled()) { if (!isLocationEnabled()) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
@ -163,14 +153,14 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
protected void updateLocationMarkers() { protected void updateLocationMarkers() {
super.updateLocationMarkers(); super.updateLocationMarkers();
if (this.myLoc != null) { if (this.myLoc != null) {
this.map.getOverlays().add(new MyLocation(this, null, this.myLoc)); this.binding.map.getOverlays().add(new MyLocation(this, null, this.myLoc));
if (this.marker_fixed_to_loc) { if (this.marker_fixed_to_loc) {
map.getOverlays().add(new Marker(marker_icon, new GeoPoint(this.myLoc))); this.binding.map.getOverlays().add(new Marker(marker_icon, new GeoPoint(this.myLoc)));
} else { } else {
map.getOverlays().add(new Marker(marker_icon)); this.binding.map.getOverlays().add(new Marker(marker_icon));
} }
} else { } else {
map.getOverlays().add(new Marker(marker_icon)); this.binding.map.getOverlays().add(new Marker(marker_icon));
} }
} }
@ -229,20 +219,18 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
this.snackBar.show(); this.snackBar.show();
} }
// Setup the fab button
final FloatingActionButton fab = findViewById(R.id.fab);
if (isLocationEnabledAndAllowed()) { if (isLocationEnabledAndAllowed()) {
fab.setVisibility(View.VISIBLE); this.binding.fab.setVisibility(View.VISIBLE);
runOnUiThread(() -> { runOnUiThread(() -> {
fab.setImageResource(marker_fixed_to_loc ? R.drawable.ic_gps_fixed_white_24dp : this.binding.fab.setImageResource(marker_fixed_to_loc ? R.drawable.ic_gps_fixed_white_24dp :
R.drawable.ic_gps_not_fixed_white_24dp); R.drawable.ic_gps_not_fixed_white_24dp);
fab.setContentDescription(getResources().getString( this.binding.fab.setContentDescription(getResources().getString(
marker_fixed_to_loc ? R.string.action_unfix_from_location : R.string.action_fix_to_location marker_fixed_to_loc ? R.string.action_unfix_from_location : R.string.action_fix_to_location
)); ));
fab.invalidate(); this.binding.fab.invalidate();
}); });
} else { } else {
fab.setVisibility(View.GONE); this.binding.fab.setVisibility(View.GONE);
} }
} }
} }

View File

@ -1,17 +1,17 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.app.ActionBar;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.location.Location; import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton; import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -25,6 +25,7 @@ import java.util.regex.Pattern;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityShowLocationBinding;
import eu.siacs.conversations.ui.util.LocationHelper; import eu.siacs.conversations.ui.util.LocationHelper;
import eu.siacs.conversations.ui.util.UriHelper; import eu.siacs.conversations.ui.util.UriHelper;
import eu.siacs.conversations.ui.widget.Marker; import eu.siacs.conversations.ui.widget.Marker;
@ -34,7 +35,7 @@ import eu.siacs.conversations.ui.widget.MyLocation;
public class ShowLocationActivity extends LocationActivity implements LocationListener { public class ShowLocationActivity extends LocationActivity implements LocationListener {
private GeoPoint loc = Config.Map.INITIAL_POS; private GeoPoint loc = Config.Map.INITIAL_POS;
private FloatingActionButton navigationButton; private ActivityShowLocationBinding binding;
private Uri createGeoUri() { private Uri createGeoUri() {
@ -45,19 +46,13 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final ActionBar actionBar = getActionBar(); this.binding = DataBindingUtil.setContentView(this,R.layout.activity_show_location);
if (actionBar != null) { setSupportActionBar((Toolbar) binding.toolbar);
actionBar.setDisplayHomeAsUpEnabled(true);
}
setContentView(R.layout.activity_show_location);
setSupportActionBar(findViewById(R.id.toolbar));
configureActionBar(getSupportActionBar()); configureActionBar(getSupportActionBar());
setupMapView(this.loc); setupMapView(this.binding.map, this.loc);
// Setup the fab button this.binding.fab.setOnClickListener(view -> startNavigation());
this.navigationButton = findViewById(R.id.fab);
this.navigationButton.setOnClickListener(view -> startNavigation());
final Intent intent = getIntent(); final Intent intent = getIntent();
if (intent != null) { if (intent != null) {
@ -157,9 +152,9 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
protected void updateLocationMarkers() { protected void updateLocationMarkers() {
super.updateLocationMarkers(); super.updateLocationMarkers();
if (this.myLoc != null) { if (this.myLoc != null) {
this.map.getOverlays().add(new MyLocation(this, null, this.myLoc)); this.binding.map.getOverlays().add(new MyLocation(this, null, this.myLoc));
} }
this.map.getOverlays().add(new Marker(this.marker_icon, this.loc)); this.binding.map.getOverlays().add(new Marker(this.marker_icon, this.loc));
} }
@Override @Override
@ -175,6 +170,7 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
if (clipboard != null) { if (clipboard != null) {
final ClipData clip = ClipData.newPlainText("location", createGeoUri().toString()); final ClipData clip = ClipData.newPlainText("location", createGeoUri().toString());
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Toast.makeText(this,R.string.url_copied_to_clipboard,Toast.LENGTH_SHORT).show();
} }
return true; return true;
case R.id.action_share_location: case R.id.action_share_location:
@ -204,9 +200,7 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
protected void updateUi() { protected void updateUi() {
final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=0,0")); final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=0,0"));
final ComponentName component = i.resolveActivity(getPackageManager()); final ComponentName component = i.resolveActivity(getPackageManager());
if (this.navigationButton != null) { this.binding.fab.setVisibility(component == null ? View.GONE : View.VISIBLE);
this.navigationButton.setVisibility(component == null ? View.GONE : View.VISIBLE);
}
} }
@Override @Override

View File

@ -1,66 +1,75 @@
<android.support.design.widget.CoordinatorLayout <layout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/snackbarCoordinator" xmlns:tools="http://schemas.android.com/tools">
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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.ShareLocationActivity">
<include layout="@layout/toolbar" />
<org.osmdroid.views.MapView android:id="@+id/map" <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_above="@+id/button_bar"/> tools:context=".ui.ShareLocationActivity">
<LinearLayout <include
android:id="@+id/button_bar" android:id="@+id/toolbar"
android:layout_width="wrap_content" layout="@layout/toolbar"/>
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
tools:ignore="RtlHardcoded">
<Button <android.support.design.widget.CoordinatorLayout
android:id="@+id/cancel_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"
android:textAppearance="@style/TextAppearance.Conversations.Body1"/>
<View android:id="@+id/snackbar_coordinator"
android:layout_width="1dp" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="7dp" android:layout_above="@+id/button_bar" >
android:layout_marginTop="7dp"
android:background="@color/accent"/>
<Button <android.support.design.widget.FloatingActionButton
android:id="@+id/share_button" android:id="@+id/fab"
style="?android:attr/borderlessButtonStyle" android:layout_width="wrap_content"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_above="@+id/button_bar"
android:layout_alignParentEnd="true"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:contentDescription="@string/action_unfix_from_location"
android:src="?attr/icon_gps_fixed"/>
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:id="@+id/button_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_alignParentBottom="true"
android:text="@string/share_with" android:layout_alignParentLeft="true"
android:textAppearance="@style/TextAppearance.Conversations.Body1"/> android:layout_alignParentRight="true"
</LinearLayout> tools:ignore="RtlHardcoded">
<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:src="?attr/icon_gps_fixed"
android:layout_alignParentEnd="true"
android:layout_above="@+id/button_bar"
android:contentDescription="@string/action_unfix_from_location"
android:layout_margin="16dp" />
</RelativeLayout> <Button
</android.support.design.widget.CoordinatorLayout> android:id="@+id/cancel_button"
style="@style/Widget.Conversations.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"/>
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginBottom="7dp"
android:layout_marginTop="7dp"
android:background="?attr/divider"/>
<Button
android:id="@+id/share_button"
style="@style/Widget.Conversations.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/share"/>
</LinearLayout>
</RelativeLayout>
</layout>

View File

@ -1,25 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <layout 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_height="match_parent"
tools:context=".ui.ShowLocationActivity">
<include layout="@layout/toolbar" /> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.ShowLocationActivity">
<org.osmdroid.views.MapView android:id="@+id/map" <include
android:layout_width="fill_parent" android:id="@+id/toolbar"
android:layout_height="fill_parent"/> layout="@layout/toolbar"/>
<android.support.design.widget.FloatingActionButton <org.osmdroid.views.MapView
android:id="@+id/fab" android:id="@+id/map"
android:layout_width="wrap_content" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="fill_parent"/>
android:layout_gravity="end|bottom"
android:src="?attr/icon_directions" <android.support.design.widget.FloatingActionButton
android:tint="@color/white" android:id="@+id/fab"
android:layout_alignParentEnd="true" android:layout_width="wrap_content"
android:contentDescription="@string/action_unfix_from_location" android:layout_height="wrap_content"
android:layout_margin="16dp" android:layout_alignParentBottom="true"
android:layout_alignParentBottom="true"/> android:layout_alignParentEnd="true"
</RelativeLayout> android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:contentDescription="@string/action_unfix_from_location"
android:src="?attr/icon_directions"
android:tint="@color/white"/>
</RelativeLayout>
</layout>

View File

@ -296,7 +296,7 @@
<string name="copy_original_url">Copy original URL</string> <string name="copy_original_url">Copy original URL</string>
<string name="send_again">Send again</string> <string name="send_again">Send again</string>
<string name="file_url">File URL</string> <string name="file_url">File URL</string>
<string name="url_copied_to_clipboard">URL copied to clipboard</string> <string name="url_copied_to_clipboard">Copied URL to clipboard</string>
<string name="scan_qr_code">Scan 2D Barcode</string> <string name="scan_qr_code">Scan 2D Barcode</string>
<string name="show_qr_code">Show 2D Barcode</string> <string name="show_qr_code">Show 2D Barcode</string>
<string name="show_block_list">Show block list</string> <string name="show_block_list">Show block list</string>
@ -698,4 +698,5 @@
<string name="action_directions">Directions</string> <string name="action_directions">Directions</string>
<string name="title_activity_share_location">Share location</string> <string name="title_activity_share_location">Share location</string>
<string name="title_activity_show_location">Show location</string> <string name="title_activity_show_location">Show location</string>
<string name="share">Share</string>
</resources> </resources>

View File

@ -38,6 +38,10 @@
<item name="android:textSize">?TextSizeBody1</item> <item name="android:textSize">?TextSizeBody1</item>
</style> </style>
<style name="Widget.Conversations.Button.Borderless" parent="@style/Widget.AppCompat.Button.Borderless">
<item name="android:textSize">?TextSizeBody2</item>
</style>
<style name="TextAppearance.Conversations.Design.Hint" parent="TextAppearance.Design.Hint"> <style name="TextAppearance.Conversations.Design.Hint" parent="TextAppearance.Design.Hint">
<item name="android:textSize">?TextSizeCaption</item> <item name="android:textSize">?TextSizeCaption</item>