[android] add: Autodownload map on zoom.

This commit is contained in:
Alexander Marchuk 2016-01-29 14:04:40 +03:00 committed by Sergey Yershov
parent fdd99bb263
commit c4b55eeed5
9 changed files with 106 additions and 30 deletions

View file

@ -12,7 +12,10 @@
#include "base/logging.hpp"
#include "platform/file_logging.hpp"
#include "platform/settings.hpp"
using namespace storage;
using namespace storage_utils;
extern "C"
{
@ -31,25 +34,57 @@ extern "C"
#pragma clang pop_options
static void CallOnDownloadCountryClicked(shared_ptr<jobject> const & obj, storage::TIndex const & idx, int options, jmethodID methodID)
static void CallOnDownloadClicked(shared_ptr<jobject> const & obj, TIndex const & idx, int options, jmethodID methodID)
{
JNIEnv * env = jni::GetEnv();
env->CallVoidMethod(*obj.get(), methodID, idx.m_group, idx.m_country, idx.m_region, options);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MapFragment_nativeConnectDownloadButton(JNIEnv * env, jobject thiz)
static void OnCancelDownload(TIndex const & idx)
{
jmethodID methodID = jni::GetMethodID(env, thiz, "onDownloadCountryClicked", "(IIII)V");
g_framework->NativeFramework()->SetDownloadCountryListener(bind(&CallOnDownloadCountryClicked,
jni::make_global_ref(thiz), _1, _2, methodID));
GetMapLayout().CancelDownloading(idx);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MapFragment_nativeConnectDownloaderListeners(JNIEnv * env, jobject thiz)
{
g_framework->NativeFramework()->SetDownloadCountryListener([env, thiz](TIndex const & idx, int options)
{
jmethodID methodID = jni::GetMethodID(env, thiz, "onDownloadClicked", "(IIII)V");
env->CallVoidMethod(thiz, methodID, idx.m_group, idx.m_country, idx.m_region, options);
});
g_framework->NativeFramework()->SetDownloadCancelListener([](TIndex const & idx)
{
GetMapLayout().CancelDownloading(idx);
});
g_framework->NativeFramework()->SetAutoDownloadListener([](TIndex const & idx)
{
if (g_framework->NeedMigrate())
return;
bool autoDownload = true;
Settings::Get("AutoDownloadEnabled", autoDownload);
if (autoDownload && Platform::ConnectionStatus() == Platform::EConnectionType::CONNECTION_WIFI)
GetMapLayout().DownloadMap(idx, MapOptions::Map);
});
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MapFragment_nativeDisconnectListeners(JNIEnv * env, jclass clazz)
{
g_framework->NativeFramework()->SetDownloadCountryListener(nullptr);
g_framework->NativeFramework()->SetDownloadCancelListener(nullptr);
g_framework->NativeFramework()->SetAutoDownloadListener(nullptr);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MapFragment_nativeDownloadCountry(JNIEnv * env, jclass clazz, jobject idx, jint options)
{
storage::TIndex index = storage::ToNative(idx);
storage::ActiveMapsLayout & layout = storage_utils::GetMapLayout();
TIndex index = ToNative(idx);
ActiveMapsLayout & layout = storage_utils::GetMapLayout();
if (options == -1)
layout.RetryDownloading(index);
else

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_autodownload" translatable="false">AutoDownloadMap</string>
<string name="pref_3d" translatable="false">3D</string>
<string name="pref_3d_buildings" translatable="false">3DBuildings</string>
<string name="pref_track_record" translatable="false">TrackRecord</string>

View file

@ -30,23 +30,30 @@
android:entryValues="@array/map_style_values"
android:order="4"/>
<SwitchPreference
android:key="@string/pref_autodownload"
android:title="@string/autodownload"
android:switchTextOn=""
android:switchTextOff=""
android:order="5"/>
<SwitchPreference
android:key="@string/pref_3d_buildings"
android:title="@string/pref_map_3d_buildings_title"
android:switchTextOn=""
android:switchTextOff=""
android:order="5"/>
android:order="6"/>
<Preference
android:key="@string/pref_yota"
android:title="@string/yopme_pref_title"
android:summary="@string/yopme_pref_summary"
android:order="6"/>
android:order="7"/>
<ListPreference
android:key="@string/pref_track_record"
android:title="@string/pref_track_record_title"
android:entries="@array/track_length"
android:entryValues="@array/track_length_values"
android:order="7"/>
android:order="8"/>
</PreferenceScreen>

View file

@ -28,21 +28,26 @@
android:entryValues="@array/map_style_values"
android:order="4"/>
<CheckBoxPreference
android:key="@string/pref_autodownload"
android:title="@string/autodownload"
android:order="5"/>
<CheckBoxPreference
android:key="@string/pref_3d_buildings"
android:title="@string/pref_map_3d_buildings_title"
android:order="5"/>
android:order="6"/>
<Preference
android:key="@string/pref_yota"
android:title="@string/yopme_pref_title"
android:summary="@string/yopme_pref_summary"
android:order="6"/>
android:order="7"/>
<ListPreference
android:key="@string/pref_track_record"
android:title="@string/pref_track_record_title"
android:entries="@array/track_length"
android:entryValues="@array/track_length_values"
android:order="7"/>
android:order="8"/>
</PreferenceScreen>

View file

@ -58,13 +58,11 @@ public class MapFragment extends BaseMwmFragment
private boolean mEngineCreated;
private static boolean sWasCopyrightDisplayed;
public interface MapRenderingListener
interface MapRenderingListener
{
void onRenderingInitialized();
}
public static final String FRAGMENT_TAG = MapFragment.class.getName();
private void setupWidgets(int width, int height)
{
mHeight = height;
@ -224,7 +222,14 @@ public class MapFragment extends BaseMwmFragment
super.onViewCreated(view, savedInstanceState);
final SurfaceView surfaceView = (SurfaceView) view.findViewById(R.id.map_surfaceview);
surfaceView.getHolder().addCallback(this);
nativeConnectDownloadButton();
nativeConnectDownloaderListeners();
}
@Override
public void onDestroyView()
{
super.onDestroyView();
nativeDisconnectListeners();
}
@Override
@ -276,7 +281,7 @@ public class MapFragment extends BaseMwmFragment
}
@SuppressWarnings("UnusedDeclaration")
public void onDownloadCountryClicked(final int group, final int country, final int region, final int options)
public void onDownloadClicked(final int group, final int country, final int region, final int options)
{
UiThread.run(new Runnable()
{
@ -309,7 +314,8 @@ public class MapFragment extends BaseMwmFragment
});
}
private native void nativeConnectDownloadButton();
private native void nativeConnectDownloaderListeners();
private static native void nativeDisconnectListeners();
private static native void nativeDownloadCountry(MapStorage.Index index, int options);
static native void nativeCompassUpdated(double magneticNorth, double trueNorth, boolean forceRedraw);
static native void nativeScalePlus();

View file

@ -394,13 +394,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
});
mMapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag(MapFragment.FRAGMENT_TAG);
mMapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag(MapFragment.class.getName());
if (mMapFragment == null)
{
mMapFragment = (MapFragment) MapFragment.instantiate(this, MapFragment.class.getName(), null);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.map_fragment_container, mMapFragment, MapFragment.FRAGMENT_TAG)
.replace(R.id.map_fragment_container, mMapFragment, MapFragment.class.getName())
.commit();
}
mFrame.setOnTouchListener(this);

View file

@ -3,15 +3,14 @@ package com.mapswithme.maps.ads;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.util.SparseArray;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.util.Config;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.Config;
import com.mapswithme.util.concurrency.UiThread;
import java.lang.ref.WeakReference;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.util.Config;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.concurrency.UiThread;
public enum LikesManager
{
INSTANCE;

View file

@ -136,6 +136,18 @@ public class MapPrefsFragment extends BaseXmlSettingsFragment
}
});
TwoStatePreference prefAutodownload = (TwoStatePreference)findPreference(getString(R.string.pref_autodownload));
prefAutodownload.setChecked(Config.isAutoDownloadEnabled());
prefAutodownload.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
Config.setAutoDownloadEnabled((Boolean)newValue);
return true;
}
});
final Framework.Params3dMode _3d = new Framework.Params3dMode();
Framework.nativeGet3dMode(_3d);

