NekoX/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java

1115 lines
57 KiB
Java
Raw Normal View History

2013-10-25 17:19:00 +02:00
/*
2015-10-29 18:10:07 +01:00
* This is the source code of Telegram for Android v. 3.x.x.
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).
*
2017-03-31 01:58:05 +02:00
* Copyright Nikolai Kudashov, 2013-2017.
2013-10-25 17:19:00 +02:00
*/
package org.telegram.ui;
2015-10-29 18:10:07 +01:00
import android.Manifest;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.StateListAnimator;
import android.annotation.SuppressLint;
2015-10-29 18:10:07 +01:00
import android.annotation.TargetApi;
import android.app.Activity;
2014-08-08 12:17:06 +02:00
import android.content.Context;
2015-10-29 18:10:07 +01:00
import android.content.DialogInterface;
import android.content.Intent;
2015-10-29 18:10:07 +01:00
import android.content.pm.PackageManager;
import android.graphics.Outline;
2017-03-31 01:58:05 +02:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
2013-10-25 17:19:00 +02:00
import android.location.Location;
2014-08-08 12:17:06 +02:00
import android.location.LocationManager;
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;
import android.view.ViewOutlineProvider;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
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;
import com.google.android.gms.maps.MapView;
2013-10-25 17:19:00 +02:00
import com.google.android.gms.maps.MapsInitializer;
2016-10-11 13:57:01 +02:00
import com.google.android.gms.maps.OnMapReadyCallback;
2013-10-25 17:19:00 +02:00
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
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;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.UserObject;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.LocaleController;
2017-03-31 01:58:05 +02:00
import org.telegram.messenger.support.widget.LinearLayoutManager;
import org.telegram.messenger.support.widget.RecyclerView;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.TLRPC;
import org.telegram.messenger.MessageObject;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.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;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.ActionBar.ThemeDescription;
import org.telegram.ui.Adapters.BaseLocationAdapter;
import org.telegram.ui.Adapters.LocationActivityAdapter;
import org.telegram.ui.Adapters.LocationActivitySearchAdapter;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Cells.GraySectionCell;
import org.telegram.ui.Cells.LocationCell;
import org.telegram.ui.Cells.LocationLoadingCell;
import org.telegram.ui.Cells.LocationPoweredCell;
import org.telegram.ui.Cells.SendLocationCell;
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;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.CombinedDrawable;
import org.telegram.ui.Components.EmptyTextProgressView;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.MapPlaceholderDrawable;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.RecyclerListView;
2013-10-25 17:19:00 +02:00
import java.util.ArrayList;
2014-08-08 12:17:06 +02:00
import java.util.List;
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;
private BackupImageView avatarImageView;
private TextView nameTextView;
private MapView mapView;
2017-03-31 01:58:05 +02:00
private EmptyTextProgressView emptyView;
private FrameLayout mapViewClip;
private LocationActivityAdapter adapter;
2017-03-31 01:58:05 +02:00
private RecyclerListView listView;
private RecyclerListView searchListView;
private LocationActivitySearchAdapter searchAdapter;
private ImageView markerImageView;
private ImageView markerXImageView;
private ImageView locationButton;
2017-03-31 01:58:05 +02:00
private ImageView routeButton;
private FrameLayout bottomView;
private LinearLayoutManager layoutManager;
private AvatarDrawable avatarDrawable;
private AnimatorSet animatorSet;
2015-10-29 18:10:07 +01:00
private boolean checkPermission = true;
private boolean searching;
private boolean searchWas;
private boolean wasResults;
2016-10-11 13:57:01 +02:00
private boolean mapsInitialized;
private boolean onResumeCalled;
2013-10-25 17:19:00 +02:00
private Location myLocation;
private Location userLocation;
private int markerTop;
2013-10-25 17:19:00 +02:00
private MessageObject messageObject;
private boolean userLocationMoved = false;
private boolean firstWas = false;
private CircleOptions circleOptions;
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);
private final static int share = 1;
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;
public interface LocationActivityDelegate {
void didSelectLocation(TLRPC.MessageMedia location);
}
2013-10-25 17:19:00 +02:00
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
2014-06-17 17:10:02 +02:00
swipeBackEnabled = false;
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.locationPermissionGranted);
2013-10-25 17:19:00 +02:00
if (messageObject != null) {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
2013-10-25 17:19:00 +02:00
}
return true;
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.locationPermissionGranted);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
2016-05-25 23:49:47 +02:00
try {
if (mapView != null) {
mapView.onDestroy();
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
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);
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
2015-04-09 20:00:14 +02:00
}
2015-10-29 18:10:07 +01:00
actionBar.setAddToContainer(messageObject != null);
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);
}
} 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) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
}
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();
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);
2017-03-31 01:58:05 +02:00
searchListView.setEmptyView(emptyView);
}
@Override
2015-06-29 19:12:11 +02:00
public void onSearchCollapse() {
searching = false;
searchWas = false;
searchListView.setEmptyView(null);
listView.setVisibility(View.VISIBLE);
mapViewClip.setVisibility(View.VISIBLE);
searchListView.setVisibility(View.GONE);
2017-03-31 01:58:05 +02:00
emptyView.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);
2017-03-31 01:58:05 +02:00
item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map));
item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite));
item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid));
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);
2017-03-31 01:58:05 +02:00
Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_profile_actionBackground), Theme.getColor(Theme.key_profile_actionPressedBackground));
if (Build.VERSION.SDK_INT < 21) {
Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile).mutate();
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
drawable = combinedDrawable;
}
locationButton.setBackgroundDrawable(drawable);
locationButton.setImageResource(R.drawable.myloc_on);
locationButton.setScaleType(ImageView.ScaleType.CENTER);
2017-03-31 01:58:05 +02:00
locationButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_profile_actionIcon), PorterDuff.Mode.MULTIPLY));
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() {
@SuppressLint("NewApi")
@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) {
mapView = new MapView(context);
frameLayout.setBackgroundDrawable(new MapPlaceholderDrawable());
2016-10-11 13:57:01 +02:00
final MapView map = mapView;
new Thread(new Runnable() {
@Override
public void run() {
try {
map.onCreate(null);
} catch (Exception e) {
//this will cause exception, but will preload google maps?
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (mapView != null && getParentActivity() != null) {
try {
map.onCreate(null);
MapsInitializer.initialize(getParentActivity());
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap map) {
googleMap = map;
googleMap.setPadding(0, 0, 0, AndroidUtilities.dp(10));
onMapInit();
}
});
mapsInitialized = true;
if (onResumeCalled) {
mapView.onResume();
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2016-10-11 13:57:01 +02:00
}
}
}
});
}
}).start();
2017-03-31 01:58:05 +02:00
bottomView = new FrameLayout(context);
Drawable background = context.getResources().getDrawable(R.drawable.location_panel);
background.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhite), PorterDuff.Mode.MULTIPLY));
bottomView.setBackgroundDrawable(background);
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) {
2015-10-29 18:10:07 +01:00
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4);
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);
2017-03-31 01:58:05 +02:00
nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
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);
2017-03-31 01:58:05 +02:00
distanceTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteValueText));
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);
2017-03-31 01:58:05 +02:00
routeButton = new ImageView(context);
drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
if (Build.VERSION.SDK_INT < 21) {
Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
drawable = combinedDrawable;
}
routeButton.setBackgroundDrawable(drawable);
routeButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
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() {
@SuppressLint("NewApi")
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
2017-03-31 01:58:05 +02:00
frameLayout.addView(routeButton, 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, 28));
routeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2016-04-22 15:49:00 +02:00
if (Build.VERSION.SDK_INT >= 23) {
Activity activity = getParentActivity();
if (activity != null) {
if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
showPermissionAlert(true);
return;
}
}
}
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) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
}
}
});
2017-03-31 01:58:05 +02:00
frameLayout.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, 100));
locationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT >= 23) {
Activity activity = getParentActivity();
if (activity != null) {
if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
2016-04-22 15:49:00 +02:00
showPermissionAlert(true);
2015-10-29 18:10:07 +01:00
return;
}
}
}
if (myLocation != null && googleMap != null) {
2015-10-29 18:10:07 +01:00
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(myLocation.getLatitude(), myLocation.getLongitude()), googleMap.getMaxZoomLevel() - 4));
}
}
});
2015-04-09 20:00:14 +02:00
} else {
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
2017-03-31 01:58:05 +02:00
listView = new RecyclerListView(context);
listView.setAdapter(adapter = new LocationActivityAdapter(context));
listView.setVerticalScrollBarEnabled(false);
2017-03-31 01:58:05 +02:00
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
2017-03-31 01:58:05 +02:00
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
2017-03-31 01:58:05 +02:00
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (adapter.getItemCount() == 0) {
return;
}
2017-03-31 01:58:05 +02:00
int position = layoutManager.findFirstVisibleItemPosition();
if (position == RecyclerView.NO_POSITION) {
return;
}
updateClipView(position);
}
});
2017-03-31 01:58:05 +02:00
listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
@Override
2017-03-31 01:58:05 +02:00
public void onItemClick(View view, int position) {
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 (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) {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(200);
animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 1.0f));
animatorSet.start();
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);
}
};
2016-10-11 13:57:01 +02:00
final MapView map = mapView;
new Thread(new Runnable() {
@Override
public void run() {
try {
map.onCreate(null);
} catch (Exception e) {
//this will cause exception, but will preload google maps?
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (mapView != null && getParentActivity() != null) {
try {
map.onCreate(null);
MapsInitializer.initialize(getParentActivity());
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap map) {
googleMap = map;
googleMap.setPadding(0, 0, 0, AndroidUtilities.dp(10));
onMapInit();
}
});
mapsInitialized = true;
if (onResumeCalled) {
mapView.onResume();
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2016-10-11 13:57:01 +02:00
}
}
}
});
}
}).start();
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));
markerImageView = new ImageView(context);
markerImageView.setImageResource(R.drawable.map_pin);
mapViewClip.addView(markerImageView, LayoutHelper.createFrame(24, 42, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
markerXImageView = new ImageView(context);
markerXImageView.setAlpha(0.0f);
2017-03-31 01:58:05 +02:00
markerXImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_location_markerX), PorterDuff.Mode.MULTIPLY));
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) {
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT >= 23) {
Activity activity = getParentActivity();
if (activity != null) {
if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
2016-04-22 15:49:00 +02:00
showPermissionAlert(false);
2015-10-29 18:10:07 +01:00
return;
}
}
}
if (myLocation != null && googleMap != null) {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(200);
animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 0.0f));
animatorSet.start();
adapter.setCustomLocation(null);
userLocationMoved = false;
googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(myLocation.getLatitude(), myLocation.getLongitude())));
}
}
});
locationButton.setAlpha(0.0f);
2017-03-31 01:58:05 +02:00
emptyView = new EmptyTextProgressView(context);
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
emptyView.setShowAtCenter(true);
emptyView.setVisibility(View.GONE);
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
2017-03-31 01:58:05 +02:00
searchListView = new RecyclerListView(context);
searchListView.setVisibility(View.GONE);
2017-03-31 01:58:05 +02:00
searchListView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
searchListView.setAdapter(searchAdapter = new LocationActivitySearchAdapter(context));
frameLayout.addView(searchListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
2017-03-31 01:58:05 +02:00
searchListView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
2017-03-31 01:58:05 +02:00
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
});
2017-03-31 01:58:05 +02:00
searchListView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
@Override
2017-03-31 01:58:05 +02:00
public void onItemClick(View view, int position) {
TLRPC.TL_messageMediaVenue object = searchAdapter.getItem(position);
if (object != null && delegate != null) {
delegate.didSelectLocation(object);
}
finishFragment();
}
});
frameLayout.addView(actionBar);
2015-04-09 20:00:14 +02:00
}
2016-10-11 13:57:01 +02:00
return fragmentView;
}
private void onMapInit() {
if (googleMap == null) {
return;
}
if (messageObject != null) {
LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
try {
2016-10-11 13:57:01 +02:00
googleMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)));
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
2016-10-11 13:57:01 +02:00
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4);
googleMap.moveCamera(position);
} else {
userLocation = new Location("network");
userLocation.setLatitude(20.659322);
userLocation.setLongitude(-11.406250);
}
2016-10-11 13:57:01 +02:00
try {
googleMap.setMyLocationEnabled(true);
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2016-10-11 13:57:01 +02:00
}
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);
}
});
positionMarker(myLocation = getLastLocation());
}
2015-04-09 20:00:14 +02:00
2016-04-22 15:49:00 +02:00
private void showPermissionAlert(boolean byButton) {
2015-10-29 18:10:07 +01:00
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
2016-04-22 15:49:00 +02:00
if (byButton) {
builder.setMessage(LocaleController.getString("PermissionNoLocationPosition", R.string.PermissionNoLocationPosition));
} else {
builder.setMessage(LocaleController.getString("PermissionNoLocation", R.string.PermissionNoLocation));
}
2015-10-29 18:10:07 +01:00
builder.setNegativeButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), new DialogInterface.OnClickListener() {
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onClick(DialogInterface dialog, int which) {
if (getParentActivity() == null) {
return;
}
try {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName()));
getParentActivity().startActivity(intent);
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2015-10-29 18:10:07 +01:00
}
}
});
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
}
@Override
2015-10-29 18:10:07 +01:00
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
if (isOpen) {
try {
if (mapView.getParent() instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) mapView.getParent();
viewGroup.removeView(mapView);
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2015-10-29 18:10:07 +01:00
}
if (mapViewClip != null) {
mapViewClip.addView(mapView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, overScrollHeight + AndroidUtilities.dp(10), Gravity.TOP | Gravity.LEFT));
2017-03-31 01:58:05 +02:00
updateClipView(layoutManager.findFirstVisibleItemPosition());
2016-10-11 13:57:01 +02:00
} else if (fragmentView != null) {
2015-10-29 18:10:07 +01:00
((FrameLayout) fragmentView).addView(mapView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
2015-06-29 19:12:11 +02:00
}
}
}
private void updateClipView(int firstVisibleItem) {
2017-03-31 01:58:05 +02:00
if (firstVisibleItem == RecyclerView.NO_POSITION) {
return;
}
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);
}
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
}
} else {
if (mapView.getVisibility() == View.INVISIBLE) {
mapView.setVisibility(View.VISIBLE);
mapViewClip.setVisibility(View.VISIBLE);
2015-04-09 20:00:14 +02:00
}
}
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);
2016-10-11 13:57:01 +02:00
layoutParams = (FrameLayout.LayoutParams) mapView.getLayoutParams();
if (layoutParams != null && layoutParams.height != overScrollHeight + AndroidUtilities.dp(10)) {
layoutParams.height = overScrollHeight + AndroidUtilities.dp(10);
if (googleMap != null) {
googleMap.setPadding(0, 0, 0, AndroidUtilities.dp(10));
2015-04-09 20:00:14 +02:00
}
2016-10-11 13:57:01 +02:00
mapView.setLayoutParams(layoutParams);
}
}
}
}
2015-04-09 20:00:14 +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();
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
}
adapter.notifyDataSetChanged();
2015-04-09 20:00:14 +02:00
if (resume) {
2017-03-31 01:58:05 +02:00
layoutManager.scrollToPositionWithOffset(0, -(int) (AndroidUtilities.dp(56) * 2.5f + AndroidUtilities.dp(36 + 66)));
updateClipView(layoutManager.findFirstVisibleItemPosition());
listView.post(new Runnable() {
@Override
public void run() {
2017-03-31 01:58:05 +02:00
layoutManager.scrollToPositionWithOffset(0, -(int) (AndroidUtilities.dp(56) * 2.5f + AndroidUtilities.dp(36 + 66)));
updateClipView(layoutManager.findFirstVisibleItemPosition());
}
});
} else {
2017-03-31 01:58:05 +02:00
updateClipView(layoutManager.findFirstVisibleItemPosition());
}
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;
if (messageObject.isForwarded()) {
2016-03-06 02:49:31 +01:00
if (messageObject.messageOwner.fwd_from.channel_id != 0) {
fromId = -messageObject.messageOwner.fwd_from.channel_id;
2015-09-24 22:52:02 +02:00
} else {
2016-03-06 02:49:31 +01:00
fromId = messageObject.messageOwner.fwd_from.from_id;
2015-09-24 22:52:02 +02:00
}
2013-10-25 17:19:00 +02:00
}
2015-09-24 22:52:02 +02:00
String name = "";
TLRPC.FileLocation photo = null;
2017-03-31 01:58:05 +02:00
avatarDrawable = null;
2015-09-24 22:52:02 +02:00
if (fromId > 0) {
TLRPC.User user = MessagesController.getInstance().getUser(fromId);
if (user != null) {
if (user.photo != null) {
photo = user.photo.photo_small;
}
avatarDrawable = new AvatarDrawable(user);
name = UserObject.getUserName(user);
}
} else {
TLRPC.Chat chat = MessagesController.getInstance().getChat(-fromId);
if (chat != null) {
if (chat.photo != null) {
photo = chat.photo.photo_small;
}
avatarDrawable = new AvatarDrawable(chat);
name = chat.title;
2013-10-25 17:19:00 +02:00
}
2015-09-24 22:52:02 +02:00
}
if (avatarDrawable != null) {
avatarImageView.setImage(photo, null, avatarDrawable);
nameTextView.setText(name);
} else {
avatarImageView.setImageDrawable(null);
2013-10-25 17:19:00 +02:00
}
}
}
private void positionMarker(Location location) {
if (location == null) {
return;
}
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 {
distanceTextView.setText(String.format("%.2f %s", distance / 1000.0f, LocaleController.getString("KMetersAway", R.string.KMetersAway)));
2013-10-25 17:19:00 +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;
2015-10-29 18:10:07 +01:00
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4);
2013-10-25 17:19:00 +02:00
googleMap.moveCamera(position);
}
}
}
}
public void setMessageObject(MessageObject message) {
messageObject = message;
}
2013-10-25 17:19:00 +02:00
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.updateInterfaces) {
2015-04-09 20:00:14 +02:00
int mask = (Integer) args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
updateUserData();
}
} else if (id == NotificationCenter.closeChats) {
2013-10-25 17:19:00 +02:00
removeSelfFromStack();
} else if (id == NotificationCenter.locationPermissionGranted) {
if (googleMap != null) {
try {
googleMap.setMyLocationEnabled(true);
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
}
2013-10-25 17:19:00 +02:00
}
}
@Override
public void onPause() {
super.onPause();
2016-10-11 13:57:01 +02:00
if (mapView != null && mapsInitialized) {
try {
mapView.onPause();
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
}
2016-10-11 13:57:01 +02:00
onResumeCalled = false;
}
@Override
public void onResume() {
super.onResume();
2015-09-24 22:52:02 +02:00
AndroidUtilities.removeAdjustResize(getParentActivity(), classGuid);
2016-10-11 13:57:01 +02:00
if (mapView != null && mapsInitialized) {
2016-03-16 13:26:32 +01:00
try {
mapView.onResume();
} catch (Throwable e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2016-04-22 15:49:00 +02:00
}
}
2016-10-11 13:57:01 +02:00
onResumeCalled = true;
2016-04-22 15:49:00 +02:00
if (googleMap != null) {
try {
googleMap.setMyLocationEnabled(true);
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2016-03-16 13:26:32 +01:00
}
}
2015-04-09 20:00:14 +02:00
updateUserData();
fixLayoutInternal(true);
2015-10-29 18:10:07 +01:00
if (checkPermission && Build.VERSION.SDK_INT >= 23) {
Activity activity = getParentActivity();
if (activity != null) {
checkPermission = false;
if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 2);
}
}
}
}
@Override
public void onLowMemory() {
super.onLowMemory();
2016-10-11 13:57:01 +02:00
if (mapView != null && mapsInitialized) {
mapView.onLowMemory();
}
}
public void setDelegate(LocationActivityDelegate delegate) {
this.delegate = delegate;
}
private void updateSearchInterface() {
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
2017-03-31 01:58:05 +02:00
@Override
public ThemeDescription[] getThemeDescriptions() {
ThemeDescription.ThemeDescriptionDelegate сellDelegate = new ThemeDescription.ThemeDescriptionDelegate() {
@Override
public void didSetColor(int color) {
updateUserData();
}
};
return new ThemeDescription[]{
new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite),
new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault),
new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault),
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon),
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle),
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector),
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SEARCH, null, null, null, null, Theme.key_actionBarDefaultSearch),
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SEARCHPLACEHOLDER, null, null, null, null, Theme.key_actionBarDefaultSearchPlaceholder),
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground),
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem),
new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector),
new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider),
new ThemeDescription(emptyView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_emptyListPlaceholder),
new ThemeDescription(emptyView, ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_progressCircle),
new ThemeDescription(locationButton, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_profile_actionIcon),
new ThemeDescription(locationButton, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_profile_actionBackground),
new ThemeDescription(locationButton, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_profile_actionPressedBackground),
new ThemeDescription(bottomView, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhite),
new ThemeDescription(nameTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
new ThemeDescription(distanceTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteValueText),
new ThemeDescription(routeButton, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chats_actionIcon),
new ThemeDescription(routeButton, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_chats_actionBackground),
new ThemeDescription(routeButton, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_chats_actionPressedBackground),
new ThemeDescription(markerXImageView, 0, null, null, null, null, Theme.key_location_markerX),
new ThemeDescription(listView, 0, new Class[]{GraySectionCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2),
new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{GraySectionCell.class}, null, null, null, Theme.key_graySection),
new ThemeDescription(null, 0, null, null, new Drawable[]{Theme.avatar_photoDrawable, Theme.avatar_broadcastDrawable}, сellDelegate, Theme.key_avatar_text),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundRed),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundOrange),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundViolet),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundGreen),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundCyan),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundBlue),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundPink),
new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{SendLocationCell.class}, new String[]{"imageView"}, null, null, null, Theme.key_location_sendLocationIcon),
new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_USEBACKGROUNDDRAWABLE, new Class[]{SendLocationCell.class}, new String[]{"imageView"}, null, null, null, Theme.key_location_sendLocationBackground),
new ThemeDescription(listView, 0, new Class[]{SendLocationCell.class}, new String[]{"titleTextView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueText7),
new ThemeDescription(listView, 0, new Class[]{SendLocationCell.class}, new String[]{"accurateTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{LocationCell.class}, new String[]{"imageView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
new ThemeDescription(listView, 0, new Class[]{LocationCell.class}, new String[]{"nameTextView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
new ThemeDescription(listView, 0, new Class[]{LocationCell.class}, new String[]{"addressTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
new ThemeDescription(searchListView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{LocationCell.class}, new String[]{"imageView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
new ThemeDescription(searchListView, 0, new Class[]{LocationCell.class}, new String[]{"nameTextView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
new ThemeDescription(searchListView, 0, new Class[]{LocationCell.class}, new String[]{"addressTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
new ThemeDescription(listView, 0, new Class[]{LocationLoadingCell.class}, new String[]{"progressBar"}, null, null, null, Theme.key_progressCircle),
new ThemeDescription(listView, 0, new Class[]{LocationLoadingCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
new ThemeDescription(listView, 0, new Class[]{LocationPoweredCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
new ThemeDescription(listView, 0, new Class[]{LocationPoweredCell.class}, new String[]{"imageView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
new ThemeDescription(listView, 0, new Class[]{LocationPoweredCell.class}, new String[]{"textView2"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
};
}
2013-10-25 17:19:00 +02:00
}