[android] fix: Code review fixes.

This commit is contained in:
Alexander Marchuk 2015-10-16 17:38:37 +03:00
parent 2917f424da
commit b5600e7fed
12 changed files with 176 additions and 162 deletions

View file

@ -7,24 +7,25 @@ extern "C"
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_util_Config_nativeGetBoolean(JNIEnv * env, jclass thiz, jstring name, jboolean defaultVal)
{
bool val = defaultVal;
Settings::Get(jni::ToNativeString(env, name), val);
return val;
bool val;
if (Settings::Get(jni::ToNativeString(env, name), val))
return static_cast<jboolean>(val);
return defaultVal;
}
JNIEXPORT void JNICALL
Java_com_mapswithme_util_Config_nativeSetBoolean(JNIEnv * env, jclass thiz, jstring name, jboolean val)
{
bool flag = val;
(void)Settings::Set(jni::ToNativeString(env, name), flag);
(void)Settings::Set(jni::ToNativeString(env, name), static_cast<bool>(val));
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_util_Config_nativeGetInt(JNIEnv * env, jclass thiz, jstring name, jint defaultValue)
{
jint value;
int32_t value;
if (Settings::Get(jni::ToNativeString(env, name), value))
return value;
return static_cast<jint>(value);
return defaultValue;
}
@ -32,15 +33,15 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_util_Config_nativeSetInt(JNIEnv * env, jclass thiz, jstring name, jint value)
{
(void)Settings::Set(jni::ToNativeString(env, name), value);
(void)Settings::Set(jni::ToNativeString(env, name), static_cast<int32_t>(value));
}
JNIEXPORT jlong JNICALL
Java_com_mapswithme_util_Config_nativeGetLong(JNIEnv * env, jclass thiz, jstring name, jlong defaultValue)
{
jlong value;
int64_t value;
if (Settings::Get(jni::ToNativeString(env, name), value))
return value;
return static_cast<jlong>(value);
return defaultValue;
}
@ -48,15 +49,15 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_util_Config_nativeSetLong(JNIEnv * env, jclass thiz, jstring name, jlong value)
{
(void)Settings::Set(jni::ToNativeString(env, name), value);
(void)Settings::Set(jni::ToNativeString(env, name), static_cast<int64_t>(value));
}
JNIEXPORT jdouble JNICALL
Java_com_mapswithme_util_Config_nativeGetDouble(JNIEnv * env, jclass thiz, jstring name, jdouble defaultValue)
{
jdouble value;
double value;
if (Settings::Get(jni::ToNativeString(env, name), value))
return value;
return static_cast<jdouble>(value);
return defaultValue;
}
@ -64,13 +65,7 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_util_Config_nativeSetDouble(JNIEnv * env, jclass thiz, jstring name, jdouble value)
{
(void)Settings::Set(jni::ToNativeString(env, name), value);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_util_Config_nativeSetString(JNIEnv * env, jclass thiz, jstring name, jstring value)
{
(void)Settings::Set(jni::ToNativeString(env, name), jni::ToNativeString(env, value));
(void)Settings::Set(jni::ToNativeString(env, name), static_cast<double>(value));
}
JNIEXPORT jstring JNICALL
@ -82,4 +77,10 @@ extern "C"
return defaultValue;
}
JNIEXPORT void JNICALL
Java_com_mapswithme_util_Config_nativeSetString(JNIEnv * env, jclass thiz, jstring name, jstring value)
{
(void)Settings::Set(jni::ToNativeString(env, name), jni::ToNativeString(env, value));
}
} // extern "C"

View file

@ -45,14 +45,6 @@
<item name="android:fontFamily" tools:ignore="NewApi">@string/robotoRegular</item>
</style>
<style name="MwmWidget.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/base_green</item>
<item name="android:displayOptions">homeAsUp|showTitle</item>
<item name="android:titleTextAppearance" tools:ignore="NewApi">@style/MwmTextAppearance.Toolbar.Title</item>
<item name="android:homeAsUpIndicator">@drawable/abc_ic_ab_back_mtrl_am_alpha</item>
<item name="homeAsUpIndicator">@drawable/abc_ic_ab_back_mtrl_am_alpha</item>
</style>
<style name="MwmWidget.ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">?attr/colorPrimary</item>
<item name="android:elevation" tools:ignore="NewApi">@dimen/appbar_elevation</item>
@ -70,7 +62,7 @@
<item name="colorAccent">@android:color/white</item>
</style>
<style name="MwmWidget.ListView" parent="android:Widget.Holo.Light.ListView">
<style name="MwmWidget.ListView" parent="Widget.AppCompat.ListView">
<item name="android:fadingEdge">none</item>
<item name="android:divider">@color/base_black_divider</item>
<item name="android:background">@null</item>
@ -80,7 +72,7 @@
<item name="android:cacheColorHint">@android:color/transparent</item>
</style>
<style name="MwmWidget.TextView" parent="android:Widget.Holo.Light.TextView">
<style name="MwmWidget.TextView" parent="android:Widget.TextView">
<item name="android:background">@android:color/transparent</item>
</style>

View file

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

View file

@ -1,12 +1,10 @@
package com.mapswithme.maps.settings;
import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
@ -24,16 +22,26 @@ import com.mapswithme.util.sharing.ShareOption;
import com.mapswithme.util.statistics.AlohaHelper;
import com.mapswithme.util.statistics.Statistics;
public class AboutFragment extends Fragment
public class AboutFragment extends BaseSettingsFragment
implements View.OnClickListener
{
private View mFrame;
private BaseShadowController mShadowController;
@Override
protected int getLayoutRes()
{
return R.layout.about;
}
@Override
protected BaseShadowController createShadowController()
{
((View)mFrame.getParent()).setPadding(0, 0, 0, 0);
return new ScrollViewShadowController((ObservableScrollView)mFrame.findViewById(R.id.content_frame));
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
mFrame = inflater.inflate(R.layout.about, container, false);
super.onCreateView(inflater, container, savedInstanceState);
((TextView)mFrame.findViewById(R.id.version))
.setText(getString(R.string.version, BuildConfig.VERSION_NAME));
@ -50,27 +58,6 @@ public class AboutFragment extends Fragment
return mFrame;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
if (((PreferenceActivity)getActivity()).onIsMultiPane())
{
((View)mFrame.getParent()).setPadding(0, 0, 0, 0);
mShadowController = new ScrollViewShadowController((ObservableScrollView)mFrame.findViewById(R.id.content_frame)).attach();
}
}
@Override
public void onDestroyView()
{
super.onDestroyView();
if (mShadowController != null)
mShadowController.detach();
}
@Override
public void onClick(View v)
{

View file

@ -0,0 +1,57 @@
package com.mapswithme.maps.settings;
import android.app.Fragment;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapswithme.maps.R;
import com.mapswithme.maps.widget.BaseShadowController;
import com.mapswithme.util.UiUtils;
abstract class BaseSettingsFragment extends Fragment
{
protected View mFrame;
private BaseShadowController mShadowController;
protected abstract @LayoutRes int getLayoutRes();
protected abstract BaseShadowController createShadowController();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
mFrame = inflater.inflate(getLayoutRes(), container, false);
return mFrame;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
if (((PreferenceActivity)getActivity()).onIsMultiPane())
mShadowController = createShadowController().attach();
}
@Override
public void onDestroyView()
{
super.onDestroyView();
if (mShadowController != null)
mShadowController.detach();
}
protected static void adjustMargins(View view)
{
int margin = UiUtils.dimen(R.dimen.margin_half);
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
lp.leftMargin = margin;
lp.rightMargin = margin;
view.setLayoutParams(lp);
}
}

View file

@ -1,9 +1,7 @@
package com.mapswithme.maps.settings;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
@ -16,18 +14,30 @@ import com.mapswithme.maps.widget.ObservableWebView;
import com.mapswithme.maps.widget.WebViewShadowController;
import com.mapswithme.util.Constants;
public class CopyrightFragment extends Fragment
public class CopyrightFragment extends BaseSettingsFragment
implements OnBackPressListener
{
private WebContainerDelegate mDelegate;
private BaseShadowController mShadowController;
@Override
protected int getLayoutRes()
{
return R.layout.fragment_prefs_copyright;
}
@Override
protected BaseShadowController createShadowController()
{
adjustMargins(mDelegate.getWebView());
return new WebViewShadowController((ObservableWebView)mDelegate.getWebView());
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View frame = inflater.inflate(R.layout.fragment_prefs_copyright, container, false);
super.onCreateView(inflater, container, savedInstanceState);
mDelegate = new WebContainerDelegate(frame, Constants.Url.COPYRIGHT)
mDelegate = new WebContainerDelegate(mFrame, Constants.Url.COPYRIGHT)
{
@Override
protected void doStartActivity(Intent intent)
@ -36,27 +46,7 @@ public class CopyrightFragment extends Fragment
}
};
return frame;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
if (((PreferenceActivity)getActivity()).onIsMultiPane())
{
HelpFragment.adjustMargins(mDelegate.getWebView());
mShadowController = new WebViewShadowController((ObservableWebView)mDelegate.getWebView()).attach();
}
}
@Override
public void onDestroyView()
{
super.onDestroyView();
if (mShadowController != null)
mShadowController.detach();
return mFrame;
}
@Override

View file

@ -1,11 +1,9 @@
package com.mapswithme.maps.settings;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
@ -17,21 +15,33 @@ import com.mapswithme.maps.widget.BaseShadowController;
import com.mapswithme.maps.widget.ObservableWebView;
import com.mapswithme.maps.widget.WebViewShadowController;
import com.mapswithme.util.Constants;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.statistics.AlohaHelper;
import com.mapswithme.util.statistics.Statistics;
public class HelpFragment extends Fragment
public class HelpFragment extends BaseSettingsFragment
{
private View mFrame;
private WebContainerDelegate mDelegate;
private BaseShadowController mShadowController;
@Override
protected int getLayoutRes()
{
return R.layout.fragment_prefs_help;
}
@Override
protected BaseShadowController createShadowController()
{
((View)mFrame.getParent()).setPadding(0, 0, 0, 0);
adjustMargins(mDelegate.getWebView());
return new WebViewShadowController((ObservableWebView)mDelegate.getWebView())
.addBottomShadow();
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
mFrame = inflater.inflate(R.layout.fragment_prefs_help, container, false);
super.onCreateView(inflater, container, savedInstanceState);
mDelegate = new WebContainerDelegate(mFrame, Constants.Url.FAQ)
{
@ -88,36 +98,4 @@ public class HelpFragment extends Fragment
return mFrame;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
if (((PreferenceActivity)getActivity()).onIsMultiPane())
{
((View)mFrame.getParent()).setPadding(0, 0, 0, 0);
adjustMargins(mDelegate.getWebView());
mShadowController = new WebViewShadowController((ObservableWebView)mDelegate.getWebView())
.addBottomShadow()
.attach();
}
}
@Override
public void onDestroyView()
{
super.onDestroyView();
if (mShadowController != null)
mShadowController.detach();
}
static void adjustMargins(View view)
{
int margin = UiUtils.dimen(R.dimen.margin_half);
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
lp.leftMargin = margin;
lp.rightMargin = margin;
view.setLayoutParams(lp);
}
}

View file

@ -27,7 +27,7 @@ public class SettingsActivity extends PreferenceActivity
{
private final FragmentListHelper mFragmentListHelper = new FragmentListHelper();
private AppCompatDelegate mDelegate;
private String mNextBreadcrumb;
private CharSequence mNextBreadcrumb;
private AppCompatDelegate getDelegate()
{
@ -84,12 +84,13 @@ public class SettingsActivity extends PreferenceActivity
Toolbar toolbar = (Toolbar) toolbarHolder.findViewById(R.id.toolbar);
UiUtils.showHomeUpButton(toolbar);
// Yes, attach it twice
// First, add toolbar view to UI.
root.addView(toolbarHolder, 0);
// Second, attach it as ActionBar (it does not add view, so we need previous step).
getDelegate().setSupportActionBar(toolbar);
MwmApplication.get().initCounters();
MwmApplication.get().initNativeCore();
MwmApplication.get().initCounters();
ViewServer.get(this).addWindow(this);
}

View file

@ -12,6 +12,7 @@ import com.mapswithme.util.Utils;
import java.util.List;
public class StoragePathFragment extends BaseMwmListFragment
implements StoragePathManager.MoveFilesListener
{
private StoragePathManager mPathManager = new StoragePathManager();
private StoragePathAdapter mAdapter;
@ -39,36 +40,11 @@ public class StoragePathFragment extends BaseMwmListFragment
if (mAdapter != null)
mAdapter.updateList(storageItems, currentStorageIndex, StorageUtils.getWritableDirSize());
}
}, new StoragePathManager.MoveFilesListener()
{
@Override
public void moveFilesFinished(String newPath)
{
mAdapter.updateList(mPathManager.getStorageItems(), mPathManager.getCurrentStorageIndex(), StorageUtils.getWritableDirSize());
}
}, this);
@Override
public void moveFilesFailed(int errorCode)
{
if (!isAdded())
return;
if (mAdapter == null)
mAdapter = new StoragePathAdapter(mPathManager, getActivity());
final String message = "Failed to move maps with internal error: " + errorCode;
final Activity activity = getActivity();
new AlertDialog.Builder(activity)
.setTitle(message)
.setPositiveButton(R.string.report_a_bug, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Utils.sendSupportMail(activity, message);
}
}).show();
}
});
initAdapter();
mAdapter.updateList(mPathManager.getStorageItems(), mPathManager.getCurrentStorageIndex(), StorageUtils.getWritableDirSize());
setListAdapter(mAdapter);
}
@ -80,9 +56,32 @@ public class StoragePathFragment extends BaseMwmListFragment
mPathManager.stopExternalStorageWatching();
}
private void initAdapter()
@Override
public void moveFilesFinished(String newPath)
{
if (mAdapter == null)
mAdapter = new StoragePathAdapter(mPathManager, getActivity());
mAdapter.updateList(mPathManager.getStorageItems(), mPathManager.getCurrentStorageIndex(), StorageUtils.getWritableDirSize());
}
@Override
public void moveFilesFailed(int errorCode)
{
if (!isAdded())
return;
final String message = "Failed to move maps with internal error: " + errorCode;
final Activity activity = getActivity();
if (activity.isFinishing())
return;
new AlertDialog.Builder(activity)
.setTitle(message)
.setPositiveButton(R.string.report_a_bug, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Utils.sendSupportMail(activity, message);
}
}).show();
}
}

