[android] remove unused Java classes

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
Arnaud Vergnet 2022-07-03 02:49:08 +02:00 committed by Alexander Borsuk
parent 4e52e730e6
commit f9e8ba4c18
37 changed files with 14 additions and 2066 deletions

View file

@ -92,12 +92,7 @@
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/margin_base"/>
<com.mapswithme.maps.widget.FadeView
android:id="@+id/fade_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:visibility="gone"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</FrameLayout>

View file

@ -1,6 +0,0 @@
package com.mapswithme.maps;
public interface ClickMenuDelegate
{
void onMenuItemClick();
}

View file

@ -1,61 +0,0 @@
package com.mapswithme.maps;
import java.util.Timer;
import java.util.TimerTask;
public class VideoTimer
{
private static final String TAG = "VideoTimer";
Timer m_timer;
private native void nativeInit();
private native void nativeRun();
public class VideoTimerTask extends TimerTask
{
@Override
public void run()
{
nativeRun();
}
}
VideoTimerTask m_timerTask;
int m_interval;
public VideoTimer()
{
m_interval = 1000 / 60;
nativeInit();
}
void start()
{
m_timerTask = new VideoTimerTask();
m_timer = new Timer("VideoTimer");
m_timer.scheduleAtFixedRate(m_timerTask, 0, m_interval);
}
void resume()
{
m_timerTask = new VideoTimerTask();
m_timer = new Timer("VideoTimer");
m_timer.scheduleAtFixedRate(m_timerTask, 0, m_interval);
}
void pause()
{
m_timer.cancel();
}
void stop()
{
m_timer.cancel();
}
}

View file

@ -1,8 +0,0 @@
package com.mapswithme.maps.adapter;
public interface AdapterIndexAndPosition
{
int getRelativePosition();
int getIndex();
}

View file

@ -1,35 +0,0 @@
package com.mapswithme.maps.adapter;
final class AdapterIndexAndPositionImpl implements AdapterIndexAndPosition
{
private final int mIndex;
private final int mRelativePosition;
AdapterIndexAndPositionImpl(int index, int relativePosition)
{
mIndex = index;
mRelativePosition = relativePosition;
}
@Override
public int getRelativePosition()
{
return mRelativePosition;
}
@Override
public int getIndex()
{
return mIndex;
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder("AdapterIndexAndPositionImpl{");
sb.append("mIndex=").append(mIndex);
sb.append(", mRelativePosition=").append(mRelativePosition);
sb.append('}');
return sb.toString();
}
}

View file

@ -1,8 +0,0 @@
package com.mapswithme.maps.adapter;
public interface AdapterIndexAndViewType
{
int getRelativeViewType();
int getIndex();
}

View file

@ -1,55 +0,0 @@
package com.mapswithme.maps.adapter;
final class AdapterIndexAndViewTypeImpl implements AdapterIndexAndViewType
{
private final int mIndex;
private final int mViewType;
AdapterIndexAndViewTypeImpl(int index, int viewType)
{
mIndex = index;
mViewType = viewType;
}
@Override
public int getRelativeViewType()
{
return mViewType;
}
@Override
public int getIndex()
{
return mIndex;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AdapterIndexAndViewTypeImpl that = (AdapterIndexAndViewTypeImpl) o;
if (mIndex != that.mIndex) return false;
return mViewType == that.mViewType;
}
@Override
public int hashCode()
{
int result = mIndex;
result = 31 * result + mViewType;
return result;
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder("AdapterIndexAndViewTypeImpl{");
sb.append("mIndex=").append(mIndex);
sb.append(", mViewType=").append(mViewType);
sb.append('}');
return sb.toString();
}
}

View file

@ -1,14 +0,0 @@
package com.mapswithme.maps.adapter;
import androidx.annotation.NonNull;
public interface AdapterPositionConverter
{
@NonNull
AdapterIndexAndPosition toRelativePositionAndAdapterIndex(int absPosition);
@NonNull
AdapterIndexAndViewType toRelativeViewTypeAndAdapterIndex(int absViewType);
int toAbsoluteViewType(int relViewType, int adapterIndex);
}

View file

@ -1,117 +0,0 @@
package com.mapswithme.maps.adapter;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class RecyclerCompositeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
@NonNull
private final List<RecyclerView.Adapter<? extends RecyclerView.ViewHolder>> mAdapters = new ArrayList<>();
@NonNull
private final AdapterPositionConverter mIndexConverter;
@SafeVarargs
public RecyclerCompositeAdapter(@NonNull AdapterPositionConverter indexConverter,
@NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder>... adapters)
{
mIndexConverter = indexConverter;
mAdapters.addAll(Arrays.asList(adapters));
}
@Override
public final int getItemCount()
{
int total = 0;
for (RecyclerView.Adapter<? extends RecyclerView.ViewHolder> each : mAdapters)
{
total += each.getItemCount();
}
return total;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int absViewType)
{
AdapterIndexAndViewType indexAndViewType = mIndexConverter.toRelativeViewTypeAndAdapterIndex(absViewType);
int adapterIndex = indexAndViewType.getIndex();
int relViewType = indexAndViewType.getRelativeViewType();
RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter = mAdapters.get(adapterIndex);
return adapter.onCreateViewHolder(parent, relViewType);
}
@Override
public int getItemViewType(int position)
{
AdapterIndexAndPosition indexAndPosition = mIndexConverter.toRelativePositionAndAdapterIndex(position);
int adapterIndex = indexAndPosition.getIndex();
RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter = mAdapters.get(adapterIndex);
int relViewType = adapter.getItemViewType(indexAndPosition.getRelativePosition());
int absViewType = mIndexConverter.toAbsoluteViewType(relViewType, adapterIndex);
return absViewType;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
AdapterIndexAndPosition indexAndPosition = mIndexConverter.toRelativePositionAndAdapterIndex(position);
int adapterIndex = indexAndPosition.getIndex();
RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter = mAdapters.get(adapterIndex);
int relPosition = indexAndPosition.getRelativePosition();
bindViewHolder(adapter, holder, relPosition);
}
@SuppressWarnings("unchecked")
private <Holder extends RecyclerView.ViewHolder> void bindViewHolder(@NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter,
@NonNull Holder holder,
int position)
{
((RecyclerView.Adapter<Holder>) adapter).onBindViewHolder(holder, position);
}
protected static abstract class AbstractAdapterPositionConverter implements AdapterPositionConverter
{
@NonNull
@Override
public AdapterIndexAndPosition toRelativePositionAndAdapterIndex(int absPosition)
{
return getIndexAndPositionItems().get(absPosition);
}
@NonNull
@Override
public AdapterIndexAndViewType toRelativeViewTypeAndAdapterIndex(int absViewType)
{
return getIndexAndViewTypeItems().get(absViewType);
}
@Override
public int toAbsoluteViewType(int relViewType, int adapterIndex)
{
AdapterIndexAndViewType indexAndViewType = new AdapterIndexAndViewTypeImpl(adapterIndex, relViewType);
List<AdapterIndexAndViewType> items = getIndexAndViewTypeItems();
int indexOf = items.indexOf(indexAndViewType);
if (indexOf < 0)
{
throw new IllegalArgumentException("Item " + indexAndViewType + " not found in list : " +
Arrays.toString(items.toArray()));
}
return indexOf;
}
@NonNull
protected abstract List<AdapterIndexAndViewType> getIndexAndViewTypeItems();
@NonNull
protected abstract List<AdapterIndexAndPosition> getIndexAndPositionItems();
}
}

View file

@ -1,76 +0,0 @@
package com.mapswithme.maps.adapter;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
public final class RepeatablePairPositionConverter extends RecyclerCompositeAdapter.AbstractAdapterPositionConverter
{
private static final int FIRST_ADAPTER_INDEX = 0;
private static final int SECOND_ADAPTER_INDEX = 1;
@NonNull
private final List<AdapterIndexAndPosition> mIndexAndPositions;
@NonNull
private final List<AdapterIndexAndViewType> mIndexAndViewTypes;
public RepeatablePairPositionConverter(@NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> first,
@NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> second)
{
Pair<List<AdapterIndexAndPosition>, List<AdapterIndexAndViewType>> pair = mixDataSet(first,
second);
mIndexAndPositions = pair.first;
mIndexAndViewTypes = pair.second;
}
@NonNull
private static Pair<List<AdapterIndexAndPosition>, List<AdapterIndexAndViewType>> mixDataSet(
@NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> first,
@NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> second)
{
List<AdapterIndexAndPosition> indexAndPositions = new ArrayList<>();
List<AdapterIndexAndViewType> indexAndViewTypes = new ArrayList<>();
int secondAdapterCount = second.getItemCount();
int firstAdapterCount = first.getItemCount();
if (secondAdapterCount != firstAdapterCount)
throw new IllegalArgumentException("firstAdapterCount different from secondAdapterCount");
for (int i = 0; i < secondAdapterCount; i++)
{
indexAndPositions.add(new AdapterIndexAndPositionImpl(FIRST_ADAPTER_INDEX, i));
indexAndPositions.add(new AdapterIndexAndPositionImpl(SECOND_ADAPTER_INDEX, i));
AdapterIndexAndViewType viewTypeFirst = new AdapterIndexAndViewTypeImpl(FIRST_ADAPTER_INDEX, first.getItemViewType(i));
AdapterIndexAndViewType viewTypeSecond = new AdapterIndexAndViewTypeImpl(SECOND_ADAPTER_INDEX, second.getItemViewType(i));
if (!indexAndViewTypes.contains(viewTypeFirst))
indexAndViewTypes.add(viewTypeFirst);
if (!indexAndViewTypes.contains(viewTypeSecond))
indexAndViewTypes.add(viewTypeSecond);
}
return new Pair<>(indexAndPositions, indexAndViewTypes);
}
@NonNull
@Override
protected List<AdapterIndexAndViewType> getIndexAndViewTypeItems()
{
return mIndexAndViewTypes;
}
@NonNull
@Override
protected List<AdapterIndexAndPosition> getIndexAndPositionItems()
{
return mIndexAndPositions;
}
}

View file

@ -1,45 +0,0 @@
package com.mapswithme.maps.base;
import android.os.Bundle;
import androidx.annotation.CallSuper;
import androidx.appcompat.widget.Toolbar;
import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;
public abstract class BaseMwmExtraTitleActivity extends BaseMwmFragmentActivity
{
protected static final String EXTRA_TITLE = "activity_title";
@Override
@CallSuper
protected void onSafeCreate(Bundle savedInstanceState)
{
super.onSafeCreate(savedInstanceState);
String title = "";
Bundle bundle = getIntent().getExtras();
if (bundle != null)
{
title = bundle.getString(EXTRA_TITLE);
}
Toolbar toolbar = getToolbar();
UiUtils.extendViewWithStatusBar(toolbar);
toolbar.setTitle(title);
UiUtils.showHomeUpButton(toolbar);
displayToolbarAsActionBar();
}
@Override
protected int getContentLayoutResId()
{
return R.layout.activity_fragment_and_toolbar;
}
@Override
protected int getFragmentContentResId()
{
return R.id.fragment_container;
}
}

View file

@ -1,43 +0,0 @@
package com.mapswithme.maps.base;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.ListFragment;
import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
@Deprecated
public abstract class BaseMwmListFragment extends ListFragment
{
private Toolbar mToolbar;
@Override
public void onAttach(Context context)
{
super.onAttach(context);
Utils.detachFragmentIfCoreNotInitialized(context, this);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
mToolbar = view.findViewById(R.id.toolbar);
if (mToolbar != null)
{
UiUtils.setupNavigationIcon(mToolbar, v -> Utils.navigateToParent(getActivity()));
}
}
public Toolbar getToolbar()
{
return mToolbar;
}
}

View file

@ -1,22 +0,0 @@
package com.mapswithme.maps.base;
import android.app.Activity;
import android.view.View;
import androidx.annotation.NonNull;
import com.mapswithme.maps.widget.ToolbarController;
public class FinishActivityToolbarController extends ToolbarController
{
public FinishActivityToolbarController(@NonNull View root, @NonNull Activity activity)
{
super(root, activity);
}
@Override
public void onUpClick()
{
requireActivity().finish();
}
}

View file

