Example usage for android.app Instrumentation sendKeyDownUpSync

List of usage examples for android.app Instrumentation sendKeyDownUpSync

Introduction

In this page you can find the example usage for android.app Instrumentation sendKeyDownUpSync.

Prototype

public void sendKeyDownUpSync(int key) 

Source Link

Document

Sends an up and down key event sync to the currently focused window.

Usage

From source file:Main.java

public static void volumeAdd() {
    new Thread(new Runnable() {
        @Override//from w  ww.  j  a  v  a 2s  .  com
        public void run() {
            Instrumentation m_Instrumentation = new Instrumentation();
            m_Instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_UP);
        }
    }).start();
}

From source file:Main.java

/**
 * this function work by permission./*from   ww w  . j a v  a  2  s.c o m*/
 */
public static void pressHome() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Instrumentation m_Instrumentation = new Instrumentation();
            m_Instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_HOME);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            m_Instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_HOME);
        }
    }).start();

}

From source file:com.king.base.util.SystemUtils.java

/**
 * ??//from  w  w w. j  ava2 s  .c  om
 * @param keyCode
 */
public static void sendKeyCode(final int keyCode) {
    asyncThread(new Runnable() {
        @Override
        public void run() {
            try {
                Instrumentation inst = new Instrumentation();
                inst.sendKeyDownUpSync(keyCode);
            } catch (Exception e) {
                LogUtils.e("Exception when sendPointerSync", e);
            }
        }
    });
}

From source file:com.waz.zclient.pages.extendedcursor.emoji.EmojiKeyboardLayout.java

private void init() {
    currentEmojiSize = EmojiSize.MEDIUM;
    categoryPositions = new int[CATEGORY_COUNT];

    emojiAdapter = new EmojiAdapter(getContext());

    layoutManager = new GridLayoutManager(getContext(), SPAN_COUNT, LinearLayoutManager.HORIZONTAL, false);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override/*from w  ww.j a  v a  2  s .  c o  m*/
        public int getSpanSize(int position) {
            return spaces.contains(position) ? SPAN_COUNT : 1;
        }
    });
    layoutManager.setSpanCount(SPAN_COUNT);

    recyclerView.addOnScrollListener(new EmojiScrollListener());

    tapIndicatorLayout.setShowDivider(false);
    tapIndicatorLayout.setGlyphLabels(Emojis.EMOJI_KEYBOARD_TAB_LABELS);
    tapIndicatorLayout.setTextColor(ContextCompat.getColorStateList(getContext(),
            com.waz.zclient.ui.R.color.wire__text_color_dark_selector));
    tapIndicatorLayout.setPrimaryColor(
            ContextCompat.getColor(getContext(), com.waz.zclient.ui.R.color.text__primary_dark));
    tapIndicatorLayout.setLabelHeight(getContext().getResources()
            .getDimensionPixelSize(com.waz.zclient.ui.R.dimen.sketch__emoji__keyboard__tab_label_size));
    tapIndicatorLayout.setCallback(new TabIndicatorLayout.Callback() {
        @Override
        public void onItemSelected(int pos) {
            if (pos == TAB_COUNT - 1) {
                Threading.Background().execute(new Runnable() {
                    @Override
                    public void run() {
                        Instrumentation inst = new Instrumentation();
                        inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DEL);
                    }
                });
            } else {
                tapIndicatorLayout.setSelected(pos);
                layoutManager.scrollToPositionWithOffset(getCategoryByTabPosition(pos), 0);
            }
        }
    });

    recyclerView.setAdapter(emojiAdapter);
    recyclerView.setLayoutManager(layoutManager);
    setRecyclerViewPadding(recyclerView);

    emojiAdapter.setOnEmojiClickListener(new EmojiAdapter.OnEmojiClickListener() {
        @Override
        public void onEmojiClick(String emoji, EmojiSize emojiSize) {
            if (callback != null) {
                callback.onEmojiSelected(emoji);
            }
        }
    });
}

From source file:love.juhe.androidmonkey.MonkeyKeyEvent.java

@Override
public int fireEvent(Instrumentation testRuner) {
    String note;//  w  w  w  .  j av a  2s. c  om
    if (mAction == KeyEvent.ACTION_UP) {
        note = "ACTION_UP";
    } else {
        note = "ACTION_DOWN";
    }

    MonkeyLog.l(":Typing Key (" + note + "): " + mKeyCode + "    // ");
    try {
        //         testRuner.sendKeySync(getEvent());
        testRuner.sendKeyDownUpSync(mKeyCode);
    } catch (Exception e) {
        MonkeyLog.l("Failed to send key (" + note + "): " + mKeyCode + "    // ");
        return MonkeyEvent.INJECT_FAIL;
    }

    return MonkeyEvent.INJECT_SUCCESS;
}

From source file:com.codegarden.nativenavigation.JuceActivity.java

public final void setScreenSaver(boolean enabled) {
    if (isScreenSaverEnabled != enabled) {
        isScreenSaverEnabled = enabled;/*from   w w w .  j a v  a  2 s  .  c  o m*/

        if (keepAliveTimer != null) {
            keepAliveTimer.cancel();
            keepAliveTimer = null;
        }

        if (enabled) {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        } else {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

            // If no user input is received after about 3 seconds, the OS will lower the
            // task's priority, so this timer forces it to be kept active.
            keepAliveTimer = new java.util.Timer();

            keepAliveTimer.scheduleAtFixedRate(new TimerTask() {
                @Override
                public void run() {
                    android.app.Instrumentation instrumentation = new android.app.Instrumentation();

                    try {
                        instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_UNKNOWN);
                    } catch (Exception e) {
                    }
                }
            }, 2000, 2000);
        }
    }
}

From source file:org.catrobat.catroid.uitest.util.UiTestUtils.java

/**
 * Returns to the main screen./*from ww w  .  j a v  a  2 s .c o  m*/
 * This method should be called in tearDown() in tests which use Robotium.
 * See explanation here:
 * http://stackoverflow.com/questions/7851351/robotium-in-the-suite-of-tests-each-next-test-is-
 * affected-by-the-previous-test
 */
public static void goBackToHome(Instrumentation instrumentation) {
    boolean more = true;
    while (more) {
        try {
            instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
            instrumentation.waitForIdleSync();
        } catch (SecurityException e) { // Done, at Home.
            more = false;
        }
    }
}

From source file:com.juce.JuceAppActivity.java

public final void setScreenSaver (boolean enabled)
{
    if (isScreenSaverEnabled != enabled)
    {//  w ww. j a  v  a 2  s.  c  om
        isScreenSaverEnabled = enabled;

        if (keepAliveTimer != null)
        {
            keepAliveTimer.cancel();
            keepAliveTimer = null;
        }

        if (enabled)
        {
            getWindow().clearFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
        else
        {
            getWindow().addFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

            // If no user input is received after about 3 seconds, the OS will lower the
            // task's priority, so this timer forces it to be kept active.
            keepAliveTimer = new java.util.Timer();

            keepAliveTimer.scheduleAtFixedRate (new TimerTask()
            {
                @Override
                public void run()
                {
                    android.app.Instrumentation instrumentation = new android.app.Instrumentation();

                    try
                    {
                        instrumentation.sendKeyDownUpSync (KeyEvent.KEYCODE_UNKNOWN);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }, 2000, 2000);
        }
    }
}