View file

@ -19,6 +19,7 @@ public final class Config
private static final String KEY_PREF_ZOOM_BUTTONS = "ZoomButtonsEnabled";
private static final String KEY_PREF_STATISTICS = "StatisticsEnabled";
private static final String KEY_PREF_AUTODOWNLOAD = "AutoDownloadEnabled";
private static final String KEY_LIKES_RATED_DIALOG = "RatedDialog";
private static final String KEY_LIKES_LAST_RATED_SESSION = "LastRatedSession";
@ -213,6 +214,16 @@ public final class Config
setBool(KEY_PREF_STATISTICS, enabled);
}
public static boolean isAutoDownloadEnabled()
{
return getBool(KEY_PREF_AUTODOWNLOAD, true);
}
public static void setAutoDownloadEnabled(boolean enabled)
{
setBool(KEY_PREF_AUTODOWNLOAD, enabled);
}
public static boolean isRatingApplied(Class<? extends DialogFragment> dialogFragmentClass)
{
return getBool(KEY_LIKES_RATED_DIALOG + dialogFragmentClass.getSimpleName());
@ -220,7 +231,7 @@ public final class Config
public static void setRatingApplied(Class<? extends DialogFragment> dialogFragmentClass)
{
setBool(KEY_LIKES_RATED_DIALOG + dialogFragmentClass.getSimpleName(), true);
setBool(KEY_LIKES_RATED_DIALOG + dialogFragmentClass.getSimpleName());
}
public static boolean isSessionRated(int session)
@ -240,7 +251,7 @@ public final class Config
public static void acceptRoutingDisclaimer()
{
setBool(KEY_MISC_DISCLAIMER_ACCEPTED, true);
setBool(KEY_MISC_DISCLAIMER_ACCEPTED);
}
public static boolean isKitKatMigrationComplete()