View file

@ -126,9 +126,10 @@ public final class Config
private static void incrementSessionNumber()
{
long lastSessionTimestamp = getLong(KEY_APP_LAST_SESSION_TIMESTAMP);
if (!DateUtils.isToday(lastSessionTimestamp))
setLong(KEY_APP_LAST_SESSION_TIMESTAMP, System.currentTimeMillis());
if (DateUtils.isToday(lastSessionTimestamp))
return;
setLong(KEY_APP_LAST_SESSION_TIMESTAMP, System.currentTimeMillis());
increment(KEY_APP_SESSION_NUMBER);
}

View file

@ -34,6 +34,8 @@ public class AlohaHelper
public static final String ABOUT = "about";
public static final String COPYRIGHT = "copyright";
public static final String CHANGE_UNITS = "settingsMiles";
private Settings() {}
}
// for aloha stats

View file

@ -64,6 +64,8 @@ public enum Statistics
public static final String COPYRIGHT = "Settings. Copyright.";
public static final String GROUP_MAP = "Settings. Group: map.";
public static final String GROUP_MISC = "Settings. Group: misc.";
private Settings() {}
}
public static final String SEARCH_KEY_CLICKED = "Search key pressed.";
@ -75,6 +77,8 @@ public enum Statistics
public static final String FACEBOOK_INVITE_LATER = "Facebook invites dialog cancelled.";
public static final String FACEBOOK_INVITE_INVITED = "GPlay dialog cancelled.";
public static final String RATE_DIALOG_RATED = "GPlay dialog. Rating set";
private EventName() {}
}
public static class EventParam
@ -89,6 +93,8 @@ public enum Statistics
public static final String DELAY_MILLIS = "Delay in milliseconds";
public static final String ENABLED = "Enabled";
public static final String RATING = "Rating";
private EventParam() {}
}
private static class MyTrackerParams