forked from organicmaps/organicmaps
[android] fix: Setting-up GUI widgets.
This commit is contained in:
parent
76f2b66fa1
commit
cb29205b63
5 changed files with 116 additions and 73 deletions
|
@ -149,15 +149,8 @@ bool Framework::CreateDrapeEngine(JNIEnv * env, jobject jSurface, int densityDpi
|
|||
p.m_surfaceHeight = factory->GetHeight();
|
||||
p.m_visualScale = visualScale;
|
||||
|
||||
/// @TODO (android developers) remove this stuff and create real logic for init and layout core widgets
|
||||
m_skin.reset(new gui::Skin(gui::ResolveGuiSkinFile("default"), visualScale));
|
||||
m_skin->Resize(p.m_surfaceWidth, p.m_surfaceHeight);
|
||||
m_skin->ForEach([&p](gui::EWidget widget, gui::Position const & pos)
|
||||
{
|
||||
p.m_widgetsInitInfo[widget] = pos;
|
||||
});
|
||||
|
||||
p.m_widgetsInitInfo[gui::WIDGET_SCALE_LABEL] = gui::Position(dp::LeftBottom);
|
||||
ASSERT(!m_guiPositions.empty(), ("GUI elements must be set-up before engine is created"));
|
||||
p.m_widgetsInitInfo = m_guiPositions;
|
||||
|
||||
m_work.LoadBookmarks();
|
||||
m_work.SetMyPositionModeListener(bind(&Framework::MyPositionModeChanged, this, _1));
|
||||
|
@ -192,20 +185,6 @@ void Framework::Resize(int w, int h)
|
|||
{
|
||||
m_contextFactory->CastFactory<AndroidOGLContextFactory>()->UpdateSurfaceSize();
|
||||
m_work.OnSize(w, h);
|
||||
|
||||
/// @TODO (android developers) remove this stuff and create real logic for layout core widgets
|
||||
if (m_skin)
|
||||
{
|
||||
m_skin->Resize(w, h);
|
||||
|
||||
gui::TWidgetsLayoutInfo layout;
|
||||
m_skin->ForEach([&layout](gui::EWidget w, gui::Position const & pos)
|
||||
{
|
||||
layout[w] = pos.m_pixelPivot;
|
||||
});
|
||||
|
||||
m_work.SetWidgetLayout(move(layout));
|
||||
}
|
||||
}
|
||||
|
||||
void Framework::DetachSurface()
|
||||
|
@ -484,6 +463,20 @@ void Framework::SetMyPositionMode(location::EMyPositionMode mode)
|
|||
m_currentMode = mode;
|
||||
}
|
||||
|
||||
void Framework::SetupWidget(gui::EWidget widget, float x, float y, dp::Anchor anchor)
|
||||
{
|
||||
m_guiPositions[widget] = gui::Position(m2::PointF(x, y), anchor);
|
||||
}
|
||||
|
||||
void Framework::ApplyWidgets()
|
||||
{
|
||||
gui::TWidgetsLayoutInfo layout;
|
||||
for (auto const & widget : m_guiPositions)
|
||||
layout[widget.first] = widget.second.m_pixelPivot;
|
||||
|
||||
m_work.SetWidgetLayout(move(layout));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
void Framework::ItemStatusChanged(int childPosition)
|
||||
{
|
||||
|
|
|
@ -35,8 +35,6 @@ namespace android
|
|||
drape_ptr<dp::ThreadSafeFactory> m_contextFactory;
|
||||
::Framework m_work;
|
||||
|
||||
unique_ptr<gui::Skin> m_skin;
|
||||
|
||||
typedef shared_ptr<jobject> TJobject;
|
||||
TJobject m_javaCountryListener;
|
||||
typedef map<int, TJobject> TListenerMap;
|
||||
|
@ -50,6 +48,8 @@ namespace android
|
|||
|
||||
string m_searchQuery;
|
||||
|
||||
map<gui::EWidget, gui::Position> m_guiPositions;
|
||||
|
||||
float GetBestDensity(int densityDpi);
|
||||
|
||||
void MyPositionModeChanged(location::EMyPositionMode mode);
|
||||
|
@ -157,6 +157,9 @@ namespace android
|
|||
location::EMyPositionMode GetMyPositionMode() const;
|
||||
void SetMyPositionMode(location::EMyPositionMode mode);
|
||||
|
||||
void SetupWidget(gui::EWidget widget, float x, float y, dp::Anchor anchor);
|
||||
void ApplyWidgets();
|
||||
|
||||
// Fills mapobject's metadata from UserMark
|
||||
void InjectMetadata(JNIEnv * env, jclass clazz, jobject const mapObject, UserMark const * userMark);
|
||||
|
||||
|
|
|
@ -72,18 +72,18 @@ extern "C"
|
|||
JNIEXPORT jfloatArray JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationHelper_nativeUpdateCompassSensor(JNIEnv * env, jclass clazz, jint ind, jfloatArray arr)
|
||||
{
|
||||
int const count = 3;
|
||||
int const kCount = 3;
|
||||
|
||||
// get Java array
|
||||
jfloat buffer[3];
|
||||
env->GetFloatArrayRegion(arr, 0, count, buffer);
|
||||
env->GetFloatArrayRegion(arr, 0, kCount, buffer);
|
||||
|
||||
// get the result
|
||||
g_framework->UpdateCompassSensor(ind, buffer);
|
||||
|
||||
// pass result back to Java
|
||||
jfloatArray ret = (jfloatArray)env->NewFloatArray(count);
|
||||
env->SetFloatArrayRegion(ret, 0, count, buffer);
|
||||
jfloatArray ret = (jfloatArray)env->NewFloatArray(kCount);
|
||||
env->SetFloatArrayRegion(ret, 0, kCount, buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ extern "C"
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MapFragment_nativeSurfaceResized(JNIEnv * env, jclass clazz, jint w, jint h)
|
||||
Java_com_mapswithme_maps_MapFragment_nativeSurfaceChanged(JNIEnv * env, jclass clazz, jint w, jint h)
|
||||
{
|
||||
g_framework->Resize(static_cast<int>(w), static_cast<int>(h));
|
||||
}
|
||||
|
@ -189,4 +189,16 @@ extern "C"
|
|||
g_framework->Touch(static_cast<int>(action), android::Framework::Finger(id1, x1, y1),
|
||||
android::Framework::Finger(id2, x2, y2), maskedPointer);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MapFragment_nativeSetupWidget(JNIEnv * env, jclass clazz, jint widget, jfloat x, jfloat y, jint anchor)
|
||||
{
|
||||
g_framework->SetupWidget(static_cast<gui::EWidget>(widget), static_cast<float>(x), static_cast<float>(y), static_cast<dp::Anchor>(anchor));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MapFragment_nativeApplyWidgets(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
g_framework->ApplyWidgets();
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.mapswithme.maps;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
@ -9,10 +10,11 @@ import android.util.DisplayMetrics;
|
|||
import android.view.*;
|
||||
import com.mapswithme.maps.base.BaseMwmFragment;
|
||||
import com.mapswithme.maps.downloader.DownloadHelper;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class MapFragment extends BaseMwmFragment
|
||||
implements View.OnTouchListener,
|
||||
SurfaceHolder.Callback
|
||||
implements View.OnTouchListener,
|
||||
SurfaceHolder.Callback
|
||||
{
|
||||
// Should be equal to values from Framework.cpp MultiTouchAction enum
|
||||
private static final int NATIVE_ACTION_UP = 0x01;
|
||||
|
@ -22,9 +24,9 @@ public class MapFragment extends BaseMwmFragment
|
|||
|
||||
// Should correspond to gui::EWidget from skin.hpp
|
||||
private static final int WIDGET_RULER = 0x01;
|
||||
private static final int WIDGET_COPYRIGHT = 0x02;
|
||||
private static final int WIDGET_COUNTRY_STATUS = 0x04;
|
||||
private static final int WIDGET_COMPASS = 0x08;
|
||||
private static final int WIDGET_COMPASS = 0x02;
|
||||
private static final int WIDGET_COPYRIGHT = 0x04;
|
||||
private static final int WIDGET_SCALE_LABEL = 0x08;
|
||||
|
||||
// Should correspond to dp::Anchor from drape_global.hpp
|
||||
private static final int ANCHOR_CENTER = 0x00;
|
||||
|
@ -41,8 +43,9 @@ public class MapFragment extends BaseMwmFragment
|
|||
private static final int INVALID_POINTER_MASK = 0xFF;
|
||||
private static final int INVALID_TOUCH_ID = -1;
|
||||
|
||||
private SurfaceHolder mSurfaceHolder;
|
||||
private int mDisplayDensity;
|
||||
private int mHeight;
|
||||
private boolean mRequireResize;
|
||||
private boolean mEngineCreated;
|
||||
|
||||
public interface MapRenderingListener
|
||||
{
|
||||
|
@ -54,26 +57,54 @@ public class MapFragment extends BaseMwmFragment
|
|||
@Override
|
||||
public void surfaceCreated(SurfaceHolder surfaceHolder)
|
||||
{
|
||||
mSurfaceHolder = surfaceHolder;
|
||||
final Surface surface = surfaceHolder.getSurface();
|
||||
if (nativeIsEngineCreated())
|
||||
nativeAttachSurface(mSurfaceHolder.getSurface());
|
||||
{
|
||||
nativeAttachSurface(surface);
|
||||
mRequireResize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
mRequireResize = false;
|
||||
final Rect rect = surfaceHolder.getSurfaceFrame();
|
||||
setupWidgets(rect.width(), rect.height());
|
||||
|
||||
final DisplayMetrics metrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
|
||||
mEngineCreated = nativeCreateEngine(surface, metrics.densityDpi);
|
||||
if (mEngineCreated)
|
||||
onRenderingInitialized();
|
||||
else
|
||||
initEngine();
|
||||
reportUnsupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int w, int h)
|
||||
public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height)
|
||||
{
|
||||
nativeSurfaceResized(w, h);
|
||||
if (!mEngineCreated)
|
||||
return;
|
||||
|
||||
if (!mRequireResize && surfaceHolder.isCreating())
|
||||
return;
|
||||
|
||||
nativeSurfaceChanged(width, height);
|
||||
|
||||
mRequireResize = false;
|
||||
setupWidgets(width, height);
|
||||
nativeApplyWidgets();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder surfaceHolder)
|
||||
{
|
||||
mSurfaceHolder = null;
|
||||
if (!mEngineCreated)
|
||||
return;
|
||||
|
||||
if (getActivity() == null || !getActivity().isChangingConfigurations())
|
||||
{
|
||||
// We're in the main thread here. So nothing from the queue will be run between these two calls.
|
||||
// Destroy engine first, then clear the queue that theoretically can be filled by nativeDestroyEngine().
|
||||
nativeDestroyEngine();
|
||||
MwmApplication.get().clearFunctorsOnUiThread();
|
||||
} else
|
||||
|
@ -95,9 +126,6 @@ public class MapFragment extends BaseMwmFragment
|
|||
public void onCreate(Bundle b)
|
||||
{
|
||||
super.onCreate(b);
|
||||
final DisplayMetrics metrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
mDisplayDensity = metrics.densityDpi;
|
||||
setRetainInstance(true);
|
||||
}
|
||||
|
||||
|
@ -157,37 +185,42 @@ public class MapFragment extends BaseMwmFragment
|
|||
}
|
||||
}
|
||||
|
||||
private void initEngine()
|
||||
{
|
||||
if (nativeCreateEngine(mSurfaceHolder.getSurface(), mDisplayDensity))
|
||||
onRenderingInitialized();
|
||||
else
|
||||
reportUnsupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
return inflater.inflate(R.layout.fragment_map, container, false);
|
||||
}
|
||||
|
||||
protected void applyWidgetPivots(final int mapHeight, final int mapWidth)
|
||||
private void setupWidgets(int width, int height)
|
||||
{
|
||||
//Framework.setWidgetPivot(Framework.MAP_WIDGET_RULER,
|
||||
// mSurfaceWidth - UiUtils.dimen(R.dimen.margin_ruler_right),
|
||||
// mSurfaceHeight - UiUtils.dimen(R.dimen.margin_ruler_bottom));
|
||||
//Framework.setWidgetPivot(Framework.MAP_WIDGET_COPYRIGHT,
|
||||
// mSurfaceWidth - UiUtils.dimen(R.dimen.margin_ruler_right),
|
||||
// mSurfaceHeight - UiUtils.dimen(R.dimen.margin_ruler_bottom));
|
||||
mHeight = height;
|
||||
|
||||
//adjustCompass(0);
|
||||
nativeSetupWidget(WIDGET_RULER,
|
||||
width - UiUtils.dimen(R.dimen.margin_ruler_right),
|
||||
mHeight - UiUtils.dimen(R.dimen.margin_ruler_bottom),
|
||||
ANCHOR_RIGHT_BOTTOM);
|
||||
|
||||
nativeSetupWidget(WIDGET_COPYRIGHT,
|
||||
width / 2,
|
||||
UiUtils.dimen(R.dimen.margin_base),
|
||||
ANCHOR_TOP);
|
||||
|
||||
nativeSetupWidget(WIDGET_SCALE_LABEL,
|
||||
UiUtils.dimen(R.dimen.margin_base),
|
||||
UiUtils.dimen(R.dimen.margin_base),
|
||||
ANCHOR_LEFT_TOP);
|
||||
|
||||
adjustCompass(0, false);
|
||||
}
|
||||
|
||||
public void adjustCompass(int offset)
|
||||
public void adjustCompass(int offset, boolean forceRedraw)
|
||||
{
|
||||
//Framework.setWidgetPivot(Framework.MAP_WIDGET_COMPASS,
|
||||
// UiUtils.dimen(R.dimen.margin_compass_left) + offset,
|
||||
// mSurfaceHeight - UiUtils.dimen(R.dimen.margin_compass_bottom));
|
||||
nativeSetupWidget(WIDGET_COMPASS,
|
||||
UiUtils.dimen(R.dimen.margin_compass_left) + offset,
|
||||
mHeight - UiUtils.dimen(R.dimen.margin_compass_bottom),
|
||||
ANCHOR_CENTER);
|
||||
if (forceRedraw)
|
||||
nativeApplyWidgets();
|
||||
}
|
||||
|
||||
public void onRenderingInitialized()
|
||||
|
@ -256,6 +289,8 @@ public class MapFragment extends BaseMwmFragment
|
|||
private static native void nativeDestroyEngine();
|
||||
private static native void nativeAttachSurface(Surface surface);
|
||||
private static native void nativeDetachSurface();
|
||||
private static native void nativeSurfaceResized(int w, int h);
|
||||
private static native void nativeSurfaceChanged(int w, int h);
|
||||
private static native void nativeOnTouch(int actionType, int id1, float x1, float y1, int id2, float x2, float y2, int maskedPointer);
|
||||
private static native void nativeSetupWidget(int widget, float x, float y, int anchor);
|
||||
private static native void nativeApplyWidgets();
|
||||
}
|
||||
|
|
|
@ -1166,13 +1166,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
public void adjustCompass(int offset)
|
||||
{
|
||||
if (mMapFragment != null && mMapFragment.isAdded())
|
||||
{
|
||||
mMapFragment.adjustCompass(mPanelAnimator.isVisible() ? offset : 0);
|
||||
if (mMapFragment == null || !mMapFragment.isAdded())
|
||||
return;
|
||||
|
||||
if (mLastCompassData != null)
|
||||
MapFragment.nativeCompassUpdated(mLastCompassData.magneticNorth, mLastCompassData.trueNorth, true);
|
||||
}
|
||||
mMapFragment.adjustCompass(mPanelAnimator.isVisible() ? offset : 0, true);
|
||||
|
||||
if (mLastCompassData != null)
|
||||
MapFragment.nativeCompassUpdated(mLastCompassData.magneticNorth, mLastCompassData.trueNorth, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue