forked from organicmaps/organicmaps
add short-click handling
This commit is contained in:
parent
bbc293a3c6
commit
825cd10706
4 changed files with 84 additions and 55 deletions
|
@ -43,7 +43,7 @@ namespace android
|
|||
m_isInsideDoubleClick(false),
|
||||
m_isCleanSingleClick(false),
|
||||
m_doLoadState(true),
|
||||
m_onLongClickFnsHandler(0)
|
||||
m_onClickFnsHandler(0)
|
||||
{
|
||||
ASSERT_EQUAL ( g_framework, 0, () );
|
||||
g_framework = this;
|
||||
|
@ -275,11 +275,7 @@ namespace android
|
|||
|
||||
if ((eventType == NV_MULTITOUCH_UP) && (m_isCleanSingleClick))
|
||||
{
|
||||
double seconds = m_longClickTimer.ElapsedSeconds();
|
||||
if (seconds >= LONG_CLICK_LENGTH_SEC)
|
||||
{
|
||||
CallLongClickListeners(static_cast<int>(x1), static_cast<int>(y1));
|
||||
}
|
||||
CallClickListeners(static_cast<int>(x1), static_cast<int>(y1), m_longClickTimer.ElapsedSeconds());
|
||||
if (m_work.GetGuiController()->OnTapEnded(m2::PointD(x1, y1)))
|
||||
return;
|
||||
|
||||
|
@ -529,24 +525,24 @@ namespace android
|
|||
return &m_work;
|
||||
}
|
||||
|
||||
void Framework::CallLongClickListeners(int x, int y)
|
||||
void Framework::CallClickListeners(int x, int y, double time)
|
||||
{
|
||||
map<int, TOnLongClickListener>::iterator it;
|
||||
for (it = m_onLongClickFns.begin(); it != m_onLongClickFns.end(); it++)
|
||||
map<int, TOnClickListener>::iterator it;
|
||||
for (it = m_onClickFns.begin(); it != m_onClickFns.end(); it++)
|
||||
{
|
||||
(*it).second(x, y);
|
||||
(*it).second(x, y, time);
|
||||
}
|
||||
}
|
||||
|
||||
int Framework::AddLongClickListener(Framework::TOnLongClickListener const & l)
|
||||
int Framework::AddClickListener(Framework::TOnClickListener const & l)
|
||||
{
|
||||
int handle = ++m_onLongClickFnsHandler;
|
||||
m_onLongClickFns[handle] = l;
|
||||
int handle = ++m_onClickFnsHandler;
|
||||
m_onClickFns[handle] = l;
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Framework::RemoveLongClickListener(int h)
|
||||
void Framework::RemoveClickListener(int h)
|
||||
{
|
||||
m_onLongClickFns.erase(h);
|
||||
m_onClickFns.erase(h);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
#include "../../../nv_event/nv_event.hpp"
|
||||
|
||||
#define LONG_CLICK_LENGTH_SEC 1.0
|
||||
|
||||
class CountryStatusDisplay;
|
||||
|
||||
namespace android
|
||||
|
@ -23,14 +21,15 @@ namespace android
|
|||
class Framework
|
||||
{
|
||||
private:
|
||||
typedef function<void(int,int)> TOnLongClickListener;
|
||||
typedef function<void(int, int, double)> TOnClickListener;
|
||||
::Framework m_work;
|
||||
|
||||
VideoTimer * m_videoTimer;
|
||||
|
||||
void CallRepaint();
|
||||
map<int, TOnLongClickListener> m_onLongClickFns;
|
||||
int m_onLongClickFnsHandler;
|
||||
|
||||
map<int, TOnClickListener> m_onClickFns;
|
||||
int m_onClickFnsHandler;
|
||||
NVMultiTouchEventType m_eventType; //< multitouch action
|
||||
|
||||
double m_x1;
|
||||
|
@ -54,7 +53,8 @@ namespace android
|
|||
//@}
|
||||
|
||||
math::AvgVector<float, 3> m_sensors[2];
|
||||
void CallLongClickListeners(int x, int y);
|
||||
|
||||
void CallClickListeners(int x, int y, double time);
|
||||
|
||||
public:
|
||||
Framework();
|
||||
|
@ -112,8 +112,8 @@ namespace android
|
|||
|
||||
void Scale(double k);
|
||||
|
||||
int AddLongClickListener(TOnLongClickListener const & l);
|
||||
void RemoveLongClickListener(int h);
|
||||
int AddClickListener(TOnClickListener const & l);
|
||||
void RemoveClickListener(int h);
|
||||
|
||||
|
||||
::Framework * NativeFramework();
|
||||
|
|
|
@ -7,28 +7,52 @@
|
|||
#include "../../../nv_event/nv_event.hpp"
|
||||
|
||||
#include "../../../../../map/country_status_display.hpp"
|
||||
|
||||
#define LONG_CLICK_LENGTH_SEC 1.0
|
||||
#define SHORT_CLICK_LENGTH_SEC 0.1
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void CallLongClickListener(shared_ptr<jobject> obj, int x, int y)
|
||||
void CallClickListener(shared_ptr<jobject> obj, int x, int y, double seconds)
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
jmethodID methodID = jni::GetJavaMethodID(env, *obj.get(), "onLongClick", "(II)V");
|
||||
env->CallVoidMethod(*obj.get(), methodID, x, y);
|
||||
jmethodID methodID = 0;
|
||||
if (seconds > LONG_CLICK_LENGTH_SEC)
|
||||
{
|
||||
methodID = jni::GetJavaMethodID(env, *obj.get(), "onLongClick", "(II)V");
|
||||
}
|
||||
else if(seconds <= SHORT_CLICK_LENGTH_SEC)
|
||||
{
|
||||
methodID = jni::GetJavaMethodID(env, *obj.get(), "onClick", "(II)V");
|
||||
}
|
||||
if (methodID != 0)
|
||||
{
|
||||
env->CallVoidMethod(*obj.get(), methodID, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_addOnLongClickListener(JNIEnv * env, jobject thiz, jobject l)
|
||||
{
|
||||
return g_framework->AddLongClickListener(bind(&CallLongClickListener,jni::make_global_ref(l), _1, _2));
|
||||
return g_framework->AddClickListener(bind(&CallClickListener,jni::make_global_ref(l), _1, _2, _3));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_addOnClickListener(JNIEnv * env, jobject thiz, jobject l)
|
||||
{
|
||||
return g_framework->AddClickListener(bind(&CallClickListener,jni::make_global_ref(l), _1, _2, _3));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_removeOnLongClickListener(int h)
|
||||
{
|
||||
g_framework->RemoveLongClickListener(h);
|
||||
g_framework->RemoveClickListener(h);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_removeOnClickListener(int h)
|
||||
{
|
||||
g_framework->RemoveClickListener(h);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
|
|
@ -40,29 +40,24 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
private BroadcastReceiver m_externalStorageReceiver = null;
|
||||
private AlertDialog m_storageDisconnectedDialog = null;
|
||||
private int m_longClickHandler;
|
||||
private int m_clickHandler;
|
||||
|
||||
/// @note Always implement onLongClick function like this:
|
||||
/*
|
||||
@Override
|
||||
public boolean onLongClick(View v)
|
||||
{
|
||||
v.post(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
}
|
||||
});
|
||||
return super.onLongClick(v);
|
||||
}*/
|
||||
private interface OnLongClickListener
|
||||
{
|
||||
void onLongClick(int x, int y);
|
||||
}
|
||||
|
||||
private interface OnClickListenter
|
||||
{
|
||||
void onClick(int x, int y);
|
||||
}
|
||||
|
||||
private native int addOnLongClickListener(Object l);
|
||||
private native void removeOnLongClickListener(int h);
|
||||
|
||||
private native int addOnClickListener(Object l);
|
||||
private native void removeOnClickListener(int h);
|
||||
|
||||
private LocationService getLocationService()
|
||||
{
|
||||
return mApplication.getLocationService();
|
||||
|
@ -218,11 +213,6 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
nativeScale(2.0 / 3);
|
||||
}
|
||||
|
||||
public void onBookmarksClicked(View v)
|
||||
{
|
||||
startActivity(new Intent(this, BookmarkCategoriesActivity.class));
|
||||
}
|
||||
|
||||
public void onBookmarksClicked(View v)
|
||||
{
|
||||
if (!mApplication.isProVersion())
|
||||
|
@ -231,7 +221,7 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
}
|
||||
else
|
||||
{
|
||||
//startActivity(new Intent(this, BookmarkCategoriesActivity.class));
|
||||
startActivity(new Intent(this, BookmarkCategoriesActivity.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,7 +361,6 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
{
|
||||
// Show Facebook page in browser.
|
||||
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/MapsWithMe"));
|
||||
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
@ -559,10 +548,33 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
nativeConnectDownloadButton();
|
||||
|
||||
alignZoomButtons();
|
||||
m_longClickHandler = addOnLongClickListener(new OnLongClickListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onLongClick(int x, int y)
|
||||
{
|
||||
}
|
||||
});
|
||||
m_clickHandler = addOnClickListener(new OnClickListenter()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(int x, int y)
|
||||
{
|
||||
}
|
||||
});
|
||||
//m_timer = new VideoTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
removeOnClickListener(m_clickHandler);
|
||||
removeOnLongClickListener(m_longClickHandler);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void alignZoomButtons()
|
||||
{
|
||||
// Get screen density
|
||||
|
@ -620,17 +632,14 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.close, new DialogInterface.OnClickListener()
|
||||
}).setNegativeButton(R.string.close, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
else if (errorCode == LocationService.ERROR_GPS_OFF)
|
||||
|
|
Loading…
Add table
Reference in a new issue