@ -27,7 +27,7 @@ import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
import com.mapswithme.maps.dialog.DialogUtils;
import com.mapswithme.maps.dialog.EditTextDialogFragment;
import com.mapswithme.maps.widget.PlaceholderView;
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
import com.mapswithme.maps.widget.recycler.DividerItemDecorationWithPadding;
import com.mapswithme.util.StorageUtils;
import com.mapswithme.util.bottomsheet.MenuBottomSheetFragment;
import com.mapswithme.util.bottomsheet.MenuBottomSheetItem;
@ -99,8 +99,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment<Bookmark
if (rw == null) return;
rw.setNestedScrollingEnabled(false);
RecyclerView.ItemDecoration decor = ItemDecoratorFactory
.createDecoratorWithPadding(getContext());
RecyclerView.ItemDecoration decor = new DividerItemDecorationWithPadding(getContext());
rw.addItemDecoration(decor);
mCategoriesAdapterObserver = new CategoriesAdapterObserver(this);
BookmarkManager.INSTANCE.addCategoriesUpdatesListener(mCategoriesAdapterObserver);

View file

@ -38,7 +38,7 @@ import com.mapswithme.maps.search.NativeBookmarkSearchListener;
import com.mapswithme.maps.search.SearchEngine;
import com.mapswithme.maps.widget.SearchToolbarController;
import com.mapswithme.maps.widget.placepage.EditBookmarkFragment;
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
import com.mapswithme.maps.widget.recycler.DividerItemDecorationWithPadding;
import com.mapswithme.util.CrashlyticsUtils;
import com.mapswithme.util.SharingUtils;
import com.mapswithme.util.UiUtils;
@ -274,8 +274,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<ConcatAdapter
private void configureRecyclerDividers()
{
RecyclerView.ItemDecoration decorWithPadding = ItemDecoratorFactory
.createDecoratorWithPadding(requireContext());
RecyclerView.ItemDecoration decorWithPadding = new DividerItemDecorationWithPadding(requireContext());
getRecyclerView().addItemDecoration(decorWithPadding);
getRecyclerView().addOnScrollListener(mRecyclerListener);
}

View file

@ -1,58 +0,0 @@
package com.mapswithme.maps.bookmarks.data;
import android.graphics.Point;
import android.os.Parcel;
import android.os.Parcelable;
public class ParcelablePoint implements Parcelable
{
private final Point mInternalPoint;
public Point getPoint()
{
return mInternalPoint;
}
@Override
public int describeContents()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
dest.writeInt(mInternalPoint.x);
dest.writeInt(mInternalPoint.y);
}
private ParcelablePoint(Parcel in)
{
mInternalPoint = new Point(in.readInt(), in.readInt());
}
public ParcelablePoint(int x, int y)
{
mInternalPoint = new Point(x, y);
}
public ParcelablePoint(Point position)
{
mInternalPoint = new Point(position);
}
public static final Parcelable.Creator<ParcelablePoint> CREATOR = new Parcelable.Creator<ParcelablePoint>()
{
public ParcelablePoint createFromParcel(Parcel in)
{
return new ParcelablePoint(in);
}
public ParcelablePoint[] newArray(int size)
{
return new ParcelablePoint[size];
}
};
}

View file

@ -1,112 +0,0 @@
package com.mapswithme.maps.bookmarks.data;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class PaymentData implements Parcelable
{
@NonNull
private final String mServerId;
@NonNull
private final String mProductId;
@NonNull
private final String mName;
@Nullable
private final String mImgUrl;
@NonNull
private final String mAuthorName;
@NonNull
private final String mGroup;
public PaymentData(@NonNull String serverId, @NonNull String productId, @NonNull String name,
@Nullable String imgUrl, @NonNull String authorName, @NonNull String group)
{
mServerId = serverId;
mProductId = productId;
mName = name;
mImgUrl = imgUrl;
mAuthorName = authorName;
mGroup = group;
}
private PaymentData(Parcel in)
{
mServerId = in.readString();
mProductId = in.readString();
mName = in.readString();
mImgUrl = in.readString();
mAuthorName = in.readString();
mGroup = in.readString();
}
public static final Creator<PaymentData> CREATOR = new Creator<PaymentData>()
{
@Override
public PaymentData createFromParcel(Parcel in)
{
return new PaymentData(in);
}
@Override
public PaymentData[] newArray(int size)
{
return new PaymentData[size];
}
};
@NonNull
public String getServerId()
{
return mServerId;
}
@NonNull
public String getProductId()
{
return mProductId;
}
@NonNull
public String getName()
{
return mName;
}
@Nullable
public String getImgUrl()
{
return mImgUrl;
}
@NonNull
public String getAuthorName()
{
return mAuthorName;
}
@NonNull
public String getGroup()
{
return mGroup;
}
@Override
public int describeContents()
{
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
dest.writeString(mServerId);
dest.writeString(mProductId);
dest.writeString(mName);
dest.writeString(mImgUrl);
dest.writeString(mAuthorName);
dest.writeString(mGroup);
}
}

View file

@ -1,7 +0,0 @@
package com.mapswithme.maps.content;
public interface CoreDetachable
{
void attachCore();
void detachCore();
}

View file

@ -1,208 +0,0 @@
package com.mapswithme.maps.widget;
import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.mapswithme.maps.R;
import com.mapswithme.util.ThemeUtils;
import com.mapswithme.util.UiUtils;
/**
* This widget allows the user to flip left and right through pages of data.
* Also it can be configured with indicator view that will be placed below of pages.
* The indicator will be drawn as the gray dots. A dots count will be equal page count.
* The bold dot corresponds the current page.
* <p>
* There are few dependencies that should be provided to get this
* widget work:
* <p>
* <ul>
* <li>@see {@link ViewPager}</li>
* <li>@see {@link PagerAdapter}</li>
* <li>An indicator. It's a {@link ViewGroup} which will consist dots. If the indicator
* is not needed this dependency can be missed or <code>null</code></li>
* <li>@see {@link Context}</li>
* <li>A page listener is an observable mechanism for listening page changing. It can be missed or null</li>
* </ul>
*/
public class DotPager implements ViewPager.OnPageChangeListener
{
@NonNull
private final ViewPager mPager;
@NonNull
private final PagerAdapter mAdapter;
@Nullable
private final ViewGroup mIndicator;
@NonNull
private final ImageView[] mDots;
@NonNull
private final Context mContext;
@Nullable
private final OnPageChangedListener mListener;
@StringRes
private final int mActiveDotDrawableResId;
@StringRes
private final int mInactiveDotDrawableResId;
private DotPager(@NonNull Builder builder)
{
mContext = builder.mContext;
mPager = builder.mPager;
mAdapter = builder.mAdapter;
mIndicator = builder.mIndicatorContainer;
mListener = builder.mListener;
mDots = new ImageView[mAdapter.getCount()];
mActiveDotDrawableResId = builder.mActiveDotDrawableResId;
mInactiveDotDrawableResId = builder.mInactiveDotDrawableResId;
}
public void show()
{
configure();
updateIndicator();
}
private void configure()
{
configurePager();
configureIndicator();
}
private void configurePager()
{
mPager.setAdapter(mAdapter);
mPager.clearOnPageChangeListeners();
mPager.addOnPageChangeListener(this);
}
private void configureIndicator()
{
if (mIndicator == null)
return;
mIndicator.removeAllViews();
if (mAdapter.getCount() == 1)
return;
for (int i = 0; i < mDots.length; i++)
{
mDots[i] = new ImageView(mContext);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 0, UiUtils.dimen(mContext, R.dimen.margin_half), 0);
mIndicator.addView(mDots[i], i, layoutParams);
}
}
@Override
public void onPageSelected(int position)
{
if (mIndicator != null)
updateIndicator();
if (mListener != null)
mListener.onPageChanged(position);
}
private void updateIndicator()
{
if (mAdapter.getCount() == 1)
return;
int currentPage = mPager.getCurrentItem();
for (int i = 0; i < mAdapter.getCount(); i++)
{
boolean isCurPage = i == currentPage;
@DrawableRes int dotDrawable;
if (ThemeUtils.isNightTheme(mContext))
dotDrawable = isCurPage ? R.drawable.news_marker_active_night : R.drawable.news_marker_inactive_night;
else
dotDrawable = isCurPage ? mActiveDotDrawableResId : mInactiveDotDrawableResId;
mDots[i].setImageResource(dotDrawable);
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{
//no op
}
@Override
public void onPageScrollStateChanged(int state)
{
//no op
}
public static class Builder
{
@NonNull
private final ViewPager mPager;
@NonNull
private final PagerAdapter mAdapter;
@Nullable
private ViewGroup mIndicatorContainer;
@NonNull
private final Context mContext;
@Nullable
private OnPageChangedListener mListener;
@DrawableRes
private int mActiveDotDrawableResId = R.drawable.news_marker_active;
@DrawableRes
private int mInactiveDotDrawableResId = R.drawable.news_marker_inactive;
public Builder(@NonNull Context context, @NonNull ViewPager pager, @NonNull PagerAdapter adapter)
{
mContext = context;
mPager = pager;
mAdapter = adapter;
}
public Builder setIndicatorContainer(@NonNull ViewGroup indicatorContainer)
{
mIndicatorContainer = indicatorContainer;
return this;
}
public Builder setPageChangedListener(@Nullable OnPageChangedListener listener)
{
mListener = listener;
return this;
}
@NonNull
public Builder setActiveDotDrawable(@DrawableRes int resId)
{
mActiveDotDrawableResId = resId;
return this;
}
@NonNull
public Builder setInactiveDotDrawable(@DrawableRes int resId)
{
mInactiveDotDrawableResId = resId;
return this;
}
public DotPager build()
{
return new DotPager(this);
}
}
public interface OnPageChangedListener
{
void onPageChanged(int position);
}
}

View file

@ -1,99 +0,0 @@
package com.mapswithme.maps.widget;
import android.animation.Animator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.FrameLayout;
import androidx.annotation.IntegerRes;
import androidx.annotation.NonNull;
import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;
public class FadeView extends FrameLayout
{
private static final float FADE_ALPHA_VALUE = 0.4f;
@IntegerRes
private static final int DURATION_RES_ID = R.integer.anim_fade_main;
private final Animator.AnimatorListener mFadeInListener = new UiUtils.SimpleAnimatorListener()
{
@Override
public void onAnimationEnd(Animator animation)
{
UiUtils.show(FadeView.this);
animation.removeListener(this);
}
};
private final Animator.AnimatorListener mFadeOutListener = new UiUtils.SimpleAnimatorListener()
{
@Override
public void onAnimationEnd(Animator animation)
{
UiUtils.hide(FadeView.this);
animation.removeListener(this);
}
};
public interface Listener
{
boolean onTouch();
}
private Listener mListener;
public FadeView(Context context)
{
super(context);
}
public FadeView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public FadeView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
}
public void setListener(Listener listener)
{
mListener = listener;
}
public void fadeIn()
{
setAlpha(0.0f);
UiUtils.show(this);
animate().alpha(FADE_ALPHA_VALUE)
.setDuration(getResources().getInteger(DURATION_RES_ID))
.setListener(mFadeInListener)
.start();
}
public void fadeOut()
{
setAlpha(FADE_ALPHA_VALUE);
animate().alpha(0.0f)
.setDuration(getResources().getInteger(DURATION_RES_ID))
.setListener(mFadeOutListener)
.start();
}
@Override
public boolean onTouchEvent(@NonNull MotionEvent event)
{
if (event.getAction() != MotionEvent.ACTION_DOWN)
return true;
if (mListener == null || mListener.onTouch())
fadeOut();
return true;
}
}

View file

@ -1,72 +0,0 @@
package com.mapswithme.maps.widget;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import java.util.NoSuchElementException;
public class FragmentPageViewProvider implements PageViewProvider
{
private static final String ANDROID_SWITCHER_TAG_SEGMENT = "android:switcher:";
private static final String SEPARATOR_TAG_SEGMENT = ":";
@NonNull
private final FragmentManager mFragManager;
private final int mPagerId;
FragmentPageViewProvider(@NonNull FragmentManager fragManager, @NonNull ViewPager pager)
{
checkAdapterClass(pager);
mFragManager = fragManager;
mPagerId = pager.getId();
}
private static void checkAdapterClass(@NonNull ViewPager pager)
{
try
{
FragmentPagerAdapter adapter = (FragmentPagerAdapter) pager.getAdapter();
if (adapter == null)
throw new IllegalStateException("Adapter not found");
}
catch (ClassCastException e)
{
throw new IllegalStateException("Adapter has to be FragmentPagerAdapter or its descendant");
}
}
@Nullable
@Override
public View findViewByIndex(int index)
{
String tag = makePagerFragmentTag(index);
Fragment page = getSupportFragmentManager().findFragmentByTag(tag);
if (page == null)
throw new NoSuchElementException("No such element for tag : " + tag);
return page.getView();
}
private int getId()
{
return mPagerId;
}
@NonNull
private FragmentManager getSupportFragmentManager()
{
return mFragManager;
}
@NonNull
private String makePagerFragmentTag(int index)
{
return ANDROID_SWITCHER_TAG_SEGMENT + getId() + SEPARATOR_TAG_SEGMENT + index;
}
}

View file

@ -1,33 +0,0 @@
package com.mapswithme.maps.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;
/**
* Workaround for not appearing soft keyboard in webview.
* Check bugreport at https://code.google.com/p/android/issues/detail?id=7189 for more details.
*/
public class InputWebView extends WebView
{
public InputWebView(Context context)
{
super(context);
}
public InputWebView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public InputWebView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
}
@Override
public boolean onCheckIsTextEditor()
{
return true;
}
}

View file

@ -1,163 +0,0 @@
package com.mapswithme.maps.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;
public class InteractiveCounterView extends RelativeLayout
{
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private View mMinusView;
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private View mPlusView;
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private TextView mCounterView;
@Nullable
private String mTitle;
@Nullable
private String mSubtitle;
private int mMinValue;
private int mMaxValue;
private int mDefaultValue;
@DrawableRes
private int mIconRes;
@Nullable
private CounterChangeListener mChangeListener;
@NonNull
private final OnClickListener mPlusClickListener = new OnClickListener()
{
@Override
public void onClick(View v)
{
int value = getCurrentValue();
mCounterView.setText(String.valueOf(++value));
updateConstraints();
if (mChangeListener != null)
mChangeListener.onChange();
}
};
@NonNull
private final OnClickListener mMinusClickListener = new OnClickListener()
{
@Override
public void onClick(View v)
{
int value = getCurrentValue();
mCounterView.setText(String.valueOf(--value));
updateConstraints();
if (mChangeListener != null)
mChangeListener.onChange();
}
};
public InteractiveCounterView(Context context)
{
super(context);
}
public InteractiveCounterView(Context context, AttributeSet attrs)
{
super(context, attrs);
init(attrs);
}
public InteractiveCounterView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
init(attrs);
}
public InteractiveCounterView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
{
super(context, attrs, defStyleAttr, defStyleRes);
init(attrs);
}
private void init(@Nullable AttributeSet attrs)
{
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InteractiveCounterView);
try
{
mMinValue = a.getInt(R.styleable.InteractiveCounterView_minValue, 0);
mMaxValue = a.getInt(R.styleable.InteractiveCounterView_maxValue, Integer.MAX_VALUE);
mDefaultValue = a.getInt(R.styleable.InteractiveCounterView_android_defaultValue, mMinValue);
mIconRes = a.getResourceId(R.styleable.InteractiveCounterView_android_src, UiUtils.NO_ID);
mTitle = a.getString(R.styleable.InteractiveCounterView_title);
mSubtitle = a.getString(R.styleable.InteractiveCounterView_subtitle);
LayoutInflater.from(getContext()).inflate(R.layout.interactive_counter, this, true);
}
finally
{
a.recycle();
}
}
@Override
protected void onFinishInflate()
{
super.onFinishInflate();
ImageView iconView = findViewById(R.id.icon);
iconView.setImageResource(mIconRes);
TextView titleView = findViewById(R.id.title);
UiUtils.showIf(!TextUtils.isEmpty(mTitle), titleView);
titleView.setText(mTitle);
TextView subtitleView = findViewById(R.id.subtitle);
UiUtils.showIf(!TextUtils.isEmpty(mSubtitle), subtitleView);
subtitleView.setText(mSubtitle);
mMinusView = findViewById(R.id.minus);
mMinusView.setOnClickListener(mMinusClickListener);
mPlusView = findViewById(R.id.plus);
mPlusView.setOnClickListener(mPlusClickListener);
mCounterView = findViewById(R.id.counter);
if (mDefaultValue >= mMinValue && mDefaultValue <= mMaxValue)
mCounterView.setText(String.valueOf(mDefaultValue));
else
mCounterView.setText(String.valueOf(mMinValue));
updateConstraints();
}
public int getCurrentValue()
{
return Integer.parseInt(mCounterView.getText().toString());
}
public void setCurrentValue(int value)
{
mCounterView.setText(String.valueOf(value));
updateConstraints();
}
private void updateConstraints()
{
int value = getCurrentValue();
mMinusView.setEnabled(value != mMinValue);
mPlusView.setEnabled(value != mMaxValue);
}
public void setChangeListener(@Nullable CounterChangeListener listener)
{
mChangeListener = listener;
}
public interface CounterChangeListener
{
void onChange();
}
}

View file

@ -1,56 +0,0 @@
package com.mapswithme.maps.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.text.Layout;
import android.util.AttributeSet;
import android.widget.TextView;
public class LineCountTextView extends TextView
{
public interface OnLineCountCalculatedListener
{
void onLineCountCalculated(boolean grater);
}
private OnLineCountCalculatedListener mListener;
public LineCountTextView(Context context)
{
super(context);
}
public LineCountTextView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public LineCountTextView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Layout layout = getLayout();
if (layout != null)
{
int textHeight = layout.getHeight();
int viewHeight = getHeight();
if (mListener != null)
{
mListener.onLineCountCalculated(textHeight > viewHeight);
}
}
}
public void setListener(OnLineCountCalculatedListener listener)
{
mListener = listener;
}
}

View file

@ -1,11 +0,0 @@
package com.mapswithme.maps.widget;
import android.view.View;
import androidx.annotation.Nullable;
interface PageViewProvider
{
@Nullable
View findViewByIndex(int index);
}

View file

@ -1,15 +0,0 @@
package com.mapswithme.maps.widget;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager.widget.ViewPager;
class PageViewProviderFactory
{
@NonNull
static PageViewProvider defaultProvider(@NonNull FragmentActivity activity,
@NonNull ViewPager pager)
{
return new FragmentPageViewProvider(activity.getSupportFragmentManager(), pager);
}
}

View file

@ -1,84 +0,0 @@
package com.mapswithme.maps.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import androidx.annotation.AttrRes;
import androidx.annotation.DrawableRes;
import com.mapswithme.util.Graphics;
public class RotateByAlphaDrawable extends Drawable
{
private final Drawable mBaseDrawable;
private Rect mBounds;
private float mAngle;
private float mBaseAngle;
public RotateByAlphaDrawable(Context context, @DrawableRes int resId, @AttrRes int tintAttr, boolean transparent)
{
super();
mBaseDrawable = Graphics.tint(context, resId, tintAttr);
computeAngle(transparent ? 0x00 : 0xFF);
}
private void computeAngle(int alpha)
{
mAngle = (alpha - 0xFF) / 3 + mBaseAngle;
}
public RotateByAlphaDrawable setBaseAngle(float angle)
{
mBaseAngle = angle;
return this;
}
public RotateByAlphaDrawable setInnerBounds(Rect bounds)
{
mBounds = bounds;
setBounds(mBounds);
return this;
}
@Override
public void setAlpha(int alpha)
{
mBaseDrawable.setAlpha(alpha);
computeAngle(alpha);
}
@Override
public void setColorFilter(ColorFilter cf)
{
mBaseDrawable.setColorFilter(cf);
}
@Override
public int getOpacity()
{
return mBaseDrawable.getOpacity();
}
@Override
protected void onBoundsChange(Rect bounds)
{
if (mBounds != null)
bounds = mBounds;
super.onBoundsChange(bounds);
mBaseDrawable.setBounds(bounds);
}
@Override
public void draw(Canvas canvas)
{
canvas.save();
canvas.rotate(mAngle, mBaseDrawable.getBounds().width() / 2, mBaseDrawable.getBounds().height() / 2);
mBaseDrawable.draw(canvas);
canvas.restore();
}
}

View file

@ -1,30 +0,0 @@
package com.mapswithme.maps.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;
public class StaticGridView extends GridView
{
public StaticGridView(Context context)
{
super(context);
}
public StaticGridView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public StaticGridView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST));
getLayoutParams().height = getMeasuredHeight();
}
}

View file

@ -1,46 +0,0 @@
package com.mapswithme.maps.widget;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
/**
* Same as {@link TransitionDrawable} but correctly tracks transition direction.
* I.e. if transition is in "start" state, {@link #reverseTransition(int)} does not start straight transition.
*/
public class TrackedTransitionDrawable extends TransitionDrawable
{
private boolean mStart = true;
public TrackedTransitionDrawable(Drawable[] layers)
{
super(layers);
}
@Override
public void startTransition(int durationMillis)
{
if (!mStart)
return;
mStart = false;
super.startTransition(durationMillis);
}
@Override
public void reverseTransition(int duration)
{
if (mStart)
return;
mStart = true;
super.reverseTransition(duration);
}
@Override
public void resetTransition()
{
mStart = true;
super.resetTransition();
}
}

View file

@ -1,15 +1,21 @@
package com.mapswithme.maps.widget.recycler;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.annotation.DimenRes;
import androidx.annotation.Dimension;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.Holders;
import java.util.Objects;
public class DividerItemDecorationWithPadding extends RecyclerView.ItemDecoration
{
@Dimension
@ -17,10 +23,10 @@ public class DividerItemDecorationWithPadding extends RecyclerView.ItemDecoratio
@NonNull
private final Drawable mDivider;
public DividerItemDecorationWithPadding(@NonNull Drawable divider, @Dimension int startMargin)
public DividerItemDecorationWithPadding(@NonNull Context context)
{
mDivider = divider;
mStartMargin = startMargin;
mDivider = Objects.requireNonNull(context.getDrawable(R.drawable.divider_base));
mStartMargin = context.getResources().getDimensionPixelSize(R.dimen.margin_quadruple_plus_half);
}
@Override

View file

@ -1,129 +0,0 @@
package com.mapswithme.maps.widget.recycler;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
/**
* Adds interior dividers to a RecyclerView with a GridLayoutManager.
*/
public class GridDividerItemDecoration extends RecyclerView.ItemDecoration
{
@NonNull
private final Drawable mHorizontalDivider;
@NonNull
private final Drawable mVerticalDivider;
private final int mNumColumns;
/**
* Sole constructor. Takes in {@link Drawable} objects to be used as
* horizontal and vertical dividers.
*
* @param horizontalDivider A divider {@code Drawable} to be drawn on the
* rows of the grid of the RecyclerView
* @param verticalDivider A divider {@code Drawable} to be drawn on the
* columns of the grid of the RecyclerView
* @param numColumns The number of columns in the grid of the RecyclerView
*/
public GridDividerItemDecoration(@NonNull Drawable horizontalDivider,
@NonNull Drawable verticalDivider, int numColumns)
{
mHorizontalDivider = horizontalDivider;
mVerticalDivider = verticalDivider;
mNumColumns = numColumns;
}
/**
* Draws horizontal and/or vertical dividers onto the parent RecyclerView.
*
* @param canvas The {@link Canvas} onto which dividers will be drawn
* @param parent The RecyclerView onto which dividers are being added
* @param state The current RecyclerView.State of the RecyclerView
*/
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state)
{
drawHorizontalDividers(canvas, parent);
drawVerticalDividers(canvas, parent);
}
/**
* Determines the size and location of offsets between items in the parent
* RecyclerView.
*
* @param outRect The {@link Rect} of offsets to be added around the child view
* @param view The child view to be decorated with an offset
* @param parent The RecyclerView onto which dividers are being added
* @param state The current RecyclerView.State of the RecyclerView
*/
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
{
super.getItemOffsets(outRect, view, parent, state);
boolean childIsInLeftmostColumn = (parent.getChildAdapterPosition(view) % mNumColumns) == 0;
if (!childIsInLeftmostColumn)
outRect.left = mHorizontalDivider.getIntrinsicWidth();
boolean childIsInFirstRow = (parent.getChildAdapterPosition(view)) < mNumColumns;
if (!childIsInFirstRow)
outRect.top = mVerticalDivider.getIntrinsicHeight();
}
/**
* Adds horizontal dividers to a RecyclerView with a GridLayoutManager or
* its subclass.
*
* @param canvas The {@link Canvas} onto which dividers will be drawn
* @param parent The RecyclerView onto which dividers are being added
*/
private void drawHorizontalDividers(Canvas canvas, RecyclerView parent)
{
int parentTop = parent.getPaddingTop();
int parentBottom = parent.getHeight() - parent.getPaddingBottom();
for (int i = 0; i < mNumColumns; i++)
{
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int parentLeft = child.getRight() + params.rightMargin;
int parentRight = parentLeft + mHorizontalDivider.getIntrinsicWidth();
mHorizontalDivider.setBounds(parentLeft, parentTop, parentRight, parentBottom);
mHorizontalDivider.draw(canvas);
}
}
/**
* Adds vertical dividers to a RecyclerView with a GridLayoutManager or its
* subclass.
*
* @param canvas The {@link Canvas} onto which dividers will be drawn
* @param parent The RecyclerView onto which dividers are being added
*/
private void drawVerticalDividers(Canvas canvas, RecyclerView parent)
{
int parentLeft = parent.getPaddingLeft();
int parentRight = parent.getWidth() - parent.getPaddingRight();
int childCount = parent.getChildCount();
int numRows = (childCount + (mNumColumns - 1)) / mNumColumns;
for (int i = 0; i < numRows - 1; i++)
{
View child = parent.getChildAt(i * mNumColumns);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int parentTop = child.getBottom() + params.bottomMargin;
int parentBottom = parentTop + mVerticalDivider.getIntrinsicHeight();
mVerticalDivider.setBounds(parentLeft, parentTop, parentRight, parentBottom);
mVerticalDivider.draw(canvas);
}
}
}

