forked from organicmaps/organicmaps
[android] long click add long click to MWMActivity
This commit is contained in:
parent
c97194bdac
commit
48e0c780bf
7 changed files with 127 additions and 7 deletions
|
@ -49,7 +49,6 @@ namespace android
|
|||
g_framework = this;
|
||||
|
||||
m_videoTimer = new VideoTimer(bind(&Framework::CallRepaint, this));
|
||||
|
||||
size_t const measurementsCount = 5;
|
||||
m_sensors[0].SetCount(measurementsCount);
|
||||
m_sensors[1].SetCount(measurementsCount);
|
||||
|
@ -237,6 +236,7 @@ namespace android
|
|||
|
||||
void Framework::Touch(int action, int mask, double x1, double y1, double x2, double y2)
|
||||
{
|
||||
//TODO Çàâîäèì òàéìåð
|
||||
NVMultiTouchEventType eventType = (NVMultiTouchEventType)action;
|
||||
|
||||
// processing double-click
|
||||
|
@ -253,6 +253,8 @@ namespace android
|
|||
{
|
||||
if (eventType == NV_MULTITOUCH_DOWN)
|
||||
{
|
||||
//TODO strt timer
|
||||
m_longClickTimer.Reset();
|
||||
m_isCleanSingleClick = true;
|
||||
m_lastX1 = x1;
|
||||
m_lastY1 = y1;
|
||||
|
@ -265,18 +267,25 @@ namespace android
|
|||
{
|
||||
if ((fabs(x1 - m_lastX1) > 10)
|
||||
|| (fabs(y1 - m_lastY1) > 10))
|
||||
{
|
||||
m_isCleanSingleClick = false;
|
||||
//TODO stop timer
|
||||
}
|
||||
|
||||
if (m_work.GetGuiController()->OnTapMoved(m2::PointD(x1, y1)))
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventType == NV_MULTITOUCH_UP)
|
||||
if (m_work.GetGuiController()->OnTapEnded(m2::PointD(x1, y1)))
|
||||
return;
|
||||
|
||||
if ((eventType == NV_MULTITOUCH_UP) && (m_isCleanSingleClick))
|
||||
{
|
||||
double seconds = m_longClickTimer.ElapsedSeconds();
|
||||
if ( seconds >= LONG_CLICK_LENGTH_SEC)
|
||||
{
|
||||
CallLongClickListeners((int)x1,(int) y1);
|
||||
}
|
||||
if (m_work.GetGuiController()->OnTapEnded(m2::PointD(x1, y1)))
|
||||
return;
|
||||
|
||||
|
@ -506,4 +515,25 @@ namespace android
|
|||
{
|
||||
return &m_work;
|
||||
}
|
||||
|
||||
void Framework::CallLongClickListeners(int x, int y)
|
||||
{
|
||||
map<int, TOnLongClickListener>::iterator it;
|
||||
for ( it=m_onLongClickFns.begin() ; it != m_onLongClickFns.end(); it++ )
|
||||
{
|
||||
(*it).second(x,y);
|
||||
}
|
||||
}
|
||||
|
||||
int Framework::AddLongClickListener(Framework::TOnLongClickListener l)
|
||||
{
|
||||
int handle = ++m_onLongClickFnsHandle;
|
||||
m_onLongClickFns[handle] = l;
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Framework::RemoveLongClickListener(int h)
|
||||
{
|
||||
m_onLongClickFns.erase(m_onLongClickFns.find(h));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "../../../../../map/drawer.hpp"
|
||||
#include "../../../../../map/window_handle.hpp"
|
||||
#include "../../../../../map/feature_vec_model.hpp"
|
||||
#include "../../../../../base/logging.hpp"
|
||||
|
||||
#include "../../../../../geometry/avg_vector.hpp"
|
||||
|
||||
|
@ -14,6 +15,8 @@
|
|||
|
||||
#include "../../../nv_event/nv_event.hpp"
|
||||
|
||||
#define LONG_CLICK_LENGTH_SEC 1.0
|
||||
|
||||
class CountryStatusDisplay;
|
||||
|
||||
namespace android
|
||||
|
@ -21,12 +24,14 @@ namespace android
|
|||
class Framework
|
||||
{
|
||||
private:
|
||||
typedef function<void(int,int)> TOnLongClickListener;
|
||||
::Framework m_work;
|
||||
|
||||
VideoTimer * m_videoTimer;
|
||||
|
||||
void CallRepaint();
|
||||
|
||||
map<int, TOnLongClickListener> m_onLongClickFns;
|
||||
int m_onLongClickFnsHandle;
|
||||
NVMultiTouchEventType m_eventType; //< multitouch action
|
||||
|
||||
double m_x1;
|
||||
|
@ -37,7 +42,7 @@ namespace android
|
|||
bool m_hasFirst;
|
||||
bool m_hasSecond;
|
||||
int m_mask;
|
||||
|
||||
my::Timer m_longClickTimer;
|
||||
bool m_doLoadState;
|
||||
|
||||
/// @name Single click processing parameters.
|
||||
|
@ -50,6 +55,7 @@ namespace android
|
|||
//@}
|
||||
|
||||
math::AvgVector<float, 3> m_sensors[2];
|
||||
void CallLongClickListeners(int x, int y);
|
||||
|
||||
public:
|
||||
Framework();
|
||||
|
@ -104,6 +110,10 @@ namespace android
|
|||
|
||||
void Scale(double k);
|
||||
|
||||
int AddLongClickListener(TOnLongClickListener l);
|
||||
void RemoveLongClickListener(int h);
|
||||
|
||||
|
||||
::Framework * NativeFramework();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -207,7 +207,9 @@ int32_t NVEventAppMain(int32_t argc, char** argv)
|
|||
ev = NULL;
|
||||
NVEventDoneWithEvent(false);
|
||||
break;
|
||||
case NV_EVENT_LONG_CLICK:
|
||||
|
||||
break;
|
||||
case NV_EVENT_TOUCH:
|
||||
// if (!s_glesAutopaused)
|
||||
{
|
||||
|
|
|
@ -7,11 +7,33 @@
|
|||
#include "../../../nv_event/nv_event.hpp"
|
||||
|
||||
#include "../../../../../map/country_status_display.hpp"
|
||||
|
||||
|
||||
#include "../../../../../base/logging.hpp"
|
||||
/*
|
||||
private native int addOnLongClickListener( l);
|
||||
private native void removeOnLongClickListener(int h);*/
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void CallLongClickListener(shared_ptr<jobject> obj, int x, int y)
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
jmethodID methodID = jni::GetJavaMethodID(env, *obj.get(), "onLongClick", "(II)V");
|
||||
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));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_removeOnLongClickListener(int h)
|
||||
{
|
||||
g_framework->RemoveLongClickListener(h);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_nativeOnLocationError(JNIEnv * env, jobject thiz,
|
||||
int errorCode)
|
||||
|
|
|
@ -339,10 +339,11 @@ const char* NVEventGetEventStr(NVEventType eventType)
|
|||
case NV_EVENT_STOP: return "NV_EVENT_STOP";
|
||||
case NV_EVENT_QUIT: return "NV_EVENT_QUIT";
|
||||
case NV_EVENT_USER: return "NV_EVENT_USER";
|
||||
case NV_EVENT_LONG_CLICK: return "NV_EVENT_LONG_CLICK";
|
||||
}
|
||||
|
||||
// update this if you end up having to edit something.
|
||||
CT_ASSERT(NEED_TO_ADD_STRING_HERE, NV_EVENT_NUM_EVENTS == 17);
|
||||
CT_ASSERT(NEED_TO_ADD_STRING_HERE, NV_EVENT_NUM_EVENTS == 18);
|
||||
return "unknown event type!";
|
||||
}
|
||||
|
||||
|
@ -518,6 +519,16 @@ static jboolean NVEventTouchEvent(JNIEnv* env, jobject thiz, jint action, jint
|
|||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
static jboolean NVEventLongClickEvent(JNIEnv * env, jobject thiz, jint x, jint y)
|
||||
{
|
||||
NVEvent ev;
|
||||
ev.m_type = NV_EVENT_LONG_CLICK;
|
||||
ev.m_data.m_multi.m_x1 = x;
|
||||
ev.m_data.m_multi.m_y1 = y;
|
||||
NVEventInsert(&ev);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
static jboolean NVEventMultiTouchEvent(JNIEnv* env, jobject thiz, jint action,
|
||||
jboolean hasFirst, jboolean hasSecond, jint mx1, jint my1, jint mx2, jint my2)
|
||||
{
|
||||
|
@ -616,6 +627,8 @@ static jboolean NVEventAccelerometerEvent(JNIEnv* env, jobject thiz, jfloat valu
|
|||
|
||||
static jboolean onDestroyNative(JNIEnv* env, jobject thiz);
|
||||
|
||||
|
||||
|
||||
static jboolean onCreateNative(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
if (s_globalThiz)
|
||||
|
@ -899,6 +912,11 @@ void InitNVEvent(JavaVM* vm)
|
|||
"()Z",
|
||||
(void *) onDestroyNative
|
||||
},
|
||||
{
|
||||
"onLongClickNative",
|
||||
"(II)Z",
|
||||
(void *) NVEventLongClickEvent
|
||||
},
|
||||
{
|
||||
"multiTouchEvent",
|
||||
"(IZZIIIILandroid/view/MotionEvent;)Z",
|
||||
|
|
|
@ -75,6 +75,8 @@ typedef enum NVEventType
|
|||
NV_EVENT_TOUCH,
|
||||
/** Multi-touch events */
|
||||
NV_EVENT_MULTITOUCH,
|
||||
/** Long Click Event */
|
||||
NV_EVENT_LONG_CLICK,
|
||||
/** Accelerometer events */
|
||||
NV_EVENT_ACCEL,
|
||||
/** onStart lifecycle events */
|
||||
|
|
|
@ -38,6 +38,30 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
private MWMApplication mApplication = null;
|
||||
private BroadcastReceiver m_externalStorageReceiver = null;
|
||||
private AlertDialog m_storageDisconnectedDialog = null;
|
||||
private int m_longClickHandler;
|
||||
|
||||
private interface OnLongClickListener
|
||||
{
|
||||
void onLongClick(int x, int y);
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public boolean onLongClick(View v)
|
||||
{
|
||||
v.post(new Runnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
return super.onLongClick(v);
|
||||
}*/
|
||||
|
||||
private native int addOnLongClickListener(Object l);
|
||||
private native void removeOnLongClickListener(int h);
|
||||
|
||||
private LocationService getLocationService()
|
||||
{
|
||||
|
@ -194,6 +218,18 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
nativeScale(2.0 / 3);
|
||||
}
|
||||
|
||||
public void onBookmarksClicked(View v)
|
||||
{
|
||||
if (!mApplication.isProVersion())
|
||||
{
|
||||
showProVersionBanner(getString(R.string.search_available_in_pro_version));
|
||||
}
|
||||
else
|
||||
{
|
||||
//startActivity(new Intent(this, BookmarkCategoriesActivity.class));
|
||||
}
|
||||
}
|
||||
|
||||
public void onMyPositionClicked(View v)
|
||||
{
|
||||
final LocationState state = mApplication.getLocationState();
|
||||
|
|
Loading…
Add table
Reference in a new issue