mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
center AddPoiView on map, adapt centering to keyboard appearing/disappearing
This commit is contained in:
+1
-1
@@ -62,7 +62,7 @@ dependencies {
|
||||
}
|
||||
implementation 'com.annimon:stream:1.1.8' // brings future java streams api to SDK Version < 24
|
||||
implementation 'com.codewaves.stickyheadergrid:stickyheadergrid:0.9.4' // glues the current time segment text in the gallery to the top.
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.3.2'
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1'
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
|
||||
@@ -5,11 +5,16 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".map.MapActivity">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
<org.thoughtcrime.securesms.components.InputAwareLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/inputAwareContainer"
|
||||
>
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</org.thoughtcrime.securesms.components.InputAwareLayout>
|
||||
|
||||
<include layout="@layout/bottom_map_sheet" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
@@ -71,4 +71,8 @@ public class AddPoiView extends LinearLayoutCompat {
|
||||
public void setOnMessageSentListener(SendingTask.OnMessageSentListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public EditText getMessageView() {
|
||||
return messageView;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.thoughtcrime.securesms.BaseActivity;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.ConversationActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.InputAwareLayout;
|
||||
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
|
||||
import org.thoughtcrime.securesms.components.rangeslider.TimeRangeSlider;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.geolocation.DcLocation;
|
||||
@@ -48,7 +50,10 @@ import static org.thoughtcrime.securesms.map.MapDataManager.MARKER_SELECTED;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.MESSAGE_ID;
|
||||
import static org.thoughtcrime.securesms.map.model.MapSource.INFO_WINDOW_LAYER;
|
||||
|
||||
public class MapActivity extends BaseActivity implements Observer, TimeRangeSlider.OnTimestampChangedListener {
|
||||
public class MapActivity extends BaseActivity implements Observer,
|
||||
TimeRangeSlider.OnTimestampChangedListener,
|
||||
KeyboardAwareLinearLayout.OnKeyboardShownListener,
|
||||
KeyboardAwareLinearLayout.OnKeyboardHiddenListener {
|
||||
|
||||
public static final String TAG = MapActivity.class.getSimpleName();
|
||||
public static final String CHAT_ID = "chat_id";
|
||||
@@ -61,6 +66,7 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
|
||||
DCMapFragment mapFragment;
|
||||
MarkerViewManager markerViewManager;
|
||||
private int chatId;
|
||||
private InputAwareLayout inputAwareContainer;
|
||||
|
||||
public static void lazyMapboxInit(Context context) {
|
||||
try {
|
||||
@@ -110,7 +116,9 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
|
||||
|
||||
this.mapboxMap = mapboxMap;
|
||||
this.markerViewManager = new MarkerViewManager(mapFragment.getMapView(), mapboxMap);
|
||||
|
||||
inputAwareContainer = findViewById(R.id.inputAwareContainer);
|
||||
inputAwareContainer.addOnKeyboardHiddenListener(this);
|
||||
inputAwareContainer.addOnKeyboardShownListener(this);
|
||||
|
||||
final LatLng lastMapCenter = Prefs.getMapCenter(this.getApplicationContext(), chatId);
|
||||
if (lastMapCenter != null) {
|
||||
@@ -156,8 +164,7 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
|
||||
handleAddPoiClick(point));
|
||||
|
||||
|
||||
mapboxMap.addOnMapLongClickListener(point ->
|
||||
handlePoiLongClick(point));
|
||||
mapboxMap.addOnMapLongClickListener(this::handlePoiLongClick);
|
||||
|
||||
SwitchCompat switchCompat = this.findViewById(R.id.locationTraceSwitch);
|
||||
switchCompat.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
@@ -312,13 +319,21 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
|
||||
}
|
||||
|
||||
if (markerViewManager.hasMarkers()) {
|
||||
MarkerView markerView = markerViewManager.getCenteredMarker();
|
||||
if (markerView != null && markerView.getView() instanceof AddPoiView) {
|
||||
AddPoiView view = (AddPoiView) markerView.getView();
|
||||
inputAwareContainer.hideCurrentInput(view.getMessageView());
|
||||
}
|
||||
markerViewManager.removeMarkers();
|
||||
} else {
|
||||
AddPoiView addPoiView = new AddPoiView(this);
|
||||
addPoiView.setLatLng(point);
|
||||
addPoiView.setChatId(chatId);
|
||||
addPoiView.setOnMessageSentListener(markerViewManager);
|
||||
markerViewManager.addMarker(new MarkerView(point, addPoiView));
|
||||
MarkerView markerView = new MarkerView(point, addPoiView);
|
||||
markerViewManager.addMarker(markerView);
|
||||
inputAwareContainer.showSoftkey(addPoiView.getMessageView());
|
||||
markerViewManager.center(markerView);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -349,4 +364,13 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyboardHidden() {
|
||||
markerViewManager.onKeyboardShown(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyboardShown() {
|
||||
markerViewManager.onKeyboardShown(inputAwareContainer.getKeyboardHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,10 @@ public class MarkerView {
|
||||
update();
|
||||
}
|
||||
|
||||
public LatLng getLatLng() {
|
||||
return latLng;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a callback to be invoked when position placement is calculated.
|
||||
* <p>
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.thoughtcrime.securesms.map;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdate;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
@@ -18,6 +21,8 @@ public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListe
|
||||
private final MapboxMap mapboxMap;
|
||||
private final List<MarkerView> markers = new ArrayList<>();
|
||||
private boolean initialised;
|
||||
private MarkerView centeredMarker;
|
||||
private int keyboardHeight = 0;
|
||||
|
||||
/**
|
||||
* Create a MarkerViewManager.
|
||||
@@ -90,6 +95,8 @@ public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListe
|
||||
for (MarkerView markerView : markers) {
|
||||
mapView.removeView(markerView.getView());
|
||||
}
|
||||
|
||||
centeredMarker = null;
|
||||
markers.clear();
|
||||
}
|
||||
|
||||
@@ -110,4 +117,34 @@ public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListe
|
||||
public void onMessageSent() {
|
||||
removeMarkers();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void center(MarkerView view) {
|
||||
centeredMarker = view;
|
||||
view.getView().post(() -> {
|
||||
int markerWidth = view.getView().getWidth();
|
||||
CameraPosition currentPosition = mapboxMap.getCameraPosition();
|
||||
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder().
|
||||
target(view.getLatLng()).
|
||||
bearing(currentPosition.bearing).
|
||||
tilt(currentPosition.tilt).
|
||||
zoom(currentPosition.zoom).
|
||||
padding(0d , 0d, markerWidth / 2d, keyboardHeight).
|
||||
build());
|
||||
mapboxMap.easeCamera(cameraUpdate);
|
||||
});
|
||||
}
|
||||
|
||||
MarkerView getCenteredMarker() {
|
||||
return centeredMarker;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void onKeyboardShown(int keyboardHeight) {
|
||||
this.keyboardHeight = keyboardHeight;
|
||||
if (centeredMarker != null) {
|
||||
center(centeredMarker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user