[android] fix: BottomSheet colorization.

This commit is contained in:
Alexander Marchuk 2015-12-24 15:43:12 +03:00 committed by Constantin Shalnev
parent 3955669fc0
commit 5a3e49bc5f
4 changed files with 98 additions and 39 deletions

View file

@ -606,7 +606,7 @@ public class BottomSheet extends Dialog implements DialogInterface {
*/
public static class Builder {
private final Context context;
protected final Context context;
private int theme;
private final ActionMenu menu;
private CharSequence title;
@ -860,6 +860,10 @@ public class BottomSheet extends Dialog implements DialogInterface {
this.dismissListener = listener;
return this;
}
public Menu getMenu() {
return menu;
}
}

View file

@ -21,7 +21,6 @@ import android.widget.TextView;
import java.lang.ref.WeakReference;
import com.cocosw.bottomsheet.BottomSheet;
import com.mapswithme.maps.MapStorage;
import com.mapswithme.maps.R;
import com.mapswithme.maps.downloader.DownloadHelper;
@ -33,7 +32,7 @@ import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.statistics.Statistics;
public abstract class BaseDownloadAdapter extends BaseAdapter
abstract class BaseDownloadAdapter extends BaseAdapter
{
static final int TYPE_GROUP = 0;
static final int TYPE_COUNTRY_GROUP = 1;
@ -43,7 +42,7 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
static final int TYPES_COUNT = 5;
private int mActiveAnimationsCount;
public static final String PROPERTY_TRANSLATION_X = "translationX";
private static final String PROPERTY_TRANSLATION_X = "translationX";
private static final long ANIMATION_LENGTH = 250;
private final Handler mHandler = new Handler();
private ListView mListView;
@ -52,7 +51,7 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
{
private final WeakReference<BaseDownloadAdapter> mAdapterReference;
public SafeAdapterRunnable(BaseDownloadAdapter adapter)
private SafeAdapterRunnable(BaseDownloadAdapter adapter)
{
mAdapterReference = new WeakReference<>(adapter);
}
@ -73,22 +72,22 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
private final SafeAdapterRunnable mDatasetChangedRunnable = new SafeAdapterRunnable(this);
protected final LayoutInflater mInflater;
protected final DownloadFragment mFragment;
protected final boolean mHasGoogleStore;
final LayoutInflater mInflater;
final DownloadFragment mFragment;
private final boolean mHasGoogleStore;
protected final String mStatusDownloaded;
protected final String mStatusFailed;
protected final String mStatusOutdated;
protected final String mStatusNotDownloaded;
protected final String mMapOnly;
private final String mStatusDownloaded;
private final String mStatusFailed;
private final String mStatusOutdated;
private final String mStatusNotDownloaded;
private final String mMapOnly;
private final int mColorDownloaded;
private final int mColorOutdated;
private final int mColorNotDownloaded;
private final int mColorFailed;
public BaseDownloadAdapter(DownloadFragment fragment)
BaseDownloadAdapter(DownloadFragment fragment)
{
mFragment = fragment;
mInflater = mFragment.getLayoutInflater();
@ -142,7 +141,7 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
@Override
public abstract CountryItem getItem(int position);
protected void processNotDownloaded(final String name, final int position, final int newOptions, final ViewHolder holder)
private void processNotDownloaded(final String name, final int position, final int newOptions, final ViewHolder holder)
{
final long[] remoteSizes = getRemoteItemSizes(position);
final long size = newOptions > StorageOptions.MAP_OPTION_MAP_ONLY ? remoteSizes[0] : remoteSizes[1];
@ -157,7 +156,7 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
});
}
protected void confirmDownloadCancellation(final ViewHolder holder, final int position, final String name)
private void confirmDownloadCancellation(final ViewHolder holder, final int position, final String name)
{
final Dialog dlg = new AlertDialog.Builder(mFragment.getActivity())
.setTitle(name)
@ -176,7 +175,7 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
dlg.show();
}
protected void processOutOfDate(final String name, final int position, final int newOptions)
private void processOutOfDate(final String name, final int position, final int newOptions)
{
final long[] remoteSizes = getRemoteItemSizes(position);
final long size = newOptions > StorageOptions.MAP_OPTION_MAP_ONLY ? remoteSizes[0] : remoteSizes[1];
@ -191,7 +190,7 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
});
}
protected void processOnDisk(final String name, final int position, final int newOptions)
private void processOnDisk(final String name, final int position, final int newOptions)
{
new AlertDialog.Builder(mFragment.getActivity())
.setTitle(name)
@ -401,7 +400,7 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
sizes = getDownloadableItemSizes(position);
setHolderSizeString(holder, 0, sizes[1]);
setHolderPercentText(holder, mStatusOutdated);
setHolderPercentColor(holder, ThemeUtils.getColor(mListView.getContext(), R.attr.colorPrimary));
setHolderPercentColor(holder, ThemeUtils.getColor(mListView.getContext(), R.attr.colorAccent));
break;
case MapStorage.ON_DISK:
@ -787,9 +786,9 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
long[] remoteSizes = getRemoteItemSizes(position);
BottomSheet.Builder bs = BottomSheetHelper.create(mFragment.getActivity())
.title(name)
.listener(menuItemClickListener);
BottomSheetHelper.Builder bs = BottomSheetHelper.create(mFragment.getActivity())
.title(name)
.listener(menuItemClickListener);
if (status == MapStorage.ON_DISK_OUT_OF_DATE)
{
@ -851,6 +850,6 @@ public abstract class BaseDownloadAdapter extends BaseAdapter
break;
}
bs.show();
bs.tint().show();
}
}