View file

@ -1,39 +0,0 @@
package com.mapswithme.maps.widget.recycler;
import android.content.Context;
import android.graphics.Rect;
import android.view.View;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;
class HotelDividerItemDecoration extends DividerItemDecoration
{
/**
* Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a
* {@link LinearLayoutManager}.
*
* @param context Current context, it will be used to access resources.
* @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}.
*/
HotelDividerItemDecoration(Context context, int orientation)
{
super(context, orientation);
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
{
super.getItemOffsets(outRect, view, parent, state);
int itemCount = state.getItemCount();
int itemPosition = parent.getChildAdapterPosition(view);
// Last position.
if (itemPosition != RecyclerView.NO_POSITION && itemPosition > 0
&& itemCount > 0 && itemPosition == itemCount - 1)
{
outRect.set(0, 0, 0, 0);
}
}
}

View file

@ -1,91 +0,0 @@
package com.mapswithme.maps.widget.recycler;
import android.content.Context;
import androidx.annotation.DimenRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;
import com.mapswithme.maps.R;
import java.util.Objects;
public class ItemDecoratorFactory
{
@NonNull
public static RecyclerView.ItemDecoration createHotelGalleryDecorator(@NonNull Context context,
int orientation)
{
DividerItemDecoration decoration = new HotelDividerItemDecoration(context, orientation);
@DrawableRes
int dividerId = R.drawable.divider_transparent_quarter;
decoration.setDrawable(Objects.requireNonNull(ContextCompat.getDrawable(context, dividerId)));
return decoration;
}
@NonNull
public static RecyclerView.ItemDecoration createSponsoredGalleryDecorator(@NonNull Context context,
int orientation)
{
DividerItemDecoration decoration = new SponsoredDividerItemDecoration(context, orientation);
@DrawableRes
int dividerId = R.drawable.divider_transparent_half;
decoration.setDrawable(Objects.requireNonNull(ContextCompat.getDrawable(context, dividerId)));
return decoration;
}
public static RecyclerView.ItemDecoration createPlacePagePromoGalleryDecorator(@NonNull Context context,
int orientation)
{
DividerItemDecoration decoration = new SponsoredDividerItemDecoration(context, orientation);
@DrawableRes
int dividerId = R.drawable.divider_transparent_quarter;
decoration.setDrawable(Objects.requireNonNull(ContextCompat.getDrawable(context, dividerId)));
return decoration;
}
@NonNull
public static RecyclerView.ItemDecoration createRatingRecordDecorator(@NonNull Context context,
int orientation,
@DrawableRes int dividerResId)
{
DividerItemDecoration decoration = new DividerItemDecoration(context, orientation);
decoration.setDrawable(Objects.requireNonNull(ContextCompat.getDrawable(context, dividerResId)));
return decoration;
}
@NonNull
public static RecyclerView.ItemDecoration createDefaultDecorator(@NonNull Context context,
int orientation)
{
return new DividerItemDecoration(context, orientation);
}
@NonNull
public static RecyclerView.ItemDecoration createVerticalDefaultDecorator(@NonNull Context context)
{
return new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);
}
@NonNull
public static RecyclerView.ItemDecoration createDecoratorWithPadding(@NonNull Context context)
{
@DrawableRes
int dividerRes = R.drawable.divider_base;
@DimenRes
int marginDimen = R.dimen.margin_quadruple_plus_half;
return new DividerItemDecorationWithPadding(
Objects.requireNonNull(context.getDrawable(dividerRes)),
context.getResources().getDimensionPixelSize(marginDimen));
}
@NonNull
public static RecyclerView.ItemDecoration createRatingRecordDecorator(@NonNull Context context,
int horizontal)
{
return createRatingRecordDecorator(context, horizontal, R.drawable.divider_transparent_base);
}
}

View file

@ -1,114 +0,0 @@
package com.mapswithme.maps.widget.recycler;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.core.view.ViewPropertyAnimatorListener;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;
import com.mapswithme.util.UiUtils;
public class SingleChangeItemAnimator extends SimpleItemAnimator
{
private static final int DURATION = 350;
@Nullable
private ViewPropertyAnimatorCompat mAnimation;
private boolean mFinished;
@Override
public long getChangeDuration()
{
return DURATION;
}
@Override
public boolean animateChange(final RecyclerView.ViewHolder oldHolder,
final RecyclerView.ViewHolder newHolder, int fromLeft, int fromTop,
int toLeft, int toTop)
{
mAnimation = ViewCompat.animate(oldHolder.itemView);
if (mAnimation == null)
return false;
mFinished = false;
ViewGroup group = (ViewGroup) ((ViewGroup) oldHolder.itemView).getChildAt(0);
for (int i = 0; i < group.getChildCount(); i++)
UiUtils.hide(group.getChildAt(i));
int from = oldHolder.itemView.getWidth();
int target = newHolder.itemView.getWidth();
oldHolder.itemView.setPivotX(0.0f);
mAnimation
.setDuration(getChangeDuration())
.scaleX(((float) target / (float) from))
.setListener(new ViewPropertyAnimatorListener()
{
@Override
public void onAnimationStart(View view) {}
@Override
public void onAnimationCancel(View view) {}
@Override
public void onAnimationEnd(View view)
{
mFinished = true;
mAnimation.setListener(null);
UiUtils.hide(oldHolder.itemView, newHolder.itemView);
dispatchChangeFinished(oldHolder, true);
dispatchChangeFinished(newHolder, false);
dispatchAnimationsFinished();
onAnimationFinished();
}
})
.start();
return false;
}
public void onAnimationFinished() {}
@Override
public void endAnimation(RecyclerView.ViewHolder item)
{
if (mAnimation != null)
mAnimation.cancel();
}
@Override
public void endAnimations()
{
if (mAnimation != null)
mAnimation.cancel();
}
@Override
public boolean isRunning()
{
return mAnimation != null && !mFinished;
}
@Override
public boolean animateRemove(final RecyclerView.ViewHolder holder)
{
return false;
}
@Override
public boolean animateAdd(RecyclerView.ViewHolder holder)
{
return false;
}
@Override
public boolean animateMove(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY)
{
return false;
}
@Override
public void runPendingAnimations() {}
}

View file

@ -1,43 +0,0 @@
package com.mapswithme.maps.widget.recycler;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
class SponsoredDividerItemDecoration extends DividerItemDecoration
{
private int mDividerWidth;
/**
* Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a
* {@link LinearLayoutManager}.
*
* @param context Current context, it will be used to access resources.
* @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}.
*/
SponsoredDividerItemDecoration(Context context, int orientation)
{
super(context, orientation);
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
{
super.getItemOffsets(outRect, view, parent, state);
// First element.
if (parent.getChildAdapterPosition(view) == 0)
outRect.left = mDividerWidth;
}
@Override
public void setDrawable(@NonNull Drawable drawable)
{
super.setDrawable(drawable);
mDividerWidth = drawable.getIntrinsicWidth();
}
}

View file

@ -1,90 +0,0 @@
package com.mapswithme.maps.widget.recycler;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
/**
* Adds interior dividers to a RecyclerView with a TagLayoutManager or its
* subclass.
*/
public class TagItemDecoration extends RecyclerView.ItemDecoration
{
@NonNull
private final Drawable mDivider;
public TagItemDecoration(@NonNull Drawable divider)
{
mDivider = divider;
}
/**
* Draws horizontal and vertical dividers onto the parent RecyclerView.
*
* @param canvas The {@link Canvas} onto which dividers will be drawn
* @param parent The RecyclerView onto which dividers are being added
* @param state The current RecyclerView.State of the RecyclerView
*/
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state)
{
if (state.isMeasuring())
return;
int parentRight = parent.getWidth() - parent.getPaddingRight();
int parentLeft = parent.getPaddingLeft();
int lastHeight = Integer.MIN_VALUE;
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++)
{
View child = parent.getChildAt(i);
if (child.getTop() <= lastHeight)
{
mDivider.setBounds(child.getLeft() - mDivider.getIntrinsicWidth(),
child.getTop(),
child.getLeft(),
child.getBottom());
}
else
{
mDivider.setBounds(parentLeft,
child.getTop() - mDivider.getIntrinsicHeight(),
parentRight,
child.getTop());
}
mDivider.draw(canvas);
lastHeight = child.getTop();
}
}
/**
* Determines the size and location of offsets between items in the parent
* RecyclerView.
*
* @param outRect The {@link Rect} of offsets to be added around the child
* view
* @param view The child view to be decorated with an offset
* @param parent The RecyclerView onto which dividers are being added
* @param state The current RecyclerView.State of the RecyclerView
*/
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
{
super.getItemOffsets(outRect, view, parent, state);
outRect.left = mDivider.getIntrinsicWidth();
outRect.top = mDivider.getIntrinsicHeight();
}
@NonNull
protected Drawable getDivider()
{
return mDivider;
}
}

View file

@ -1,61 +0,0 @@
package com.mapswithme.maps.widget.recycler;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
/**
* This LayoutManager designed only for use with RecyclerView.setNestedScrollingEnabled(false)
* and recycle item must be wrap_content or fixed size
*/
public class TagLayoutManager extends RecyclerView.LayoutManager
{
public TagLayoutManager()
{
setAutoMeasureEnabled(true);
}
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams()
{
return new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT,
RecyclerView.LayoutParams.WRAP_CONTENT);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
{
detachAndScrapAttachedViews(recycler);
int widthUsed = 0;
int heightUsed = 0;
int lineHeight = 0;
int itemsCountOneLine = 0;
for (int i = 0; i < getItemCount(); i++)
{
View child = recycler.getViewForPosition(i);
addView(child);
measureChildWithMargins(child, widthUsed, heightUsed);
int width = getDecoratedMeasuredWidth(child);
int height = getDecoratedMeasuredHeight(child);
lineHeight = Math.max(lineHeight, height);
if (widthUsed + width >= getWidth())
{
widthUsed = 0;
if (itemsCountOneLine > 0)
{
itemsCountOneLine = -1;
heightUsed += lineHeight;
child.forceLayout();
measureChildWithMargins(child, widthUsed, heightUsed);
width = getDecoratedMeasuredWidth(child);
height = getDecoratedMeasuredHeight(child);
}
lineHeight = 0;
}
layoutDecorated(child, widthUsed, heightUsed, widthUsed + width, heightUsed + height);
widthUsed += width;
itemsCountOneLine++;
}
}
}