changed appbar,statusbar and refactored WikipediaDialogFragment
This commit is contained in:
parent
94e53b8ecb
commit
7cbba3d625
2 changed files with 89 additions and 102 deletions
|
@ -9,79 +9,54 @@
|
|||
android:background="?attr/wikivoyage_bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/toolbar_height"
|
||||
android:background="?attr/wikivoyage_app_bar_color"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/toolbar_height"
|
||||
osmand:contentInsetLeft="54dp"
|
||||
osmand:contentInsetStart="54dp">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
osmand:layout_scrollFlags="scroll|enterAlways"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
osmand:contentInsetLeft="0dp"
|
||||
osmand:contentInsetStart="0dp"
|
||||
osmand:contentInsetRight="0dp"
|
||||
osmand:contentInsetEnd="0dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title_text_view"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/back_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:src="@drawable/ic_arrow_back"
|
||||
android:contentDescription="@string/shared_string_back" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/select_language_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
android:layout_marginTop="@dimen/content_padding_small"
|
||||
android:layout_marginLeft="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginRight="@dimen/context_menu_padding_margin_small"
|
||||
tools:background="?attr/ctx_menu_controller_bg"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="@dimen/context_menu_padding_margin_tiny"
|
||||
android:textAllCaps="true"
|
||||
tools:textColor="?attr/ctx_menu_controller_text_color"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="RU"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/list_header_padding"
|
||||
android:paddingBottom="@dimen/list_header_padding"
|
||||
android:textSize="@dimen/map_button_text_size"
|
||||
tools:text="Title"/>
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/select_language_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
android:layout_marginLeft="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginRight="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginTop="@dimen/content_padding_small"
|
||||
android:drawablePadding="@dimen/context_menu_padding_margin_small"
|
||||
android:gravity="center_vertical"
|
||||
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||
android:padding="@dimen/context_menu_padding_margin_tiny"
|
||||
android:textSize="@dimen/text_button_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:background="@drawable/wikipedia_select_lang_bg_dark_n"
|
||||
tools:drawableLeft="@drawable/ic_action_map_language"
|
||||
tools:ignore="UnusedAttribute"
|
||||
tools:text="En"
|
||||
tools:textColor="?attr/wikivoyage_active_color" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -6,24 +6,26 @@ import android.content.Context;
|
|||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
|
@ -31,6 +33,7 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.data.Amenity;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -41,7 +44,7 @@ import java.util.Set;
|
|||
import java.util.TreeSet;
|
||||
|
||||
|
||||
public class WikipediaDialogFragment extends DialogFragment {
|
||||
public class WikipediaDialogFragment extends BaseOsmAndDialogFragment {
|
||||
|
||||
public static final String TAG = "WikipediaDialogFragment";
|
||||
|
||||
|
@ -52,8 +55,10 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
"</head>";
|
||||
private static final String FOOTER_INNER = "</body></html>";
|
||||
|
||||
private View mainView;
|
||||
private WebView contentWebView;
|
||||
private TextView articleToolbarText;
|
||||
private TextView readFullArticleButton;
|
||||
private TextView selectLanguageTextView;
|
||||
|
||||
private boolean darkMode;
|
||||
private Amenity amenity;
|
||||
|
@ -79,9 +84,16 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Dialog dialog = new Dialog(getContext(), getTheme());
|
||||
if (!getMyApplication().getSettings().DO_NOT_USE_ANIMATIONS.get()) {
|
||||
dialog.getWindow().getAttributes().windowAnimations = R.style.Animations_Alpha;
|
||||
int themeId = darkMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme_LightStatusBar;
|
||||
Dialog dialog = new Dialog(getContext(), themeId);
|
||||
if (!getSettings().DO_NOT_USE_ANIMATIONS.get()) {
|
||||
Window window = dialog.getWindow();
|
||||
if (window != null) {
|
||||
window.getAttributes().windowAnimations = R.style.Animations_Alpha;
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
window.setStatusBarColor(getResolvedColor(getStatusBarColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
@ -90,32 +102,17 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
mainView = inflater.inflate(R.layout.wikipedia_dialog_fragment, container, false);
|
||||
View mainView = inflater.inflate(R.layout.wikipedia_dialog_fragment, container, false);
|
||||
|
||||
mainView.setBackgroundColor(ContextCompat.getColor(getContext(), darkMode ? R.color.ctx_menu_bottom_view_bg_dark : R.color.ctx_menu_bottom_view_bg_light));
|
||||
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
||||
|
||||
AppBarLayout appBarLayout = (AppBarLayout) mainView.findViewById(R.id.app_bar);
|
||||
appBarLayout.setBackgroundColor(ContextCompat.getColor(getContext(), darkMode ? R.color.ctx_menu_buttons_bg_dark: R.color.ctx_menu_buttons_bg_light));
|
||||
|
||||
int toolbarTextColor = ContextCompat.getColor(getContext(), R.color.dashboard_subheader_text_light);
|
||||
|
||||
ImageButton backButton = (ImageButton) mainView.findViewById(R.id.back_button);
|
||||
backButton.setImageDrawable(getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_arrow_back, toolbarTextColor));
|
||||
backButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
TextView titleTextView = (TextView) mainView.findViewById(R.id.title_text_view);
|
||||
titleTextView.setTextColor(toolbarTextColor);
|
||||
articleToolbarText = (TextView) mainView.findViewById(R.id.title_text_view);
|
||||
|
||||
ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(getContext(), darkMode,
|
||||
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
||||
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
||||
|
||||
final TextView readFullArticleButton = (TextView) mainView.findViewById(R.id.read_full_article);
|
||||
readFullArticleButton = (TextView) mainView.findViewById(R.id.read_full_article);
|
||||
|
||||
readFullArticleButton.setBackgroundResource(darkMode ? R.drawable.bt_round_long_night : R.drawable.bt_round_long_day);
|
||||
readFullArticleButton.setTextColor(buttonColorStateList);
|
||||
|
@ -125,7 +122,7 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
readFullArticleButton.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_world_globe_dark), null, null, null);
|
||||
readFullArticleButton.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.content_padding_small));
|
||||
|
||||
final TextView selectLanguageTextView = mainView.findViewById(R.id.select_language_text_view);
|
||||
selectLanguageTextView = mainView.findViewById(R.id.select_language_text_view);
|
||||
selectLanguageTextView.setTextColor(buttonColorStateList);
|
||||
selectLanguageTextView.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_action_map_language), null, null, null);
|
||||
selectLanguageTextView.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.context_menu_padding_margin_small));
|
||||
|
@ -186,9 +183,8 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
|
||||
final String langSelected = lng;
|
||||
final String title = amenity.getName(langSelected);
|
||||
((TextView) mainView.findViewById(R.id.title_text_view)).setText(title);
|
||||
|
||||
mainView.findViewById(R.id.read_full_article).setOnClickListener(new View.OnClickListener() {
|
||||
articleToolbarText.setText(title);
|
||||
readFullArticleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String article = "https://" + langSelected.toLowerCase() + ".wikipedia.org/wiki/" + title.replace(' ', '_');
|
||||
|
@ -196,7 +192,6 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
}
|
||||
});
|
||||
|
||||
final TextView selectLanguageTextView = mainView.findViewById(R.id.select_language_text_view);
|
||||
selectLanguageTextView.setText(langSelected);
|
||||
selectLanguageTextView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -260,11 +255,7 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
|
||||
private Drawable getIcon(int resId) {
|
||||
int colorId = darkMode ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n;
|
||||
return getMyApplication().getIconsCache().getIcon(resId, colorId);
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
return getIcon(resId, colorId);
|
||||
}
|
||||
|
||||
public static boolean showInstance(AppCompatActivity activity, Amenity amenity, String lang) {
|
||||
|
@ -289,4 +280,25 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
public static boolean showInstance(AppCompatActivity activity, Amenity amenity) {
|
||||
return showInstance(activity, amenity, null);
|
||||
}
|
||||
|
||||
protected void setupToolbar(Toolbar toolbar) {
|
||||
toolbar.setNavigationIcon(getIcon(R.drawable.ic_arrow_back, R.color.icon_color));
|
||||
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
protected int getStatusBarColor() {
|
||||
return darkMode ? R.color.status_bar_wikivoyage_article_dark : R.color.status_bar_wikivoyage_article_light;
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
protected int getResolvedColor(@ColorRes int colorId) {
|
||||
return ContextCompat.getColor(getContext(), colorId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue