Skip to content

Instantly share code, notes, and snippets.

@matthewmorrone
matthewmorrone / lang.groovy
Created December 2, 2020 18:39
groovy language detection
// Language detection and translation thanks to the Google language APIs
// Script inspired by Glen Smith's article:
// http://blogs.bytecode.com.au/glen/2009/07/30/getting-groovy-with-google-language-translation-apis.html
def text = URLEncoder.encode("J'ai envie de manger des fraises", "UTF-8")
def detectUrl = "http://www.google.com/uds/GlangDetect?v=1.0&q=${text}".toURL()
def langGuessResponse = jsonToGroovyMap(detectUrl.text)
def lang = langGuessResponse.responseData.language
private int longClickDuration = 3000;
private boolean isLongPress = false;
numEquipeCheat.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
isLongPress = true;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@matthewmorrone
matthewmorrone / CustomEditTextPreference.java
Last active November 10, 2020 22:20
stuff to reimplement
package com.custom.keyboard;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
// import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import top.defaults.colorpicker.ColorPickerPopup;
EditText editText = new EditText(this) {
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
final InputConnection ic = super.onCreateInputConnection(editorInfo);
EditorInfoCompat.setContentMimeTypes(editorInfo,
new String [] {"image/png"});
final InputConnectionCompat.OnCommitContentListener callback =
new InputConnectionCompat.OnCommitContentListener() {
@Override
@matthewmorrone
matthewmorrone / setOnTouchListener.java
Created October 29, 2020 07:39
attempt to prevent outside touch from dismissing
wordbar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
System.out.println(view+" "+motionEvent);
if (motionEvent.getX() < 0 || motionEvent.getX() > popupWindow.getWidth()) return true;
if (motionEvent.getY() < 0 || motionEvent.getY() > popupWindow.getHeight()) return true;
return false;
public static void makeKeyboardTransparent(InputMethodService service) {
try {
View decorView = service.getWindow().getWindow().getDecorView();
final int viewId = fetchInternalRId("fullscreenArea");
View fullscreenArea = decorView.findViewById(viewId);
if (fullscreenArea != null) {
modifyView(fullscreenArea);
return;
}
} catch (Exception e) {
float x1, x2, y1, y2, dx, dy;
String direction;
boolean isDown = false;
Keyboard.Key activeKey;
public String getDirection(MotionEvent me) {
switch(me.getAction()) {
case MotionEvent.ACTION_DOWN: {
isDown = true;
package name.boyle.chris.sgtpuzzles;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
/*
* Copyright (C) 2008-2009 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
package sra.keyboard;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager;