[android] Add showcase item to menu.

This commit is contained in:
Dmitry Yunitsky 2015-11-24 12:27:55 +03:00
parent 3c77d6a12b
commit 1daa30543b
19 changed files with 411 additions and 125 deletions

View file

@ -235,6 +235,10 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<activity
android:name="ru.mail.android.mytarget.ads.MyTargetActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<receiver
android:name="com.mapswithme.maps.background.ConnectivityChangedReceiver"
android:enabled="true"

View file

@ -5,32 +5,50 @@
extern "C"
{
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_PrivateVariables_alohalyticsUrl(JNIEnv * env, jclass)
Java_com_mapswithme_maps_PrivateVariables_alohalyticsUrl(JNIEnv * env, jclass clazz)
{
return env->NewStringUTF(ALOHALYTICS_URL);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_PrivateVariables_flurryKey(JNIEnv * env, jclass)
Java_com_mapswithme_maps_PrivateVariables_flurryKey(JNIEnv * env, jclass clazz)
{
return env->NewStringUTF(FLURRY_KEY);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_PrivateVariables_myTrackerKey(JNIEnv * env, jclass)
Java_com_mapswithme_maps_PrivateVariables_myTrackerKey(JNIEnv * env, jclass clazz)
{
return env->NewStringUTF(MY_TRACKER_KEY);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_PrivateVariables_parseApplicationId(JNIEnv * env, jclass)
Java_com_mapswithme_maps_PrivateVariables_parseApplicationId(JNIEnv * env, jclass clazz)
{
return env->NewStringUTF(PARSE_APPLICATION_ID);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_PrivateVariables_parseClientKey(JNIEnv * env, jclass)
Java_com_mapswithme_maps_PrivateVariables_parseClientKey(JNIEnv * env, jclass clazz)
{
return env->NewStringUTF(PARSE_CLIENT_KEY);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_PrivateVariables_myTargetSlot(JNIEnv * env, jclass clazz)
{
return env->NewStringUTF(MY_TARGET_KEY);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_PrivateVariables_myTargetCheckUrl(JNIEnv * env, jclass clazz)
{
return env->NewStringUTF(AD_PERMISION_SERVER_URL);
}
JNIEXPORT jlong JNICALL
Java_com_mapswithme_maps_PrivateVariables_myTargetCheckInterval(JNIEnv * env, jclass clazz)
{
return static_cast<jlong>(AD_PERMISION_CHECK_DURATION);
}
}

View file

@ -1,30 +1,24 @@
# obfuscate supportV7 menu subclasses. it fixes bug with some Samsung and other devices ROMS based on android 4.2.2.
# more details here : https://code.google.com/p/android/issues/detail?id=78377
-keep class !android.support.v7.internal.view.menu.**,** {*;}
# support library bug
-dontwarn android.support.**
# flurry
-dontwarn com.flurry.**
# support library bug
-dontwarn android.support.**
# parse
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn com.facebook.**
# myTarget
-dontwarn ru.mail.android.mytarget.**
-dontwarn com.mopub.**
-dontoptimize
-keepattributes **
# log proguard info
#
#-verbose
#
#-printseeds seeds.txt
#-printusage unused.txt
#-printmapping mapping.txt
# Gson support
-keep class com.mapswithme.util.Gsonable
-keep class * implements com.mapswithme.util.Gsonable

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Fallback layout for pre-Honeycomb MR2 (API 13) devices.
TODO: Remove me later. -->
<merge>
<include layout="@layout/menu_content_grid"/>
</merge>

View file

@ -1,49 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_half"
android:layout_marginBottom="@dimen/margin_half"
android:orientation="vertical">
<TextView android:id="@+id/search"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_search"
android:text="@string/search"
tools:background="#200000FF"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_half"
android:layout_marginTop="@dimen/margin_half"
android:orientation="vertical">
<TextView
android:id="@+id/search"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_search"
android:text="@string/search"
tools:background="#200000FF"/>
<TextView android:id="@+id/bookmarks"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_bookmarks"
android:text="@string/bookmarks"
tools:background="#40FF00FF"/>
<TextView
android:id="@+id/bookmarks"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_bookmarks"
android:text="@string/bookmarks"
tools:background="#40FF00FF"/>
<FrameLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/download_maps"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_download"
android:text="@string/download_maps"
tools:background="#2000FF00"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/download_maps"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_download"
android:text="@string/download_maps"
tools:background="#2000FF00"/>
<TextView android:id="@+id/counter"
style="@style/MwmTextAppearance.Counter"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="@dimen/margin_base"
android:visibility="gone"
tools:visibility="visible"
tools:text="9999"/>
<TextView
android:id="@+id/counter"
style="@style/MwmTextAppearance.Counter"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="@dimen/margin_base"
android:visibility="gone"
tools:text="9999"
tools:visibility="visible"/>
</FrameLayout>
<TextView android:id="@+id/settings"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_settings"
android:text="@string/settings"
tools:background="#20FF0000"/>
<TextView
android:id="@+id/settings"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_settings"
android:text="@string/settings"
tools:background="#20FF0000"/>
<TextView android:id="@+id/share"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_share"
android:text="@string/share_my_location"
tools:background="#400FF000"/>
<TextView
android:id="@+id/showcase"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_showcase"
android:visibility="gone"
tools:visibility="visible"
tools:background="#20FF0000"/>
<TextView
android:id="@+id/share"
style="@style/MwmTheme.Menu.Content.ListItem"
android:drawableLeft="@drawable/ic_menu_share"
android:text="@string/share_my_location"
tools:background="#400FF000"/>
</LinearLayout>

View file

@ -1,51 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:background="#200000F0">
<TextView android:id="@+id/search"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_menu_search"
android:text="@string/search"
tools:background="#200000FF"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:background="#200000F0">
<TextView
android:id="@+id/search"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_menu_search"
android:text="@string/search"
tools:background="#200000FF"/>
<TextView android:id="@+id/bookmarks"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_menu_bookmarks"
android:text="@string/bookmarks"
tools:background="#200000FF"/>
<TextView
android:id="@+id/bookmarks"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_menu_bookmarks"
android:text="@string/bookmarks"
tools:background="#200000FF"/>
<FrameLayout style="@style/MwmTheme.Menu.Content.GridItem">
<TextView android:id="@+id/download_maps"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_menu_download"
android:text="@string/download_maps"
tools:text="Some long long long long long long text"
tools:background="#200000FF"/>
<FrameLayout
style="@style/MwmTheme.Menu.Content.GridItem">
<TextView
android:id="@+id/download_maps"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_menu_download"
android:text="@string/download_maps"
tools:background="#200000FF"
tools:text="Some long long long long long long text"/>
<TextView android:id="@+id/counter"
style="@style/MwmTextAppearance.Counter"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="14dp"
android:layout_marginTop="10dp"
android:visibility="gone"
tools:visibility="visible"
tools:text="1000"/>
<TextView
android:id="@+id/counter"
style="@style/MwmTextAppearance.Counter"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="14dp"
android:layout_marginTop="10dp"
android:visibility="gone"
tools:text="1000"
tools:visibility="visible"/>
</FrameLayout>
<TextView android:id="@+id/settings"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_menu_settings"
android:text="@string/settings"
tools:background="#200000FF"/>
<TextView
android:id="@+id/settings"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_menu_settings"
android:text="@string/settings"
tools:background="#200000FF"/>
<TextView android:id="@+id/share"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_menu_share"
android:text="@string/share_my_location"
tools:background="#200000FF"/>
<TextView
android:id="@+id/showcase"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_showcase"
android:visibility="gone"
tools:background="#200000FF"
tools:visibility="visible"/>
<TextView
android:id="@+id/share"
style="@style/MwmTheme.Menu.Content.GridItem.Text"
android:drawableTop="@drawable/ic_menu_share"
android:text="@string/share_my_location"
tools:background="#200000FF"/>
</LinearLayout>

View file

@ -40,6 +40,7 @@
<string name="pref_map_style" translatable="false">MapStyle</string>
<string name="pref_tts_enabled" translatable="false">TtsEnabled</string>
<string name="pref_tts_language" translatable="false">TtsLanguage</string>
<string name="pref_showcase_switched_on" translatable="false">DisplayShowcase</string>
<string name="notification_ticker_ltr" translatable="false">%1$s: %2$s</string>
<string name="notification_ticker_rtl" translatable="false">%2$s :%1$s</string>

View file

@ -1,18 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:key="@string/pref_showcase_switched_on"
android:title="@string/showcase_settings_title"
android:defaultValue="true"
android:switchTextOff=""
android:switchTextOn=""/>
<SwitchPreference
android:key="@string/pref_send_statistics"
android:title="@string/allow_statistics"
android:summary="@string/allow_statistics_hint"
android:switchTextOn=""
android:switchTextOff=""/>
android:switchTextOff=""
android:switchTextOn=""/>
<SwitchPreference
android:key="@string/pref_play_services"
android:title="Google Play Services"
android:summary="@string/pref_use_google_play"
android:defaultValue="true"
android:switchTextOn=""
android:switchTextOff=""/>
android:switchTextOff=""
android:switchTextOn=""/>
</PreferenceScreen>

View file

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="@string/pref_showcase_switched_on"
android:title="@string/showcase_settings_title"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="@string/pref_send_statistics"
android:title="@string/allow_statistics"

View file

@ -21,6 +21,7 @@ import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.mapswithme.country.ActiveCountryTree;
import com.mapswithme.country.DownloadActivity;
import com.mapswithme.country.DownloadFragment;
@ -38,7 +39,11 @@ import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.bookmarks.data.MapObject.ApiPoint;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.LocationPredictor;
import com.mapswithme.maps.routing.*;
import com.mapswithme.maps.routing.NavigationController;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.routing.RoutingInfo;
import com.mapswithme.maps.routing.RoutingPlanFragment;
import com.mapswithme.maps.routing.RoutingPlanInplaceController;
import com.mapswithme.maps.search.FloatingSearchToolbarController;
import com.mapswithme.maps.search.SearchActivity;
import com.mapswithme.maps.search.SearchEngine;
@ -52,15 +57,25 @@ import com.mapswithme.maps.widget.menu.MainMenu;
import com.mapswithme.maps.widget.placepage.BasePlacePageAnimationController;
import com.mapswithme.maps.widget.placepage.PlacePageView;
import com.mapswithme.maps.widget.placepage.PlacePageView.State;
import com.mapswithme.util.*;
import com.mapswithme.util.BottomSheetHelper;
import com.mapswithme.util.Config;
import com.mapswithme.util.InputUtils;
import com.mapswithme.util.LocationUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.Yota;
import com.mapswithme.util.sharing.ShareOption;
import com.mapswithme.util.sharing.SharingHelper;
import com.mapswithme.util.statistics.AlohaHelper;
import com.mapswithme.util.statistics.MytargetHelper;
import com.mapswithme.util.statistics.Statistics;
import java.io.Serializable;
import java.util.Stack;
import ru.mail.android.mytarget.nativeads.NativeAppwallAd;
import ru.mail.android.mytarget.nativeads.banners.NativeAppwallBanner;
public class MwmActivity extends BaseMwmFragmentActivity
implements LocationHelper.LocationListener,
@ -100,6 +115,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private MainMenu mMainMenu;
private PanelAnimator mPanelAnimator;
private MytargetHelper mMytargetHelper;
private int mLocationStateModeListenerId = LocationState.SLOT_UNDEFINED;
@ -515,6 +531,17 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
});
break;
case SHOWCASE:
closeMenuAndRun(AlohaHelper.MENU_SHOWCASE, new Runnable()
{
@Override
public void run()
{
mMytargetHelper.displayShowcase();
}
});
break;
}
}
});
@ -727,11 +754,38 @@ public class MwmActivity extends BaseMwmFragmentActivity
mMainMenu.onResume();
}
@Override
protected void onStart()
private void initShowcase()
{
super.onStart();
NativeAppwallAd.AppwallAdListener listener = new NativeAppwallAd.AppwallAdListener()
{
@Override
public void onLoad(NativeAppwallAd nativeAppwallAd)
{
if (nativeAppwallAd.getBanners().isEmpty())
{
mMainMenu.showShowcase(false);
return;
}
final NativeAppwallBanner menuBanner = nativeAppwallAd.getBanners().get(0);
mMainMenu.showShowcase(true);
mMainMenu.setShowcaseText(menuBanner.getTitle());
mMainMenu.setShowcaseDrawable(menuBanner.getIcon().getBitmap());
}
@Override
public void onNoAd(String reason, NativeAppwallAd nativeAppwallAd)
{
mMainMenu.showShowcase(false);
}
@Override
public void onClick(NativeAppwallBanner nativeAppwallBanner, NativeAppwallAd nativeAppwallAd) {}
@Override
public void onDismissDialog(NativeAppwallAd nativeAppwallAd) {}
};
mMytargetHelper = new MytargetHelper(listener, this);
}
@Override
@ -805,6 +859,20 @@ public class MwmActivity extends BaseMwmFragmentActivity
LocationState.INSTANCE.invalidatePosition();
}
@Override
protected void onStart()
{
super.onStart();
initShowcase();
}
@Override
protected void onStop()
{
super.onStop();
mMytargetHelper.cancel();
}
@Override
public void onBackPressed()
{

View file

@ -10,4 +10,10 @@ public class PrivateVariables
public static native String myTrackerKey();
public static native String parseApplicationId();
public static native String parseClientKey();
public static native String myTargetSlot();
public static native String myTargetCheckUrl();
/**
* @return interval in seconds
*/
public static native long myTargetCheckInterval();
}

View file

@ -2,6 +2,7 @@ package com.mapswithme.maps.widget.menu;
import android.animation.Animator;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
@ -12,6 +13,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.mapswithme.country.ActiveCountryTree;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmActivity;
@ -54,7 +56,6 @@ public class MainMenu
private final int mButtonsWidth = UiUtils.dimen(R.dimen.menu_line_button_width);
private final int mPanelWidth = UiUtils.dimen(R.dimen.panel_width);
private final Container mContainer;
private final ViewGroup mFrame;
private final View mButtonsFrame;
@ -82,7 +83,6 @@ public class MainMenu
private boolean mAnimating;
private final MwmActivity.LeftAnimationTrackListener mAnimationTrackListener = new MwmActivity.LeftAnimationTrackListener()
{
private float mSymmetricalGapScale;
@ -133,7 +133,6 @@ public class MainMenu
}
};
public enum Item
{
TOGGLE(R.id.toggle),
@ -142,7 +141,8 @@ public class MainMenu
BOOKMARKS(R.id.bookmarks),
SHARE(R.id.share),
DOWNLOADER(R.id.download_maps),
SETTINGS(R.id.settings);
SETTINGS(R.id.settings),
SHOWCASE(R.id.showcase);
private final int mViewId;
@ -152,14 +152,12 @@ public class MainMenu
}
}
public interface Container
{
Activity getActivity();
void onItemClick(Item item);
}
private class AnimationListener extends UiUtils.SimpleAnimatorListener
{
@Override
@ -175,7 +173,6 @@ public class MainMenu
}
}
private class Toggle
{
final ImageView mButton;
@ -184,7 +181,6 @@ public class MainMenu
final TransitionDrawable mOpenImage;
final TransitionDrawable mCollapseImage;
public Toggle(View frame)
{
mButton = (ImageView) frame.findViewById(R.id.toggle);
@ -245,7 +241,7 @@ public class MainMenu
View res = frame.findViewById(item.mViewId);
if (res != null)
{
if ((res.getTag() instanceof String) && TAG_COLLAPSE.equals(res.getTag()))
if (TAG_COLLAPSE.equals(res.getTag()))
mCollapseViews.add(res);
res.setOnClickListener(new View.OnClickListener()
@ -346,6 +342,7 @@ public class MainMenu
mapItem(Item.SHARE);
mapItem(Item.DOWNLOADER);
mapItem(Item.SETTINGS);
mapItem(Item.SHOWCASE);
adjustCollapsedItems();
adjustTransparency();
@ -543,6 +540,23 @@ public class MainMenu
return mAnimationTrackListener;
}
public void showShowcase(boolean show)
{
UiUtils.showIf(show, mItemViews.get(Item.SHOWCASE));
}
public void setShowcaseText(String text)
{
((TextView)mItemViews.get(Item.SHOWCASE)).setText(text);
}
public void setShowcaseDrawable(Bitmap bitmap)
{
// TODO d.yunitsky uncomment or delete in future, when decision with dynamic vs static icons will be made
// final Drawable drawable = new BitmapDrawable(mFrame.getResources(), Bitmap.createScaledBitmap(bitmap, UiUtils.dp(48), UiUtils.dp(48), true));
// ((TextView) mItemViews.get(Item.SHOWCASE)).setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
}
public Button getRouteStartButton()
{
return mRouteStartButton;

View file

@ -52,6 +52,7 @@ public class AlohaHelper
// menu actions
public static final String MENU_DOWNLOADER = "downloader";
public static final String MENU_SETTINGS = "settingsAndMore";
public static final String MENU_SHOWCASE = "showcase";
public static final String MENU_SHARE = "share@";
public static final String MENU_POINT2POINT = "point2point";
// place page

View file

@ -0,0 +1,142 @@
package com.mapswithme.util.statistics;
import android.app.Activity;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.WorkerThread;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.PrivateVariables;
import com.mapswithme.maps.R;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.concurrency.ThreadPool;
import com.mapswithme.util.concurrency.UiThread;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import ru.mail.android.mytarget.core.net.Hosts;
import ru.mail.android.mytarget.nativeads.NativeAppwallAd;
public final class MytargetHelper
{
// for caching of myTarget setting achieved from server
private static final String PREF_CHECK = "MyTargetCheck";
private static final String PREF_CHECK_MILLIS = "MyTargetCheckTimestamp";
private static final String CHECK_URL = PrivateVariables.myTargetCheckUrl();
private static final long CHECK_INTERVAL_MILLIS = PrivateVariables.myTargetCheckInterval() * 1000;
private static final int TIMEOUT = 1000;
private NativeAppwallAd mShowcase;
private Activity mActivity;
private NativeAppwallAd.AppwallAdListener mListener;
static
{
Hosts.setMyComHost();
}
public MytargetHelper(@NonNull NativeAppwallAd.AppwallAdListener listener, @NonNull Activity activity)
{
mListener = listener;
mActivity = activity;
if (!ConnectionState.isConnected() ||
isAdSwitchedOff())
{
listener.onNoAd("Switched off", null);
return;
}
ThreadPool.getWorker().execute(new Runnable()
{
@Override
public void run()
{
final boolean showShowcase = getShowcaseSetting();
UiThread.run(new Runnable()
{
@Override
public void run()
{
if (mListener == null || mActivity == null)
return;
if (!showShowcase)
{
mListener.onNoAd("Switched off on server", null);
return;
}
loadShowcase(mListener, mActivity);
}
});
}
});
}
public void cancel()
{
mListener = null;
mActivity = null;
}
@WorkerThread
private boolean getShowcaseSetting()
{
final long lastCheckMillis = MwmApplication.prefs().getLong(PREF_CHECK_MILLIS, 0);
final long currentMillis = System.currentTimeMillis();
if (currentMillis - lastCheckMillis < CHECK_INTERVAL_MILLIS)
return MwmApplication.prefs().getBoolean(PREF_CHECK, false);
MwmApplication.prefs().edit().putLong(PREF_CHECK_MILLIS, currentMillis).commit();
HttpURLConnection connection = null;
try
{
final URL url = new URL(CHECK_URL);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("HEAD");
connection.setConnectTimeout(TIMEOUT);
connection.setReadTimeout(TIMEOUT);
connection.connect();
final boolean showShowcase = connection.getResponseCode() == HttpURLConnection.HTTP_OK;
MwmApplication.prefs().edit().putBoolean(PREF_CHECK, showShowcase).commit();
return showShowcase;
} catch (MalformedURLException ignored)
{
} catch (IOException e)
{
e.printStackTrace();
} finally
{
if (connection != null)
connection.disconnect();
}
return false;
}
private void loadShowcase(NativeAppwallAd.AppwallAdListener listener, Activity activity)
{
mShowcase = new NativeAppwallAd(Integer.parseInt(PrivateVariables.myTargetSlot()), activity);
mShowcase.setListener(listener);
mShowcase.load();
}
public void displayShowcase()
{
mShowcase.show();
}
public static boolean isAdSwitchedOff()
{
return !PreferenceManager.getDefaultSharedPreferences(MwmApplication.get())
.getBoolean(MwmApplication.get().getString(R.string.pref_showcase_switched_on), true);
}
}