2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2013-12-20 20:25:49 +01:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 17:19:00 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
import android.animation.StateListAnimator;
|
2014-08-08 12:17:06 +02:00
|
|
|
import android.content.Context;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Outline;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.location.Location;
|
2014-08-08 12:17:06 +02:00
|
|
|
import android.location.LocationManager;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.MotionEvent;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.view.ViewGroup;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.view.ViewOutlineProvider;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.ListView;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.google.android.gms.maps.CameraUpdate;
|
|
|
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
|
|
|
import com.google.android.gms.maps.GoogleMap;
|
2014-06-04 01:31:48 +02:00
|
|
|
import com.google.android.gms.maps.MapView;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
import com.google.android.gms.maps.MapsInitializer;
|
2013-10-25 17:19:00 +02:00
|
|
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
2015-05-03 13:48:36 +02:00
|
|
|
import com.google.android.gms.maps.model.CircleOptions;
|
2013-10-25 17:19:00 +02:00
|
|
|
import com.google.android.gms.maps.model.LatLng;
|
|
|
|
import com.google.android.gms.maps.model.MarkerOptions;
|
2014-03-22 23:31:55 +01:00
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.android.UserObject;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2014-06-04 01:31:48 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.LocaleController;
|
2014-02-28 23:28:25 +01:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.MessageObject;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.MessagesController;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.R;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Adapters.BaseLocationAdapter;
|
|
|
|
import org.telegram.ui.Adapters.LocationActivityAdapter;
|
|
|
|
import org.telegram.ui.Adapters.LocationActivitySearchAdapter;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
import org.telegram.ui.Components.MapPlaceholderDrawable;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
import java.util.ArrayList;
|
2014-08-08 12:17:06 +02:00
|
|
|
import java.util.List;
|
2015-05-03 13:48:36 +02:00
|
|
|
import java.util.Locale;
|
2014-08-08 12:17:06 +02:00
|
|
|
|
2013-12-26 17:46:13 +01:00
|
|
|
public class LocationActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private GoogleMap googleMap;
|
|
|
|
private TextView distanceTextView;
|
2015-05-03 13:48:36 +02:00
|
|
|
private BackupImageView avatarImageView;
|
|
|
|
private TextView nameTextView;
|
|
|
|
private MapView mapView;
|
|
|
|
private FrameLayout mapViewClip;
|
|
|
|
private LocationActivityAdapter adapter;
|
|
|
|
private ListView listView;
|
|
|
|
private ListView searchListView;
|
|
|
|
private LocationActivitySearchAdapter searchAdapter;
|
|
|
|
private LinearLayout emptyTextLayout;
|
|
|
|
private ImageView markerImageView;
|
|
|
|
private ImageView markerXImageView;
|
|
|
|
private ImageView locationButton;
|
|
|
|
|
|
|
|
private AnimatorSet animatorSet;
|
|
|
|
|
|
|
|
private boolean searching;
|
|
|
|
private boolean searchWas;
|
|
|
|
|
|
|
|
private boolean wasResults;
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private Location myLocation;
|
|
|
|
private Location userLocation;
|
2015-05-03 13:48:36 +02:00
|
|
|
private int markerTop;
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private MessageObject messageObject;
|
|
|
|
private boolean userLocationMoved = false;
|
|
|
|
private boolean firstWas = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
private CircleOptions circleOptions;
|
2014-08-22 16:24:33 +02:00
|
|
|
private LocationActivityDelegate delegate;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
private int overScrollHeight = AndroidUtilities.displaySize.x - ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(66);
|
2015-05-03 13:48:36 +02:00
|
|
|
private int halfHeight;
|
|
|
|
|
|
|
|
private final static int share = 1;
|
2014-04-02 19:36:57 +02:00
|
|
|
private final static int map_list_menu_map = 2;
|
|
|
|
private final static int map_list_menu_satellite = 3;
|
|
|
|
private final static int map_list_menu_hybrid = 4;
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface LocationActivityDelegate {
|
2015-05-03 13:48:36 +02:00
|
|
|
void didSelectLocation(TLRPC.MessageMedia location);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean needAddActionBar() {
|
|
|
|
return messageObject != null;
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
2014-06-17 17:10:02 +02:00
|
|
|
swipeBackEnabled = false;
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (messageObject != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
|
2014-06-04 01:31:48 +02:00
|
|
|
if (mapView != null) {
|
|
|
|
mapView.onDestroy();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (adapter != null) {
|
|
|
|
adapter.destroy();
|
|
|
|
}
|
|
|
|
if (searchAdapter != null) {
|
|
|
|
searchAdapter.destroy();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setAllowOverlayTitle(true);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBar.setOccupyStatusBar(false);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
|
|
|
} else if (id == map_list_menu_map) {
|
|
|
|
if (googleMap != null) {
|
|
|
|
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
|
|
|
|
}
|
|
|
|
} else if (id == map_list_menu_satellite) {
|
|
|
|
if (googleMap != null) {
|
|
|
|
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
|
|
|
|
}
|
|
|
|
} else if (id == map_list_menu_hybrid) {
|
|
|
|
if (googleMap != null) {
|
|
|
|
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (id == share) {
|
|
|
|
try {
|
|
|
|
double lat = messageObject.messageOwner.media.geo.lat;
|
|
|
|
double lon = messageObject.messageOwner.media.geo._long;
|
|
|
|
getParentActivity().startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:" + lat + "," + lon + "?q=" + lat + "," + lon)));
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2015-05-03 13:48:36 +02:00
|
|
|
if (messageObject != null) {
|
|
|
|
if (messageObject.messageOwner.media.title != null && messageObject.messageOwner.media.title.length() > 0) {
|
|
|
|
actionBar.setTitle(messageObject.messageOwner.media.title);
|
|
|
|
if (messageObject.messageOwner.media.address != null && messageObject.messageOwner.media.address.length() > 0) {
|
|
|
|
actionBar.setSubtitle(messageObject.messageOwner.media.address);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation));
|
|
|
|
}
|
|
|
|
menu.addItem(share, R.drawable.share);
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation));
|
|
|
|
|
|
|
|
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
|
|
|
|
@Override
|
|
|
|
public void onSearchExpand() {
|
|
|
|
searching = true;
|
|
|
|
listView.setVisibility(View.GONE);
|
|
|
|
mapViewClip.setVisibility(View.GONE);
|
|
|
|
searchListView.setVisibility(View.VISIBLE);
|
|
|
|
searchListView.setEmptyView(emptyTextLayout);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-29 19:12:11 +02:00
|
|
|
public void onSearchCollapse() {
|
2015-05-03 13:48:36 +02:00
|
|
|
searching = false;
|
|
|
|
searchWas = false;
|
|
|
|
searchListView.setEmptyView(null);
|
|
|
|
listView.setVisibility(View.VISIBLE);
|
|
|
|
mapViewClip.setVisibility(View.VISIBLE);
|
|
|
|
searchListView.setVisibility(View.GONE);
|
|
|
|
emptyTextLayout.setVisibility(View.GONE);
|
|
|
|
searchAdapter.searchDelayed(null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(EditText editText) {
|
|
|
|
if (searchAdapter == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String text = editText.getText().toString();
|
|
|
|
if (text.length() != 0) {
|
|
|
|
searchWas = true;
|
|
|
|
}
|
|
|
|
searchAdapter.searchDelayed(text, userLocation);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
|
|
|
|
item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0);
|
|
|
|
item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0);
|
|
|
|
item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0);
|
2015-05-03 13:48:36 +02:00
|
|
|
fragmentView = new FrameLayout(context) {
|
|
|
|
private boolean first = true;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
fixLayoutInternal(first);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
|
|
|
|
|
|
|
locationButton = new ImageView(context);
|
|
|
|
locationButton.setBackgroundResource(R.drawable.floating_user_states);
|
|
|
|
locationButton.setImageResource(R.drawable.myloc_on);
|
|
|
|
locationButton.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
StateListAnimator animator = new StateListAnimator();
|
|
|
|
animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(locationButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
|
|
|
|
animator.addState(new int[]{}, ObjectAnimator.ofFloat(locationButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
|
|
|
|
locationButton.setStateListAnimator(animator);
|
|
|
|
locationButton.setOutlineProvider(new ViewOutlineProvider() {
|
|
|
|
@Override
|
|
|
|
public void getOutline(View view, Outline outline) {
|
|
|
|
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (messageObject != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
mapView = new MapView(context);
|
|
|
|
frameLayout.setBackgroundDrawable(new MapPlaceholderDrawable());
|
|
|
|
mapView.onCreate(null);
|
|
|
|
try {
|
|
|
|
MapsInitializer.initialize(context);
|
|
|
|
googleMap = mapView.getMap();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameLayout bottomView = new FrameLayout(context);
|
|
|
|
bottomView.setBackgroundResource(R.drawable.location_panel);
|
|
|
|
frameLayout.addView(bottomView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 60, Gravity.LEFT | Gravity.BOTTOM));
|
|
|
|
bottomView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (userLocation != null) {
|
|
|
|
LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
|
|
|
|
if (googleMap != null) {
|
|
|
|
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
|
|
|
|
googleMap.animateCamera(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
avatarImageView = new BackupImageView(context);
|
|
|
|
avatarImageView.setRoundRadius(AndroidUtilities.dp(20));
|
|
|
|
bottomView.addView(avatarImageView, LayoutHelper.createFrame(40, 40, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 12, 12, LocaleController.isRTL ? 12 : 0, 0));
|
|
|
|
|
|
|
|
nameTextView = new TextView(context);
|
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
nameTextView.setTextColor(0xff212121);
|
|
|
|
nameTextView.setMaxLines(1);
|
|
|
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
nameTextView.setSingleLine(true);
|
|
|
|
nameTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
|
|
|
|
bottomView.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 12 : 72, 10, LocaleController.isRTL ? 72 : 12, 0));
|
|
|
|
|
|
|
|
distanceTextView = new TextView(context);
|
|
|
|
distanceTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
distanceTextView.setTextColor(0xff2f8cc9);
|
|
|
|
distanceTextView.setMaxLines(1);
|
|
|
|
distanceTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
distanceTextView.setSingleLine(true);
|
|
|
|
distanceTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
|
|
|
|
bottomView.addView(distanceTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 12 : 72, 33, LocaleController.isRTL ? 72 : 12, 0));
|
|
|
|
|
|
|
|
userLocation = new Location("network");
|
|
|
|
userLocation.setLatitude(messageObject.messageOwner.media.geo.lat);
|
|
|
|
userLocation.setLongitude(messageObject.messageOwner.media.geo._long);
|
|
|
|
if (googleMap != null) {
|
|
|
|
LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
|
|
|
|
try {
|
|
|
|
googleMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)));
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
|
|
|
|
googleMap.moveCamera(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageView routeButton = new ImageView(context);
|
|
|
|
routeButton.setBackgroundResource(R.drawable.floating_states);
|
|
|
|
routeButton.setImageResource(R.drawable.navigate);
|
|
|
|
routeButton.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
StateListAnimator animator = new StateListAnimator();
|
|
|
|
animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(routeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
|
|
|
|
animator.addState(new int[]{}, ObjectAnimator.ofFloat(routeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
|
|
|
|
routeButton.setStateListAnimator(animator);
|
|
|
|
routeButton.setOutlineProvider(new ViewOutlineProvider() {
|
|
|
|
@Override
|
|
|
|
public void getOutline(View view, Outline outline) {
|
|
|
|
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
frameLayout.addView(routeButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 28));
|
|
|
|
routeButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (myLocation != null) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(String.format(Locale.US, "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", myLocation.getLatitude(), myLocation.getLongitude(), messageObject.messageOwner.media.geo.lat, messageObject.messageOwner.media.geo._long)));
|
|
|
|
getParentActivity().startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
frameLayout.addView(locationButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 100));
|
|
|
|
locationButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (myLocation != null && googleMap != null) {
|
|
|
|
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(myLocation.getLatitude(), myLocation.getLongitude()), googleMap.getMaxZoomLevel() - 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
searchWas = false;
|
|
|
|
searching = false;
|
|
|
|
mapViewClip = new FrameLayout(context);
|
|
|
|
mapViewClip.setBackgroundDrawable(new MapPlaceholderDrawable());
|
|
|
|
if (adapter != null) {
|
|
|
|
adapter.destroy();
|
|
|
|
}
|
|
|
|
if (searchAdapter != null) {
|
|
|
|
searchAdapter.destroy();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
listView = new ListView(context);
|
|
|
|
listView.setAdapter(adapter = new LocationActivityAdapter(context));
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
listView.setDividerHeight(0);
|
|
|
|
listView.setDivider(null);
|
|
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
|
|
|
|
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
if (totalItemCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
updateClipView(firstVisibleItem);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
if (position == 1) {
|
|
|
|
if (delegate != null && userLocation != null) {
|
|
|
|
TLRPC.TL_messageMediaGeo location = new TLRPC.TL_messageMediaGeo();
|
|
|
|
location.geo = new TLRPC.TL_geoPoint();
|
|
|
|
location.geo.lat = userLocation.getLatitude();
|
|
|
|
location.geo._long = userLocation.getLongitude();
|
|
|
|
delegate.didSelectLocation(location);
|
|
|
|
}
|
|
|
|
finishFragment();
|
|
|
|
} else {
|
|
|
|
TLRPC.TL_messageMediaVenue object = adapter.getItem(position);
|
|
|
|
if (object != null && delegate != null) {
|
|
|
|
delegate.didSelectLocation(object);
|
|
|
|
}
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
adapter.setDelegate(new BaseLocationAdapter.BaseLocationAdapterDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didLoadedSearchResult(ArrayList<TLRPC.TL_messageMediaVenue> places) {
|
|
|
|
if (!wasResults && !places.isEmpty()) {
|
|
|
|
wasResults = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
adapter.setOverScrollHeight(overScrollHeight);
|
|
|
|
|
|
|
|
frameLayout.addView(mapViewClip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
|
|
|
|
|
|
|
|
mapView = new MapView(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
if (animatorSet != null) {
|
|
|
|
animatorSet.cancel();
|
|
|
|
}
|
|
|
|
animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop + -AndroidUtilities.dp(10)),
|
|
|
|
ObjectAnimator.ofFloat(markerXImageView, "alpha", 1.0f));
|
|
|
|
animatorSet.start();
|
|
|
|
} else if (ev.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
if (animatorSet != null) {
|
|
|
|
animatorSet.cancel();
|
|
|
|
}
|
|
|
|
animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop),
|
|
|
|
ObjectAnimator.ofFloat(markerXImageView, "alpha", 0.0f));
|
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
if (!userLocationMoved) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 1.0f));
|
|
|
|
animatorSet.start();
|
|
|
|
} else {
|
|
|
|
locationButton.setVisibility(VISIBLE);
|
|
|
|
}
|
|
|
|
userLocationMoved = true;
|
|
|
|
}
|
|
|
|
if (googleMap != null && userLocation != null) {
|
|
|
|
userLocation.setLatitude(googleMap.getCameraPosition().target.latitude);
|
|
|
|
userLocation.setLongitude(googleMap.getCameraPosition().target.longitude);
|
|
|
|
}
|
|
|
|
adapter.setCustomLocation(userLocation);
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mapView.onCreate(null);
|
|
|
|
try {
|
|
|
|
MapsInitializer.initialize(context);
|
|
|
|
googleMap = mapView.getMap();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
View shadow = new View(context);
|
|
|
|
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
|
2015-07-22 20:56:37 +02:00
|
|
|
mapViewClip.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
markerImageView = new ImageView(context);
|
|
|
|
markerImageView.setImageResource(R.drawable.map_pin);
|
|
|
|
mapViewClip.addView(markerImageView, LayoutHelper.createFrame(24, 42, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
markerXImageView = new ImageView(context);
|
|
|
|
markerXImageView.setAlpha(0.0f);
|
|
|
|
markerXImageView.setImageResource(R.drawable.place_x);
|
|
|
|
mapViewClip.addView(markerXImageView, LayoutHelper.createFrame(14, 14, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
|
|
|
|
}
|
|
|
|
|
|
|
|
mapViewClip.addView(locationButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));
|
|
|
|
locationButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (myLocation != null && googleMap != null) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 0.0f));
|
|
|
|
animatorSet.start();
|
|
|
|
} else {
|
|
|
|
locationButton.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
adapter.setCustomLocation(null);
|
|
|
|
userLocationMoved = false;
|
|
|
|
googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(myLocation.getLatitude(), myLocation.getLongitude())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
locationButton.setAlpha(0.0f);
|
|
|
|
} else {
|
|
|
|
locationButton.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
emptyTextLayout = new LinearLayout(context);
|
|
|
|
emptyTextLayout.setVisibility(View.GONE);
|
|
|
|
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
frameLayout.addView(emptyTextLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
|
|
|
|
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
TextView emptyTextView = new TextView(context);
|
|
|
|
emptyTextView.setTextColor(0xff808080);
|
|
|
|
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
|
|
|
emptyTextView.setGravity(Gravity.CENTER);
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
|
|
|
|
emptyTextLayout.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));
|
|
|
|
|
|
|
|
FrameLayout frameLayoutEmpty = new FrameLayout(context);
|
|
|
|
emptyTextLayout.addView(frameLayoutEmpty, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));
|
|
|
|
|
|
|
|
searchListView = new ListView(context);
|
|
|
|
searchListView.setVisibility(View.GONE);
|
|
|
|
searchListView.setDividerHeight(0);
|
|
|
|
searchListView.setDivider(null);
|
|
|
|
searchListView.setAdapter(searchAdapter = new LocationActivitySearchAdapter(context));
|
|
|
|
frameLayout.addView(searchListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
|
|
|
|
searchListView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
|
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
TLRPC.TL_messageMediaVenue object = searchAdapter.getItem(position);
|
|
|
|
if (object != null && delegate != null) {
|
|
|
|
delegate.didSelectLocation(object);
|
|
|
|
}
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (googleMap != null) {
|
|
|
|
userLocation = new Location("network");
|
|
|
|
userLocation.setLatitude(20.659322);
|
|
|
|
userLocation.setLongitude(-11.406250);
|
|
|
|
}
|
|
|
|
|
|
|
|
frameLayout.addView(actionBar);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (googleMap != null) {
|
|
|
|
googleMap.setMyLocationEnabled(true);
|
|
|
|
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
|
|
|
|
googleMap.getUiSettings().setZoomControlsEnabled(false);
|
|
|
|
googleMap.getUiSettings().setCompassEnabled(false);
|
|
|
|
googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onMyLocationChange(Location location) {
|
|
|
|
positionMarker(location);
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
positionMarker(myLocation = getLastLocation());
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
return fragmentView;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void onOpenAnimationEnd() {
|
2015-06-29 19:12:11 +02:00
|
|
|
try {
|
|
|
|
if (mapView.getParent() instanceof ViewGroup) {
|
|
|
|
ViewGroup viewGroup = (ViewGroup) mapView.getParent();
|
|
|
|
viewGroup.removeView(mapView);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (mapViewClip != null) {
|
|
|
|
mapViewClip.addView(mapView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, overScrollHeight + AndroidUtilities.dp(10), Gravity.TOP | Gravity.LEFT));
|
|
|
|
updateClipView(listView.getFirstVisiblePosition());
|
|
|
|
} else {
|
|
|
|
((FrameLayout) fragmentView).addView(mapView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void updateClipView(int firstVisibleItem) {
|
|
|
|
int height = 0;
|
|
|
|
int top = 0;
|
|
|
|
View child = listView.getChildAt(0);
|
|
|
|
if (child != null) {
|
|
|
|
if (firstVisibleItem == 0) {
|
|
|
|
top = child.getTop();
|
|
|
|
height = overScrollHeight + (top < 0 ? top : 0);
|
|
|
|
halfHeight = (top < 0 ? top : 0) / 2;
|
|
|
|
}
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mapViewClip.getLayoutParams();
|
|
|
|
if (layoutParams != null) {
|
|
|
|
if (height <= 0) {
|
|
|
|
if (mapView.getVisibility() == View.VISIBLE) {
|
|
|
|
mapView.setVisibility(View.INVISIBLE);
|
|
|
|
mapViewClip.setVisibility(View.INVISIBLE);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
|
|
|
if (mapView.getVisibility() == View.INVISIBLE) {
|
|
|
|
mapView.setVisibility(View.VISIBLE);
|
|
|
|
mapViewClip.setVisibility(View.VISIBLE);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
mapViewClip.setTranslationY(Math.min(0, top));
|
|
|
|
mapView.setTranslationY(Math.max(0, -top / 2));
|
|
|
|
markerImageView.setTranslationY(markerTop = -top - AndroidUtilities.dp(42) + height / 2);
|
|
|
|
markerXImageView.setTranslationY(-top - AndroidUtilities.dp(7) + height / 2);
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (googleMap != null) {
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) mapView.getLayoutParams();
|
|
|
|
if (layoutParams != null && layoutParams.height != overScrollHeight + AndroidUtilities.dp(10)) {
|
|
|
|
layoutParams.height = overScrollHeight + AndroidUtilities.dp(10);
|
|
|
|
googleMap.setPadding(0, 0, 0, AndroidUtilities.dp(10));
|
|
|
|
mapView.setLayoutParams(layoutParams);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
|
|
|
markerTop = 0;
|
|
|
|
layoutParams.height = height;
|
|
|
|
mapViewClip.setLayoutParams(layoutParams);
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams = (FrameLayout.LayoutParams) markerImageView.getLayoutParams();
|
|
|
|
layoutParams.topMargin = height / 2 - AndroidUtilities.dp(42);
|
|
|
|
markerImageView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
if (googleMap != null) {
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) mapView.getLayoutParams();
|
|
|
|
if (layoutParams != null) {
|
|
|
|
layoutParams.topMargin = halfHeight;
|
|
|
|
layoutParams.height = overScrollHeight + AndroidUtilities.dp(10);
|
|
|
|
googleMap.setPadding(0, 0, 0, AndroidUtilities.dp(10));
|
|
|
|
mapView.setLayoutParams(layoutParams);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void fixLayoutInternal(final boolean resume) {
|
|
|
|
if (listView != null) {
|
2015-07-22 20:56:37 +02:00
|
|
|
int height = (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight();
|
2015-05-03 13:48:36 +02:00
|
|
|
int viewHeight = fragmentView.getMeasuredHeight();
|
|
|
|
if (viewHeight == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
overScrollHeight = viewHeight - AndroidUtilities.dp(66) - height;
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
|
|
|
|
layoutParams.topMargin = height;
|
|
|
|
listView.setLayoutParams(layoutParams);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) mapViewClip.getLayoutParams();
|
|
|
|
layoutParams.topMargin = height;
|
|
|
|
layoutParams.height = overScrollHeight;
|
|
|
|
mapViewClip.setLayoutParams(layoutParams);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) searchListView.getLayoutParams();
|
|
|
|
layoutParams.topMargin = height;
|
|
|
|
searchListView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
adapter.setOverScrollHeight(overScrollHeight);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) mapView.getLayoutParams();
|
|
|
|
if (layoutParams != null) {
|
|
|
|
layoutParams.height = overScrollHeight + AndroidUtilities.dp(10);
|
|
|
|
if (googleMap != null) {
|
|
|
|
googleMap.setPadding(0, 0, 0, AndroidUtilities.dp(10));
|
|
|
|
}
|
|
|
|
mapView.setLayoutParams(layoutParams);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
adapter.notifyDataSetChanged();
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (resume) {
|
|
|
|
listView.setSelectionFromTop(0, -(int) (AndroidUtilities.dp(56) * 2.5f + AndroidUtilities.dp(36 + 66)));
|
|
|
|
updateClipView(listView.getFirstVisiblePosition());
|
|
|
|
listView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
listView.setSelectionFromTop(0, -(int) (AndroidUtilities.dp(56) * 2.5f + AndroidUtilities.dp(36 + 66)));
|
|
|
|
updateClipView(listView.getFirstVisiblePosition());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
updateClipView(listView.getFirstVisiblePosition());
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 12:17:06 +02:00
|
|
|
private Location getLastLocation() {
|
|
|
|
LocationManager lm = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);
|
|
|
|
List<String> providers = lm.getProviders(true);
|
|
|
|
Location l = null;
|
|
|
|
for (int i = providers.size() - 1; i >= 0; i--) {
|
|
|
|
l = lm.getLastKnownLocation(providers.get(i));
|
|
|
|
if (l != null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private void updateUserData() {
|
|
|
|
if (messageObject != null && avatarImageView != null) {
|
|
|
|
int fromId = messageObject.messageOwner.from_id;
|
2015-03-19 00:09:45 +01:00
|
|
|
if (messageObject.isForwarded()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
fromId = messageObject.messageOwner.fwd_from_id;
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(fromId);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (user != null) {
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
if (user.photo != null) {
|
|
|
|
photo = user.photo.photo_small;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarImageView.setImage(photo, null, new AvatarDrawable(user));
|
2015-06-29 19:12:11 +02:00
|
|
|
nameTextView.setText(UserObject.getUserName(user));
|
2015-03-19 00:09:45 +01:00
|
|
|
} else {
|
|
|
|
avatarImageView.setImageDrawable(null);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void positionMarker(Location location) {
|
|
|
|
if (location == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
myLocation = new Location(location);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (messageObject != null) {
|
|
|
|
if (userLocation != null && distanceTextView != null) {
|
|
|
|
float distance = location.distanceTo(userLocation);
|
|
|
|
if (distance < 1000) {
|
2015-04-09 20:00:14 +02:00
|
|
|
distanceTextView.setText(String.format("%d %s", (int) (distance), LocaleController.getString("MetersAway", R.string.MetersAway)));
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-03-22 23:31:55 +01:00
|
|
|
distanceTextView.setText(String.format("%.2f %s", distance / 1000.0f, LocaleController.getString("KMetersAway", R.string.KMetersAway)));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (googleMap != null) {
|
|
|
|
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
|
|
|
|
if (adapter != null) {
|
|
|
|
adapter.searchGooglePlacesWithQuery(null, myLocation);
|
|
|
|
adapter.setGpsLocation(myLocation);
|
|
|
|
}
|
|
|
|
if (!userLocationMoved) {
|
|
|
|
userLocation = new Location(location);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (firstWas) {
|
|
|
|
CameraUpdate position = CameraUpdateFactory.newLatLng(latLng);
|
|
|
|
googleMap.animateCamera(position);
|
|
|
|
} else {
|
|
|
|
firstWas = true;
|
|
|
|
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
|
|
|
|
googleMap.moveCamera(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
public void setMessageObject(MessageObject message) {
|
|
|
|
messageObject = message;
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.updateInterfaces) {
|
2015-04-09 20:00:14 +02:00
|
|
|
int mask = (Integer) args[0];
|
2014-02-04 19:36:55 +01:00
|
|
|
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
|
|
|
updateUserData();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.closeChats) {
|
2013-10-25 17:19:00 +02:00
|
|
|
removeSelfFromStack();
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
if (mapView != null) {
|
2014-06-14 10:36:01 +02:00
|
|
|
try {
|
|
|
|
mapView.onPause();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2015-05-03 13:48:36 +02:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
if (mapView != null) {
|
|
|
|
mapView.onResume();
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
updateUserData();
|
2015-05-03 13:48:36 +02:00
|
|
|
fixLayoutInternal(true);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLowMemory() {
|
|
|
|
super.onLowMemory();
|
|
|
|
if (mapView != null) {
|
|
|
|
mapView.onLowMemory();
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
|
|
|
|
public void setDelegate(LocationActivityDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
private void updateSearchInterface() {
|
|
|
|
if (adapter != null) {
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|