public static void showCopy(final Context c) { final CurInput ci = new CurInput(); if (!ci.init(ServiceJbKbd.inst.getCurrentInputConnection())) return; final ComMenu menu = new ComMenu(); menu.add(R.string.menu_copy_all, R.string.menu_copy_all); if (ci.hasCurLine) menu.add(R.string.menu_copy_paragraph, R.string.menu_copy_paragraph); String word = ci.getWordText(); if (!TextUtils.isEmpty(word)) menu.add(R.string.menu_copy_word, R.string.menu_copy_word); menu.show( new st.UniObserver() { @Override public int OnObserver(Object param1, Object param2) { ClipboardManager cm = (ClipboardManager) c.getSystemService(Service.CLIPBOARD_SERVICE); switch ((Integer) param1) { case R.string.menu_copy_all: ServiceJbKbd.inst.processTextEditKey(st.TXT_ED_COPY_ALL); break; case R.string.menu_copy_word: cm.setText(ci.getWordText()); break; case R.string.menu_copy_paragraph: cm.setText(ci.getLineText()); break; } return 0; } }); }
/** Функция создаёт меню для мультибуфера обмена */ public static boolean showClipboard() { Cursor c = st.stor().getClipboardCursor(); if (c == null) return false; final ComMenu menu = new ComMenu(); menu.m_state = STAT_CLIPBOARD; int pos = 0; do { String s = c.getString(0); s = s.trim(); if (s.length() > 50) s = s.substring(0, 50) + "..."; s.replace('\n', ' '); menu.add(s, pos); ++pos; } while (c.moveToPrevious()); c.close(); st.UniObserver obs = new st.UniObserver() { @Override public int OnObserver(Object param1, Object param2) { int id = ((Integer) param1).intValue(); int pos = -1; for (int i = menu.m_arItems.size() - 1; i >= 0; i--) { if (menu.m_arItems.get(i).id == id) { pos = i; break; } } if (pos < 0) return 0; if (((Boolean) param2).booleanValue()) { Intent in = new Intent(ServiceJbKbd.inst, TplEditorActivity.class) .putExtra(TplEditorActivity.EXTRA_CLIPBOARD_ENTRY, pos) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ServiceJbKbd.inst.startActivity(in); return 0; } Cursor c = st.stor().getClipboardCursor(); if (c == null) return 0; try { c.move(0 - id); String cp = c.getString(0); ServiceJbKbd.inst.onText(cp); if (ClipbrdService.inst != null) ClipbrdService.inst.checkString(cp); } catch (Throwable e) { } return 0; } }; menu.show(obs); return true; }
public static void showLangs(Context с) { final String lang[] = st.getLangsArray(с); final ComMenu menu = new ComMenu(); for (int i = 0; i < lang.length; i++) { menu.add(Lang.getLangDisplayName(lang[i]), i); } menu.show( new st.UniObserver() { @Override public int OnObserver(Object param1, Object param2) { st.kv().setLang(lang[(Integer) param1]); return 0; } }); }
@Override public View getView(int position, View convertView, ViewGroup parent) { MenuEntry me = m_menu.m_arItems.get(position); if (convertView != null) { Button b = (Button) convertView; b.setTag(me); b.setId(me.id); b.setText(me.text); } else { convertView = m_menu.newView(me); } return convertView; }