Skip to content

Commit 3156cef

Browse files
committed
- improve android handling of long press paste
1 parent 1cb7cd4 commit 3156cef

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

core/pen/source/android/os.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,4 +857,14 @@ namespace pen
857857
}
858858
}
859859

860+
bool os_tapped()
861+
{
862+
auto env = get_jni_env();
863+
if(env)
864+
{
865+
jmethodID method = env->GetMethodID(s_android_context.m_activity_class, "wasTapped", "()Z");
866+
return env->CallBooleanMethod(s_android_context.m_activity_object, method);
867+
}
868+
}
869+
860870
} // namespace pen

core/template/android/activity/pen_activity.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import android.content.SharedPreferences;
1616
import android.content.res.AssetManager;
1717
import android.content.ClipboardManager;
18-
import android.content.ClipData;
18+
1919

2020
import android.graphics.Canvas;
2121

@@ -30,6 +30,7 @@
3030
import android.view.inputmethod.EditorInfo;
3131
import android.view.MenuItem;
3232
import android.view.ViewGroup;
33+
import android.view.GestureDetector;
3334

3435
import androidx.security.crypto.EncryptedSharedPreferences;
3536
import androidx.security.crypto.MasterKey;
@@ -168,6 +169,7 @@ public class pen_activity extends Activity {
168169
private SharedPreferences m_sharedPrefs;
169170
private boolean m_canUseSharedPrefs;
170171

172+
public boolean tapped = false;
171173
public String clipboard_string = "";
172174
public boolean paste_enabled = false;
173175
final float[] lastTouch = new float[2];
@@ -261,6 +263,7 @@ protected void onCreate(Bundle arg0) {
261263
getWindow().setDecorFitsSystemWindows(false);
262264
getWindow().setStatusBarColor(android.graphics.Color.TRANSPARENT);
263265
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
266+
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
264267

265268
init(this);
266269
FMOD.init(this);
@@ -277,20 +280,34 @@ protected void onCreate(Bundle arg0) {
277280
// paste menu on long click
278281
m_surfaceView.setLongClickable(true);
279282

283+
GestureDetector gestureDetector = new GestureDetector(m_context,
284+
new GestureDetector.SimpleOnGestureListener() {
285+
@Override
286+
public boolean onSingleTapConfirmed(MotionEvent e) {
287+
tapped = true;
288+
return true;
289+
}
290+
}
291+
);
292+
280293
m_surfaceView.setOnTouchListener(new View.OnTouchListener() {
281294
@Override
282295
public boolean onTouch(View v, MotionEvent event) {
283296
if (event.getAction() == MotionEvent.ACTION_DOWN) {
284297
lastTouch[0] = event.getX();
285298
lastTouch[1] = event.getY();
286299
}
300+
gestureDetector.onTouchEvent(event);
287301
return false; // IMPORTANT: do not block long-press detection
288302
}
289303
});
290304

291305
m_surfaceView.setOnLongClickListener(new View.OnLongClickListener() {
292306
@Override
293307
public boolean onLongClick(View v) {
308+
if(!paste_enabled)
309+
return false;
310+
294311
showPastePopup(v, (int)lastTouch[0], (int)lastTouch[1]);
295312
return true;
296313
}
@@ -315,7 +332,7 @@ protected void onResume() {
315332
@Override
316333
protected void onPause() {
317334
super.onPause();
318-
335+
319336
// kill the process when app is backgrounded
320337
android.os.Process.killProcess(android.os.Process.myPid());
321338
System.exit(0);
@@ -399,7 +416,7 @@ public static void createDirectory(String strdir)
399416
{
400417
File dir = new File(strdir);
401418
if (!dir.exists()) {
402-
dir.mkdirs();
419+
dir.mkdirs();
403420
}
404421
}
405422

@@ -459,4 +476,11 @@ void clearClipboardString()
459476
{
460477
clipboard_string = "";
461478
}
479+
480+
boolean wasTapped()
481+
{
482+
boolean res = tapped;
483+
tapped = false;
484+
return res;
485+
}
462486
}

0 commit comments

Comments
 (0)