2013-10-25 17:19:00 +02:00
/ *
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v . 5 . 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 ) .
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov , 2013 - 2018 .
2020-04-04 12:19:59 +02:00
* Copyright Ruslan Boitsov , 2017 - 2020 .
2013-10-25 17:19:00 +02:00
* /
package org.telegram.ui ;
2015-10-29 18:10:07 +01:00
import android.Manifest ;
2020-11-01 14:02:57 +01:00
import android.animation.Animator ;
import android.animation.AnimatorListenerAdapter ;
2015-05-03 13:48:36 +02:00
import android.animation.AnimatorSet ;
import android.animation.ObjectAnimator ;
import android.animation.StateListAnimator ;
2019-12-31 14:08:08 +01:00
import android.animation.ValueAnimator ;
2016-06-24 12:27:15 +02:00
import android.annotation.SuppressLint ;
2015-10-29 18:10:07 +01:00
import android.app.Activity ;
2014-08-08 12:17:06 +02:00
import android.content.Context ;
2015-05-03 13:48:36 +02:00
import android.content.Intent ;
2020-11-01 14:02:57 +01:00
import android.content.SharedPreferences ;
2015-10-29 18:10:07 +01:00
import android.content.pm.PackageManager ;
2017-12-08 18:35:59 +01:00
import android.graphics.Bitmap ;
import android.graphics.BitmapFactory ;
import android.graphics.BitmapShader ;
import android.graphics.Canvas ;
import android.graphics.Color ;
import android.graphics.Matrix ;
2015-05-03 13:48:36 +02:00
import android.graphics.Outline ;
2017-12-08 18:35:59 +01:00
import android.graphics.Paint ;
2019-12-31 14:08:08 +01:00
import android.graphics.Point ;
2017-03-31 01:58:05 +02:00
import android.graphics.PorterDuff ;
import android.graphics.PorterDuffColorFilter ;
2019-12-31 14:08:08 +01:00
import android.graphics.Rect ;
2017-12-08 18:35:59 +01:00
import android.graphics.RectF ;
import android.graphics.Shader ;
2020-04-04 12:19:59 +02:00
import android.graphics.drawable.BitmapDrawable ;
2017-03-31 01:58:05 +02:00
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 ;
2015-05-03 13:48:36 +02:00
import android.net.Uri ;
import android.os.Build ;
2019-12-31 14:08:08 +01:00
import android.text.TextUtils ;
2018-07-30 04:07:02 +02:00
import android.util.SparseArray ;
2020-04-04 12:19:59 +02:00
import android.text.Html ;
import android.text.method.LinkMovementMethod ;
2019-12-31 14:08:08 +01:00
import android.util.TypedValue ;
2015-05-03 13:48:36 +02:00
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 ;
2019-12-31 14:08:08 +01:00
import android.view.animation.OvershootInterpolator ;
2015-05-03 13:48:36 +02:00
import android.widget.EditText ;
import android.widget.FrameLayout ;
import android.widget.ImageView ;
2019-12-31 14:08:08 +01:00
import android.widget.LinearLayout ;
import android.widget.TextView ;
2022-06-21 04:51:00 +02:00
import androidx.collection.LongSparseArray ;
import androidx.recyclerview.widget.DefaultItemAnimator ;
import androidx.recyclerview.widget.LinearLayoutManager ;
import androidx.recyclerview.widget.RecyclerView ;
2013-10-25 17:19:00 +02:00
2020-04-04 12:19:59 +02:00
import org.osmdroid.api.IGeoPoint ;
import org.osmdroid.api.IMapController ;
import org.osmdroid.config.Configuration ;
import org.osmdroid.events.MapListener ;
import org.osmdroid.events.ScrollEvent ;
import org.osmdroid.events.ZoomEvent ;
import org.osmdroid.tileprovider.tilesource.ITileSource ;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory ;
import org.osmdroid.tileprovider.tilesource.XYTileSource ;
import org.osmdroid.util.BoundingBox ;
import org.osmdroid.views.MapView ;
import org.osmdroid.util.GeoPoint ;
import org.osmdroid.views.Projection ;
import org.osmdroid.views.overlay.Marker ;
2020-11-01 14:02:57 +01:00
import org.osmdroid.views.overlay.Polygon ;
2020-04-04 12:19:59 +02:00
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider ;
import org.osmdroid.views.overlay.mylocation.IMyLocationProvider ;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay ;
2014-03-22 23:31:55 +01:00
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities ;
2020-04-04 12:19:59 +02:00
import org.telegram.messenger.BuildConfig ;
2022-06-21 04:51:00 +02:00
import org.telegram.messenger.ApplicationLoader ;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.ChatObject ;
2021-09-20 00:10:42 +02:00
import org.telegram.messenger.DialogObject ;
2014-06-04 01:31:48 +02:00
import org.telegram.messenger.FileLog ;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.LocaleController ;
2022-06-21 04:51:00 +02:00
import org.telegram.messenger.LocationController ;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.MessageObject ;
2022-06-21 04:51:00 +02:00
import org.telegram.messenger.MessagesController ;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.NotificationCenter ;
2013-10-25 17:19:00 +02:00
import org.telegram.messenger.R ;
2022-06-21 04:51:00 +02:00
import org.telegram.messenger.UserObject ;
import org.telegram.tgnet.TLRPC ;
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 ;
2022-06-21 04:51:00 +02:00
import org.telegram.ui.ActionBar.BaseFragment ;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme ;
import org.telegram.ui.ActionBar.ThemeDescription ;
2015-05-03 13:48:36 +02:00
import org.telegram.ui.Adapters.LocationActivityAdapter ;
import org.telegram.ui.Adapters.LocationActivitySearchAdapter ;
2019-12-31 14:08:08 +01:00
import org.telegram.ui.Cells.HeaderCell ;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Cells.LocationCell ;
2019-12-31 14:08:08 +01:00
import org.telegram.ui.Cells.LocationDirectionCell ;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Cells.LocationLoadingCell ;
import org.telegram.ui.Cells.LocationPoweredCell ;
import org.telegram.ui.Cells.SendLocationCell ;
2019-12-31 14:08:08 +01:00
import org.telegram.ui.Cells.ShadowSectionCell ;
import org.telegram.ui.Cells.SharingLiveLocationCell ;
2017-12-08 18:35:59 +01:00
import org.telegram.ui.Components.AlertsCreator ;
2014-12-01 18:56:31 +01:00
import org.telegram.ui.Components.AvatarDrawable ;
2019-07-18 15:01:39 +02:00
import org.telegram.ui.Components.BackupImageView ;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.CombinedDrawable ;
2019-12-31 14:08:08 +01:00
import org.telegram.ui.Components.CubicBezierInterpolator ;
import org.telegram.ui.Components.EditTextBoldCursor ;
2020-11-01 14:02:57 +01:00
import org.telegram.ui.Components.HintView ;
2015-05-03 13:48:36 +02:00
import org.telegram.ui.Components.LayoutHelper ;
import org.telegram.ui.Components.MapPlaceholderDrawable ;
2020-11-01 14:02:57 +01:00
import org.telegram.ui.Components.ProximitySheet ;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.RecyclerListView ;
2020-11-01 14:02:57 +01:00
import org.telegram.ui.Components.UndoView ;
2013-10-25 17:19:00 +02:00
2017-12-08 18:35:59 +01:00
import java.io.File ;
2015-05-03 13:48:36 +02:00
import java.util.ArrayList ;
2020-11-01 14:02:57 +01:00
import java.util.Arrays ;
2019-12-31 14:08:08 +01:00
import java.util.HashMap ;
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
2019-12-31 14:08:08 +01:00
private ImageView locationButton ;
2020-11-01 14:02:57 +01:00
private ImageView proximityButton ;
2019-12-31 14:08:08 +01:00
private ActionBarMenuItem mapTypeButton ;
private SearchButton searchAreaButton ;
private LinearLayout emptyView ;
private ImageView emptyImageView ;
private TextView emptyTitleTextView ;
private TextView emptySubtitleTextView ;
private Drawable shadowDrawable ;
private View shadow ;
private ActionBarMenuItem searchItem ;
private MapOverlayView overlayView ;
2020-11-01 14:02:57 +01:00
private HintView hintView ;
private UndoView [ ] undoView = new UndoView [ 2 ] ;
private boolean canUndo ;
private boolean proximityAnimationInProgress ;
2017-12-08 18:35:59 +01:00
2015-05-03 13:48:36 +02:00
private MapView mapView ;
2020-11-01 14:02:57 +01:00
private BoundingBox moveToBounds ;
2020-04-04 12:19:59 +02:00
private IGeoPoint forceUpdate ;
2019-12-31 14:08:08 +01:00
private float yOffset ;
2020-11-01 14:02:57 +01:00
private Polygon proximityCircle ;
private GeoPoint proximityCircleCenter ;
private double proximityCircleRadius ;
private double previousRadius ;
2019-12-31 14:08:08 +01:00
private boolean scrolling ;
2020-11-01 14:02:57 +01:00
private ProximitySheet proximitySheet ;
2015-05-03 13:48:36 +02:00
private FrameLayout mapViewClip ;
private LocationActivityAdapter adapter ;
2017-03-31 01:58:05 +02:00
private RecyclerListView listView ;
private RecyclerListView searchListView ;
2015-05-03 13:48:36 +02:00
private LocationActivitySearchAdapter searchAdapter ;
2019-07-18 15:01:39 +02:00
private View markerImageView ;
2017-03-31 01:58:05 +02:00
private LinearLayoutManager layoutManager ;
private AvatarDrawable avatarDrawable ;
2017-12-08 18:35:59 +01:00
private ActionBarMenuItem otherItem ;
2019-09-10 12:56:11 +02:00
private ChatActivity parentFragment ;
2017-12-08 18:35:59 +01:00
2020-04-04 12:19:59 +02:00
private TextView attributionOverlay ;
2019-12-31 14:08:08 +01:00
private boolean currentMapStyleDark ;
2017-12-08 18:35:59 +01:00
private boolean checkGpsEnabled = true ;
2022-02-01 14:00:45 +01:00
private boolean locationDenied = false ;
2017-12-08 18:35:59 +01:00
private boolean isFirstLocation = true ;
private long dialogId ;
private boolean firstFocus = true ;
private Runnable updateRunnable ;
private ArrayList < LiveLocation > markers = new ArrayList < > ( ) ;
2021-09-20 00:10:42 +02:00
private LongSparseArray < LiveLocation > markersMap = new LongSparseArray < > ( ) ;
2015-05-03 13:48:36 +02:00
2019-12-31 14:08:08 +01:00
private ArrayList < VenueLocation > placeMarkers = new ArrayList < > ( ) ;
2015-05-03 13:48:36 +02:00
private AnimatorSet animatorSet ;
2019-12-31 14:08:08 +01:00
private Marker lastPressedMarker ;
private VenueLocation lastPressedVenue ;
private FrameLayout lastPressedMarkerView ;
2015-10-29 18:10:07 +01:00
private boolean checkPermission = true ;
2020-11-01 14:02:57 +01:00
private boolean checkBackgroundPermission = true ;
private int askWithRadius ;
2015-10-29 18:10:07 +01:00
2015-05-03 13:48:36 +02:00
private boolean searching ;
private boolean searchWas ;
2019-12-31 14:08:08 +01:00
private boolean searchInProgress ;
2015-05-03 13:48:36 +02:00
private boolean wasResults ;
2016-10-11 13:57:01 +02:00
private boolean mapsInitialized ;
private boolean onResumeCalled ;
2015-05-03 13:48:36 +02:00
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 ;
2019-07-18 15:01:39 +02:00
private TLRPC . TL_channelLocation chatLocation ;
private TLRPC . TL_channelLocation initialLocation ;
2013-10-25 17:19:00 +02:00
private MessageObject messageObject ;
2019-07-18 15:01:39 +02:00
private boolean userLocationMoved ;
2019-12-31 14:08:08 +01:00
private boolean searchedForCustomLocations ;
2019-07-18 15:01:39 +02:00
private boolean firstWas ;
2014-08-22 16:24:33 +02:00
private LocationActivityDelegate delegate ;
2013-10-25 17:19:00 +02:00
2019-07-18 15:01:39 +02:00
private int locationType ;
2017-12-08 18:35:59 +01: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
2019-12-31 14:08:08 +01:00
private final static int open_in = 1 ;
private final static int share_live_location = 5 ;
2020-04-04 12:19:59 +02:00
private final static int map_list_menu_osm = 2 ;
private final static int map_list_menu_wiki = 3 ;
private final static int map_list_menu_cartodark = 4 ;
private MyLocationNewOverlay myLocationOverlay ;
2014-04-02 19:36:57 +02:00
2019-07-18 15:01:39 +02:00
public final static int LOCATION_TYPE_SEND = 0 ;
2019-12-31 14:08:08 +01:00
public final static int LOCATION_TYPE_SEND_WITH_LIVE = 1 ;
2019-07-18 15:01:39 +02:00
public final static int LOCATION_TYPE_GROUP = 4 ;
public final static int LOCATION_TYPE_GROUP_VIEW = 5 ;
2020-10-30 11:26:29 +01:00
public final static int LOCATION_TYPE_LIVE_VIEW = 6 ;
2019-07-18 15:01:39 +02:00
2019-12-31 14:08:08 +01:00
private Runnable markAsReadRunnable ;
2020-04-24 11:21:58 +02:00
public static class VenueLocation {
2019-12-31 14:08:08 +01:00
public int num ;
public Marker marker ;
public TLRPC . TL_messageMediaVenue venue ;
}
2020-04-24 11:21:58 +02:00
public static class LiveLocation {
2021-09-20 00:10:42 +02:00
public long id ;
2019-12-31 14:08:08 +01:00
public TLRPC . Message object ;
public TLRPC . User user ;
public TLRPC . Chat chat ;
public Marker marker ;
2020-11-01 14:02:57 +01:00
public Marker directionMarker ;
public boolean hasRotation ;
2019-12-31 14:08:08 +01:00
}
2020-04-24 11:21:58 +02:00
private static class SearchButton extends TextView {
2019-12-31 14:08:08 +01:00
private float additionanTranslationY ;
private float currentTranslationY ;
public SearchButton ( Context context ) {
super ( context ) ;
}
@Override
public float getTranslationX ( ) {
return additionanTranslationY ;
}
@Override
public void setTranslationX ( float translationX ) {
additionanTranslationY = translationX ;
updateTranslationY ( ) ;
}
public void setTranslation ( float value ) {
currentTranslationY = value ;
updateTranslationY ( ) ;
}
private void updateTranslationY ( ) {
setTranslationY ( currentTranslationY + additionanTranslationY ) ;
}
}
public class MapOverlayView extends FrameLayout {
private HashMap < Marker , View > views = new HashMap < > ( ) ;
public MapOverlayView ( Context context ) {
super ( context ) ;
}
2020-04-04 12:19:59 +02:00
public void addInfoView ( Marker marker , VenueLocation location ) {
2020-11-01 14:02:57 +01:00
if ( location = = null | | lastPressedVenue = = location ) {
2019-12-31 14:08:08 +01:00
return ;
}
showSearchPlacesButton ( false ) ;
if ( lastPressedMarker ! = null ) {
removeInfoView ( lastPressedMarker ) ;
lastPressedMarker = null ;
}
lastPressedVenue = location ;
lastPressedMarker = marker ;
Context context = getContext ( ) ;
FrameLayout frameLayout = new FrameLayout ( context ) ;
addView ( frameLayout , LayoutHelper . createFrame ( LayoutHelper . WRAP_CONTENT , 114 ) ) ;
lastPressedMarkerView = new FrameLayout ( context ) ;
lastPressedMarkerView . setBackgroundResource ( R . drawable . venue_tooltip ) ;
2020-11-01 14:02:57 +01:00
lastPressedMarkerView . getBackground ( ) . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_dialogBackground ) , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
frameLayout . addView ( lastPressedMarkerView , LayoutHelper . createFrame ( LayoutHelper . WRAP_CONTENT , 71 ) ) ;
lastPressedMarkerView . setAlpha ( 0 . 0f ) ;
lastPressedMarkerView . setOnClickListener ( v - > {
if ( parentFragment ! = null & & parentFragment . isInScheduleMode ( ) ) {
AlertsCreator . createScheduleDatePickerDialog ( getParentActivity ( ) , parentFragment . getDialogId ( ) , ( notify , scheduleDate ) - > {
delegate . didSelectLocation ( location . venue , locationType , notify , scheduleDate ) ;
finishFragment ( ) ;
} ) ;
} else {
delegate . didSelectLocation ( location . venue , locationType , true , 0 ) ;
finishFragment ( ) ;
}
} ) ;
TextView nameTextView = new TextView ( context ) ;
nameTextView . setTextSize ( TypedValue . COMPLEX_UNIT_DIP , 16 ) ;
nameTextView . setMaxLines ( 1 ) ;
nameTextView . setEllipsize ( TextUtils . TruncateAt . END ) ;
nameTextView . setSingleLine ( true ) ;
nameTextView . setTextColor ( Theme . getColor ( Theme . key_windowBackgroundWhiteBlackText ) ) ;
nameTextView . setTypeface ( AndroidUtilities . getTypeface ( " fonts/rmedium.ttf " ) ) ;
nameTextView . setGravity ( LocaleController . isRTL ? Gravity . RIGHT : Gravity . LEFT ) ;
lastPressedMarkerView . addView ( nameTextView , LayoutHelper . createFrame ( LayoutHelper . WRAP_CONTENT , LayoutHelper . WRAP_CONTENT , Gravity . TOP | ( LocaleController . isRTL ? Gravity . RIGHT : Gravity . LEFT ) , 18 , 10 , 18 , 0 ) ) ;
TextView addressTextView = new TextView ( context ) ;
addressTextView . setTextSize ( TypedValue . COMPLEX_UNIT_DIP , 14 ) ;
addressTextView . setMaxLines ( 1 ) ;
addressTextView . setEllipsize ( TextUtils . TruncateAt . END ) ;
addressTextView . setSingleLine ( true ) ;
addressTextView . setTextColor ( Theme . getColor ( Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
addressTextView . setGravity ( LocaleController . isRTL ? Gravity . RIGHT : Gravity . LEFT ) ;
lastPressedMarkerView . addView ( addressTextView , LayoutHelper . createFrame ( LayoutHelper . WRAP_CONTENT , LayoutHelper . WRAP_CONTENT , Gravity . TOP | ( LocaleController . isRTL ? Gravity . RIGHT : Gravity . LEFT ) , 18 , 32 , 18 , 0 ) ) ;
nameTextView . setText ( location . venue . title ) ;
addressTextView . setText ( LocaleController . getString ( " TapToSendLocation " , R . string . TapToSendLocation ) ) ;
FrameLayout iconLayout = new FrameLayout ( context ) ;
iconLayout . setBackground ( Theme . createCircleDrawable ( AndroidUtilities . dp ( 36 ) , LocationCell . getColorForIndex ( location . num ) ) ) ;
frameLayout . addView ( iconLayout , LayoutHelper . createFrame ( 36 , 36 , Gravity . CENTER_HORIZONTAL | Gravity . BOTTOM , 0 , 0 , 0 , 4 ) ) ;
BackupImageView imageView = new BackupImageView ( context ) ;
imageView . setImage ( " https://ss3.4sqi.net/img/categories_v2/ " + location . venue . venue_type + " _64.png " , null , null ) ;
iconLayout . addView ( imageView , LayoutHelper . createFrame ( 30 , 30 , Gravity . CENTER ) ) ;
ValueAnimator animator = ValueAnimator . ofFloat ( 0 . 0f , 1 . 0f ) ;
animator . addUpdateListener ( new ValueAnimator . AnimatorUpdateListener ( ) {
private boolean startedInner ;
private final float [ ] animatorValues = new float [ ] { 0 . 0f , 1 . 0f } ;
@Override
public void onAnimationUpdate ( ValueAnimator animation ) {
float value = AndroidUtilities . lerp ( animatorValues , animation . getAnimatedFraction ( ) ) ;
if ( value > = 0 . 7f & & ! startedInner & & lastPressedMarkerView ! = null ) {
AnimatorSet animatorSet1 = new AnimatorSet ( ) ;
animatorSet1 . playTogether (
ObjectAnimator . ofFloat ( lastPressedMarkerView , View . SCALE_X , 0 . 0f , 1 . 0f ) ,
ObjectAnimator . ofFloat ( lastPressedMarkerView , View . SCALE_Y , 0 . 0f , 1 . 0f ) ,
ObjectAnimator . ofFloat ( lastPressedMarkerView , View . ALPHA , 0 . 0f , 1 . 0f ) ) ;
animatorSet1 . setInterpolator ( new OvershootInterpolator ( 1 . 02f ) ) ;
animatorSet1 . setDuration ( 250 ) ;
animatorSet1 . start ( ) ;
startedInner = true ;
}
float scale ;
if ( value < = 0 . 5f ) {
scale = 1 . 1f * CubicBezierInterpolator . EASE_OUT . getInterpolation ( value / 0 . 5f ) ;
} else if ( value < = 0 . 75f ) {
value - = 0 . 5f ;
scale = 1 . 1f - 0 . 2f * CubicBezierInterpolator . EASE_OUT . getInterpolation ( value / 0 . 25f ) ;
} else {
value - = 0 . 75f ;
scale = 0 . 9f + 0 . 1f * CubicBezierInterpolator . EASE_OUT . getInterpolation ( value / 0 . 25f ) ;
}
iconLayout . setScaleX ( scale ) ;
iconLayout . setScaleY ( scale ) ;
}
} ) ;
animator . setDuration ( 360 ) ;
animator . start ( ) ;
views . put ( marker , frameLayout ) ;
2020-04-04 12:19:59 +02:00
final IMapController controller = mapView . getController ( ) ;
2020-11-01 14:02:57 +01:00
controller . animateTo ( marker . getPosition ( ) , mapView . getZoomLevelDouble ( ) , 300L ) ;
2019-12-31 14:08:08 +01:00
}
public void removeInfoView ( Marker marker ) {
View view = views . get ( marker ) ;
if ( view ! = null ) {
removeView ( view ) ;
views . remove ( marker ) ;
}
}
2020-11-01 14:02:57 +01:00
2020-04-04 12:19:59 +02:00
//TODO
2019-12-31 14:08:08 +01:00
public void updatePositions ( ) {
2020-04-04 12:19:59 +02:00
if ( mapView = = null ) {
2019-12-31 14:08:08 +01:00
return ;
}
2020-04-04 12:19:59 +02:00
Projection projection = mapView . getProjection ( ) ;
2019-12-31 14:08:08 +01:00
for ( HashMap . Entry < Marker , View > entry : views . entrySet ( ) ) {
Marker marker = entry . getKey ( ) ;
View view = entry . getValue ( ) ;
2020-11-01 14:02:57 +01:00
Point point = projection . toPixels ( marker . getPosition ( ) , null ) ;
2019-12-31 14:08:08 +01:00
view . setTranslationX ( point . x - view . getMeasuredWidth ( ) / 2 ) ;
view . setTranslationY ( point . y - view . getMeasuredHeight ( ) + AndroidUtilities . dp ( 22 ) ) ;
}
}
}
2015-03-19 00:09:45 +01:00
public interface LocationActivityDelegate {
2019-09-10 12:56:11 +02:00
void didSelectLocation ( TLRPC . MessageMedia location , int live , boolean notify , int scheduleDate ) ;
2017-12-08 18:35:59 +01:00
}
2019-07-18 15:01:39 +02:00
public LocationActivity ( int type ) {
2017-12-08 18:35:59 +01:00
super ( ) ;
2019-07-18 15:01:39 +02:00
locationType = type ;
2020-04-24 11:28:11 +02:00
AndroidUtilities . fixGoogleMapsBug ( ) ;
2015-05-03 13:48:36 +02:00
}
2013-10-25 17:19:00 +02:00
@Override
public boolean onFragmentCreate ( ) {
super . onFragmentCreate ( ) ;
2019-07-18 15:01:39 +02:00
getNotificationCenter ( ) . addObserver ( this , NotificationCenter . closeChats ) ;
2018-07-30 04:07:02 +02:00
NotificationCenter . getGlobalInstance ( ) . addObserver ( this , NotificationCenter . locationPermissionGranted ) ;
2022-02-01 14:00:45 +01:00
NotificationCenter . getGlobalInstance ( ) . addObserver ( this , NotificationCenter . locationPermissionDenied ) ;
2020-11-01 14:02:57 +01:00
NotificationCenter . getGlobalInstance ( ) . addObserver ( this , NotificationCenter . liveLocationsChanged ) ;
2017-12-08 18:35:59 +01:00
if ( messageObject ! = null & & messageObject . isLiveLocation ( ) ) {
2019-07-18 15:01:39 +02:00
getNotificationCenter ( ) . addObserver ( this , NotificationCenter . didReceiveNewMessages ) ;
getNotificationCenter ( ) . addObserver ( this , NotificationCenter . replaceMessagesObjects ) ;
2013-10-25 17:19:00 +02:00
}
return true ;
}
@Override
public void onFragmentDestroy ( ) {
super . onFragmentDestroy ( ) ;
2018-07-30 04:07:02 +02:00
NotificationCenter . getGlobalInstance ( ) . removeObserver ( this , NotificationCenter . locationPermissionGranted ) ;
2022-02-01 14:00:45 +01:00
NotificationCenter . getGlobalInstance ( ) . removeObserver ( this , NotificationCenter . locationPermissionDenied ) ;
2020-11-01 14:02:57 +01:00
NotificationCenter . getGlobalInstance ( ) . removeObserver ( this , NotificationCenter . liveLocationsChanged ) ;
2019-07-18 15:01:39 +02:00
getNotificationCenter ( ) . removeObserver ( this , NotificationCenter . closeChats ) ;
getNotificationCenter ( ) . removeObserver ( this , NotificationCenter . didReceiveNewMessages ) ;
getNotificationCenter ( ) . removeObserver ( this , NotificationCenter . replaceMessagesObjects ) ;
2020-04-04 12:19:59 +02:00
// TODO
// proper exit, like upstream does with
// setMyLocationEnabled(false);
2020-11-01 14:02:57 +01:00
if ( undoView [ 0 ] ! = null ) {
undoView [ 0 ] . hide ( true , 0 ) ;
}
2015-05-03 13:48:36 +02:00
if ( adapter ! = null ) {
adapter . destroy ( ) ;
}
if ( searchAdapter ! = null ) {
searchAdapter . destroy ( ) ;
}
2017-12-08 18:35:59 +01:00
if ( updateRunnable ! = null ) {
AndroidUtilities . cancelRunOnUIThread ( updateRunnable ) ;
updateRunnable = null ;
}
2019-12-31 14:08:08 +01:00
if ( markAsReadRunnable ! = null ) {
AndroidUtilities . cancelRunOnUIThread ( markAsReadRunnable ) ;
markAsReadRunnable = null ;
}
2013-10-25 17:19:00 +02:00
}
2020-11-01 14:02:57 +01:00
private UndoView getUndoView ( ) {
if ( undoView [ 0 ] . getVisibility ( ) = = View . VISIBLE ) {
UndoView old = undoView [ 0 ] ;
undoView [ 0 ] = undoView [ 1 ] ;
undoView [ 1 ] = old ;
old . hide ( true , 2 ) ;
mapViewClip . removeView ( undoView [ 0 ] ) ;
mapViewClip . addView ( undoView [ 0 ] ) ;
}
return undoView [ 0 ] ;
}
2020-02-13 19:26:53 +01:00
@Override
public boolean isSwipeBackEnabled ( MotionEvent event ) {
return false ;
}
2013-10-25 17:19:00 +02:00
@Override
2015-07-22 20:56:37 +02:00
public View createView ( Context context ) {
2019-12-31 14:08:08 +01:00
searchWas = false ;
searching = false ;
searchInProgress = false ;
if ( adapter ! = null ) {
adapter . destroy ( ) ;
}
if ( searchAdapter ! = null ) {
searchAdapter . destroy ( ) ;
}
if ( chatLocation ! = null ) {
userLocation = new Location ( " network " ) ;
userLocation . setLatitude ( chatLocation . geo_point . lat ) ;
userLocation . setLongitude ( chatLocation . geo_point . _long ) ;
} else if ( messageObject ! = null ) {
userLocation = new Location ( " network " ) ;
userLocation . setLatitude ( messageObject . messageOwner . media . geo . lat ) ;
userLocation . setLongitude ( messageObject . messageOwner . media . geo . _long ) ;
}
2022-02-01 14:00:45 +01:00
locationDenied = Build . VERSION . SDK_INT > = 23 & & getParentActivity ( ) ! = null & & getParentActivity ( ) . checkSelfPermission ( Manifest . permission . ACCESS_COARSE_LOCATION ) ! = PackageManager . PERMISSION_GRANTED ;
2019-12-31 14:08:08 +01:00
actionBar . setBackgroundColor ( Theme . getColor ( Theme . key_dialogBackground ) ) ;
actionBar . setTitleColor ( Theme . getColor ( Theme . key_dialogTextBlack ) ) ;
actionBar . setItemsColor ( Theme . getColor ( Theme . key_dialogTextBlack ) , false ) ;
actionBar . setItemsBackgroundColor ( Theme . getColor ( Theme . key_dialogButtonSelector ) , false ) ;
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
}
2017-12-08 18:35:59 +01:00
actionBar . setAddToContainer ( false ) ;
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 ( ) ;
2019-12-31 14:08:08 +01:00
} else if ( id = = open_in ) {
2015-05-03 13:48:36 +02:00
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 ) ;
2014-06-04 01:31:48 +02:00
}
2019-12-31 14:08:08 +01:00
} else if ( id = = share_live_location ) {
2020-11-01 14:02:57 +01:00
openShareLiveLocation ( 0 ) ;
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 ( ) ;
2019-07-18 15:01:39 +02:00
if ( chatLocation ! = null ) {
actionBar . setTitle ( LocaleController . getString ( " ChatLocation " , R . string . ChatLocation ) ) ;
} else if ( messageObject ! = null ) {
2017-12-08 18:35:59 +01:00
if ( messageObject . isLiveLocation ( ) ) {
actionBar . setTitle ( LocaleController . getString ( " AttachLiveLocation " , R . string . AttachLiveLocation ) ) ;
2015-05-03 13:48:36 +02:00
} else {
2017-12-08 18:35:59 +01:00
if ( messageObject . messageOwner . media . title ! = null & & messageObject . messageOwner . media . title . length ( ) > 0 ) {
actionBar . setTitle ( LocaleController . getString ( " SharedPlace " , R . string . SharedPlace ) ) ;
} else {
actionBar . setTitle ( LocaleController . getString ( " ChatLocation " , R . string . ChatLocation ) ) ;
}
2019-12-31 14:08:08 +01:00
otherItem = menu . addItem ( 0 , R . drawable . ic_ab_other ) ;
2020-11-01 14:02:57 +01:00
otherItem . addSubItem ( open_in , R . drawable . msg_openin , LocaleController . getString ( " OpenInExternalApp " , R . string . OpenInExternalApp ) ) ;
2019-12-31 14:08:08 +01:00
if ( ! getLocationController ( ) . isSharingLocation ( dialogId ) ) {
2022-06-21 04:51:00 +02:00
otherItem . addSubItem ( share_live_location , R . drawable . msg_location , LocaleController . getString ( " SendLiveLocationMenu " , R . string . SendLiveLocationMenu ) ) ;
2019-12-31 14:08:08 +01:00
}
otherItem . setContentDescription ( LocaleController . getString ( " AccDescrMoreOptions " , R . string . AccDescrMoreOptions ) ) ;
2015-05-03 13:48:36 +02:00
}
} else {
actionBar . setTitle ( LocaleController . getString ( " ShareLocation " , R . string . ShareLocation ) ) ;
2019-07-18 15:01:39 +02:00
if ( locationType ! = LOCATION_TYPE_GROUP ) {
2019-12-31 14:08:08 +01:00
overlayView = new MapOverlayView ( context ) ;
searchItem = menu . addItem ( 0 , R . drawable . ic_ab_search ) . setIsSearchField ( true ) . setActionBarMenuItemSearchListener ( new ActionBarMenuItem . ActionBarMenuItemSearchListener ( ) {
2019-07-18 15:01:39 +02:00
@Override
public void onSearchExpand ( ) {
searching = true ;
}
2015-05-03 13:48:36 +02:00
2019-07-18 15:01:39 +02:00
@Override
public void onSearchCollapse ( ) {
searching = false ;
searchWas = false ;
searchAdapter . searchDelayed ( null , null ) ;
2019-12-31 14:08:08 +01:00
updateEmptyView ( ) ;
2015-05-03 13:48:36 +02:00
}
2019-07-18 15:01:39 +02:00
@Override
public void onTextChanged ( EditText editText ) {
if ( searchAdapter = = null ) {
return ;
}
String text = editText . getText ( ) . toString ( ) ;
if ( text . length ( ) ! = 0 ) {
searchWas = true ;
2019-12-31 14:08:08 +01:00
searchItem . setShowSearchProgress ( true ) ;
if ( otherItem ! = null ) {
otherItem . setVisibility ( View . GONE ) ;
}
listView . setVisibility ( View . GONE ) ;
mapViewClip . setVisibility ( View . GONE ) ;
if ( searchListView . getAdapter ( ) ! = searchAdapter ) {
searchListView . setAdapter ( searchAdapter ) ;
}
searchListView . setVisibility ( View . VISIBLE ) ;
searchInProgress = searchAdapter . getItemCount ( ) = = 0 ;
} else {
if ( otherItem ! = null ) {
otherItem . setVisibility ( View . VISIBLE ) ;
}
listView . setVisibility ( View . VISIBLE ) ;
mapViewClip . setVisibility ( View . VISIBLE ) ;
searchListView . setAdapter ( null ) ;
searchListView . setVisibility ( View . GONE ) ;
2019-07-18 15:01:39 +02:00
}
2020-09-30 15:48:47 +02:00
updateEmptyView ( ) ;
2019-07-18 15:01:39 +02:00
searchAdapter . searchDelayed ( text , userLocation ) ;
2015-05-03 13:48:36 +02:00
}
2019-07-18 15:01:39 +02:00
} ) ;
2019-12-31 14:08:08 +01:00
searchItem . setSearchFieldHint ( LocaleController . getString ( " Search " , R . string . Search ) ) ;
searchItem . setContentDescription ( LocaleController . getString ( " Search " , R . string . Search ) ) ;
EditTextBoldCursor editText = searchItem . getSearchField ( ) ;
editText . setTextColor ( Theme . getColor ( Theme . key_dialogTextBlack ) ) ;
editText . setCursorColor ( Theme . getColor ( Theme . key_dialogTextBlack ) ) ;
editText . setHintTextColor ( Theme . getColor ( Theme . key_chat_messagePanelHint ) ) ;
2019-07-18 15:01:39 +02:00
}
2015-05-03 13:48:36 +02:00
}
2013-10-25 17:19:00 +02:00
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 ;
2020-11-01 14:02:57 +01:00
} else {
updateClipView ( true ) ;
2015-05-03 13:48:36 +02:00
}
}
2019-12-31 14:08:08 +01:00
@Override
protected boolean drawChild ( Canvas canvas , View child , long drawingTime ) {
boolean result = super . drawChild ( canvas , child , drawingTime ) ;
if ( child = = actionBar & & parentLayout ! = null ) {
parentLayout . drawHeaderShadow ( canvas , actionBar . getMeasuredHeight ( ) ) ;
}
return result ;
}
2015-05-03 13:48:36 +02:00
} ;
FrameLayout frameLayout = ( FrameLayout ) fragmentView ;
2019-12-31 14:08:08 +01:00
fragmentView . setBackgroundColor ( Theme . getColor ( Theme . key_dialogBackground ) ) ;
2015-05-03 13:48:36 +02:00
2019-12-31 14:08:08 +01:00
shadowDrawable = context . getResources ( ) . getDrawable ( R . drawable . sheet_shadow_round ) . mutate ( ) ;
2020-11-01 14:02:57 +01:00
shadowDrawable . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_dialogBackground ) , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
Rect padding = new Rect ( ) ;
shadowDrawable . getPadding ( padding ) ;
FrameLayout . LayoutParams layoutParams ;
if ( locationType = = LOCATION_TYPE_SEND | | locationType = = LOCATION_TYPE_SEND_WITH_LIVE ) {
layoutParams = new FrameLayout . LayoutParams ( ViewGroup . LayoutParams . MATCH_PARENT , AndroidUtilities . dp ( 21 ) + padding . top ) ;
} else {
layoutParams = new FrameLayout . LayoutParams ( ViewGroup . LayoutParams . MATCH_PARENT , AndroidUtilities . dp ( 6 ) + padding . top ) ;
}
layoutParams . gravity = Gravity . LEFT | Gravity . BOTTOM ;
mapViewClip = new FrameLayout ( context ) {
@Override
protected void onMeasure ( int widthMeasureSpec , int heightMeasureSpec ) {
super . onMeasure ( widthMeasureSpec , heightMeasureSpec ) ;
if ( overlayView ! = null ) {
overlayView . updatePositions ( ) ;
}
}
} ;
mapViewClip . setBackgroundDrawable ( new MapPlaceholderDrawable ( ) ) ;
if ( messageObject = = null & & ( locationType = = LOCATION_TYPE_SEND | | locationType = = LOCATION_TYPE_SEND_WITH_LIVE ) ) {
searchAreaButton = new SearchButton ( context ) ;
searchAreaButton . setTranslationX ( - AndroidUtilities . dp ( 80 ) ) ;
Drawable drawable = Theme . createSimpleSelectorRoundRectDrawable ( AndroidUtilities . dp ( 40 ) , Theme . getColor ( Theme . key_location_actionBackground ) , Theme . getColor ( Theme . key_location_actionPressedBackground ) ) ;
if ( Build . VERSION . SDK_INT < 21 ) {
Drawable shadowDrawable = context . getResources ( ) . getDrawable ( R . drawable . places_btn ) . mutate ( ) ;
2020-11-01 14:02:57 +01:00
shadowDrawable . setColorFilter ( new PorterDuffColorFilter ( 0xff000000 , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
CombinedDrawable combinedDrawable = new CombinedDrawable ( shadowDrawable , drawable , AndroidUtilities . dp ( 2 ) , AndroidUtilities . dp ( 2 ) ) ;
combinedDrawable . setFullsize ( true ) ;
drawable = combinedDrawable ;
} else {
StateListAnimator animator = new StateListAnimator ( ) ;
animator . addState ( new int [ ] { android . R . attr . state_pressed } , ObjectAnimator . ofFloat ( searchAreaButton , View . TRANSLATION_Z , AndroidUtilities . dp ( 2 ) , AndroidUtilities . dp ( 4 ) ) . setDuration ( 200 ) ) ;
animator . addState ( new int [ ] { } , ObjectAnimator . ofFloat ( searchAreaButton , View . TRANSLATION_Z , AndroidUtilities . dp ( 4 ) , AndroidUtilities . dp ( 2 ) ) . setDuration ( 200 ) ) ;
searchAreaButton . setStateListAnimator ( animator ) ;
searchAreaButton . setOutlineProvider ( new ViewOutlineProvider ( ) {
@SuppressLint ( " NewApi " )
@Override
public void getOutline ( View view , Outline outline ) {
outline . setRoundRect ( 0 , 0 , view . getMeasuredWidth ( ) , view . getMeasuredHeight ( ) , view . getMeasuredHeight ( ) / 2 ) ;
}
} ) ;
}
searchAreaButton . setBackgroundDrawable ( drawable ) ;
searchAreaButton . setTextColor ( Theme . getColor ( Theme . key_location_actionActiveIcon ) ) ;
searchAreaButton . setTextSize ( TypedValue . COMPLEX_UNIT_DIP , 14 ) ;
searchAreaButton . setTypeface ( AndroidUtilities . getTypeface ( " fonts/rmedium.ttf " ) ) ;
searchAreaButton . setText ( LocaleController . getString ( " PlacesInThisArea " , R . string . PlacesInThisArea ) ) ;
searchAreaButton . setGravity ( Gravity . CENTER ) ;
searchAreaButton . setPadding ( AndroidUtilities . dp ( 20 ) , 0 , AndroidUtilities . dp ( 20 ) , 0 ) ;
mapViewClip . addView ( searchAreaButton , LayoutHelper . createFrame ( LayoutHelper . WRAP_CONTENT , Build . VERSION . SDK_INT > = 21 ? 40 : 44 , Gravity . CENTER_HORIZONTAL | Gravity . TOP , 80 , 12 , 80 , 0 ) ) ;
searchAreaButton . setOnClickListener ( v - > {
showSearchPlacesButton ( false ) ;
adapter . searchPlacesWithQuery ( null , userLocation , true , true ) ;
searchedForCustomLocations = true ;
showResults ( ) ;
} ) ;
}
mapTypeButton = new ActionBarMenuItem ( context , null , 0 , Theme . getColor ( Theme . key_location_actionIcon ) ) ;
mapTypeButton . setClickable ( true ) ;
mapTypeButton . setSubMenuOpenSide ( 2 ) ;
mapTypeButton . setAdditionalXOffset ( AndroidUtilities . dp ( 10 ) ) ;
mapTypeButton . setAdditionalYOffset ( - AndroidUtilities . dp ( 10 ) ) ;
2020-04-04 12:19:59 +02:00
mapTypeButton . addSubItem ( map_list_menu_osm , R . drawable . msg_map , " Standard OSM " ) ;
mapTypeButton . addSubItem ( map_list_menu_wiki , R . drawable . msg_map , " Wikimedia " ) ;
mapTypeButton . addSubItem ( map_list_menu_cartodark , R . drawable . msg_map , " Carto Dark " ) ;
2019-12-31 14:08:08 +01:00
mapTypeButton . setContentDescription ( LocaleController . getString ( " AccDescrMoreOptions " , R . string . AccDescrMoreOptions ) ) ;
Drawable drawable = Theme . createSimpleSelectorCircleDrawable ( AndroidUtilities . dp ( 40 ) , Theme . getColor ( Theme . key_location_actionBackground ) , Theme . getColor ( Theme . key_location_actionPressedBackground ) ) ;
2017-03-31 01:58:05 +02:00
if ( Build . VERSION . SDK_INT < 21 ) {
Drawable shadowDrawable = context . getResources ( ) . getDrawable ( R . drawable . floating_shadow_profile ) . mutate ( ) ;
2020-11-01 14:02:57 +01:00
shadowDrawable . setColorFilter ( new PorterDuffColorFilter ( 0xff000000 , PorterDuff . Mode . MULTIPLY ) ) ;
2017-03-31 01:58:05 +02:00
CombinedDrawable combinedDrawable = new CombinedDrawable ( shadowDrawable , drawable , 0 , 0 ) ;
2019-12-31 14:08:08 +01:00
combinedDrawable . setIconSize ( AndroidUtilities . dp ( 40 ) , AndroidUtilities . dp ( 40 ) ) ;
2017-03-31 01:58:05 +02:00
drawable = combinedDrawable ;
2019-12-31 14:08:08 +01:00
} else {
StateListAnimator animator = new StateListAnimator ( ) ;
animator . addState ( new int [ ] { android . R . attr . state_pressed } , ObjectAnimator . ofFloat ( mapTypeButton , View . TRANSLATION_Z , AndroidUtilities . dp ( 2 ) , AndroidUtilities . dp ( 4 ) ) . setDuration ( 200 ) ) ;
animator . addState ( new int [ ] { } , ObjectAnimator . ofFloat ( mapTypeButton , View . TRANSLATION_Z , AndroidUtilities . dp ( 4 ) , AndroidUtilities . dp ( 2 ) ) . setDuration ( 200 ) ) ;
mapTypeButton . setStateListAnimator ( animator ) ;
mapTypeButton . setOutlineProvider ( new ViewOutlineProvider ( ) {
@SuppressLint ( " NewApi " )
@Override
public void getOutline ( View view , Outline outline ) {
outline . setOval ( 0 , 0 , AndroidUtilities . dp ( 40 ) , AndroidUtilities . dp ( 40 ) ) ;
}
} ) ;
2017-03-31 01:58:05 +02:00
}
2019-12-31 14:08:08 +01:00
mapTypeButton . setBackgroundDrawable ( drawable ) ;
2022-06-21 04:51:00 +02:00
mapTypeButton . setIcon ( R . drawable . msg_map_type ) ;
2019-12-31 14:08:08 +01:00
mapViewClip . addView ( mapTypeButton , LayoutHelper . createFrame ( Build . VERSION . SDK_INT > = 21 ? 40 : 44 , Build . VERSION . SDK_INT > = 21 ? 40 : 44 , Gravity . RIGHT | Gravity . TOP , 0 , 12 , 12 , 0 ) ) ;
2020-02-13 21:45:02 +01:00
mapTypeButton . setOnClickListener ( v - > mapTypeButton . toggleSubMenu ( ) ) ;
2019-12-31 14:08:08 +01:00
mapTypeButton . setDelegate ( id - > {
2020-04-04 12:19:59 +02:00
if ( mapView = = null ) {
2019-12-31 14:08:08 +01:00
return ;
}
2020-04-04 12:19:59 +02:00
if ( id = = map_list_menu_osm ) {
attributionOverlay . setText ( Html . fromHtml ( " © <a href= \" https://www.openstreetmap.org/copyright \" >OpenStreetMap</a> contributors " ) ) ;
mapView . setTileSource ( TileSourceFactory . MAPNIK ) ;
} else if ( id = = map_list_menu_wiki ) {
// Create a custom tile source
ITileSource tileSource = new XYTileSource (
" Wikimedia " , 0 , 19 ,
256 , " .png " ,
2020-11-01 14:02:57 +01:00
new String [ ] { " https://maps.wikimedia.org/osm-intl/ " } ,
2020-04-04 12:19:59 +02:00
" © OpenStreetMap contributors " ) ;
attributionOverlay . setText ( Html . fromHtml ( " © <a href= \" https://www.openstreetmap.org/copyright \" >OpenStreetMap</a> contributors " ) ) ;
mapView . setTileSource ( tileSource ) ;
} else if ( id = = map_list_menu_cartodark ) {
// Create a custom tile source
ITileSource tileSource = new XYTileSource (
" Carto Dark " , 0 , 20 ,
256 , " .png " ,
2020-11-01 14:02:57 +01:00
new String [ ] {
2020-04-04 12:19:59 +02:00
" https://cartodb-basemaps-a.global.ssl.fastly.net/dark_all/ " ,
" https://cartodb-basemaps-b.global.ssl.fastly.net/dark_all/ " ,
" https://cartodb-basemaps-c.global.ssl.fastly.net/dark_all/ " ,
" https://cartodb-basemaps-d.global.ssl.fastly.net/dark_all/ " } ,
" © OpenStreetMap contributors, © CARTO " ) ;
attributionOverlay . setText ( Html . fromHtml ( " © <a href= \" https://www.openstreetmap.org/copyright \" >OpenStreetMap</a> contributors, © <a href= \" https://carto.com/attributions \" >CARTO</a> " ) ) ;
mapView . setTileSource ( tileSource ) ;
2019-12-31 14:08:08 +01:00
}
} ) ;
2020-04-04 12:19:59 +02:00
mapViewClip . addView ( getAttributionOverlay ( context ) , LayoutHelper . createFrame ( LayoutHelper . WRAP_CONTENT , LayoutHelper . WRAP_CONTENT , ( LocaleController . isRTL ? Gravity . RIGHT : Gravity . LEFT ) | Gravity . BOTTOM , LocaleController . isRTL ? 0 : 4 , 0 , LocaleController . isRTL ? 4 : 0 , 20 ) ) ;
2019-12-31 14:08:08 +01:00
locationButton = new ImageView ( context ) ;
drawable = Theme . createSimpleSelectorCircleDrawable ( AndroidUtilities . dp ( 40 ) , Theme . getColor ( Theme . key_location_actionBackground ) , Theme . getColor ( Theme . key_location_actionPressedBackground ) ) ;
if ( Build . VERSION . SDK_INT < 21 ) {
Drawable shadowDrawable = context . getResources ( ) . getDrawable ( R . drawable . floating_shadow_profile ) . mutate ( ) ;
2020-11-01 14:02:57 +01:00
shadowDrawable . setColorFilter ( new PorterDuffColorFilter ( 0xff000000 , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
CombinedDrawable combinedDrawable = new CombinedDrawable ( shadowDrawable , drawable , 0 , 0 ) ;
combinedDrawable . setIconSize ( AndroidUtilities . dp ( 40 ) , AndroidUtilities . dp ( 40 ) ) ;
drawable = combinedDrawable ;
} else {
2015-05-03 13:48:36 +02:00
StateListAnimator animator = new StateListAnimator ( ) ;
2019-07-18 15:01:39 +02:00
animator . addState ( new int [ ] { android . R . attr . state_pressed } , ObjectAnimator . ofFloat ( locationButton , View . TRANSLATION_Z , AndroidUtilities . dp ( 2 ) , AndroidUtilities . dp ( 4 ) ) . setDuration ( 200 ) ) ;
animator . addState ( new int [ ] { } , ObjectAnimator . ofFloat ( locationButton , View . TRANSLATION_Z , AndroidUtilities . dp ( 4 ) , AndroidUtilities . dp ( 2 ) ) . setDuration ( 200 ) ) ;
2015-05-03 13:48:36 +02:00
locationButton . setStateListAnimator ( animator ) ;
locationButton . setOutlineProvider ( new ViewOutlineProvider ( ) {
2016-06-24 12:27:15 +02:00
@SuppressLint ( " NewApi " )
2015-05-03 13:48:36 +02:00
@Override
public void getOutline ( View view , Outline outline ) {
2019-12-31 14:08:08 +01:00
outline . setOval ( 0 , 0 , AndroidUtilities . dp ( 40 ) , AndroidUtilities . dp ( 40 ) ) ;
2015-05-03 13:48:36 +02:00
}
} ) ;
}
2019-12-31 14:08:08 +01:00
locationButton . setBackgroundDrawable ( drawable ) ;
2022-06-21 04:51:00 +02:00
locationButton . setImageResource ( R . drawable . msg_current_location ) ;
2019-12-31 14:08:08 +01:00
locationButton . setScaleType ( ImageView . ScaleType . CENTER ) ;
2020-11-01 14:02:57 +01:00
locationButton . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_location_actionActiveIcon ) , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
locationButton . setTag ( Theme . key_location_actionActiveIcon ) ;
locationButton . setContentDescription ( LocaleController . getString ( " AccDescrMyLocation " , R . string . AccDescrMyLocation ) ) ;
FrameLayout . LayoutParams layoutParams1 = LayoutHelper . createFrame ( Build . VERSION . SDK_INT > = 21 ? 40 : 44 , Build . VERSION . SDK_INT > = 21 ? 40 : 44 , Gravity . RIGHT | Gravity . BOTTOM , 0 , 0 , 12 , 12 ) ;
layoutParams1 . bottomMargin + = layoutParams . height - padding . top ;
mapViewClip . addView ( locationButton , layoutParams1 ) ;
locationButton . setOnClickListener ( v - > {
if ( Build . VERSION . SDK_INT > = 23 ) {
Activity activity = getParentActivity ( ) ;
if ( activity ! = null ) {
if ( activity . checkSelfPermission ( Manifest . permission . ACCESS_COARSE_LOCATION ) ! = PackageManager . PERMISSION_GRANTED ) {
showPermissionAlert ( false ) ;
return ;
}
}
}
2020-11-01 14:02:57 +01:00
if ( ! checkGpsEnabled ( ) ) {
return ;
}
2019-12-31 14:08:08 +01:00
if ( messageObject ! = null | | chatLocation ! = null ) {
2020-04-04 12:19:59 +02:00
if ( myLocation ! = null & & mapView ! = null ) {
final IMapController controller = mapView . getController ( ) ;
2020-11-01 14:02:57 +01:00
controller . animateTo ( new GeoPoint ( myLocation . getLatitude ( ) , myLocation . getLongitude ( ) ) , mapView . getMaxZoomLevel ( ) - 2 , null ) ;
2019-12-31 14:08:08 +01:00
}
} else {
2020-04-04 12:19:59 +02:00
if ( myLocation ! = null & & mapView ! = null ) {
2020-11-01 14:02:57 +01:00
locationButton . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_location_actionActiveIcon ) , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
locationButton . setTag ( Theme . key_location_actionActiveIcon ) ;
adapter . setCustomLocation ( null ) ;
userLocationMoved = false ;
showSearchPlacesButton ( false ) ;
2020-04-04 12:19:59 +02:00
final IMapController controller = mapView . getController ( ) ;
controller . animateTo ( new GeoPoint ( myLocation . getLatitude ( ) , myLocation . getLongitude ( ) ) ) ;
2019-12-31 14:08:08 +01:00
if ( searchedForCustomLocations ) {
if ( myLocation ! = null ) {
adapter . searchPlacesWithQuery ( null , myLocation , true , true ) ;
}
searchedForCustomLocations = false ;
showResults ( ) ;
}
}
}
removeInfoView ( ) ;
} ) ;
2013-10-25 17:19:00 +02:00
2020-11-01 14:02:57 +01:00
proximityButton = new ImageView ( context ) ;
drawable = Theme . createSimpleSelectorCircleDrawable ( AndroidUtilities . dp ( 40 ) , Theme . getColor ( Theme . key_location_actionBackground ) , Theme . getColor ( Theme . key_location_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 ( 40 ) , AndroidUtilities . dp ( 40 ) ) ;
drawable = combinedDrawable ;
} else {
StateListAnimator animator = new StateListAnimator ( ) ;
animator . addState ( new int [ ] { android . R . attr . state_pressed } , ObjectAnimator . ofFloat ( proximityButton , View . TRANSLATION_Z , AndroidUtilities . dp ( 2 ) , AndroidUtilities . dp ( 4 ) ) . setDuration ( 200 ) ) ;
animator . addState ( new int [ ] { } , ObjectAnimator . ofFloat ( proximityButton , View . TRANSLATION_Z , AndroidUtilities . dp ( 4 ) , AndroidUtilities . dp ( 2 ) ) . setDuration ( 200 ) ) ;
proximityButton . setStateListAnimator ( animator ) ;
proximityButton . setOutlineProvider ( new ViewOutlineProvider ( ) {
@SuppressLint ( " NewApi " )
@Override
public void getOutline ( View view , Outline outline ) {
outline . setOval ( 0 , 0 , AndroidUtilities . dp ( 40 ) , AndroidUtilities . dp ( 40 ) ) ;
}
} ) ;
}
proximityButton . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_location_actionIcon ) , PorterDuff . Mode . MULTIPLY ) ) ;
proximityButton . setBackgroundDrawable ( drawable ) ;
proximityButton . setScaleType ( ImageView . ScaleType . CENTER ) ;
proximityButton . setContentDescription ( LocaleController . getString ( " AccDescrLocationNotify " , R . string . AccDescrLocationNotify ) ) ;
mapViewClip . addView ( proximityButton , LayoutHelper . createFrame ( Build . VERSION . SDK_INT > = 21 ? 40 : 44 , Build . VERSION . SDK_INT > = 21 ? 40 : 44 , Gravity . RIGHT | Gravity . TOP , 0 , 12 + 50 , 12 , 0 ) ) ;
proximityButton . setOnClickListener ( v - > {
if ( getParentActivity ( ) = = null | | myLocation = = null | | ! checkGpsEnabled ( ) | | mapView = = null ) {
return ;
}
if ( hintView ! = null ) {
hintView . hide ( ) ;
}
SharedPreferences preferences = MessagesController . getGlobalMainSettings ( ) ;
preferences . edit ( ) . putInt ( " proximityhint " , 3 ) . commit ( ) ;
LocationController . SharingLocationInfo info = getLocationController ( ) . getSharingLocationInfo ( dialogId ) ;
if ( canUndo ) {
undoView [ 0 ] . hide ( true , 1 ) ;
}
if ( info ! = null & & info . proximityMeters > 0 ) {
proximityButton . setImageResource ( R . drawable . msg_location_alert ) ;
if ( proximityCircle ! = null ) {
mapView . getOverlayManager ( ) . remove ( proximityCircle ) ;
proximityCircle = null ;
}
canUndo = true ;
getUndoView ( ) . showWithAction ( 0 , UndoView . ACTION_PROXIMITY_REMOVED , 0 , null ,
( ) - > {
getLocationController ( ) . setProximityLocation ( dialogId , 0 , true ) ;
canUndo = false ;
} , ( ) - > {
proximityButton . setImageResource ( R . drawable . msg_location_alert2 ) ;
createCircle ( info . proximityMeters ) ;
canUndo = false ;
} ) ;
return ;
}
openProximityAlert ( ) ;
} ) ;
TLRPC . Chat chat = null ;
2021-09-20 00:10:42 +02:00
if ( DialogObject . isChatDialog ( dialogId ) ) {
chat = getMessagesController ( ) . getChat ( - dialogId ) ;
2020-11-01 14:02:57 +01:00
}
if ( messageObject = = null | | ! messageObject . isLiveLocation ( ) | | messageObject . isExpiredLiveLocation ( getConnectionsManager ( ) . getCurrentTime ( ) ) | | ChatObject . isChannel ( chat ) & & ! chat . megagroup ) {
proximityButton . setVisibility ( View . GONE ) ;
proximityButton . setImageResource ( R . drawable . msg_location_alert ) ;
} else {
LocationController . SharingLocationInfo myInfo = getLocationController ( ) . getSharingLocationInfo ( dialogId ) ;
if ( myInfo ! = null & & myInfo . proximityMeters > 0 ) {
proximityButton . setImageResource ( R . drawable . msg_location_alert2 ) ;
} else {
2021-09-20 00:10:42 +02:00
if ( DialogObject . isUserDialog ( dialogId ) & & messageObject . getFromChatId ( ) = = getUserConfig ( ) . getClientUserId ( ) ) {
2020-11-01 14:02:57 +01:00
proximityButton . setVisibility ( View . INVISIBLE ) ;
proximityButton . setAlpha ( 0 . 0f ) ;
proximityButton . setScaleX ( 0 . 4f ) ;
proximityButton . setScaleY ( 0 . 4f ) ;
}
proximityButton . setImageResource ( R . drawable . msg_location_alert ) ;
}
}
hintView = new HintView ( context , 6 , true ) ;
hintView . setVisibility ( View . INVISIBLE ) ;
hintView . setShowingDuration ( 4000 ) ;
mapViewClip . addView ( hintView , LayoutHelper . createFrame ( LayoutHelper . WRAP_CONTENT , LayoutHelper . WRAP_CONTENT , Gravity . LEFT | Gravity . TOP , 10 , 0 , 10 , 0 ) ) ;
2019-12-31 14:08:08 +01:00
emptyView = new LinearLayout ( context ) ;
emptyView . setOrientation ( LinearLayout . VERTICAL ) ;
emptyView . setGravity ( Gravity . CENTER_HORIZONTAL ) ;
emptyView . setPadding ( 0 , AndroidUtilities . dp ( 60 + 100 ) , 0 , 0 ) ;
emptyView . setVisibility ( View . GONE ) ;
frameLayout . addView ( emptyView , LayoutHelper . createFrame ( LayoutHelper . MATCH_PARENT , LayoutHelper . MATCH_PARENT ) ) ;
emptyView . setOnTouchListener ( ( v , event ) - > true ) ;
emptyImageView = new ImageView ( context ) ;
emptyImageView . setImageResource ( R . drawable . location_empty ) ;
2020-11-01 14:02:57 +01:00
emptyImageView . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_dialogEmptyImage ) , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
emptyView . addView ( emptyImageView , LayoutHelper . createLinear ( LayoutHelper . WRAP_CONTENT , LayoutHelper . WRAP_CONTENT ) ) ;
emptyTitleTextView = new TextView ( context ) ;
emptyTitleTextView . setTextColor ( Theme . getColor ( Theme . key_dialogEmptyText ) ) ;
emptyTitleTextView . setGravity ( Gravity . CENTER ) ;
emptyTitleTextView . setTypeface ( AndroidUtilities . getTypeface ( " fonts/rmedium.ttf " ) ) ;
emptyTitleTextView . setTextSize ( TypedValue . COMPLEX_UNIT_DIP , 17 ) ;
emptyTitleTextView . setText ( LocaleController . getString ( " NoPlacesFound " , R . string . NoPlacesFound ) ) ;
emptyView . addView ( emptyTitleTextView , LayoutHelper . createLinear ( LayoutHelper . WRAP_CONTENT , LayoutHelper . WRAP_CONTENT , Gravity . CENTER , 0 , 11 , 0 , 0 ) ) ;
emptySubtitleTextView = new TextView ( context ) ;
emptySubtitleTextView . setTextColor ( Theme . getColor ( Theme . key_dialogEmptyText ) ) ;
emptySubtitleTextView . setGravity ( Gravity . CENTER ) ;
emptySubtitleTextView . setTextSize ( TypedValue . COMPLEX_UNIT_DIP , 15 ) ;
emptySubtitleTextView . setPadding ( AndroidUtilities . dp ( 40 ) , 0 , AndroidUtilities . dp ( 40 ) , 0 ) ;
emptyView . addView ( emptySubtitleTextView , LayoutHelper . createLinear ( LayoutHelper . WRAP_CONTENT , LayoutHelper . WRAP_CONTENT , Gravity . CENTER , 0 , 6 , 0 , 0 ) ) ;
2017-12-08 18:35:59 +01:00
listView = new RecyclerListView ( context ) ;
2021-09-20 00:10:42 +02:00
listView . setAdapter ( adapter = new LocationActivityAdapter ( context , locationType , dialogId , false , null ) {
2017-12-08 18:35:59 +01:00
@Override
2019-12-31 14:08:08 +01:00
protected void onDirectionClick ( ) {
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 ;
if ( messageObject ! = null ) {
intent = new Intent ( 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 ) ) ) ;
} else {
intent = new Intent ( Intent . ACTION_VIEW , Uri . parse ( String . format ( Locale . US , " http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f " , myLocation . getLatitude ( ) , myLocation . getLongitude ( ) , chatLocation . geo_point . lat , chatLocation . geo_point . _long ) ) ) ;
}
getParentActivity ( ) . startActivity ( intent ) ;
} catch ( Exception e ) {
FileLog . e ( e ) ;
}
}
2015-05-03 13:48:36 +02:00
}
2017-12-08 18:35:59 +01:00
} ) ;
2022-02-01 14:00:45 +01:00
adapter . setMyLocationDenied ( locationDenied ) ;
2020-11-01 14:02:57 +01:00
adapter . setUpdateRunnable ( ( ) - > updateClipView ( false ) ) ;
2019-12-31 14:08:08 +01:00
listView . setVerticalScrollBarEnabled ( false ) ;
listView . setLayoutManager ( layoutManager = new LinearLayoutManager ( context , LinearLayoutManager . VERTICAL , false ) ) ;
2017-12-08 18:35:59 +01:00
frameLayout . addView ( listView , LayoutHelper . createFrame ( LayoutHelper . MATCH_PARENT , LayoutHelper . MATCH_PARENT , Gravity . LEFT | Gravity . TOP ) ) ;
2015-05-03 13:48:36 +02:00
2017-12-08 18:35:59 +01:00
listView . setOnScrollListener ( new RecyclerView . OnScrollListener ( ) {
@Override
2019-12-31 14:08:08 +01:00
public void onScrollStateChanged ( RecyclerView recyclerView , int newState ) {
scrolling = newState ! = RecyclerView . SCROLL_STATE_IDLE ;
if ( ! scrolling & & forceUpdate ! = null ) {
forceUpdate = null ;
2017-12-08 18:35:59 +01:00
}
2019-12-31 14:08:08 +01:00
}
@Override
public void onScrolled ( RecyclerView recyclerView , int dx , int dy ) {
2020-11-01 14:02:57 +01:00
updateClipView ( false ) ;
2019-12-31 14:08:08 +01:00
if ( forceUpdate ! = null ) {
yOffset + = dy ;
2015-05-03 13:48:36 +02:00
}
}
2017-12-08 18:35:59 +01:00
} ) ;
2019-12-31 14:08:08 +01:00
( ( DefaultItemAnimator ) listView . getItemAnimator ( ) ) . setDelayAnimations ( false ) ;
2019-01-23 18:03:33 +01:00
listView . setOnItemClickListener ( ( view , position ) - > {
2019-07-18 15:01:39 +02:00
if ( locationType = = LOCATION_TYPE_GROUP ) {
if ( position = = 1 ) {
TLRPC . TL_messageMediaVenue venue = ( TLRPC . TL_messageMediaVenue ) adapter . getItem ( position ) ;
if ( venue = = null ) {
return ;
}
if ( dialogId = = 0 ) {
2019-09-10 12:56:11 +02:00
delegate . didSelectLocation ( venue , LOCATION_TYPE_GROUP , true , 0 ) ;
2019-07-18 15:01:39 +02:00
finishFragment ( ) ;
} else {
final AlertDialog [ ] progressDialog = new AlertDialog [ ] { new AlertDialog ( getParentActivity ( ) , 3 ) } ;
TLRPC . TL_channels_editLocation req = new TLRPC . TL_channels_editLocation ( ) ;
req . address = venue . address ;
2021-09-20 00:10:42 +02:00
req . channel = getMessagesController ( ) . getInputChannel ( - dialogId ) ;
2019-07-18 15:01:39 +02:00
req . geo_point = new TLRPC . TL_inputGeoPoint ( ) ;
req . geo_point . lat = venue . geo . lat ;
req . geo_point . _long = venue . geo . _long ;
int requestId = getConnectionsManager ( ) . sendRequest ( req , ( response , error ) - > AndroidUtilities . runOnUIThread ( ( ) - > {
try {
progressDialog [ 0 ] . dismiss ( ) ;
} catch ( Throwable ignore ) {
}
progressDialog [ 0 ] = null ;
2019-09-10 12:56:11 +02:00
delegate . didSelectLocation ( venue , LOCATION_TYPE_GROUP , true , 0 ) ;
2019-07-18 15:01:39 +02:00
finishFragment ( ) ;
} ) ) ;
progressDialog [ 0 ] . setOnCancelListener ( dialog - > getConnectionsManager ( ) . cancelRequest ( requestId , true ) ) ;
showDialog ( progressDialog [ 0 ] ) ;
}
}
} else if ( locationType = = LOCATION_TYPE_GROUP_VIEW ) {
2020-04-04 12:19:59 +02:00
if ( mapView ! = null ) {
final IMapController controller = mapView . getController ( ) ;
2020-11-01 14:02:57 +01:00
controller . animateTo ( new GeoPoint ( chatLocation . geo_point . lat , chatLocation . geo_point . _long ) , mapView . getMaxZoomLevel ( ) - 2 , null ) ;
2019-07-18 15:01:39 +02:00
}
2020-11-01 14:02:57 +01:00
} else if ( position = = 1 & & messageObject ! = null & & ( ! messageObject . isLiveLocation ( ) | | locationType = = LOCATION_TYPE_LIVE_VIEW ) ) {
2020-04-04 12:19:59 +02:00
if ( mapView ! = null ) {
final IMapController controller = mapView . getController ( ) ;
2020-11-01 14:02:57 +01:00
controller . animateTo ( new GeoPoint ( messageObject . messageOwner . media . geo . lat , messageObject . messageOwner . media . geo . _long ) , mapView . getMaxZoomLevel ( ) - 2 , null ) ;
2019-01-23 18:03:33 +01:00
}
2019-07-18 15:01:39 +02:00
} else if ( position = = 1 & & locationType ! = 2 ) {
2019-01-23 18:03:33 +01:00
if ( delegate ! = null & & userLocation ! = null ) {
2019-12-31 14:08:08 +01:00
if ( lastPressedMarkerView ! = null ) {
lastPressedMarkerView . callOnClick ( ) ;
2019-09-10 12:56:11 +02:00
} else {
2019-12-31 14:08:08 +01:00
TLRPC . TL_messageMediaGeo location = new TLRPC . TL_messageMediaGeo ( ) ;
location . geo = new TLRPC . TL_geoPoint ( ) ;
location . geo . lat = AndroidUtilities . fixLocationCoord ( userLocation . getLatitude ( ) ) ;
location . geo . _long = AndroidUtilities . fixLocationCoord ( userLocation . getLongitude ( ) ) ;
if ( parentFragment ! = null & & parentFragment . isInScheduleMode ( ) ) {
AlertsCreator . createScheduleDatePickerDialog ( getParentActivity ( ) , parentFragment . getDialogId ( ) , ( notify , scheduleDate ) - > {
delegate . didSelectLocation ( location , locationType , notify , scheduleDate ) ;
finishFragment ( ) ;
} ) ;
} else {
delegate . didSelectLocation ( location , locationType , true , 0 ) ;
finishFragment ( ) ;
}
2019-09-10 12:56:11 +02:00
}
2019-01-23 18:03:33 +01:00
}
2019-07-18 15:01:39 +02:00
} else if ( position = = 2 & & locationType = = 1 | | position = = 1 & & locationType = = 2 | | position = = 3 & & locationType = = 3 ) {
if ( getLocationController ( ) . isSharingLocation ( dialogId ) ) {
getLocationController ( ) . removeSharingLocation ( dialogId ) ;
2017-12-08 18:35:59 +01:00
finishFragment ( ) ;
} else {
2020-11-01 14:02:57 +01:00
openShareLiveLocation ( 0 ) ;
2015-05-03 13:48:36 +02:00
}
2019-01-23 18:03:33 +01:00
} else {
Object object = adapter . getItem ( position ) ;
if ( object instanceof TLRPC . TL_messageMediaVenue ) {
2019-09-10 12:56:11 +02:00
if ( parentFragment ! = null & & parentFragment . isInScheduleMode ( ) ) {
2019-12-31 14:08:08 +01:00
AlertsCreator . createScheduleDatePickerDialog ( getParentActivity ( ) , parentFragment . getDialogId ( ) , ( notify , scheduleDate ) - > {
2019-09-10 12:56:11 +02:00
delegate . didSelectLocation ( ( TLRPC . TL_messageMediaVenue ) object , locationType , notify , scheduleDate ) ;
finishFragment ( ) ;
} ) ;
} else {
delegate . didSelectLocation ( ( TLRPC . TL_messageMediaVenue ) object , locationType , true , 0 ) ;
finishFragment ( ) ;
2019-01-23 18:03:33 +01:00
}
} else if ( object instanceof LiveLocation ) {
2019-07-18 15:01:39 +02:00
LiveLocation liveLocation = ( LiveLocation ) object ;
2020-04-04 12:19:59 +02:00
final IMapController controller = mapView . getController ( ) ;
2020-11-01 14:02:57 +01:00
controller . animateTo ( liveLocation . marker . getPosition ( ) , mapView . getMaxZoomLevel ( ) - 2 , null ) ;
2019-01-23 18:03:33 +01:00
}
2017-12-08 18:35:59 +01:00
}
} ) ;
2019-12-31 14:08:08 +01:00
adapter . setDelegate ( dialogId , this : : updatePlacesMarkers ) ;
2017-12-08 18:35:59 +01:00
adapter . setOverScrollHeight ( overScrollHeight ) ;
2015-05-03 13:48:36 +02:00
2017-12-08 18:35:59 +01:00
frameLayout . addView ( mapViewClip , LayoutHelper . createFrame ( LayoutHelper . MATCH_PARENT , LayoutHelper . MATCH_PARENT , Gravity . LEFT | Gravity . TOP ) ) ;
2015-05-03 13:48:36 +02:00
2017-12-08 18:35:59 +01:00
mapView = new MapView ( context ) {
2019-12-31 14:08:08 +01:00
@Override
public boolean dispatchTouchEvent ( MotionEvent ev ) {
MotionEvent eventToRecycle = null ;
if ( yOffset ! = 0 ) {
2020-01-01 23:29:20 +01:00
ev = eventToRecycle = MotionEvent . obtain ( ev ) ;
eventToRecycle . offsetLocation ( 0 , - yOffset / 2 ) ;
2019-12-31 14:08:08 +01:00
}
boolean result = super . dispatchTouchEvent ( ev ) ;
if ( eventToRecycle ! = null ) {
eventToRecycle . recycle ( ) ;
}
return result ;
}
2017-12-08 18:35:59 +01:00
@Override
2020-04-04 12:19:59 +02:00
public boolean onTouchEvent ( MotionEvent ev ) {
2019-07-18 15:01:39 +02:00
if ( messageObject = = null & & chatLocation = = null ) {
2016-06-24 12:27:15 +02:00
if ( ev . getAction ( ) = = MotionEvent . ACTION_DOWN ) {
if ( animatorSet ! = null ) {
animatorSet . cancel ( ) ;
}
animatorSet = new AnimatorSet ( ) ;
animatorSet . setDuration ( 200 ) ;
2019-12-31 14:08:08 +01:00
animatorSet . playTogether ( ObjectAnimator . ofFloat ( markerImageView , View . TRANSLATION_Y , markerTop - AndroidUtilities . dp ( 10 ) ) ) ;
2016-06-24 12:27:15 +02:00
animatorSet . start ( ) ;
} else if ( ev . getAction ( ) = = MotionEvent . ACTION_UP ) {
if ( animatorSet ! = null ) {
animatorSet . cancel ( ) ;
2015-05-03 13:48:36 +02:00
}
2019-12-31 14:08:08 +01:00
yOffset = 0 ;
2016-06-24 12:27:15 +02:00
animatorSet = new AnimatorSet ( ) ;
animatorSet . setDuration ( 200 ) ;
2019-12-31 14:08:08 +01:00
animatorSet . playTogether ( ObjectAnimator . ofFloat ( markerImageView , View . TRANSLATION_Y , markerTop ) ) ;
2016-06-24 12:27:15 +02:00
animatorSet . start ( ) ;
2019-07-18 15:01:39 +02:00
adapter . fetchLocationAddress ( ) ;
2015-05-03 13:48:36 +02:00
}
if ( ev . getAction ( ) = = MotionEvent . ACTION_MOVE ) {
if ( ! userLocationMoved ) {
2020-11-01 14:02:57 +01:00
locationButton . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_location_actionIcon ) , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
locationButton . setTag ( Theme . key_location_actionIcon ) ;
2015-05-03 13:48:36 +02:00
userLocationMoved = true ;
}
2020-04-04 12:19:59 +02:00
if ( mapView ! = null ) {
2019-12-31 14:08:08 +01:00
if ( userLocation ! = null ) {
2020-04-04 12:19:59 +02:00
userLocation . setLatitude ( mapView . getMapCenter ( ) . getLatitude ( ) ) ;
userLocation . setLongitude ( mapView . getMapCenter ( ) . getLongitude ( ) ) ;
2019-12-31 14:08:08 +01:00
}
2015-05-03 13:48:36 +02:00
}
adapter . setCustomLocation ( userLocation ) ;
}
}
2020-04-04 12:19:59 +02:00
return super . onTouchEvent ( ev ) ;
2017-12-08 18:35:59 +01:00
}
2020-11-01 14:02:57 +01:00
@Override
protected void onLayout ( boolean changed , int left , int top , int right , int bottom ) {
super . onLayout ( changed , left , top , right , bottom ) ;
AndroidUtilities . runOnUIThread ( ( ) - > {
if ( moveToBounds ! = null ) {
mapView . zoomToBoundingBox ( moveToBounds , false , AndroidUtilities . dp ( 80 + 33 ) ) ;
moveToBounds = null ;
}
} ) ;
}
2017-12-08 18:35:59 +01:00
} ;
2020-04-04 12:19:59 +02:00
AndroidUtilities . runOnUIThread ( ( ) - > {
if ( mapView ! = null & & getParentActivity ( ) ! = null ) {
mapView . setPadding ( AndroidUtilities . dp ( 70 ) , 0 , AndroidUtilities . dp ( 70 ) , AndroidUtilities . dp ( 10 ) ) ;
onMapInit ( ) ;
mapsInitialized = true ;
if ( isActiveThemeDark ( ) ) {
/ * currentMapStyleDark = true ;
MapStyleOptions style = MapStyleOptions . loadRawResourceStyle ( ApplicationLoader . applicationContext , R . raw . mapstyle_night ) ;
googleMap . setMapStyle ( style ) ;
* /
//TODO Dark?
2019-01-23 18:03:33 +01:00
}
2020-04-04 12:19:59 +02:00
if ( onResumeCalled ) {
mapView . onResume ( ) ;
}
}
} ) ;
2015-05-03 13:48:36 +02:00
2019-07-18 15:01:39 +02:00
if ( messageObject = = null & & chatLocation = = null ) {
2020-11-01 14:02:57 +01:00
if ( chat ! = null & & locationType = = LOCATION_TYPE_GROUP & & dialogId ! = 0 ) {
FrameLayout frameLayout1 = new FrameLayout ( context ) ;
frameLayout1 . setBackgroundResource ( R . drawable . livepin ) ;
mapViewClip . addView ( frameLayout1 , LayoutHelper . createFrame ( 62 , 76 , Gravity . TOP | Gravity . CENTER_HORIZONTAL ) ) ;
2019-07-18 15:01:39 +02:00
2020-11-01 14:02:57 +01:00
BackupImageView backupImageView = new BackupImageView ( context ) ;
backupImageView . setRoundRadius ( AndroidUtilities . dp ( 26 ) ) ;
2021-04-17 01:59:59 +02:00
backupImageView . setForUserOrChat ( chat , new AvatarDrawable ( chat ) ) ;
2020-11-01 14:02:57 +01:00
frameLayout1 . addView ( backupImageView , LayoutHelper . createFrame ( 52 , 52 , Gravity . LEFT | Gravity . TOP , 5 , 5 , 0 , 0 ) ) ;
2019-07-18 15:01:39 +02:00
2020-11-01 14:02:57 +01:00
markerImageView = frameLayout1 ;
markerImageView . setTag ( 1 ) ;
2019-07-18 15:01:39 +02:00
}
2015-05-03 13:48:36 +02:00
2019-07-18 15:01:39 +02:00
if ( markerImageView = = null ) {
ImageView imageView = new ImageView ( context ) ;
imageView . setImageResource ( R . drawable . map_pin2 ) ;
mapViewClip . addView ( imageView , LayoutHelper . createFrame ( 28 , 48 , Gravity . TOP | Gravity . CENTER_HORIZONTAL ) ) ;
markerImageView = imageView ;
}
2015-05-03 13:48:36 +02:00
2017-03-31 01:58:05 +02:00
searchListView = new RecyclerListView ( context ) ;
2015-05-03 13:48:36 +02:00
searchListView . setVisibility ( View . GONE ) ;
2017-03-31 01:58:05 +02:00
searchListView . setLayoutManager ( new LinearLayoutManager ( context , LinearLayoutManager . VERTICAL , false ) ) ;
2019-12-31 14:08:08 +01:00
searchAdapter = new LocationActivitySearchAdapter ( context ) {
@Override
public void notifyDataSetChanged ( ) {
if ( searchItem ! = null ) {
searchItem . setShowSearchProgress ( searchAdapter . isSearching ( ) ) ;
}
if ( emptySubtitleTextView ! = null ) {
emptySubtitleTextView . setText ( AndroidUtilities . replaceTags ( LocaleController . formatString ( " NoPlacesFoundInfo " , R . string . NoPlacesFoundInfo , searchAdapter . getLastSearchString ( ) ) ) ) ;
}
super . notifyDataSetChanged ( ) ;
}
} ;
searchAdapter . setDelegate ( 0 , places - > {
searchInProgress = false ;
updateEmptyView ( ) ;
} ) ;
2015-05-03 13:48:36 +02:00
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 ( ) {
2015-05-03 13:48:36 +02:00
@Override
2017-03-31 01:58:05 +02:00
public void onScrollStateChanged ( RecyclerView recyclerView , int newState ) {
if ( newState = = RecyclerView . SCROLL_STATE_DRAGGING & & searching & & searchWas ) {
2015-05-03 13:48:36 +02:00
AndroidUtilities . hideKeyboard ( getParentActivity ( ) . getCurrentFocus ( ) ) ;
}
}
} ) ;
2019-01-23 18:03:33 +01:00
searchListView . setOnItemClickListener ( ( view , position ) - > {
TLRPC . TL_messageMediaVenue object = searchAdapter . getItem ( position ) ;
if ( object ! = null & & delegate ! = null ) {
2019-09-10 12:56:11 +02:00
if ( parentFragment ! = null & & parentFragment . isInScheduleMode ( ) ) {
2019-12-31 14:08:08 +01:00
AlertsCreator . createScheduleDatePickerDialog ( getParentActivity ( ) , parentFragment . getDialogId ( ) , ( notify , scheduleDate ) - > {
2019-09-10 12:56:11 +02:00
delegate . didSelectLocation ( object , locationType , notify , scheduleDate ) ;
finishFragment ( ) ;
} ) ;
} else {
delegate . didSelectLocation ( object , locationType , true , 0 ) ;
finishFragment ( ) ;
}
2015-05-03 13:48:36 +02:00
}
} ) ;
2019-07-18 15:01:39 +02:00
} else if ( messageObject ! = null & & ! messageObject . isLiveLocation ( ) | | chatLocation ! = null ) {
if ( chatLocation ! = null ) {
adapter . setChatLocation ( chatLocation ) ;
} else if ( messageObject ! = null ) {
adapter . setMessageObject ( messageObject ) ;
}
2017-12-08 18:35:59 +01:00
}
2020-11-01 14:02:57 +01:00
if ( messageObject ! = null & & locationType = = LOCATION_TYPE_LIVE_VIEW ) {
adapter . setMessageObject ( messageObject ) ;
}
for ( int a = 0 ; a < 2 ; a + + ) {
undoView [ a ] = new UndoView ( context ) ;
undoView [ a ] . setAdditionalTranslationY ( AndroidUtilities . dp ( 10 ) ) ;
if ( Build . VERSION . SDK_INT > = 21 ) {
undoView [ a ] . setTranslationZ ( AndroidUtilities . dp ( 5 ) ) ;
}
mapViewClip . addView ( undoView [ a ] , LayoutHelper . createFrame ( LayoutHelper . MATCH_PARENT , LayoutHelper . WRAP_CONTENT , Gravity . BOTTOM | Gravity . LEFT , 8 , 0 , 8 , 8 ) ) ;
}
2017-12-08 18:35:59 +01:00
2019-12-31 14:08:08 +01:00
shadow = new View ( context ) {
private RectF rect = new RectF ( ) ;
@Override
protected void onDraw ( Canvas canvas ) {
shadowDrawable . setBounds ( - padding . left , 0 , getMeasuredWidth ( ) + padding . right , getMeasuredHeight ( ) ) ;
shadowDrawable . draw ( canvas ) ;
if ( locationType = = LOCATION_TYPE_SEND | | locationType = = LOCATION_TYPE_SEND_WITH_LIVE ) {
int w = AndroidUtilities . dp ( 36 ) ;
int y = padding . top + AndroidUtilities . dp ( 10 ) ;
rect . set ( ( getMeasuredWidth ( ) - w ) / 2 , y , ( getMeasuredWidth ( ) + w ) / 2 , y + AndroidUtilities . dp ( 4 ) ) ;
int color = Theme . getColor ( Theme . key_sheet_scrollUp ) ;
int alpha = Color . alpha ( color ) ;
Theme . dialogs_onlineCirclePaint . setColor ( color ) ;
canvas . drawRoundRect ( rect , AndroidUtilities . dp ( 2 ) , AndroidUtilities . dp ( 2 ) , Theme . dialogs_onlineCirclePaint ) ;
2017-12-08 18:35:59 +01:00
}
}
2019-12-31 14:08:08 +01:00
} ;
2020-11-01 14:02:57 +01:00
if ( Build . VERSION . SDK_INT > = 21 ) {
shadow . setTranslationZ ( AndroidUtilities . dp ( 6 ) ) ;
}
2019-12-31 14:08:08 +01:00
mapViewClip . addView ( shadow , layoutParams ) ;
if ( messageObject = = null & & chatLocation = = null & & initialLocation ! = null ) {
userLocationMoved = true ;
2020-11-01 14:02:57 +01:00
locationButton . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_location_actionIcon ) , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
locationButton . setTag ( Theme . key_location_actionIcon ) ;
2015-04-09 20:00:14 +02:00
}
2017-12-08 18:35:59 +01:00
frameLayout . addView ( actionBar ) ;
2019-12-31 14:08:08 +01:00
updateEmptyView ( ) ;
2017-12-08 18:35:59 +01:00
2016-10-11 13:57:01 +02:00
return fragmentView ;
}
2020-01-02 16:08:53 +01:00
private boolean isActiveThemeDark ( ) {
Theme . ThemeInfo info = Theme . getActiveTheme ( ) ;
if ( info . isDark ( ) ) {
return true ;
}
int color = Theme . getColor ( Theme . key_windowBackgroundWhite ) ;
return AndroidUtilities . computePerceivedBrightness ( color ) < 0 . 721f ;
}
2019-12-31 14:08:08 +01:00
private void updateEmptyView ( ) {
if ( searching ) {
if ( searchInProgress ) {
searchListView . setEmptyView ( null ) ;
emptyView . setVisibility ( View . GONE ) ;
searchListView . setVisibility ( View . GONE ) ;
} else {
searchListView . setEmptyView ( emptyView ) ;
}
} else {
emptyView . setVisibility ( View . GONE ) ;
}
}
private void showSearchPlacesButton ( boolean show ) {
if ( show & & searchAreaButton ! = null & & searchAreaButton . getTag ( ) = = null ) {
if ( myLocation = = null | | userLocation = = null | | userLocation . distanceTo ( myLocation ) < 300 ) {
show = false ;
}
}
if ( searchAreaButton = = null | | show & & searchAreaButton . getTag ( ) ! = null | | ! show & & searchAreaButton . getTag ( ) = = null ) {
return ;
}
searchAreaButton . setTag ( show ? 1 : null ) ;
AnimatorSet animatorSet = new AnimatorSet ( ) ;
animatorSet . playTogether ( ObjectAnimator . ofFloat ( searchAreaButton , View . TRANSLATION_X , show ? 0 : - AndroidUtilities . dp ( 80 ) ) ) ;
animatorSet . setDuration ( 180 ) ;
animatorSet . setInterpolator ( CubicBezierInterpolator . EASE_OUT ) ;
animatorSet . start ( ) ;
}
2020-04-04 12:19:59 +02:00
private TextView getAttributionOverlay ( Context context ) {
attributionOverlay = new TextView ( context ) ;
attributionOverlay . setText ( Html . fromHtml ( " © <a href= \" https://www.openstreetmap.org/copyright \" >OpenStreetMap</a> contributors " ) ) ;
2020-11-01 14:02:57 +01:00
attributionOverlay . setShadowLayer ( 1 , - 1 , - 1 , Color . WHITE ) ;
2020-04-04 12:19:59 +02:00
attributionOverlay . setLinksClickable ( true ) ;
attributionOverlay . setMovementMethod ( LinkMovementMethod . getInstance ( ) ) ;
return attributionOverlay ;
}
2017-12-08 18:35:59 +01:00
private Bitmap createUserBitmap ( LiveLocation liveLocation ) {
Bitmap result = null ;
try {
TLRPC . FileLocation photo = null ;
if ( liveLocation . user ! = null & & liveLocation . user . photo ! = null ) {
photo = liveLocation . user . photo . photo_small ;
} else if ( liveLocation . chat ! = null & & liveLocation . chat . photo ! = null ) {
photo = liveLocation . chat . photo . photo_small ;
}
2020-11-01 14:02:57 +01:00
result = Bitmap . createBitmap ( AndroidUtilities . dp ( 62 ) , AndroidUtilities . dp ( 85 ) , Bitmap . Config . ARGB_8888 ) ;
2017-12-08 18:35:59 +01:00
result . eraseColor ( Color . TRANSPARENT ) ;
Canvas canvas = new Canvas ( result ) ;
2020-11-01 14:02:57 +01:00
Drawable drawable = ApplicationLoader . applicationContext . getResources ( ) . getDrawable ( R . drawable . map_pin_photo ) ;
drawable . setBounds ( 0 , 0 , AndroidUtilities . dp ( 62 ) , AndroidUtilities . dp ( 85 ) ) ;
2017-12-08 18:35:59 +01:00
drawable . draw ( canvas ) ;
Paint roundPaint = new Paint ( Paint . ANTI_ALIAS_FLAG ) ;
RectF bitmapRect = new RectF ( ) ;
canvas . save ( ) ;
if ( photo ! = null ) {
2022-06-21 04:51:00 +02:00
File path = getFileLoader ( ) . getPathToAttach ( photo , true ) ;
2017-12-08 18:35:59 +01:00
Bitmap bitmap = BitmapFactory . decodeFile ( path . toString ( ) ) ;
if ( bitmap ! = null ) {
BitmapShader shader = new BitmapShader ( bitmap , Shader . TileMode . CLAMP , Shader . TileMode . CLAMP ) ;
Matrix matrix = new Matrix ( ) ;
2020-11-01 14:02:57 +01:00
float scale = AndroidUtilities . dp ( 50 ) / ( float ) bitmap . getWidth ( ) ;
matrix . postTranslate ( AndroidUtilities . dp ( 6 ) , AndroidUtilities . dp ( 6 ) ) ;
2017-12-08 18:35:59 +01:00
matrix . postScale ( scale , scale ) ;
roundPaint . setShader ( shader ) ;
shader . setLocalMatrix ( matrix ) ;
2020-11-01 14:02:57 +01:00
bitmapRect . set ( AndroidUtilities . dp ( 6 ) , AndroidUtilities . dp ( 6 ) , AndroidUtilities . dp ( 50 + 6 ) , AndroidUtilities . dp ( 50 + 6 ) ) ;
canvas . drawRoundRect ( bitmapRect , AndroidUtilities . dp ( 25 ) , AndroidUtilities . dp ( 25 ) , roundPaint ) ;
2017-12-08 18:35:59 +01:00
}
} else {
AvatarDrawable avatarDrawable = new AvatarDrawable ( ) ;
if ( liveLocation . user ! = null ) {
avatarDrawable . setInfo ( liveLocation . user ) ;
} else if ( liveLocation . chat ! = null ) {
avatarDrawable . setInfo ( liveLocation . chat ) ;
}
2020-11-01 14:02:57 +01:00
canvas . translate ( AndroidUtilities . dp ( 6 ) , AndroidUtilities . dp ( 6 ) ) ;
avatarDrawable . setBounds ( 0 , 0 , AndroidUtilities . dp ( 50 ) , AndroidUtilities . dp ( 50 ) ) ;
2017-12-08 18:35:59 +01:00
avatarDrawable . draw ( canvas ) ;
}
canvas . restore ( ) ;
try {
canvas . setBitmap ( null ) ;
} catch ( Exception e ) {
//don't promt, this will crash on 2.x
}
} catch ( Throwable e ) {
FileLog . e ( e ) ;
}
return result ;
}
2021-09-20 00:10:42 +02:00
private long getMessageId ( TLRPC . Message message ) {
2020-09-30 15:48:47 +02:00
if ( message . from_id ! = null ) {
return MessageObject . getFromChatId ( message ) ;
2017-12-08 18:35:59 +01:00
} else {
2021-09-20 00:10:42 +02:00
return MessageObject . getDialogId ( message ) ;
2017-12-08 18:35:59 +01:00
}
}
2020-11-01 14:02:57 +01:00
private void openProximityAlert ( ) {
if ( proximityCircle = = null ) {
createCircle ( 500 ) ;
proximityCircleRadius = 500 ;
} else {
previousRadius = proximityCircleRadius ;
}
TLRPC . User user ;
2021-09-20 00:10:42 +02:00
if ( DialogObject . isUserDialog ( dialogId ) ) {
user = getMessagesController ( ) . getUser ( dialogId ) ;
2020-11-01 14:02:57 +01:00
} else {
user = null ;
}
proximitySheet = new ProximitySheet ( getParentActivity ( ) , user , ( move , radius ) - > {
if ( proximityCircle ! = null ) {
proximityCircleRadius = radius ;
proximityCircle . setPoints ( Polygon . pointsAsCircle ( proximityCircleCenter , radius ) ) ;
if ( move ) {
moveToBounds ( radius , true , true ) ;
}
}
2021-09-20 00:10:42 +02:00
if ( DialogObject . isChatDialog ( dialogId ) ) {
2020-11-01 14:02:57 +01:00
return true ;
}
for ( int a = 0 , N = markers . size ( ) ; a < N ; a + + ) {
LiveLocation location = markers . get ( a ) ;
if ( location . object = = null | | UserObject . isUserSelf ( location . user ) ) {
continue ;
}
TLRPC . GeoPoint point = location . object . media . geo ;
Location loc = new Location ( " network " ) ;
loc . setLatitude ( point . lat ) ;
loc . setLongitude ( point . _long ) ;
if ( myLocation . distanceTo ( loc ) > radius ) {
return true ;
}
}
return false ;
} , ( move , radius ) - > {
LocationController . SharingLocationInfo info = getLocationController ( ) . getSharingLocationInfo ( dialogId ) ;
if ( info = = null ) {
AlertDialog . Builder builder = new AlertDialog . Builder ( getParentActivity ( ) ) ;
builder . setTitle ( LocaleController . getString ( " ShareLocationAlertTitle " , R . string . ShareLocationAlertTitle ) ) ;
builder . setMessage ( LocaleController . getString ( " ShareLocationAlertText " , R . string . ShareLocationAlertText ) ) ;
builder . setPositiveButton ( LocaleController . getString ( " ShareLocationAlertButton " , R . string . ShareLocationAlertButton ) , ( dialog , id ) - > shareLiveLocation ( user , 900 , radius ) ) ;
builder . setNegativeButton ( LocaleController . getString ( " Cancel " , R . string . Cancel ) , null ) ;
showDialog ( builder . create ( ) ) ;
return false ;
}
proximitySheet . setRadiusSet ( ) ;
proximityButton . setImageResource ( R . drawable . msg_location_alert2 ) ;
getUndoView ( ) . showWithAction ( 0 , UndoView . ACTION_PROXIMITY_SET , radius , user , null , null ) ;
getLocationController ( ) . setProximityLocation ( dialogId , radius , true ) ;
return true ;
} , ( ) - > {
if ( mapView ! = null ) {
mapView . setPadding ( AndroidUtilities . dp ( 70 ) , 0 , AndroidUtilities . dp ( 70 ) , AndroidUtilities . dp ( 10 ) ) ;
}
if ( ! proximitySheet . getRadiusSet ( ) ) {
if ( previousRadius > 0 ) {
proximityCircleRadius = previousRadius ;
proximityCircle . setPoints ( Polygon . pointsAsCircle ( proximityCircleCenter , previousRadius ) ) ;
} else if ( proximityCircle ! = null ) {
mapView . getOverlayManager ( ) . remove ( proximityCircle ) ;
proximityCircle = null ;
}
}
proximitySheet = null ;
} ) ;
FrameLayout frameLayout = ( FrameLayout ) fragmentView ;
frameLayout . addView ( proximitySheet , LayoutHelper . createFrame ( LayoutHelper . MATCH_PARENT , LayoutHelper . MATCH_PARENT ) ) ;
proximitySheet . show ( ) ;
}
private void openShareLiveLocation ( int proximityRadius ) {
if ( delegate = = null | | getParentActivity ( ) = = null | | myLocation = = null | | ! checkGpsEnabled ( ) ) {
2019-12-31 14:08:08 +01:00
return ;
}
2020-11-01 14:02:57 +01:00
if ( checkBackgroundPermission & & Build . VERSION . SDK_INT > = 29 ) {
Activity activity = getParentActivity ( ) ;
if ( activity ! = null ) {
askWithRadius = proximityRadius ;
checkBackgroundPermission = false ;
SharedPreferences preferences = MessagesController . getGlobalMainSettings ( ) ;
int lastTime = preferences . getInt ( " backgroundloc " , 0 ) ;
if ( Math . abs ( System . currentTimeMillis ( ) / 1000 - lastTime ) > 24 * 60 * 60 & & activity . checkSelfPermission ( Manifest . permission . ACCESS_BACKGROUND_LOCATION ) ! = PackageManager . PERMISSION_GRANTED ) {
preferences . edit ( ) . putInt ( " backgroundloc " , ( int ) ( System . currentTimeMillis ( ) / 1000 ) ) . commit ( ) ;
2021-09-20 00:10:42 +02:00
AlertsCreator . createBackgroundLocationPermissionDialog ( activity , getMessagesController ( ) . getUser ( getUserConfig ( ) . getClientUserId ( ) ) , ( ) - > openShareLiveLocation ( askWithRadius ) , null ) . show ( ) ;
2020-11-01 14:02:57 +01:00
return ;
}
}
}
TLRPC . User user ;
2021-09-20 00:10:42 +02:00
if ( DialogObject . isUserDialog ( dialogId ) ) {
user = getMessagesController ( ) . getUser ( dialogId ) ;
2020-11-01 14:02:57 +01:00
} else {
user = null ;
2019-12-31 14:08:08 +01:00
}
2021-09-20 00:10:42 +02:00
showDialog ( AlertsCreator . createLocationUpdateDialog ( getParentActivity ( ) , user , param - > shareLiveLocation ( user , param , proximityRadius ) , null ) ) ;
2020-11-01 14:02:57 +01:00
}
private void shareLiveLocation ( TLRPC . User user , int period , int radius ) {
TLRPC . TL_messageMediaGeoLive location = new TLRPC . TL_messageMediaGeoLive ( ) ;
location . geo = new TLRPC . TL_geoPoint ( ) ;
location . geo . lat = AndroidUtilities . fixLocationCoord ( myLocation . getLatitude ( ) ) ;
location . geo . _long = AndroidUtilities . fixLocationCoord ( myLocation . getLongitude ( ) ) ;
location . heading = LocationController . getHeading ( myLocation ) ;
location . flags | = 1 ;
location . period = period ;
location . proximity_notification_radius = radius ;
location . flags | = 8 ;
delegate . didSelectLocation ( location , locationType , true , 0 ) ;
if ( radius > 0 ) {
proximitySheet . setRadiusSet ( ) ;
proximityButton . setImageResource ( R . drawable . msg_location_alert2 ) ;
if ( proximitySheet ! = null ) {
proximitySheet . dismiss ( ) ;
}
getUndoView ( ) . showWithAction ( 0 , UndoView . ACTION_PROXIMITY_SET , radius , user , null , null ) ;
} else {
2019-12-31 14:08:08 +01:00
finishFragment ( ) ;
2020-11-01 14:02:57 +01:00
}
2019-12-31 14:08:08 +01:00
}
private Bitmap [ ] bitmapCache = new Bitmap [ 7 ] ;
2020-11-01 14:02:57 +01:00
2019-12-31 14:08:08 +01:00
private Bitmap createPlaceBitmap ( int num ) {
if ( bitmapCache [ num % 7 ] ! = null ) {
return bitmapCache [ num % 7 ] ;
}
try {
Paint paint = new Paint ( Paint . ANTI_ALIAS_FLAG ) ;
paint . setColor ( 0xffffffff ) ;
Bitmap bitmap = Bitmap . createBitmap ( AndroidUtilities . dp ( 12 ) , AndroidUtilities . dp ( 12 ) , Bitmap . Config . ARGB_8888 ) ;
Canvas canvas = new Canvas ( bitmap ) ;
canvas . drawCircle ( AndroidUtilities . dp ( 6 ) , AndroidUtilities . dp ( 6 ) , AndroidUtilities . dp ( 6 ) , paint ) ;
paint . setColor ( LocationCell . getColorForIndex ( num ) ) ;
canvas . drawCircle ( AndroidUtilities . dp ( 6 ) , AndroidUtilities . dp ( 6 ) , AndroidUtilities . dp ( 5 ) , paint ) ;
canvas . setBitmap ( null ) ;
return bitmapCache [ num % 7 ] = bitmap ;
} catch ( Throwable e ) {
FileLog . e ( e ) ;
}
return null ;
}
private void updatePlacesMarkers ( ArrayList < TLRPC . TL_messageMediaVenue > places ) {
if ( places = = null ) {
return ;
}
for ( int a = 0 , N = placeMarkers . size ( ) ; a < N ; a + + ) {
2020-04-04 12:19:59 +02:00
placeMarkers . get ( a ) . marker . remove ( mapView ) ;
2019-12-31 14:08:08 +01:00
}
placeMarkers . clear ( ) ;
for ( int a = 0 , N = places . size ( ) ; a < N ; a + + ) {
TLRPC . TL_messageMediaVenue venue = places . get ( a ) ;
try {
2020-04-04 12:19:59 +02:00
Marker marker = new Marker ( mapView ) ;
marker . setPosition ( new GeoPoint ( venue . geo . lat , venue . geo . _long ) ) ;
marker . setIcon ( new BitmapDrawable ( getParentActivity ( ) . getResources ( ) , createPlaceBitmap ( a ) ) ) ;
marker . setAnchor ( 0 . 5f , 0 . 5f ) ;
mapView . getOverlays ( ) . add ( marker ) ;
marker . setTitle ( venue . title ) ;
marker . setSnippet ( venue . address ) ;
2019-12-31 14:08:08 +01:00
VenueLocation venueLocation = new VenueLocation ( ) ;
venueLocation . num = a ;
2020-04-04 12:19:59 +02:00
venueLocation . marker = marker ;
2019-12-31 14:08:08 +01:00
venueLocation . venue = venue ;
placeMarkers . add ( venueLocation ) ;
2020-04-04 12:19:59 +02:00
marker . setOnMarkerClickListener ( new Marker . OnMarkerClickListener ( ) {
@Override
public boolean onMarkerClick ( Marker marker , MapView mapView ) {
markerImageView . setVisibility ( View . INVISIBLE ) ;
if ( ! userLocationMoved ) {
2020-11-01 14:02:57 +01:00
locationButton . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_location_actionIcon ) , PorterDuff . Mode . MULTIPLY ) ) ;
2020-04-04 12:19:59 +02:00
locationButton . setTag ( Theme . key_location_actionIcon ) ;
userLocationMoved = true ;
}
overlayView . addInfoView ( marker , venueLocation ) ;
return true ;
}
} ) ;
2019-12-31 14:08:08 +01:00
} catch ( Exception e ) {
FileLog . e ( e ) ;
}
}
}
2017-12-08 18:35:59 +01:00
private LiveLocation addUserMarker ( TLRPC . Message message ) {
LiveLocation liveLocation ;
2020-04-04 12:19:59 +02:00
GeoPoint latLng = new GeoPoint ( message . media . geo . lat , message . media . geo . _long ) ;
2020-09-30 15:48:47 +02:00
if ( ( liveLocation = markersMap . get ( MessageObject . getFromChatId ( message ) ) ) = = null ) {
2017-12-08 18:35:59 +01:00
liveLocation = new LiveLocation ( ) ;
liveLocation . object = message ;
2020-09-30 15:48:47 +02:00
if ( liveLocation . object . from_id instanceof TLRPC . TL_peerUser ) {
liveLocation . user = getMessagesController ( ) . getUser ( liveLocation . object . from_id . user_id ) ;
liveLocation . id = liveLocation . object . from_id . user_id ;
2017-12-08 18:35:59 +01:00
} else {
2021-09-20 00:10:42 +02:00
long did = MessageObject . getDialogId ( message ) ;
if ( DialogObject . isUserDialog ( did ) ) {
2019-07-18 15:01:39 +02:00
liveLocation . user = getMessagesController ( ) . getUser ( did ) ;
2017-12-08 18:35:59 +01:00
} else {
2019-07-18 15:01:39 +02:00
liveLocation . chat = getMessagesController ( ) . getChat ( - did ) ;
2017-12-08 18:35:59 +01:00
}
2020-09-30 15:48:47 +02:00
liveLocation . id = did ;
2017-12-08 18:35:59 +01:00
}
try {
2020-04-04 12:19:59 +02:00
Marker marker = new Marker ( mapView ) ;
marker . setPosition ( latLng ) ;
// InfoWindow workaround
marker . setOnMarkerClickListener ( new Marker . OnMarkerClickListener ( ) {
@Override
public boolean onMarkerClick ( Marker marker , MapView mapView ) {
return false ;
}
} ) ;
2017-12-08 18:35:59 +01:00
Bitmap bitmap = createUserBitmap ( liveLocation ) ;
if ( bitmap ! = null ) {
2020-04-04 12:19:59 +02:00
marker . setIcon ( new BitmapDrawable ( getParentActivity ( ) . getResources ( ) , bitmap ) ) ;
marker . setAnchor ( 0 . 5f , 0 . 907f ) ;
mapView . getOverlays ( ) . add ( marker ) ;
liveLocation . marker = marker ;
2020-11-01 14:02:57 +01:00
if ( ! UserObject . isUserSelf ( liveLocation . user ) ) {
Marker directionMarker = new Marker ( mapView ) ;
directionMarker . setPosition ( latLng ) ;
directionMarker . setFlat ( true ) ;
directionMarker . setIcon ( getParentActivity ( ) . getResources ( ) . getDrawable ( R . drawable . map_pin_circle ) ) ;
directionMarker . setAnchor ( 0 . 5f , 0 . 5f ) ;
mapView . getOverlayManager ( ) . add ( directionMarker ) ;
liveLocation . directionMarker = directionMarker ;
if ( message . media . heading ! = 0 ) {
liveLocation . directionMarker . setRotation ( message . media . heading ) ;
liveLocation . directionMarker . setIcon ( getParentActivity ( ) . getResources ( ) . getDrawable ( R . drawable . map_pin_cone2 ) ) ;
liveLocation . hasRotation = true ;
} else {
liveLocation . directionMarker . setRotation ( 0 ) ;
liveLocation . directionMarker . setIcon ( getParentActivity ( ) . getResources ( ) . getDrawable ( R . drawable . map_pin_circle ) ) ;
liveLocation . hasRotation = false ;
}
}
2017-12-08 18:35:59 +01:00
markers . add ( liveLocation ) ;
markersMap . put ( liveLocation . id , liveLocation ) ;
2019-07-18 15:01:39 +02:00
LocationController . SharingLocationInfo myInfo = getLocationController ( ) . getSharingLocationInfo ( dialogId ) ;
if ( liveLocation . id = = getUserConfig ( ) . getClientUserId ( ) & & myInfo ! = null & & liveLocation . object . id = = myInfo . mid & & myLocation ! = null ) {
2020-11-01 14:02:57 +01:00
GeoPoint latLng1 = new GeoPoint ( myLocation . getLatitude ( ) , myLocation . getLongitude ( ) ) ;
liveLocation . marker . setPosition ( latLng1 ) ;
2017-12-08 18:35:59 +01:00
}
}
} catch ( Exception e ) {
FileLog . e ( e ) ;
}
} else {
liveLocation . object = message ;
liveLocation . marker . setPosition ( latLng ) ;
}
2020-11-01 14:02:57 +01:00
if ( proximitySheet ! = null ) {
proximitySheet . updateText ( true , true ) ;
}
2017-12-08 18:35:59 +01:00
return liveLocation ;
}
2019-07-18 15:01:39 +02:00
private LiveLocation addUserMarker ( TLRPC . TL_channelLocation location ) {
2020-04-04 12:19:59 +02:00
GeoPoint latLng = new GeoPoint ( location . geo_point . lat , location . geo_point . _long ) ;
2019-07-18 15:01:39 +02:00
LiveLocation liveLocation = new LiveLocation ( ) ;
2021-09-20 00:10:42 +02:00
if ( DialogObject . isUserDialog ( dialogId ) ) {
liveLocation . user = getMessagesController ( ) . getUser ( dialogId ) ;
2019-07-18 15:01:39 +02:00
} else {
2021-09-20 00:10:42 +02:00
liveLocation . chat = getMessagesController ( ) . getChat ( - dialogId ) ;
2019-07-18 15:01:39 +02:00
}
2021-09-20 00:10:42 +02:00
liveLocation . id = dialogId ;
2019-07-18 15:01:39 +02:00
try {
2020-04-04 12:19:59 +02:00
Marker marker = new Marker ( mapView ) ;
marker . setPosition ( latLng ) ;
// InfoWindow workaround
marker . setOnMarkerClickListener ( new Marker . OnMarkerClickListener ( ) {
@Override
public boolean onMarkerClick ( Marker marker , MapView mapView ) {
return false ;
}
} ) ;
2019-07-18 15:01:39 +02:00
Bitmap bitmap = createUserBitmap ( liveLocation ) ;
if ( bitmap ! = null ) {
2020-04-04 12:19:59 +02:00
marker . setIcon ( new BitmapDrawable ( getParentActivity ( ) . getResources ( ) , bitmap ) ) ;
marker . setAnchor ( 0 . 5f , 0 . 907f ) ;
mapView . getOverlays ( ) . add ( marker ) ;
liveLocation . marker = marker ;
2020-11-01 14:02:57 +01:00
if ( ! UserObject . isUserSelf ( liveLocation . user ) ) {
Marker directionMarker = new Marker ( mapView ) ;
;
directionMarker . setPosition ( latLng ) ;
directionMarker . setFlat ( true ) ;
directionMarker . setIcon ( getParentActivity ( ) . getResources ( ) . getDrawable ( R . drawable . map_pin_circle ) ) ;
directionMarker . setAnchor ( 0 . 5f , 0 . 5f ) ;
mapView . getOverlayManager ( ) . add ( directionMarker ) ;
liveLocation . directionMarker = directionMarker ;
}
2019-07-18 15:01:39 +02:00
markers . add ( liveLocation ) ;
markersMap . put ( liveLocation . id , liveLocation ) ;
}
} catch ( Exception e ) {
FileLog . e ( e ) ;
}
return liveLocation ;
}
2016-10-11 13:57:01 +02:00
private void onMapInit ( ) {
2020-04-04 12:19:59 +02:00
if ( mapView = = null ) {
2016-10-11 13:57:01 +02:00
return ;
}
2020-04-04 12:19:59 +02:00
//Paris, Tour Eiffel
2020-11-01 14:02:57 +01:00
GeoPoint initLocation = new GeoPoint ( 48 . 85825 , 2 . 29448 ) ;
2020-04-04 12:19:59 +02:00
final IMapController controller = mapView . getController ( ) ;
mapView . setMaxZoomLevel ( 20 . 0 ) ;
mapView . setMultiTouchControls ( true ) ;
mapView . setBuiltInZoomControls ( false ) ;
controller . setCenter ( initLocation ) ;
controller . setZoom ( 7 . ) ;
2019-07-18 15:01:39 +02:00
if ( chatLocation ! = null ) {
LiveLocation liveLocation = addUserMarker ( chatLocation ) ;
2020-04-04 12:19:59 +02:00
controller . setCenter ( liveLocation . marker . getPosition ( ) ) ;
controller . setZoom ( mapView . getMaxZoomLevel ( ) - 2 ) ;
2019-07-18 15:01:39 +02:00
} else if ( messageObject ! = null ) {
2017-12-08 18:35:59 +01:00
if ( messageObject . isLiveLocation ( ) ) {
LiveLocation liveLocation = addUserMarker ( messageObject . messageOwner ) ;
if ( ! getRecentLocations ( ) ) {
2020-04-04 12:19:59 +02:00
controller . setCenter ( liveLocation . marker . getPosition ( ) ) ;
controller . setZoom ( mapView . getMaxZoomLevel ( ) - 2 ) ;
2017-12-08 18:35:59 +01:00
}
} else {
2020-04-04 12:19:59 +02:00
GeoPoint latLng = new GeoPoint ( userLocation . getLatitude ( ) , userLocation . getLongitude ( ) ) ;
Marker marker = new Marker ( mapView ) ;
marker . setPosition ( latLng ) ;
// InfoWindow workaround
marker . setOnMarkerClickListener ( new Marker . OnMarkerClickListener ( ) {
@Override
public boolean onMarkerClick ( Marker marker , MapView mapView ) {
return false ;
}
} ) ;
if ( Build . VERSION . SDK_INT > = 21 ) {
marker . setIcon ( getParentActivity ( ) . getDrawable ( R . drawable . map_pin ) ) ;
} else {
marker . setIcon ( getParentActivity ( ) . getResources ( ) . getDrawable ( R . drawable . map_pin2 ) ) ;
2017-12-08 18:35:59 +01:00
}
2020-04-04 12:19:59 +02:00
marker . setAnchor ( Marker . ANCHOR_CENTER , Marker . ANCHOR_BOTTOM ) ;
mapView . getOverlays ( ) . add ( marker ) ;
controller . setCenter ( latLng ) ;
controller . setZoom ( mapView . getMaxZoomLevel ( ) - 2 ) ;
2017-12-08 18:35:59 +01:00
firstFocus = false ;
getRecentLocations ( ) ;
2016-01-11 18:19:48 +01:00
}
2016-10-11 13:57:01 +02:00
} else {
userLocation = new Location ( " network " ) ;
2019-07-18 15:01:39 +02:00
if ( initialLocation ! = null ) {
2020-04-04 12:19:59 +02:00
GeoPoint latLng = new GeoPoint ( initialLocation . geo_point . lat , initialLocation . geo_point . _long ) ;
controller . setCenter ( latLng ) ;
controller . setZoom ( mapView . getMaxZoomLevel ( ) - 2 ) ;
2019-07-18 15:01:39 +02:00
userLocation . setLatitude ( initialLocation . geo_point . lat ) ;
userLocation . setLongitude ( initialLocation . geo_point . _long ) ;
adapter . setCustomLocation ( userLocation ) ;
} else {
2020-04-04 12:19:59 +02:00
userLocation . setLatitude ( 48 . 85825 ) ;
userLocation . setLongitude ( 2 . 29448 ) ;
2019-07-18 15:01:39 +02:00
}
2015-05-03 13:48:36 +02:00
}
2014-06-04 01:31:48 +02:00
2020-04-04 12:19:59 +02:00
GpsMyLocationProvider imlp = new GpsMyLocationProvider ( getParentActivity ( ) ) ;
imlp . setLocationUpdateMinDistance ( 10 ) ;
imlp . setLocationUpdateMinTime ( 10000 ) ;
imlp . addLocationSource ( LocationManager . NETWORK_PROVIDER ) ;
myLocationOverlay = new MyLocationNewOverlay ( imlp , mapView ) {
@Override
public void onLocationChanged ( final Location location , IMyLocationProvider source ) {
super . onLocationChanged ( location , source ) ;
if ( location ! = null ) {
AndroidUtilities . runOnUIThread ( new Runnable ( ) {
@Override
public void run ( ) {
positionMarker ( location ) ;
LocationController . getInstance ( currentAccount ) . setGoogleMapLocation ( location , isFirstLocation ) ;
isFirstLocation = false ;
}
} ) ;
}
}
} ;
myLocationOverlay . enableMyLocation ( ) ;
myLocationOverlay . setDrawAccuracyEnabled ( true ) ;
2020-11-01 14:02:57 +01:00
myLocationOverlay . setPersonIcon ( BitmapFactory . decodeResource ( getParentActivity ( ) . getResources ( ) , R . drawable . map_pin_circle ) ) ;
2020-04-04 12:19:59 +02:00
//TODO
mapView . addMapListener ( new MapListener ( ) {
@Override
public boolean onScroll ( ScrollEvent event ) {
2019-12-31 14:08:08 +01:00
showSearchPlacesButton ( true ) ;
removeInfoView ( ) ;
if ( ! scrolling & & ( locationType = = LOCATION_TYPE_SEND | | locationType = = LOCATION_TYPE_SEND_WITH_LIVE ) & & listView . getChildCount ( ) > 0 ) {
View view = listView . getChildAt ( 0 ) ;
if ( view ! = null ) {
RecyclerView . ViewHolder holder = listView . findContainingViewHolder ( view ) ;
if ( holder ! = null & & holder . getAdapterPosition ( ) = = 0 ) {
int min = locationType = = LOCATION_TYPE_SEND ? 0 : AndroidUtilities . dp ( 66 ) ;
int top = view . getTop ( ) ;
if ( top < - min ) {
2020-04-04 12:19:59 +02:00
forceUpdate = mapView . getMapCenter ( ) ; //TODO. Strange variable
2019-12-31 14:08:08 +01:00
listView . smoothScrollBy ( 0 , top + min ) ;
}
}
}
}
2020-04-04 12:19:59 +02:00
return false ;
2019-12-31 14:08:08 +01:00
}
2020-04-04 12:19:59 +02:00
@Override
public boolean onZoom ( ZoomEvent event ) {
return false ;
2019-12-31 14:08:08 +01:00
}
2020-04-04 12:19:59 +02:00
} ) ;
myLocationOverlay . runOnFirstFix ( new Runnable ( ) {
public void run ( ) {
AndroidUtilities . runOnUIThread ( new Runnable ( ) {
@Override
public void run ( ) {
positionMarker ( myLocationOverlay . getLastFix ( ) ) ;
getLocationController ( ) . getInstance ( currentAccount ) . setGoogleMapLocation ( myLocationOverlay . getLastFix ( ) , isFirstLocation ) ;
isFirstLocation = false ;
}
} ) ;
2019-12-31 14:08:08 +01:00
}
} ) ;
2020-04-04 12:19:59 +02:00
mapView . getOverlays ( ) . add ( myLocationOverlay ) ;
mapView . addMapListener ( new MapListener ( ) {
@Override
public boolean onScroll ( ScrollEvent event ) {
if ( overlayView ! = null ) {
overlayView . updatePositions ( ) ;
}
return false ;
}
@Override
public boolean onZoom ( ZoomEvent event ) {
return false ;
2019-12-31 14:08:08 +01:00
}
} ) ;
2016-10-11 13:57:01 +02:00
positionMarker ( myLocation = getLastLocation ( ) ) ;
2020-04-04 12:19:59 +02:00
attributionOverlay . bringToFront ( ) ;
2017-12-08 18:35:59 +01:00
if ( checkGpsEnabled & & getParentActivity ( ) ! = null ) {
checkGpsEnabled = false ;
2020-11-01 14:02:57 +01:00
checkGpsEnabled ( ) ;
}
if ( proximityButton ! = null & & proximityButton . getVisibility ( ) = = View . VISIBLE ) {
LocationController . SharingLocationInfo myInfo = getLocationController ( ) . getSharingLocationInfo ( dialogId ) ;
if ( myInfo ! = null & & myInfo . proximityMeters > 0 ) {
createCircle ( myInfo . proximityMeters ) ;
2018-07-30 04:07:02 +02:00
}
2020-11-01 14:02:57 +01:00
}
}
2019-01-23 18:03:33 +01:00
2020-11-01 14:02:57 +01:00
private boolean checkGpsEnabled ( ) {
if ( ! getParentActivity ( ) . getPackageManager ( ) . hasSystemFeature ( PackageManager . FEATURE_LOCATION_GPS ) ) {
return true ;
}
try {
LocationManager lm = ( LocationManager ) ApplicationLoader . applicationContext . getSystemService ( Context . LOCATION_SERVICE ) ;
if ( ! lm . isProviderEnabled ( LocationManager . GPS_PROVIDER ) ) {
AlertDialog . Builder builder = new AlertDialog . Builder ( getParentActivity ( ) ) ;
2022-03-11 17:49:54 +01:00
builder . setTopAnimation ( R . raw . permission_request_location , AlertsCreator . PERMISSIONS_REQUEST_TOP_ICON_SIZE , false , Theme . getColor ( Theme . key_dialogTopBackground ) ) ;
2020-11-01 14:02:57 +01:00
builder . setMessage ( LocaleController . getString ( " GpsDisabledAlertText " , R . string . GpsDisabledAlertText ) ) ;
builder . setPositiveButton ( LocaleController . getString ( " ConnectingToProxyEnable " , R . string . ConnectingToProxyEnable ) , ( dialog , id ) - > {
if ( getParentActivity ( ) = = null ) {
return ;
}
try {
getParentActivity ( ) . startActivity ( new Intent ( android . provider . Settings . ACTION_LOCATION_SOURCE_SETTINGS ) ) ;
} catch ( Exception ignore ) {
}
} ) ;
builder . setNegativeButton ( LocaleController . getString ( " Cancel " , R . string . Cancel ) , null ) ;
showDialog ( builder . create ( ) ) ;
return false ;
2017-12-08 18:35:59 +01:00
}
2020-11-01 14:02:57 +01:00
} catch ( Exception e ) {
FileLog . e ( e ) ;
2017-12-08 18:35:59 +01:00
}
2020-11-01 14:02:57 +01:00
return true ;
}
private void createCircle ( int meters ) {
if ( mapView = = null ) {
return ;
}
proximityCircleCenter = new GeoPoint ( myLocation . getLatitude ( ) , myLocation . getLongitude ( ) ) ;
proximityCircleRadius = meters ;
proximityCircle = new Polygon ( ) ;
proximityCircle . setPoints ( Polygon . pointsAsCircle ( proximityCircleCenter , meters ) ) ;
if ( isActiveThemeDark ( ) ) {
2020-12-24 06:53:38 +01:00
proximityCircle . getOutlinePaint ( ) . setColor ( 0x9666A3D7 ) ;
proximityCircle . getFillPaint ( ) . setColor ( 0x1c66A3D7 ) ;
2020-11-01 14:02:57 +01:00
} else {
2020-12-24 06:53:38 +01:00
proximityCircle . getOutlinePaint ( ) . setColor ( 0x964286F5 ) ;
proximityCircle . getOutlinePaint ( ) . setColor ( 0x1c4286F5 ) ;
2020-11-01 14:02:57 +01:00
}
// TODO: set dash /gap
proximityCircle . getOutlinePaint ( ) . setStrokeWidth ( 2 ) ;
mapView . getOverlayManager ( ) . add ( proximityCircle ) ;
2015-05-03 13:48:36 +02:00
}
2015-04-09 20:00:14 +02:00
2019-12-31 14:08:08 +01:00
private void removeInfoView ( ) {
if ( lastPressedMarker ! = null ) {
markerImageView . setVisibility ( View . VISIBLE ) ;
overlayView . removeInfoView ( lastPressedMarker ) ;
lastPressedMarker = null ;
lastPressedVenue = null ;
lastPressedMarkerView = null ;
}
}
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 ( ) ) ;
2022-03-11 17:49:54 +01:00
builder . setTopAnimation ( R . raw . permission_request_location , AlertsCreator . PERMISSIONS_REQUEST_TOP_ICON_SIZE , false , Theme . getColor ( Theme . key_dialogTopBackground ) ) ;
2016-04-22 15:49:00 +02:00
if ( byButton ) {
2022-03-11 17:49:54 +01:00
builder . setMessage ( LocaleController . getString ( " PermissionNoLocationNavigation " , R . string . PermissionNoLocationNavigation ) ) ;
2016-04-22 15:49:00 +02:00
} else {
2022-03-11 17:49:54 +01:00
builder . setMessage ( LocaleController . getString ( " PermissionNoLocationFriends " , R . string . PermissionNoLocationFriends ) ) ;
2016-04-22 15:49:00 +02:00
}
2019-01-23 18:03:33 +01:00
builder . setNegativeButton ( LocaleController . getString ( " PermissionOpenSettings " , R . string . PermissionOpenSettings ) , ( dialog , 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 ) {
FileLog . e ( e ) ;
2015-10-29 18:10:07 +01:00
}
} ) ;
builder . setPositiveButton ( LocaleController . getString ( " OK " , R . string . OK ) , null ) ;
showDialog ( builder . create ( ) ) ;
}
2015-05-03 13:48:36 +02:00
@Override
2015-10-29 18:10:07 +01:00
public void onTransitionAnimationEnd ( boolean isOpen , boolean backward ) {
2019-12-31 14:08:08 +01:00
if ( isOpen & & ! backward ) {
2015-10-29 18:10:07 +01:00
try {
if ( mapView . getParent ( ) instanceof ViewGroup ) {
ViewGroup viewGroup = ( ViewGroup ) mapView . getParent ( ) ;
viewGroup . removeView ( mapView ) ;
}
2019-12-31 14:08:08 +01:00
} catch ( Exception ignore ) {
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 ) ) ;
2019-12-31 14:08:08 +01:00
if ( overlayView ! = null ) {
try {
if ( overlayView . getParent ( ) instanceof ViewGroup ) {
ViewGroup viewGroup = ( ViewGroup ) overlayView . getParent ( ) ;
viewGroup . removeView ( overlayView ) ;
}
} catch ( Exception ignore ) {
}
mapViewClip . addView ( overlayView , 1 , LayoutHelper . createFrame ( LayoutHelper . MATCH_PARENT , overScrollHeight + AndroidUtilities . dp ( 10 ) , Gravity . TOP | Gravity . LEFT ) ) ;
}
2020-11-01 14:02:57 +01:00
updateClipView ( false ) ;
maybeShowProximityHint ( ) ;
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
}
2015-05-03 13:48:36 +02:00
}
}
2014-06-04 01:31:48 +02:00
2020-11-01 14:02:57 +01:00
private void maybeShowProximityHint ( ) {
if ( proximityButton = = null | | proximityButton . getVisibility ( ) ! = View . VISIBLE | | proximityAnimationInProgress ) {
return ;
}
SharedPreferences preferences = MessagesController . getGlobalMainSettings ( ) ;
int val = preferences . getInt ( " proximityhint " , 0 ) ;
if ( val < 3 ) {
preferences . edit ( ) . putInt ( " proximityhint " , + + val ) . commit ( ) ;
2021-09-20 00:10:42 +02:00
if ( DialogObject . isUserDialog ( dialogId ) ) {
TLRPC . User user = getMessagesController ( ) . getUser ( dialogId ) ;
2020-11-01 14:02:57 +01:00
hintView . setOverrideText ( LocaleController . formatString ( " ProximityTooltioUser " , R . string . ProximityTooltioUser , UserObject . getFirstName ( user ) ) ) ;
} else {
hintView . setOverrideText ( LocaleController . getString ( " ProximityTooltioGroup " , R . string . ProximityTooltioGroup ) ) ;
}
hintView . showForView ( proximityButton , true ) ;
}
}
2019-12-31 14:08:08 +01:00
private void showResults ( ) {
if ( adapter . getItemCount ( ) = = 0 ) {
return ;
}
int position = layoutManager . findFirstVisibleItemPosition ( ) ;
if ( position ! = 0 ) {
2017-03-31 01:58:05 +02:00
return ;
}
2015-05-03 13:48:36 +02:00
View child = listView . getChildAt ( 0 ) ;
2019-12-31 14:08:08 +01:00
int offset = AndroidUtilities . dp ( 258 ) + child . getTop ( ) ;
if ( offset < 0 | | offset > AndroidUtilities . dp ( 258 ) ) {
return ;
}
listView . smoothScrollBy ( 0 , offset ) ;
}
2020-11-01 14:02:57 +01:00
private void updateClipView ( boolean fromLayout ) {
2019-12-31 14:08:08 +01:00
int height = 0 ;
int top ;
RecyclerView . ViewHolder holder = listView . findViewHolderForAdapterPosition ( 0 ) ;
if ( holder ! = null ) {
top = ( int ) holder . itemView . getY ( ) ;
2020-04-24 11:21:58 +02:00
height = overScrollHeight + ( Math . min ( top , 0 ) ) ;
2019-12-31 14:08:08 +01:00
} else {
top = - mapViewClip . getMeasuredHeight ( ) ;
}
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 ) ;
if ( overlayView ! = null ) {
overlayView . setVisibility ( View . INVISIBLE ) ;
2015-04-09 20:00:14 +02:00
}
2019-12-31 14:08:08 +01:00
}
} else {
if ( mapView . getVisibility ( ) = = View . INVISIBLE ) {
mapView . setVisibility ( View . VISIBLE ) ;
mapViewClip . setVisibility ( View . VISIBLE ) ;
if ( overlayView ! = null ) {
overlayView . setVisibility ( View . VISIBLE ) ;
2015-04-09 20:00:14 +02:00
}
2015-05-03 13:48:36 +02:00
}
2019-12-31 14:08:08 +01:00
}
2014-06-04 01:31:48 +02:00
2019-12-31 14:08:08 +01:00
mapViewClip . setTranslationY ( Math . min ( 0 , top ) ) ;
mapView . setTranslationY ( Math . max ( 0 , - top / 2 ) ) ;
if ( overlayView ! = null ) {
overlayView . setTranslationY ( Math . max ( 0 , - top / 2 ) ) ;
}
float translationY = Math . min ( overScrollHeight - mapTypeButton . getMeasuredHeight ( ) - AndroidUtilities . dp ( 64 + ( locationType = = LOCATION_TYPE_SEND | | locationType = = LOCATION_TYPE_SEND_WITH_LIVE ? 30 : 10 ) ) , - top ) ;
mapTypeButton . setTranslationY ( translationY ) ;
2020-11-01 14:02:57 +01:00
proximityButton . setTranslationY ( translationY ) ;
if ( hintView ! = null ) {
hintView . setExtraTranslationY ( translationY ) ;
}
2019-12-31 14:08:08 +01:00
if ( searchAreaButton ! = null ) {
searchAreaButton . setTranslation ( translationY ) ;
}
if ( markerImageView ! = null ) {
markerImageView . setTranslationY ( markerTop = - top - AndroidUtilities . dp ( markerImageView . getTag ( ) = = null ? 48 : 69 ) + height / 2 ) ;
}
2020-11-01 14:02:57 +01:00
if ( ! fromLayout ) {
layoutParams = ( FrameLayout . LayoutParams ) mapView . getLayoutParams ( ) ;
2016-10-11 13:57:01 +02:00
if ( layoutParams ! = null & & layoutParams . height ! = overScrollHeight + AndroidUtilities . dp ( 10 ) ) {
layoutParams . height = overScrollHeight + AndroidUtilities . dp ( 10 ) ;
2020-11-01 14:02:57 +01:00
if ( mapView ! = null ) {
mapView . setPadding ( AndroidUtilities . dp ( 70 ) , 0 , AndroidUtilities . dp ( 70 ) , AndroidUtilities . dp ( 10 ) ) ;
}
mapView . setLayoutParams ( layoutParams ) ;
}
if ( overlayView ! = null ) {
layoutParams = ( FrameLayout . LayoutParams ) overlayView . getLayoutParams ( ) ;
if ( layoutParams ! = null & & layoutParams . height ! = overScrollHeight + AndroidUtilities . dp ( 10 ) ) {
layoutParams . height = overScrollHeight + AndroidUtilities . dp ( 10 ) ;
overlayView . setLayoutParams ( layoutParams ) ;
}
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 ;
}
2020-11-01 14:02:57 +01:00
if ( locationType = = LOCATION_TYPE_LIVE_VIEW ) {
overScrollHeight = viewHeight - AndroidUtilities . dp ( 66 ) - height ;
} else if ( locationType = = 2 ) {
2019-12-31 14:08:08 +01:00
overScrollHeight = viewHeight - AndroidUtilities . dp ( 66 + 7 ) - height ;
} else {
overScrollHeight = viewHeight - AndroidUtilities . dp ( 66 ) - height ;
}
2015-05-03 13:48:36 +02:00
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 ) ;
2017-12-08 18:35:59 +01:00
if ( searchListView ! = null ) {
layoutParams = ( FrameLayout . LayoutParams ) searchListView . getLayoutParams ( ) ;
layoutParams . topMargin = height ;
searchListView . setLayoutParams ( layoutParams ) ;
}
2015-05-03 13:48:36 +02:00
adapter . setOverScrollHeight ( overScrollHeight ) ;
layoutParams = ( FrameLayout . LayoutParams ) mapView . getLayoutParams ( ) ;
if ( layoutParams ! = null ) {
layoutParams . height = overScrollHeight + AndroidUtilities . dp ( 10 ) ;
2020-04-04 12:19:59 +02:00
if ( mapView ! = null ) {
mapView . setPadding ( AndroidUtilities . dp ( 70 ) , 0 , AndroidUtilities . dp ( 70 ) , AndroidUtilities . dp ( 10 ) ) ;
2015-05-03 13:48:36 +02:00
}
mapView . setLayoutParams ( layoutParams ) ;
2013-10-25 17:19:00 +02:00
}
2019-12-31 14:08:08 +01:00
if ( overlayView ! = null ) {
layoutParams = ( FrameLayout . LayoutParams ) overlayView . getLayoutParams ( ) ;
if ( layoutParams ! = null ) {
layoutParams . height = overScrollHeight + AndroidUtilities . dp ( 10 ) ;
overlayView . setLayoutParams ( layoutParams ) ;
}
}
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 ) {
2019-12-31 14:08:08 +01:00
int top ;
if ( locationType = = 3 ) {
top = 73 ;
} else if ( locationType = = 1 | | locationType = = 2 ) {
top = 66 ;
} else {
top = 0 ;
}
layoutManager . scrollToPositionWithOffset ( 0 , - AndroidUtilities . dp ( top ) ) ;
2020-11-01 14:02:57 +01:00
updateClipView ( false ) ;
2019-01-23 18:03:33 +01:00
listView . post ( ( ) - > {
2019-12-31 14:08:08 +01:00
layoutManager . scrollToPositionWithOffset ( 0 , - AndroidUtilities . dp ( top ) ) ;
2020-11-01 14:02:57 +01:00
updateClipView ( false ) ;
2015-05-03 13:48:36 +02:00
} ) ;
} else {
2020-11-01 14:02:57 +01:00
updateClipView ( false ) ;
2015-05-03 13:48:36 +02:00
}
2013-10-25 17:19:00 +02:00
}
}
2014-08-08 12:17:06 +02:00
private Location getLastLocation ( ) {
2020-04-04 12:19:59 +02:00
if ( Build . VERSION . SDK_INT > = 23 & & getParentActivity ( ) . checkSelfPermission ( Manifest . permission . ACCESS_FINE_LOCATION ) ! = PackageManager . PERMISSION_GRANTED & & getParentActivity ( ) . checkSelfPermission ( Manifest . permission . ACCESS_COARSE_LOCATION ) ! = PackageManager . PERMISSION_GRANTED ) {
return null ;
} else {
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 ;
}
2014-08-08 12:17:06 +02:00
}
2020-04-04 12:19:59 +02:00
return l ;
2014-08-08 12:17:06 +02:00
}
}
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 ) ;
2019-07-18 15:01:39 +02:00
LiveLocation liveLocation = markersMap . get ( getUserConfig ( ) . getClientUserId ( ) ) ;
LocationController . SharingLocationInfo myInfo = getLocationController ( ) . getSharingLocationInfo ( dialogId ) ;
2017-12-08 18:35:59 +01:00
if ( liveLocation ! = null & & myInfo ! = null & & liveLocation . object . id = = myInfo . mid ) {
2020-11-01 14:02:57 +01:00
GeoPoint latLng = new GeoPoint ( location . getLatitude ( ) , location . getLongitude ( ) ) ;
liveLocation . marker . setPosition ( latLng ) ;
if ( liveLocation . directionMarker ! = null ) {
liveLocation . directionMarker . setPosition ( latLng ) ;
}
2017-12-08 18:35:59 +01:00
}
2020-04-04 12:19:59 +02:00
if ( messageObject = = null & & chatLocation = = null & & mapView ! = null ) {
GeoPoint latLng = new GeoPoint ( location . getLatitude ( ) , location . getLongitude ( ) ) ;
2015-05-03 13:48:36 +02:00
if ( adapter ! = null ) {
2019-12-31 14:08:08 +01:00
if ( ! searchedForCustomLocations & & locationType ! = LOCATION_TYPE_GROUP ) {
2018-07-30 04:07:02 +02:00
adapter . searchPlacesWithQuery ( null , myLocation , true ) ;
2017-12-08 18:35:59 +01:00
}
2015-05-03 13:48:36 +02:00
adapter . setGpsLocation ( myLocation ) ;
}
if ( ! userLocationMoved ) {
userLocation = new Location ( location ) ;
2013-10-25 17:19:00 +02:00
if ( firstWas ) {
2020-04-04 12:19:59 +02:00
final IMapController controller = mapView . getController ( ) ;
controller . animateTo ( latLng ) ;
2013-10-25 17:19:00 +02:00
} else {
firstWas = true ;
2020-04-04 12:19:59 +02:00
final IMapController controller = mapView . getController ( ) ;
controller . setZoom ( mapView . getMaxZoomLevel ( ) - 2 ) ;
controller . setCenter ( latLng ) ;
2013-10-25 17:19:00 +02:00
}
}
2017-12-08 18:35:59 +01:00
} else {
adapter . setGpsLocation ( myLocation ) ;
2013-10-25 17:19:00 +02:00
}
2020-11-01 14:02:57 +01:00
if ( proximitySheet ! = null ) {
proximitySheet . updateText ( true , true ) ;
}
if ( proximityCircle ! = null ) {
proximityCircleCenter = new GeoPoint ( myLocation . getLatitude ( ) , myLocation . getLongitude ( ) ) ;
proximityCircle . setPoints ( Polygon . pointsAsCircle ( proximityCircleCenter , proximityCircleRadius ) ) ;
}
2013-10-25 17:19:00 +02:00
}
2014-06-11 01:05:54 +02:00
public void setMessageObject ( MessageObject message ) {
messageObject = message ;
2017-12-08 18:35:59 +01:00
dialogId = messageObject . getDialogId ( ) ;
}
2021-09-20 00:10:42 +02:00
public void setChatLocation ( long chatId , TLRPC . TL_channelLocation location ) {
2019-07-18 15:01:39 +02:00
dialogId = - chatId ;
chatLocation = location ;
}
2017-12-08 18:35:59 +01:00
public void setDialogId ( long did ) {
dialogId = did ;
}
2019-07-18 15:01:39 +02:00
public void setInitialLocation ( TLRPC . TL_channelLocation location ) {
initialLocation = location ;
}
2019-12-31 14:08:08 +01:00
private static final double EARTHRADIUS = 6366198 ;
2020-04-04 12:19:59 +02:00
private static GeoPoint move ( GeoPoint startLL , double toNorth , double toEast ) {
double lonDiff = meterToLongitude ( toEast , startLL . getLatitude ( ) ) ;
2019-12-31 14:08:08 +01:00
double latDiff = meterToLatitude ( toNorth ) ;
2020-04-04 12:19:59 +02:00
return new GeoPoint ( startLL . getLatitude ( ) + latDiff , startLL . getLongitude ( ) + lonDiff ) ;
2019-12-31 14:08:08 +01:00
}
private static double meterToLongitude ( double meterToEast , double latitude ) {
double latArc = Math . toRadians ( latitude ) ;
double radius = Math . cos ( latArc ) * EARTHRADIUS ;
double rad = meterToEast / radius ;
return Math . toDegrees ( rad ) ;
}
private static double meterToLatitude ( double meterToNorth ) {
double rad = meterToNorth / EARTHRADIUS ;
return Math . toDegrees ( rad ) ;
}
2017-12-08 18:35:59 +01:00
private void fetchRecentLocations ( ArrayList < TLRPC . Message > messages ) {
2020-04-04 12:19:59 +02:00
BoundingBox builder = null ;
2020-11-01 14:02:57 +01:00
List < GeoPoint > geoPoints = new ArrayList < > ( ) ;
2019-07-18 15:01:39 +02:00
int date = getConnectionsManager ( ) . getCurrentTime ( ) ;
2017-12-08 18:35:59 +01:00
for ( int a = 0 ; a < messages . size ( ) ; a + + ) {
TLRPC . Message message = messages . get ( a ) ;
if ( message . date + message . media . period > date ) {
2020-11-01 14:02:57 +01:00
if ( firstFocus ) {
2020-04-04 12:19:59 +02:00
GeoPoint latLng = new GeoPoint ( message . media . geo . lat , message . media . geo . _long ) ;
2020-11-01 14:02:57 +01:00
geoPoints . add ( latLng ) ;
2017-12-08 18:35:59 +01:00
}
addUserMarker ( message ) ;
2020-11-01 14:02:57 +01:00
if ( proximityButton . getVisibility ( ) ! = View . GONE & & MessageObject . getFromChatId ( message ) ! = getUserConfig ( ) . getClientUserId ( ) ) {
proximityButton . setVisibility ( View . VISIBLE ) ;
proximityAnimationInProgress = true ;
proximityButton . animate ( ) . alpha ( 1 . 0f ) . scaleX ( 1 . 0f ) . scaleY ( 1 . 0f ) . setDuration ( 180 ) . setListener ( new AnimatorListenerAdapter ( ) {
@Override
public void onAnimationEnd ( Animator animation ) {
proximityAnimationInProgress = false ;
maybeShowProximityHint ( ) ;
}
} ) . start ( ) ;
}
2017-12-08 18:35:59 +01:00
}
}
2020-11-01 14:02:57 +01:00
if ( geoPoints . size ( ) > 0 ) {
builder = BoundingBox . fromGeoPoints ( geoPoints ) ;
2020-04-04 12:19:59 +02:00
}
if ( firstFocus ) {
2020-11-01 14:02:57 +01:00
listView . smoothScrollBy ( 0 , AndroidUtilities . dp ( 66 * 1 . 5f ) ) ;
2017-12-08 18:35:59 +01:00
firstFocus = false ;
adapter . setLiveLocations ( markers ) ;
if ( messageObject . isLiveLocation ( ) ) {
try {
2020-04-04 12:19:59 +02:00
BoundingBox bounds = builder ;
GeoPoint center = bounds . getCenterWithDateLine ( ) ; //TODO check
GeoPoint northEast = move ( center , 100 , 100 ) ;
GeoPoint southWest = move ( center , - 100 , - 100 ) ;
2020-11-01 14:02:57 +01:00
geoPoints . add ( southWest ) ;
geoPoints . add ( northEast ) ;
if ( geoPoints . size ( ) > 0 ) {
builder = BoundingBox . fromGeoPoints ( geoPoints ) ;
2020-04-04 12:19:59 +02:00
}
bounds = builder ;
2017-12-08 18:35:59 +01:00
if ( messages . size ( ) > 1 ) {
try {
2020-11-01 14:02:57 +01:00
moveToBounds = bounds ;
mapView . zoomToBoundingBox ( bounds , false , AndroidUtilities . dp ( 80 + 33 ) ) ;
moveToBounds = null ;
2017-12-08 18:35:59 +01:00
} catch ( Exception e ) {
FileLog . e ( e ) ;
}
}
} catch ( Exception ignore ) {
}
}
}
}
2020-11-01 14:02:57 +01:00
private void moveToBounds ( int radius , boolean self , boolean animated ) {
BoundingBox builder = null ;
List < GeoPoint > geoPoints = new ArrayList < > ( ) ;
geoPoints . add ( new GeoPoint ( myLocation . getLatitude ( ) , myLocation . getLongitude ( ) ) ) ;
if ( geoPoints . size ( ) > 0 ) {
builder = BoundingBox . fromGeoPoints ( geoPoints ) ;
}
if ( self ) {
try {
BoundingBox bounds = builder ;
GeoPoint center = bounds . getCenterWithDateLine ( ) ; //TODO check
GeoPoint northEast = move ( center , 100 , 100 ) ;
GeoPoint southWest = move ( center , - 100 , - 100 ) ;
geoPoints . add ( southWest ) ;
geoPoints . add ( northEast ) ;
if ( geoPoints . size ( ) > 0 ) {
builder = BoundingBox . fromGeoPoints ( geoPoints ) ;
}
bounds = builder ;
try {
int height = ( int ) ( proximitySheet . getCustomView ( ) . getMeasuredHeight ( ) - AndroidUtilities . dp ( 40 ) + mapViewClip . getTranslationY ( ) ) ;
mapView . setPadding ( AndroidUtilities . dp ( 70 ) , 0 , AndroidUtilities . dp ( 70 ) , height ) ;
if ( animated ) {
mapView . zoomToBoundingBox ( bounds , true , AndroidUtilities . dp ( 60 ) , mapView . getMaxZoomLevel ( ) , 500L ) ;
} else {
mapView . zoomToBoundingBox ( bounds , false , AndroidUtilities . dp ( 60 ) ) ;
}
} catch ( Exception e ) {
FileLog . e ( e ) ;
}
} catch ( Exception ignore ) {
}
} else {
int date = getConnectionsManager ( ) . getCurrentTime ( ) ;
for ( int a = 0 , N = markers . size ( ) ; a < N ; a + + ) {
TLRPC . Message message = markers . get ( a ) . object ;
if ( message . date + message . media . period > date ) {
GeoPoint latLng = new GeoPoint ( message . media . geo . lat , message . media . geo . _long ) ;
geoPoints . add ( latLng ) ;
}
}
try {
BoundingBox bounds = builder ;
GeoPoint center = bounds . getCenterWithDateLine ( ) ; //TODO check
GeoPoint northEast = move ( center , 100 , 100 ) ;
GeoPoint southWest = move ( center , - 100 , - 100 ) ;
geoPoints . add ( southWest ) ;
geoPoints . add ( northEast ) ;
if ( geoPoints . size ( ) > 0 ) {
builder = BoundingBox . fromGeoPoints ( geoPoints ) ;
}
bounds = builder ;
try {
int height = proximitySheet . getCustomView ( ) . getMeasuredHeight ( ) - AndroidUtilities . dp ( 100 ) ;
mapView . setPadding ( AndroidUtilities . dp ( 70 ) , 0 , AndroidUtilities . dp ( 70 ) , height ) ;
mapView . zoomToBoundingBox ( bounds , false , AndroidUtilities . dp ( 60 ) ) ;
} catch ( Exception e ) {
FileLog . e ( e ) ;
}
} catch ( Exception ignore ) {
}
}
}
2017-12-08 18:35:59 +01:00
private boolean getRecentLocations ( ) {
2019-07-18 15:01:39 +02:00
ArrayList < TLRPC . Message > messages = getLocationController ( ) . locationsCache . get ( messageObject . getDialogId ( ) ) ;
2017-12-08 18:35:59 +01:00
if ( messages ! = null & & messages . isEmpty ( ) ) {
fetchRecentLocations ( messages ) ;
} else {
messages = null ;
}
2021-09-20 00:10:42 +02:00
if ( DialogObject . isChatDialog ( dialogId ) ) {
TLRPC . Chat chat = getMessagesController ( ) . getChat ( - dialogId ) ;
2018-07-30 04:07:02 +02:00
if ( ChatObject . isChannel ( chat ) & & ! chat . megagroup ) {
return false ;
}
}
2017-12-08 18:35:59 +01:00
TLRPC . TL_messages_getRecentLocations req = new TLRPC . TL_messages_getRecentLocations ( ) ;
final long dialog_id = messageObject . getDialogId ( ) ;
2021-09-20 00:10:42 +02:00
req . peer = getMessagesController ( ) . getInputPeer ( dialog_id ) ;
2017-12-08 18:35:59 +01:00
req . limit = 100 ;
2019-07-18 15:01:39 +02:00
getConnectionsManager ( ) . sendRequest ( req , ( response , error ) - > {
2019-01-23 18:03:33 +01:00
if ( response ! = null ) {
AndroidUtilities . runOnUIThread ( ( ) - > {
2020-04-04 12:19:59 +02:00
if ( mapView = = null ) {
2019-01-23 18:03:33 +01:00
return ;
}
TLRPC . messages_Messages res = ( TLRPC . messages_Messages ) response ;
for ( int a = 0 ; a < res . messages . size ( ) ; a + + ) {
if ( ! ( res . messages . get ( a ) . media instanceof TLRPC . TL_messageMediaGeoLive ) ) {
res . messages . remove ( a ) ;
a - - ;
2017-12-08 18:35:59 +01:00
}
2019-01-23 18:03:33 +01:00
}
2019-07-18 15:01:39 +02:00
getMessagesStorage ( ) . putUsersAndChats ( res . users , res . chats , true , true ) ;
getMessagesController ( ) . putUsers ( res . users , false ) ;
getMessagesController ( ) . putChats ( res . chats , false ) ;
getLocationController ( ) . locationsCache . put ( dialog_id , res . messages ) ;
getNotificationCenter ( ) . postNotificationName ( NotificationCenter . liveLocationsCacheChanged , dialog_id ) ;
2019-01-23 18:03:33 +01:00
fetchRecentLocations ( res . messages ) ;
2019-12-31 14:08:08 +01:00
getLocationController ( ) . markLiveLoactionsAsRead ( dialogId ) ;
if ( markAsReadRunnable = = null ) {
markAsReadRunnable = ( ) - > {
getLocationController ( ) . markLiveLoactionsAsRead ( dialogId ) ;
if ( isPaused | | markAsReadRunnable = = null ) {
return ;
}
AndroidUtilities . runOnUIThread ( markAsReadRunnable , 5000 ) ;
} ;
AndroidUtilities . runOnUIThread ( markAsReadRunnable , 5000 ) ;
}
2019-01-23 18:03:33 +01:00
} ) ;
2017-12-08 18:35:59 +01:00
}
} ) ;
return messages ! = null ;
2014-06-11 01:05:54 +02:00
}
2020-11-01 14:02:57 +01:00
private double bearingBetweenLocations ( GeoPoint latLng1 , GeoPoint latLng2 ) {
double lat1 = latLng1 . getLatitude ( ) * Math . PI / 180 ;
double long1 = latLng1 . getLongitude ( ) * Math . PI / 180 ;
double lat2 = latLng2 . getLatitude ( ) * Math . PI / 180 ;
double long2 = latLng2 . getLongitude ( ) * Math . PI / 180 ;
double dLon = ( long2 - long1 ) ;
double y = Math . sin ( dLon ) * Math . cos ( lat2 ) ;
double x = Math . cos ( lat1 ) * Math . sin ( lat2 ) - Math . sin ( lat1 ) * Math . cos ( lat2 ) * Math . cos ( dLon ) ;
double brng = Math . atan2 ( y , x ) ;
brng = Math . toDegrees ( brng ) ;
brng = ( brng + 360 ) % 360 ;
return brng ;
}
2017-12-08 18:35:59 +01:00
@SuppressWarnings ( " unchecked " )
2013-10-25 17:19:00 +02:00
@Override
2018-07-30 04:07:02 +02:00
public void didReceivedNotification ( int id , int account , Object . . . args ) {
2017-12-08 18:35:59 +01:00
if ( id = = NotificationCenter . closeChats ) {
2013-10-25 17:19:00 +02:00
removeSelfFromStack ( ) ;
2016-01-11 18:19:48 +01:00
} else if ( id = = NotificationCenter . locationPermissionGranted ) {
2022-02-01 14:00:45 +01:00
locationDenied = false ;
if ( adapter ! = null ) {
adapter . setMyLocationDenied ( locationDenied ) ;
}
2020-04-04 12:19:59 +02:00
if ( mapView ! = null & & mapsInitialized ) {
myLocationOverlay . enableMyLocation ( ) ;
2016-01-11 18:19:48 +01:00
}
2022-02-01 14:00:45 +01:00
} else if ( id = = NotificationCenter . locationPermissionDenied ) {
locationDenied = true ;
if ( adapter ! = null ) {
adapter . setMyLocationDenied ( locationDenied ) ;
}
2020-11-01 14:02:57 +01:00
} else if ( id = = NotificationCenter . liveLocationsChanged ) {
if ( adapter ! = null ) {
adapter . updateLiveLocationCell ( ) ;
}
2019-01-23 18:03:33 +01:00
} else if ( id = = NotificationCenter . didReceiveNewMessages ) {
2019-09-10 12:56:11 +02:00
boolean scheduled = ( Boolean ) args [ 2 ] ;
if ( scheduled ) {
return ;
}
2017-12-08 18:35:59 +01:00
long did = ( Long ) args [ 0 ] ;
if ( did ! = dialogId | | messageObject = = null ) {
return ;
}
ArrayList < MessageObject > arr = ( ArrayList < MessageObject > ) args [ 1 ] ;
boolean added = false ;
for ( int a = 0 ; a < arr . size ( ) ; a + + ) {
MessageObject messageObject = arr . get ( a ) ;
if ( messageObject . isLiveLocation ( ) ) {
addUserMarker ( messageObject . messageOwner ) ;
added = true ;
2020-11-01 14:02:57 +01:00
} else if ( messageObject . messageOwner . action instanceof TLRPC . TL_messageActionGeoProximityReached ) {
2021-09-20 00:10:42 +02:00
if ( DialogObject . isUserDialog ( messageObject . getDialogId ( ) ) ) {
2020-11-01 14:02:57 +01:00
proximityButton . setImageResource ( R . drawable . msg_location_alert ) ;
if ( proximityCircle ! = null ) {
mapView . getOverlayManager ( ) . remove ( proximityCircle ) ;
proximityCircle = null ;
}
}
2017-12-08 18:35:59 +01:00
}
}
if ( added & & adapter ! = null ) {
adapter . setLiveLocations ( markers ) ;
}
} else if ( id = = NotificationCenter . replaceMessagesObjects ) {
long did = ( long ) args [ 0 ] ;
if ( did ! = dialogId | | messageObject = = null ) {
return ;
}
boolean updated = false ;
ArrayList < MessageObject > messageObjects = ( ArrayList < MessageObject > ) args [ 1 ] ;
for ( int a = 0 ; a < messageObjects . size ( ) ; a + + ) {
MessageObject messageObject = messageObjects . get ( a ) ;
if ( ! messageObject . isLiveLocation ( ) ) {
continue ;
}
LiveLocation liveLocation = markersMap . get ( getMessageId ( messageObject . messageOwner ) ) ;
if ( liveLocation ! = null ) {
2019-07-18 15:01:39 +02:00
LocationController . SharingLocationInfo myInfo = getLocationController ( ) . getSharingLocationInfo ( did ) ;
2017-12-08 18:35:59 +01:00
if ( myInfo = = null | | myInfo . mid ! = messageObject . getId ( ) ) {
2019-12-31 14:08:08 +01:00
liveLocation . object = messageObject . messageOwner ;
2020-11-01 14:02:57 +01:00
GeoPoint latLng = new GeoPoint ( messageObject . messageOwner . media . geo . lat , messageObject . messageOwner . media . geo . _long ) ;
liveLocation . marker . setPosition ( latLng ) ;
if ( liveLocation . directionMarker ! = null ) {
GeoPoint oldLocation = liveLocation . directionMarker . getPosition ( ) ;
liveLocation . directionMarker . setPosition ( latLng ) ;
if ( messageObject . messageOwner . media . heading ! = 0 ) {
liveLocation . directionMarker . setRotation ( messageObject . messageOwner . media . heading ) ;
if ( ! liveLocation . hasRotation ) {
liveLocation . directionMarker . setIcon ( getParentActivity ( ) . getResources ( ) . getDrawable ( R . drawable . map_pin_cone2 ) ) ;
liveLocation . hasRotation = true ;
}
} else {
if ( liveLocation . hasRotation ) {
liveLocation . directionMarker . setRotation ( 0 ) ;
liveLocation . directionMarker . setIcon ( getParentActivity ( ) . getResources ( ) . getDrawable ( R . drawable . map_pin_circle ) ) ;
liveLocation . hasRotation = false ;
}
}
}
2017-12-08 18:35:59 +01:00
}
updated = true ;
}
}
if ( updated & & adapter ! = null ) {
adapter . updateLiveLocations ( ) ;
2020-11-01 14:02:57 +01:00
if ( proximitySheet ! = null ) {
proximitySheet . updateText ( true , true ) ;
}
2017-12-08 18:35:59 +01:00
}
2013-10-25 17:19:00 +02:00
}
}
2014-06-04 01:31:48 +02:00
@Override
public void onPause ( ) {
super . onPause ( ) ;
2016-10-11 13:57:01 +02:00
if ( mapView ! = null & & mapsInitialized ) {
2014-06-14 10:36:01 +02:00
try {
mapView . onPause ( ) ;
} catch ( Exception e ) {
2017-03-31 01:58:05 +02:00
FileLog . e ( e ) ;
2014-06-14 10:36:01 +02:00
}
2020-11-01 14:02:57 +01:00
if ( mapView . getOverlays ( ) . contains ( myLocationOverlay ) ) {
2020-04-04 12:19:59 +02:00
mapView . getOverlays ( ) . remove ( myLocationOverlay ) ;
}
myLocationOverlay . disableMyLocation ( ) ;
2014-06-04 01:31:48 +02:00
}
2020-11-01 14:02:57 +01:00
if ( undoView [ 0 ] ! = null ) {
undoView [ 0 ] . hide ( true , 0 ) ;
}
2016-10-11 13:57:01 +02:00
onResumeCalled = false ;
2014-06-04 01:31:48 +02:00
}
2020-11-01 14:02:57 +01:00
@Override
public boolean onBackPressed ( ) {
if ( proximitySheet ! = null ) {
proximitySheet . dismiss ( ) ;
return false ;
}
return super . onBackPressed ( ) ;
}
@Override
protected void onBecomeFullyHidden ( ) {
if ( undoView [ 0 ] ! = null ) {
undoView [ 0 ] . hide ( true , 0 ) ;
}
}
2014-06-04 01:31:48 +02:00
@Override
public void onResume ( ) {
super . onResume ( ) ;
2018-07-30 04:07:02 +02:00
AndroidUtilities . requestAdjustResize ( getParentActivity ( ) , classGuid ) ;
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 ( ) ;
2016-04-22 15:49:00 +02:00
} catch ( Exception e ) {
2017-03-31 01:58:05 +02:00
FileLog . e ( e ) ;
2016-03-16 13:26:32 +01:00
}
2020-04-04 12:19:59 +02:00
mapView . getOverlays ( ) . add ( myLocationOverlay ) ;
myLocationOverlay . enableMyLocation ( ) ;
2014-06-04 01:31:48 +02:00
}
2020-04-04 12:19:59 +02:00
onResumeCalled = true ;
2015-05-03 13:48:36 +02:00
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 ) ;
}
}
}
2019-12-31 14:08:08 +01:00
if ( markAsReadRunnable ! = null ) {
AndroidUtilities . cancelRunOnUIThread ( markAsReadRunnable ) ;
AndroidUtilities . runOnUIThread ( markAsReadRunnable , 5000 ) ;
}
2014-06-04 01:31:48 +02:00
}
2020-11-01 14:02:57 +01:00
@Override
public void onRequestPermissionsResultFragment ( int requestCode , String [ ] permissions , int [ ] grantResults ) {
if ( requestCode = = 30 ) {
openShareLiveLocation ( askWithRadius ) ;
}
}
2014-08-22 16:24:33 +02:00
public void setDelegate ( LocationActivityDelegate delegate ) {
this . delegate = delegate ;
}
2015-05-03 13:48:36 +02:00
2019-09-10 12:56:11 +02:00
public void setChatActivity ( ChatActivity chatActivity ) {
parentFragment = chatActivity ;
}
2015-05-03 13:48:36 +02:00
private void updateSearchInterface ( ) {
if ( adapter ! = null ) {
adapter . notifyDataSetChanged ( ) ;
}
}
2017-03-31 01:58:05 +02:00
@Override
2020-04-24 11:21:58 +02:00
public ArrayList < ThemeDescription > getThemeDescriptions ( ) {
ArrayList < ThemeDescription > themeDescriptions = new ArrayList < > ( ) ;
2019-01-23 18:03:33 +01:00
ThemeDescription . ThemeDescriptionDelegate cellDelegate = ( ) - > {
2019-12-31 14:08:08 +01:00
mapTypeButton . setIconColor ( Theme . getColor ( Theme . key_location_actionIcon ) ) ;
mapTypeButton . redrawPopup ( Theme . getColor ( Theme . key_actionBarDefaultSubmenuBackground ) ) ;
mapTypeButton . setPopupItemsColor ( Theme . getColor ( Theme . key_actionBarDefaultSubmenuItemIcon ) , true ) ;
mapTypeButton . setPopupItemsColor ( Theme . getColor ( Theme . key_actionBarDefaultSubmenuItem ) , false ) ;
2020-11-01 14:02:57 +01:00
shadowDrawable . setColorFilter ( new PorterDuffColorFilter ( Theme . getColor ( Theme . key_dialogBackground ) , PorterDuff . Mode . MULTIPLY ) ) ;
2019-12-31 14:08:08 +01:00
shadow . invalidate ( ) ;
2020-04-04 12:19:59 +02:00
if ( mapView ! = null ) {
2020-01-02 16:08:53 +01:00
if ( isActiveThemeDark ( ) ) {
2019-12-31 20:46:59 +01:00
if ( ! currentMapStyleDark ) {
currentMapStyleDark = true ;
2020-04-04 12:19:59 +02:00
// TODO dark
2020-11-01 14:02:57 +01:00
if ( proximityCircle ! = null ) {
proximityCircle . getOutlinePaint ( ) . setColor ( 0xffffffff ) ;
proximityCircle . getFillPaint ( ) . setColor ( 0x20ffffff ) ;
}
2019-12-31 20:46:59 +01:00
}
} else {
if ( currentMapStyleDark ) {
currentMapStyleDark = false ;
2020-04-04 12:19:59 +02:00
// TODO dark
2020-11-01 14:02:57 +01:00
if ( proximityCircle ! = null ) {
proximityCircle . getOutlinePaint ( ) . setColor ( 0xff000000 ) ;
proximityCircle . getFillPaint ( ) . setColor ( 0x20000000 ) ;
}
2019-12-31 20:46:59 +01:00
}
2019-12-31 14:08:08 +01:00
}
}
2017-03-31 01:58:05 +02:00
} ;
2020-04-24 11:21:58 +02:00
2020-11-01 14:02:57 +01:00
for ( int a = 0 ; a < undoView . length ; a + + ) {
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , ThemeDescription . FLAG_BACKGROUNDFILTER , null , null , null , null , Theme . key_undo_background ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " undoImageView " } , null , null , null , Theme . key_undo_cancelColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " undoTextView " } , null , null , null , Theme . key_undo_cancelColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " infoTextView " } , null , null , null , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " subinfoTextView " } , null , null , null , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " textPaint " } , null , null , null , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " progressPaint " } , null , null , null , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " BODY " , Theme . key_undo_background ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " Wibe Big " , Theme . key_undo_background ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " Wibe Big 3 " , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " Wibe Small " , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " Body Main.** " , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " Body Top.** " , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " Line.** " , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " Curve Big.** " , Theme . key_undo_infoColor ) ) ;
themeDescriptions . add ( new ThemeDescription ( undoView [ a ] , 0 , new Class [ ] { UndoView . class } , new String [ ] { " leftImageView " } , " Curve Small.** " , Theme . key_undo_infoColor ) ) ;
}
2020-04-24 11:21:58 +02:00
themeDescriptions . add ( new ThemeDescription ( fragmentView , ThemeDescription . FLAG_BACKGROUND , null , null , null , cellDelegate , Theme . key_dialogBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_BACKGROUND , null , null , null , null , Theme . key_dialogBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_LISTGLOWCOLOR , null , null , null , null , Theme . key_dialogBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_AB_ITEMSCOLOR , null , null , null , null , Theme . key_dialogTextBlack ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_AB_TITLECOLOR , null , null , null , null , Theme . key_dialogTextBlack ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_AB_SELECTORCOLOR , null , null , null , null , Theme . key_dialogButtonSelector ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_AB_SEARCH , null , null , null , null , Theme . key_dialogTextBlack ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_AB_SEARCHPLACEHOLDER , null , null , null , null , Theme . key_chat_messagePanelHint ) ) ;
themeDescriptions . add ( new ThemeDescription ( searchItem ! = null ? searchItem . getSearchField ( ) : null , ThemeDescription . FLAG_CURSORCOLOR , null , null , null , null , Theme . key_dialogTextBlack ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_AB_SUBMENUBACKGROUND , null , null , null , cellDelegate , Theme . key_actionBarDefaultSubmenuBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_AB_SUBMENUITEM , null , null , null , cellDelegate , Theme . key_actionBarDefaultSubmenuItem ) ) ;
themeDescriptions . add ( new ThemeDescription ( actionBar , ThemeDescription . FLAG_AB_SUBMENUITEM | ThemeDescription . FLAG_IMAGECOLOR , null , null , null , cellDelegate , Theme . key_actionBarDefaultSubmenuItemIcon ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_SELECTOR , null , null , null , null , Theme . key_listSelector ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { View . class } , Theme . dividerPaint , null , null , Theme . key_divider ) ) ;
themeDescriptions . add ( new ThemeDescription ( emptyImageView , ThemeDescription . FLAG_IMAGECOLOR , null , null , null , null , Theme . key_dialogEmptyImage ) ) ;
themeDescriptions . add ( new ThemeDescription ( emptyTitleTextView , ThemeDescription . FLAG_TEXTCOLOR , null , null , null , null , Theme . key_dialogEmptyText ) ) ;
themeDescriptions . add ( new ThemeDescription ( emptySubtitleTextView , ThemeDescription . FLAG_TEXTCOLOR , null , null , null , null , Theme . key_dialogEmptyText ) ) ;
themeDescriptions . add ( new ThemeDescription ( shadow , 0 , null , null , null , null , Theme . key_sheet_scrollUp ) ) ;
themeDescriptions . add ( new ThemeDescription ( locationButton , ThemeDescription . FLAG_IMAGECOLOR | ThemeDescription . FLAG_CHECKTAG , null , null , null , null , Theme . key_location_actionIcon ) ) ;
themeDescriptions . add ( new ThemeDescription ( locationButton , ThemeDescription . FLAG_IMAGECOLOR | ThemeDescription . FLAG_CHECKTAG , null , null , null , null , Theme . key_location_actionActiveIcon ) ) ;
themeDescriptions . add ( new ThemeDescription ( locationButton , ThemeDescription . FLAG_BACKGROUNDFILTER , null , null , null , null , Theme . key_location_actionBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( locationButton , ThemeDescription . FLAG_BACKGROUNDFILTER | ThemeDescription . FLAG_DRAWABLESELECTEDSTATE , null , null , null , null , Theme . key_location_actionPressedBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( mapTypeButton , 0 , null , null , null , cellDelegate , Theme . key_location_actionIcon ) ) ;
themeDescriptions . add ( new ThemeDescription ( mapTypeButton , ThemeDescription . FLAG_BACKGROUNDFILTER , null , null , null , null , Theme . key_location_actionBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( mapTypeButton , ThemeDescription . FLAG_BACKGROUNDFILTER | ThemeDescription . FLAG_DRAWABLESELECTEDSTATE , null , null , null , null , Theme . key_location_actionPressedBackground ) ) ;
2020-11-01 14:02:57 +01:00
themeDescriptions . add ( new ThemeDescription ( proximityButton , 0 , null , null , null , cellDelegate , Theme . key_location_actionIcon ) ) ;
themeDescriptions . add ( new ThemeDescription ( proximityButton , ThemeDescription . FLAG_BACKGROUNDFILTER , null , null , null , null , Theme . key_location_actionBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( proximityButton , ThemeDescription . FLAG_BACKGROUNDFILTER | ThemeDescription . FLAG_DRAWABLESELECTEDSTATE , null , null , null , null , Theme . key_location_actionPressedBackground ) ) ;
2020-04-24 11:21:58 +02:00
themeDescriptions . add ( new ThemeDescription ( searchAreaButton , ThemeDescription . FLAG_TEXTCOLOR , null , null , null , null , Theme . key_location_actionActiveIcon ) ) ;
themeDescriptions . add ( new ThemeDescription ( searchAreaButton , ThemeDescription . FLAG_BACKGROUNDFILTER , null , null , null , null , Theme . key_location_actionBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( searchAreaButton , ThemeDescription . FLAG_BACKGROUNDFILTER | ThemeDescription . FLAG_DRAWABLESELECTEDSTATE , null , null , null , null , Theme . key_location_actionPressedBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , Theme . avatarDrawables , cellDelegate , Theme . key_avatar_text ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , cellDelegate , Theme . key_avatar_backgroundRed ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , cellDelegate , Theme . key_avatar_backgroundOrange ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , cellDelegate , Theme . key_avatar_backgroundViolet ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , cellDelegate , Theme . key_avatar_backgroundGreen ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , cellDelegate , Theme . key_avatar_backgroundCyan ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , cellDelegate , Theme . key_avatar_backgroundBlue ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , cellDelegate , Theme . key_avatar_backgroundPink ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , null , Theme . key_location_liveLocationProgress ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , null , Theme . key_location_placeLocationBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( null , 0 , null , null , null , null , Theme . key_dialog_liveLocationProgress ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_USEBACKGROUNDDRAWABLE | ThemeDescription . FLAG_CHECKTAG , new Class [ ] { SendLocationCell . class } , new String [ ] { " imageView " } , null , null , null , Theme . key_location_sendLocationIcon ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_USEBACKGROUNDDRAWABLE | ThemeDescription . FLAG_CHECKTAG , new Class [ ] { SendLocationCell . class } , new String [ ] { " imageView " } , null , null , null , Theme . key_location_sendLiveLocationIcon ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_BACKGROUNDFILTER | ThemeDescription . FLAG_USEBACKGROUNDDRAWABLE | ThemeDescription . FLAG_CHECKTAG , new Class [ ] { SendLocationCell . class } , new String [ ] { " imageView " } , null , null , null , Theme . key_location_sendLocationBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_BACKGROUNDFILTER | ThemeDescription . FLAG_USEBACKGROUNDDRAWABLE | ThemeDescription . FLAG_CHECKTAG , new Class [ ] { SendLocationCell . class } , new String [ ] { " imageView " } , null , null , null , Theme . key_location_sendLiveLocationBackground ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { SendLocationCell . class } , new String [ ] { " accurateTextView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_CHECKTAG , new Class [ ] { SendLocationCell . class } , new String [ ] { " titleTextView " } , null , null , null , Theme . key_location_sendLiveLocationText ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_CHECKTAG , new Class [ ] { SendLocationCell . class } , new String [ ] { " titleTextView " } , null , null , null , Theme . key_location_sendLocationText ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { LocationDirectionCell . class } , new String [ ] { " buttonTextView " } , null , null , null , Theme . key_featuredStickers_buttonText ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_USEBACKGROUNDDRAWABLE , new Class [ ] { LocationDirectionCell . class } , new String [ ] { " frameLayout " } , null , null , null , Theme . key_featuredStickers_addButton ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_USEBACKGROUNDDRAWABLE | ThemeDescription . FLAG_DRAWABLESELECTEDSTATE , new Class [ ] { LocationDirectionCell . class } , new String [ ] { " frameLayout " } , null , null , null , Theme . key_featuredStickers_addButtonPressed ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_BACKGROUNDFILTER , new Class [ ] { ShadowSectionCell . class } , null , null , null , Theme . key_windowBackgroundGrayShadow ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_BACKGROUNDFILTER | ThemeDescription . FLAG_CELLBACKGROUNDCOLOR , new Class [ ] { ShadowSectionCell . class } , null , null , null , Theme . key_windowBackgroundGray ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { HeaderCell . class } , new String [ ] { " textView " } , null , null , null , Theme . key_dialogTextBlue2 ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_BACKGROUNDFILTER , new Class [ ] { LocationCell . class } , new String [ ] { " imageView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { LocationCell . class } , new String [ ] { " nameTextView " } , null , null , null , Theme . key_windowBackgroundWhiteBlackText ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { LocationCell . class } , new String [ ] { " addressTextView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
themeDescriptions . add ( new ThemeDescription ( searchListView , ThemeDescription . FLAG_BACKGROUNDFILTER , new Class [ ] { LocationCell . class } , new String [ ] { " imageView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
themeDescriptions . add ( new ThemeDescription ( searchListView , 0 , new Class [ ] { LocationCell . class } , new String [ ] { " nameTextView " } , null , null , null , Theme . key_windowBackgroundWhiteBlackText ) ) ;
themeDescriptions . add ( new ThemeDescription ( searchListView , 0 , new Class [ ] { LocationCell . class } , new String [ ] { " addressTextView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { SharingLiveLocationCell . class } , new String [ ] { " nameTextView " } , null , null , null , Theme . key_windowBackgroundWhiteBlackText ) ) ;
2020-12-24 06:36:01 +01:00
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { SharingLiveLocationCell . class } , new String [ ] { " distanceTextView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
2020-04-24 11:21:58 +02:00
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { LocationLoadingCell . class } , new String [ ] { " progressBar " } , null , null , null , Theme . key_progressCircle ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { LocationLoadingCell . class } , new String [ ] { " textView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { LocationLoadingCell . class } , new String [ ] { " imageView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { LocationPoweredCell . class } , new String [ ] { " textView " } , null , null , null , Theme . key_windowBackgroundWhiteGrayText3 ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , ThemeDescription . FLAG_IMAGECOLOR , new Class [ ] { LocationPoweredCell . class } , new String [ ] { " imageView " } , null , null , null , Theme . key_dialogEmptyImage ) ) ;
themeDescriptions . add ( new ThemeDescription ( listView , 0 , new Class [ ] { LocationPoweredCell . class } , new String [ ] { " textView2 " } , null , null , null , Theme . key_dialogEmptyText ) ) ;
return themeDescriptions ;
2017-03-31 01:58:05 +02:00
}
2013-10-25 17:19:00 +02:00
}