diff --git a/android/res/drawable-hdpi/img_news_p2p.png b/android/res/drawable-hdpi/img_news_p2p.png new file mode 100644 index 0000000000..017882c29c Binary files /dev/null and b/android/res/drawable-hdpi/img_news_p2p.png differ diff --git a/android/res/drawable-hdpi/img_news_tts.png b/android/res/drawable-hdpi/img_news_tts.png new file mode 100644 index 0000000000..7134362647 Binary files /dev/null and b/android/res/drawable-hdpi/img_news_tts.png differ diff --git a/android/res/drawable-mdpi/img_news_p2p.png b/android/res/drawable-mdpi/img_news_p2p.png new file mode 100644 index 0000000000..9425c94b86 Binary files /dev/null and b/android/res/drawable-mdpi/img_news_p2p.png differ diff --git a/android/res/drawable-mdpi/img_news_tts.png b/android/res/drawable-mdpi/img_news_tts.png new file mode 100644 index 0000000000..2a05920080 Binary files /dev/null and b/android/res/drawable-mdpi/img_news_tts.png differ diff --git a/android/res/drawable-xhdpi/img_news_p2p.png b/android/res/drawable-xhdpi/img_news_p2p.png new file mode 100644 index 0000000000..7122f9876c Binary files /dev/null and b/android/res/drawable-xhdpi/img_news_p2p.png differ diff --git a/android/res/drawable-xhdpi/img_news_tts.png b/android/res/drawable-xhdpi/img_news_tts.png new file mode 100644 index 0000000000..284e0c2502 Binary files /dev/null and b/android/res/drawable-xhdpi/img_news_tts.png differ diff --git a/android/res/drawable-xxhdpi/img_news_p2p.png b/android/res/drawable-xxhdpi/img_news_p2p.png new file mode 100644 index 0000000000..054dcd5dc8 Binary files /dev/null and b/android/res/drawable-xxhdpi/img_news_p2p.png differ diff --git a/android/res/drawable-xxhdpi/img_news_tts.png b/android/res/drawable-xxhdpi/img_news_tts.png new file mode 100644 index 0000000000..45769d79dd Binary files /dev/null and b/android/res/drawable-xxhdpi/img_news_tts.png differ diff --git a/android/res/drawable-xxxhdpi/img_news_p2p.png b/android/res/drawable-xxxhdpi/img_news_p2p.png new file mode 100644 index 0000000000..6e520298f0 Binary files /dev/null and b/android/res/drawable-xxxhdpi/img_news_p2p.png differ diff --git a/android/res/drawable-xxxhdpi/img_news_tts.png b/android/res/drawable-xxxhdpi/img_news_tts.png new file mode 100644 index 0000000000..f1c69226e1 Binary files /dev/null and b/android/res/drawable-xxxhdpi/img_news_tts.png differ diff --git a/android/res/drawable/news_marker_active.xml b/android/res/drawable/news_marker_active.xml new file mode 100644 index 0000000000..bf545add4e --- /dev/null +++ b/android/res/drawable/news_marker_active.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/android/res/drawable/news_marker_inactive.xml b/android/res/drawable/news_marker_inactive.xml new file mode 100644 index 0000000000..0aa2646d82 --- /dev/null +++ b/android/res/drawable/news_marker_inactive.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/android/res/layout/fragment_news.xml b/android/res/layout/fragment_news.xml new file mode 100644 index 0000000000..43e6f6f12f --- /dev/null +++ b/android/res/layout/fragment_news.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/res/layout/news_page.xml b/android/res/layout/news_page.xml new file mode 100644 index 0000000000..41ba114da5 --- /dev/null +++ b/android/res/layout/news_page.xml @@ -0,0 +1,40 @@ + + + + + + + + + + \ No newline at end of file diff --git a/android/res/values/arrays.xml b/android/res/values/arrays.xml index ba68966381..bbbe628862 100644 --- a/android/res/values/arrays.xml +++ b/android/res/values/arrays.xml @@ -40,4 +40,19 @@ @string/post + + + @drawable/img_news_tts + @drawable/img_news_p2p + + + + @string/whats_new_where_to_turn + @string/whats_new_between_any_points + + + + @string/whats_new_voice_instructions + @string/whats_new_happy_day + \ No newline at end of file diff --git a/android/res/values/colors.xml b/android/res/values/colors.xml index b0fc743df6..1654a4a0e5 100644 --- a/android/res/values/colors.xml +++ b/android/res/values/colors.xml @@ -70,4 +70,7 @@ #1F000000 + + #8A000000 + #1F000000 diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index 540b0f0585..b8f60bd6ff 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -82,4 +82,7 @@ 4dp 64dp + + 560dp + 500dp diff --git a/android/res/values/styles-text.xml b/android/res/values/styles-text.xml index 0907292b49..a8e3a7190e 100644 --- a/android/res/values/styles-text.xml +++ b/android/res/values/styles-text.xml @@ -71,7 +71,6 @@ diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 1e886890bc..3c5eafcdaa 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -758,7 +758,10 @@ public class MwmActivity extends BaseMwmFragmentActivity mSearchController.refreshToolbar(); mPlacePage.onResume(); - LikesManager.INSTANCE.showDialogs(this); + + if (!NewsFragment.showOn(this)) + LikesManager.INSTANCE.showDialogs(this); + mMainMenu.onResume(); } diff --git a/android/src/com/mapswithme/maps/NewsFragment.java b/android/src/com/mapswithme/maps/NewsFragment.java new file mode 100644 index 0000000000..2a5db82cf9 --- /dev/null +++ b/android/src/com/mapswithme/maps/NewsFragment.java @@ -0,0 +1,191 @@ +package com.mapswithme.maps; + +import android.app.Dialog; +import android.content.res.TypedArray; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; +import android.support.v4.view.PagerAdapter; +import android.support.v4.view.ViewPager; +import android.view.*; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import com.mapswithme.maps.base.BaseMwmDialogFragment; +import com.mapswithme.util.Config; +import com.mapswithme.util.UiUtils; + +public class NewsFragment extends BaseMwmDialogFragment +{ + private ViewPager mPager; + private TextView mNext; + private ImageView[] mDots; + + private class Adapter extends PagerAdapter + { + private final int[] mImages; + private final String[] mTitles = MwmApplication.get().getResources().getStringArray(R.array.news_titles); + private final String[] mSubtitles = MwmApplication.get().getResources().getStringArray(R.array.news_subtitles); + + Adapter() + { + TypedArray images = MwmApplication.get().getResources().obtainTypedArray(R.array.news_images); + mImages = new int[images.length()]; + for (int i = 0; i < mImages.length; i++) + mImages[i] = images.getResourceId(i, 0); + + images.recycle(); + } + + @Override + public int getCount() + { + return mImages.length; + } + + @Override + public boolean isViewFromObject(View view, Object object) + { + return (view == object); + } + + @Override + public Object instantiateItem(ViewGroup container, int position) + { + View res = LayoutInflater.from(getActivity()).inflate(R.layout.news_page, container, false); + + ((ImageView)res.findViewById(R.id.image)) + .setImageResource(mImages[position]); + + ((TextView)res.findViewById(R.id.title)) + .setText(mTitles[position]); + + ((TextView)res.findViewById(R.id.subtitle)) + .setText(mSubtitles[position]); + + container.addView(res); + return res; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object object) + { + container.removeView((View)object); + } + } + + private void update() + { + int cur = mPager.getCurrentItem(); + for (int i = 0; i < mDots.length; i++) + { + mDots[i].setImageResource(i == cur ? R.drawable.news_marker_active + : R.drawable.news_marker_inactive); + } + + mNext.setText(cur + 1 == mDots.length ? R.string.done + : R.string.whats_new_next); + } + + private void fixPagerSize() + { + if (!UiUtils.isTablet()) + return; + + UiUtils.waitLayout(mPager, new ViewTreeObserver.OnGlobalLayoutListener() + { + @Override + public void onGlobalLayout() + { + int maxWidth = UiUtils.dimen(R.dimen.news_max_width); + int maxHeight = UiUtils.dimen(R.dimen.news_max_height); + + if (mPager.getWidth() > maxWidth || mPager.getHeight() > maxHeight) + { + mPager.setLayoutParams(new LinearLayout.LayoutParams(Math.min(maxWidth, mPager.getWidth()), + Math.min(maxHeight, mPager.getHeight()))); + } + } + }); + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setStyle(STYLE_NORMAL, UiUtils.isTablet() ? R.style.MwmMain_DialogFragment + : R.style.MwmMain_DialogFragment_Fullscreen); + } + + @Override + public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) + { + Dialog res = super.onCreateDialog(savedInstanceState); + res.requestWindowFeature(Window.FEATURE_NO_TITLE); + + View content = View.inflate(getActivity(), R.layout.fragment_news, null); + res.setContentView(content); + + mPager = (ViewPager)content.findViewById(R.id.pager); + fixPagerSize(); + mPager.setAdapter(new Adapter()); + mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() + { + @Override + public void onPageSelected(int position) + { + update(); + } + }); + + ViewGroup dots = (ViewGroup)content.findViewById(R.id.dots); + mDots = new ImageView[dots.getChildCount()]; + for (int i = 0; i < mDots.length; i++) + mDots[i] = (ImageView)dots.getChildAt(i); + + mNext = (TextView)content.findViewById(R.id.next); + mNext.setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View v) + { + if (mPager.getCurrentItem() == mDots.length - 1) + dismiss(); + else + mPager.setCurrentItem(mPager.getCurrentItem() + 1, true); + } + }); + + update(); + return res; + } + + /** + * Displays "What's new" dialog on given {@code activity}. Or not. + * @return whether "What's new" dialog should be shown. + */ + @SuppressWarnings("TryWithIdenticalCatches") + public static boolean showOn(FragmentActivity activity) + { + if (Config.getFirstInstallVersion() >= BuildConfig.VERSION_CODE) + return false; + + String tag = NewsFragment.class.getName(); + if (Config.getLastWhatsNewVersion() >= BuildConfig.VERSION_CODE) + return (activity.getSupportFragmentManager().findFragmentByTag(tag) != null); + + Config.setWhatsNewShown(); + + try + { + final NewsFragment fragment = NewsFragment.class.newInstance(); + fragment.show(activity.getSupportFragmentManager(), tag); + } catch (java.lang.InstantiationException ignored) + {} + catch (IllegalAccessException ignored) + {} + + return true; + } +} diff --git a/android/src/com/mapswithme/util/Config.java b/android/src/com/mapswithme/util/Config.java index a30e61537d..c265eeac85 100644 --- a/android/src/com/mapswithme/util/Config.java +++ b/android/src/com/mapswithme/util/Config.java @@ -25,6 +25,7 @@ public final class Config private static final String KEY_MISC_DISCLAIMER_ACCEPTED = "IsDisclaimerApproved"; private static final String KEY_MISC_KML_MOVED = "KmlBeenMoved"; private static final String KEY_MISC_KITKAT_MIGRATED = "KitKatMigrationCompleted"; + private static final String KEY_MISC_NEWS_LAST_VERSION = "WhatsNewShownVersion"; private Config() {} @@ -260,6 +261,16 @@ public final class Config setBool(KEY_MISC_KITKAT_MIGRATED); } + public static int getLastWhatsNewVersion() + { + return getInt(KEY_MISC_NEWS_LAST_VERSION); + } + + public static void setWhatsNewShown() + { + setInt(KEY_MISC_NEWS_LAST_VERSION, BuildConfig.VERSION_CODE); + } + private static native boolean nativeGetBoolean(String name, boolean defaultValue); private static native void nativeSetBoolean(String name, boolean value); private static native int nativeGetInt(String name, int defaultValue);