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

View File

@ -3,22 +3,22 @@ package eu.siacs.conversations.ui;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.location.Location;
import android.location.LocationListener;
import android.os.Build;
import android.os.Bundle;
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.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import org.osmdroid.api.IGeoPoint;
import org.osmdroid.util.GeoPoint;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityShareLocationBinding;
import eu.siacs.conversations.ui.util.LocationHelper;
import eu.siacs.conversations.ui.widget.Marker;
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 {
private Snackbar snackBar;
private ActivityShareLocationBinding binding;
private boolean marker_fixed_to_loc = false;
private static final String KEY_FIXED_TO_LOC = "fixed_to_loc";
private Boolean noAskAgain = false;
@ -50,22 +51,18 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share_location);
setSupportActionBar(findViewById(R.id.toolbar));
this.binding = DataBindingUtil.setContentView(this,R.layout.activity_share_location);
setSupportActionBar((Toolbar) binding.toolbar);
configureActionBar(getSupportActionBar());
setupMapView(Config.Map.INITIAL_POS);
setupMapView(binding.map, Config.Map.INITIAL_POS);
// Setup the cancel button
final Button cancelButton = findViewById(R.id.cancel_button);
cancelButton.setOnClickListener(view -> {
this.binding.cancelButton.setOnClickListener(view -> {
setResult(RESULT_CANCELED);
finish();
});
final CoordinatorLayout snackBarCoordinator = findViewById(R.id.snackbarCoordinator);
if (snackBarCoordinator != null) {
this.snackBar = Snackbar.make(snackBarCoordinator, R.string.location_disabled, Snackbar.LENGTH_INDEFINITE);
snackBar.setAction(R.string.enable, view -> {
this.snackBar = Snackbar.make(this.binding.snackbarCoordinator, R.string.location_disabled, Snackbar.LENGTH_INDEFINITE);
this.snackBar.setAction(R.string.enable, view -> {
if (isLocationEnabledAndAllowed()) {
updateUi();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasLocationPermissions()) {
@ -74,12 +71,8 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
});
}
// Setup the share button
final Button shareButton = findViewById(R.id.share_button);
if (shareButton != null) {
shareButton.setOnClickListener(view -> {
this.binding.shareButton.setOnClickListener(view -> {
final Intent result = new Intent();
if (marker_fixed_to_loc && myLoc != null) {
@ -88,7 +81,7 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
result.putExtra("altitude", myLoc.getAltitude());
result.putExtra("accuracy", (int) myLoc.getAccuracy());
} else {
final IGeoPoint markerPoint = map.getMapCenter();
final IGeoPoint markerPoint = this.binding.map.getMapCenter();
result.putExtra("latitude", markerPoint.getLatitude());
result.putExtra("longitude", markerPoint.getLongitude());
}
@ -96,13 +89,10 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
setResult(RESULT_OK, result);
finish();
});
}
this.marker_fixed_to_loc = isLocationEnabledAndAllowed();
// Setup the fab button
final FloatingActionButton toggleFixedMarkerButton = findViewById(R.id.fab);
toggleFixedMarkerButton.setOnClickListener(view -> {
this.binding.fab.setOnClickListener(view -> {
if (!marker_fixed_to_loc) {
if (!isLocationEnabled()) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
@ -163,14 +153,14 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
protected void updateLocationMarkers() {
super.updateLocationMarkers();
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) {
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 {
map.getOverlays().add(new Marker(marker_icon));
this.binding.map.getOverlays().add(new Marker(marker_icon));
}
} 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();
}
// Setup the fab button
final FloatingActionButton fab = findViewById(R.id.fab);
if (isLocationEnabledAndAllowed()) {
fab.setVisibility(View.VISIBLE);
this.binding.fab.setVisibility(View.VISIBLE);
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);
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
));
fab.invalidate();
this.binding.fab.invalidate();
});
} else {
fab.setVisibility(View.GONE);
this.binding.fab.setVisibility(View.GONE);
}
}
}

View File

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

View File

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

View File

@ -1,13 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.ShowLocationActivity">
<include layout="@layout/toolbar" />
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<org.osmdroid.views.MapView android:id="@+id/map"
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
@ -15,11 +20,12 @@
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="?attr/icon_directions"
android:tint="@color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:contentDescription="@string/action_unfix_from_location"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:layout_alignParentBottom="true"/>
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="send_again">Send again</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="show_qr_code">Show 2D Barcode</string>
<string name="show_block_list">Show block list</string>
@ -698,4 +698,5 @@
<string name="action_directions">Directions</string>
<string name="title_activity_share_location">Share location</string>
<string name="title_activity_show_location">Show location</string>
<string name="share">Share</string>
</resources>

View File

@ -38,6 +38,10 @@
<item name="android:textSize">?TextSizeBody1</item>
</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">
<item name="android:textSize">?TextSizeCaption</item>