forked from organicmaps/organicmaps
[android] Stylized alert dialog in all app
Changed alert button to accent color for all dialogs in the app
This commit is contained in:
parent
962f73073b
commit
1b44a7ae3f
5 changed files with 90 additions and 44 deletions
|
@ -17,6 +17,7 @@
|
|||
<dimen name="text_size_caption">14sp</dimen>
|
||||
<dimen name="text_size_icon_title">10sp</dimen>
|
||||
<dimen name="text_size_button">16sp</dimen>
|
||||
<dimen name="text_size_alert_dialog_title">20sp</dimen>
|
||||
|
||||
<!-- BASE TEXT SIZES -->
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<item name="android:windowActionBarOverlay">true</item>
|
||||
<item name="clickableBackground">?selectableItemBackground</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
|
||||
<item name="alertDialogTheme">@style/MwmTheme.DialogFragment</item>
|
||||
<item name="alertDialogTheme">@style/MwmTheme.AlertDialog</item>
|
||||
<item name="windowBackgroundForced">@color/bg_window</item>
|
||||
<item name="cardFrame">@drawable/card_frame</item>
|
||||
<item name="cardBackground">@color/bg_cards</item>
|
||||
|
@ -137,7 +137,7 @@
|
|||
<item name="clickableBackground">?selectableItemBackground</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
|
||||
|
||||
<item name="alertDialogTheme">@style/MwmTheme.Night.DialogFragment</item>
|
||||
<item name="alertDialogTheme">@style/MwmTheme.Night.AlertDialog</item>
|
||||
<item name="windowBackgroundForced">@color/bg_window_night</item>
|
||||
<item name="cardFrame">@drawable/card_frame_night</item>
|
||||
<item name="cardBackground">@color/bg_cards_night</item>
|
||||
|
|
|
@ -40,24 +40,33 @@
|
|||
<item name="android:windowBackground">@color/bg_window_night</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.DialogFragment" parent="android:Theme.Holo.Light.Dialog.NoActionBar">
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="clickableBackground">?attr/selectableItemBackground</item>
|
||||
<item name="colorControlNormal">?secondary</item>
|
||||
<item name="android:listViewStyle">@style/MwmWidget.ListView</item>
|
||||
<item name="android:textViewStyle">@style/MwmWidget.TextView</item>
|
||||
<item name="android:windowTitleStyle">@style/MwmTheme.DialogFragment.TitleStyle</item>
|
||||
<item name="android:fontFamily" tools:targetApi="jelly_bean">@string/robotoRegular</item>
|
||||
<style name="MwmTheme.AlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
|
||||
<item name="colorAccent">@color/base_accent</item>
|
||||
<item name="android:textColorPrimary">@color/black_secondary</item>
|
||||
<item name="android:textSize">@dimen/text_size_body_1</item>
|
||||
<item name="android:windowTitleStyle">@style/MwmTheme.DialogTitleStyle.Light</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.Night.DialogFragment" parent="android:Theme.Holo.Dialog.NoActionBar">
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="clickableBackground">?attr/selectableItemBackground</item>
|
||||
<item name="colorControlNormal">?secondary</item>
|
||||
<item name="android:listViewStyle">@style/MwmWidget.ListView</item>
|
||||
<item name="android:textViewStyle">@style/MwmWidget.TextView</item>
|
||||
<item name="android:windowTitleStyle">@style/MwmTheme.DialogFragment.TitleStyle</item>
|
||||
<item name="android:fontFamily" tools:targetApi="jelly_bean">@string/robotoRegular</item>
|
||||
<style name="MwmTheme.DialogTitleBase">
|
||||
<item name="android:textSize">@dimen/text_size_alert_dialog_title</item>
|
||||
<item name="android:fontFamily" tools:ignore="NewApi">@string/robotoMedium</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.DialogTitleStyle.Light" parent="MwmTheme.DialogTitleBase">
|
||||
<item name="android:textColor">@color/black_primary</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.Night.AlertDialog" parent="Theme.AppCompat.Dialog.Alert">
|
||||
<item name="colorAccent">@color/base_accent_night</item>
|
||||
<!-- Used for the message in the dialog -->
|
||||
<item name="android:textColorPrimary">@color/white_secondary</item>
|
||||
<item name="android:textSize">@dimen/text_size_body_1</item>
|
||||
<!-- Used for the title in the dialog -->
|
||||
<item name="android:windowTitleStyle">@style/MwmTheme.DialogTitleStyle.Night</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.DialogTitleStyle.Night" parent="MwmTheme.DialogTitleBase">
|
||||
<item name="android:textColor">@color/white_primary</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.EditorActivity">
|
||||
|
|
|
@ -6,11 +6,11 @@ import android.support.annotation.CallSuper;
|
|||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.auth.Authorizer;
|
||||
|
@ -34,6 +34,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
BookmarkManager.BookmarksLoadingListener,
|
||||
BookmarkCategoriesAdapter.CategoryListInterface
|
||||
{
|
||||
private static final int MAX_CATEGORY_NAME_LENGTH = 60;
|
||||
private long mSelectedCatId;
|
||||
@Nullable
|
||||
private View mLoadingPlaceholder;
|
||||
|
@ -153,8 +154,12 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
{
|
||||
if (TextUtils.isEmpty(text))
|
||||
{
|
||||
// TODO: translation is needed.
|
||||
Toast.makeText(getContext(), "A list name couldn't be empty.", Toast.LENGTH_SHORT).show();
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setTitle(R.string.bookmarks_error_title_empty_list_name)
|
||||
.setMessage(R.string.bookmarks_error_message_empty_list_name)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -191,7 +196,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
case R.id.set_edit:
|
||||
EditTextDialogFragment.show(getString(R.string.bookmark_set_name),
|
||||
BookmarkManager.INSTANCE.getCategoryName(mSelectedCatId),
|
||||
getString(R.string.rename), getString(R.string.cancel), this);
|
||||
getString(R.string.rename), getString(R.string.cancel),
|
||||
MAX_CATEGORY_NAME_LENGTH, this);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -267,9 +273,9 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
@Override
|
||||
public void onAddCategory()
|
||||
{
|
||||
EditTextDialogFragment.show(getString(R.string.bookmark_set_name),null,
|
||||
EditTextDialogFragment.show(getString(R.string.bookmark_set_name), null,
|
||||
getString(R.string.bookmarks_create_new_group),
|
||||
getString(R.string.cancel), this);
|
||||
getString(R.string.cancel), MAX_CATEGORY_NAME_LENGTH, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.support.annotation.Nullable;
|
|||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.InputFilter;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
@ -21,11 +22,13 @@ import com.mapswithme.util.InputUtils;
|
|||
|
||||
public class EditTextDialogFragment extends BaseMwmDialogFragment
|
||||
{
|
||||
public static final String EXTRA_TITLE = "DialogTitle";
|
||||
public static final String EXTRA_INITIAL = "InitialText";
|
||||
public static final String EXTRA_POSITIVE_BUTTON = "PositiveText";
|
||||
public static final String EXTRA_NEGATIVE_BUTTON = "NegativeText";
|
||||
public static final String EXTRA_HINT = "Hint";
|
||||
public static final String ARG_TITLE = "arg_dialog_title";
|
||||
public static final String ARG_INITIAL = "arg_initial";
|
||||
public static final String ARG_POSITIVE_BUTTON = "arg_positive_button";
|
||||
public static final String ARG_NEGATIVE_BUTTON = "arg_negative_button";
|
||||
public static final String ARG_HINT = "arg_hint";
|
||||
public static final String ARG_TEXT_LENGTH_LIMIT = "arg_text_length_limit";
|
||||
private static final int NO_LIMITED_TEXT_LENGTH = -1;
|
||||
|
||||
private String mTitle;
|
||||
@Nullable
|
||||
|
@ -38,19 +41,38 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
|
|||
void onSaveText(@Nullable String initialText, @Nullable String text);
|
||||
}
|
||||
|
||||
public static void show(String title, @Nullable String initialText, String positiveBtn, String negativeBtn, Fragment parent)
|
||||
public static void show(@Nullable String title, @Nullable String initialText,
|
||||
@Nullable String positiveBtn, @Nullable String negativeBtn,
|
||||
@NonNull Fragment parent)
|
||||
{
|
||||
show(title, initialText, "", positiveBtn, negativeBtn, parent);
|
||||
show(title, initialText, "", positiveBtn, negativeBtn, NO_LIMITED_TEXT_LENGTH, parent);
|
||||
}
|
||||
|
||||
public static void show(String title, String initialText, String hint, String positiveBtn, String negativeBtn, Fragment parent)
|
||||
public static void show(@Nullable String title, @Nullable String initialText,
|
||||
@Nullable String positiveBtn, @Nullable String negativeBtn,
|
||||
int textLimit, @NonNull Fragment parent)
|
||||
{
|
||||
show(title, initialText, "", positiveBtn, negativeBtn, textLimit, parent);
|
||||
}
|
||||
|
||||
public static void show(@Nullable String title, @Nullable String initialText, @Nullable String hint,
|
||||
@Nullable String positiveBtn, @Nullable String negativeBtn,
|
||||
@NonNull Fragment parent)
|
||||
{
|
||||
show(title, initialText, hint, positiveBtn, negativeBtn, NO_LIMITED_TEXT_LENGTH, parent);
|
||||
}
|
||||
|
||||
public static void show(@Nullable String title, @Nullable String initialText, @Nullable String hint,
|
||||
@Nullable String positiveBtn, @Nullable String negativeBtn, int textLimit,
|
||||
@NonNull Fragment parent)
|
||||
{
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(EXTRA_TITLE, title);
|
||||
args.putString(EXTRA_INITIAL, initialText);
|
||||
args.putString(EXTRA_POSITIVE_BUTTON, positiveBtn == null ? null : positiveBtn.toUpperCase());
|
||||
args.putString(EXTRA_NEGATIVE_BUTTON, negativeBtn == null ? null : negativeBtn.toUpperCase());
|
||||
args.putString(EXTRA_HINT, hint);
|
||||
args.putString(ARG_TITLE, title);
|
||||
args.putString(ARG_INITIAL, initialText);
|
||||
args.putString(ARG_POSITIVE_BUTTON, positiveBtn == null ? null : positiveBtn.toUpperCase());
|
||||
args.putString(ARG_NEGATIVE_BUTTON, negativeBtn == null ? null : negativeBtn.toUpperCase());
|
||||
args.putString(ARG_HINT, hint);
|
||||
args.putInt(ARG_TEXT_LENGTH_LIMIT, textLimit);
|
||||
final EditTextDialogFragment fragment = (EditTextDialogFragment) Fragment.instantiate(parent.getActivity(), EditTextDialogFragment.class.getName());
|
||||
fragment.setArguments(args);
|
||||
fragment.show(parent.getChildFragmentManager(), EditTextDialogFragment.class.getName());
|
||||
|
@ -65,12 +87,12 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
|
|||
String negativeButtonText = getString(R.string.cancel);
|
||||
if (args != null)
|
||||
{
|
||||
mTitle = args.getString(EXTRA_TITLE);
|
||||
mInitialText = args.getString(EXTRA_INITIAL);
|
||||
mHint = args.getString(EXTRA_HINT);
|
||||
mTitle = args.getString(ARG_TITLE);
|
||||
mInitialText = args.getString(ARG_INITIAL);
|
||||
mHint = args.getString(ARG_HINT);
|
||||
|
||||
positiveButtonText = args.getString(EXTRA_POSITIVE_BUTTON);
|
||||
negativeButtonText = args.getString(EXTRA_NEGATIVE_BUTTON);
|
||||
positiveButtonText = args.getString(ARG_POSITIVE_BUTTON);
|
||||
negativeButtonText = args.getString(ARG_NEGATIVE_BUTTON);
|
||||
}
|
||||
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
|
@ -100,9 +122,17 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
|
|||
private View buildView()
|
||||
{
|
||||
@SuppressLint("InflateParams") final View root = getActivity().getLayoutInflater().inflate(R.layout.dialog_edit_text, null);
|
||||
TextInputLayout inputLayout = (TextInputLayout) root.findViewById(R.id.input);
|
||||
TextInputLayout inputLayout = root.findViewById(R.id.input);
|
||||
inputLayout.setHint(TextUtils.isEmpty(mHint) ? getString(R.string.name) : mHint);
|
||||
mEtInput = (EditText) inputLayout.findViewById(R.id.et__input);
|
||||
mEtInput = inputLayout.findViewById(R.id.et__input);
|
||||
int maxLength = getArguments().getInt(ARG_TEXT_LENGTH_LIMIT);
|
||||
if (maxLength != NO_LIMITED_TEXT_LENGTH)
|
||||
{
|
||||
InputFilter[] f = new InputFilter[1];
|
||||
f[0] = new InputFilter.LengthFilter(maxLength);
|
||||
mEtInput.setFilters(f);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(mInitialText))
|
||||
{
|
||||
mEtInput.setText(mInitialText);
|
||||
|
|
Loading…
Add table
Reference in a new issue