View file

@ -6,7 +6,7 @@ import android.support.annotation.LayoutRes;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.view.View;
import com.cocosw.bottomsheet.BottomSheet;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
@ -109,18 +109,16 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
mSelectedPosition = position;
BookmarkCategory category = BookmarkManager.INSTANCE.getCategoryById(mSelectedPosition);
BottomSheet bs = BottomSheetHelper.create(getActivity())
.title(category.getName())
.sheet(R.menu.menu_bookmark_categories)
.listener(this)
.build();
BottomSheetHelper.Builder bs = BottomSheetHelper.create(getActivity())
.title(category.getName())
.sheet(R.menu.menu_bookmark_categories)
.listener(this);
MenuItem show = bs.getMenu().getItem(0);
show.setIcon(category.isVisible() ? R.drawable.ic_hide
: R.drawable.ic_show);
show.setTitle(category.isVisible() ? R.string.hide
: R.string.show);
bs.show();
bs.tint().show();
}
@Override

View file

@ -5,9 +5,11 @@ import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.MenuRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.view.MenuItem;
import java.lang.ref.WeakReference;
@ -17,11 +19,10 @@ import com.mapswithme.maps.widget.ListShadowController;
public final class BottomSheetHelper
{
public static class ShadowedBottomSheet extends BottomSheet
private static class ShadowedBottomSheet extends BottomSheet
{
private ListShadowController mShadowController;
ShadowedBottomSheet(Context context, int theme)
{
super(context, theme);
@ -78,9 +79,9 @@ public final class BottomSheetHelper
@SuppressWarnings("NullableProblems")
@Override
public BottomSheet.Builder setOnDismissListener(final DialogInterface.OnDismissListener listener)
public Builder setOnDismissListener(final DialogInterface.OnDismissListener listener)
{
return super.setOnDismissListener(new DialogInterface.OnDismissListener()
super.setOnDismissListener(new DialogInterface.OnDismissListener()
{
@Override
public void onDismiss(DialogInterface dialog)
@ -90,6 +91,63 @@ public final class BottomSheetHelper
listener.onDismiss(dialog);
}
});
return this;
}
@Override
public Builder title(CharSequence title)
{
super.title(title);
return this;
}
@Override
public Builder title(@StringRes int title)
{
super.title(title);
return this;
}
@Override
public Builder sheet(@MenuRes int xmlRes)
{
super.sheet(xmlRes);
return this;
}
@Override
public Builder sheet(int id, @NonNull Drawable icon, @NonNull CharSequence text)
{
super.sheet(id, icon, text);
return this;
}
@Override
public Builder grid()
{
super.grid();
return this;
}
@Override
public Builder listener(@NonNull MenuItem.OnMenuItemClickListener listener)
{
super.listener(listener);
return this;
}
public Builder tint()
{
for (int i = 0; i < getMenu().size(); i++)
{
MenuItem mi = getMenu().getItem(i);
Drawable icon = mi.getIcon();
if (icon != null)
mi.setIcon(Graphics.tint(context, icon));
}
return this;
}
}
@ -125,23 +183,23 @@ public final class BottomSheetHelper
}
}
public static BottomSheet.Builder create(Activity context)
public static Builder create(Activity context)
{
free();
return new Builder(context);
}
public static BottomSheet.Builder create(Activity context, @StringRes int title)
public static Builder create(Activity context, @StringRes int title)
{
return create(context).title(title);
}
public static BottomSheet.Builder createGrid(Activity context, @StringRes int title)
public static Builder createGrid(Activity context, @StringRes int title)
{
return create(context, title).grid();
}
public static BottomSheet.Builder sheet(BottomSheet.Builder builder, int id, @DrawableRes int iconRes, CharSequence text)
public static Builder sheet(Builder builder, int id, @DrawableRes int iconRes, CharSequence text)
{
Drawable icon = ContextCompat.getDrawable(MwmApplication.get(), iconRes);
return builder.sheet(id, icon, text);