Android Open Source - xposed-keyboard-tweaks Long Press Replacement Method






From Project

Back to project page xposed-keyboard-tweaks.

License

The source code is released under:

Apache License

If you think the Android project xposed-keyboard-tweaks listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ca.spacek.gkdd.blacklist.gk;
/*w  w  w. j  a  va  2s . c  o  m*/
import android.content.ContentValues;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import java.util.List;

import ca.spacek.gkdd.contentprovider.DictionaryWordContentProvider;
import ca.spacek.gkdd.data.DictionaryWordTable;
import de.robv.android.xposed.XC_MethodReplacement;

public class LongPressReplacementMethod extends XC_MethodReplacement {
    private final PackageReflection packageReflection;

    public LongPressReplacementMethod(PackageReflection packageReflection) {
        this.packageReflection = packageReflection;
    }

    @Override
  protected Object replaceHookedMethod(MethodHookParam param)
      throws Throwable {
        View view = packageReflection.getOnLongClickView(param.args);
        Context context = view.getContext();
        if (context == null) {
            Log.e("blacklist", "Couldn't add word to blacklist, context was null");
            return true;
        }

        List<String> words;
        String word;
        try {
            words = packageReflection.getSuggestedWords(param.thisObject);
            int index = (Integer) view.getTag();
            word = words.remove(index);
        }
        catch (Exception e) {
            Log.e("blacklist", "Couldn't add word to blacklist", e);
            Toast.makeText(context, "Couldn't add word to blacklist", Toast.LENGTH_SHORT).show();
            return true;
        }

        ContentValues values = new ContentValues();
        values.put(DictionaryWordTable.COLUMN_WORD, word);

    context.getContentResolver().insert(DictionaryWordContentProvider.CONTENT_URI, values);

    Toast.makeText(context, "Added word to blacklist!", Toast.LENGTH_SHORT).show();

        packageReflection.updateAndSelectNewWord(param.thisObject, words);

    return true;
  }
}




Java Source Code List

ca.spacek.gkdd.BlackList.java
ca.spacek.gkdd.CachedBlackListDictionaryWordContentObserver.java
ca.spacek.gkdd.CachedBlackList.java
ca.spacek.gkdd.DictionaryWordsListActivity.java
ca.spacek.gkdd.Initialize.java
ca.spacek.gkdd.Injector.java
ca.spacek.gkdd.blacklist.AddToBlackListHook.java
ca.spacek.gkdd.blacklist.ContextChangeHook.java
ca.spacek.gkdd.blacklist.GetSuggestedWordsHook.java
ca.spacek.gkdd.blacklist.ReflectionException.java
ca.spacek.gkdd.blacklist.SuggestionBlackLister.java
ca.spacek.gkdd.blacklist.gk.ContextManager.java
ca.spacek.gkdd.blacklist.gk.CurrentGoogleKeyboardInjector.java
ca.spacek.gkdd.blacklist.gk.LongPressReplacementMethod.java
ca.spacek.gkdd.blacklist.gk.OnSuggestedWordCallbackHandler.java
ca.spacek.gkdd.blacklist.gk.OnSuggestedWordCallbackProxyFactory.java
ca.spacek.gkdd.blacklist.gk.PackageReflection.java
ca.spacek.gkdd.blacklist.gk.SuggestedWordInfoTransform.java
ca.spacek.gkdd.blacklist.gk.hook.ProfileAddToBlackListHook.java
ca.spacek.gkdd.blacklist.gk.hook.ProfileContextChangeHook.java
ca.spacek.gkdd.blacklist.gk.hook.ProfileGetSuggestedWordsHook.java
ca.spacek.gkdd.contentprovider.DictionaryWordContentProvider.java
ca.spacek.gkdd.data.DictionaryWordDatabaseHelper.java
ca.spacek.gkdd.data.DictionaryWordTable.java