<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # TouchLongClick ~~~ package io.appium.android.bootstrap.handler; import android.os.SystemClock; import com.android.uiautomator.common.ReflectionUtils; import com.android.uiautomator.core.UiObjectNotFoundException; import io.appium.android.bootstrap.Logger; import java.lang.reflect.Method; /** * This handler is used to long click elements in the Android UI. * */ public class TouchLongClick extends TouchEvent { /* * UiAutomator has a broken longClick, so we'll try to implement it using the * touchDown / touchUp events. */ private boolean correctLongClick(final int x, final int y, final int duration) { try { /* * bridge.getClass() returns ShellUiAutomatorBridge on API 18/19 so use * the super class. */ final ReflectionUtils utils = new ReflectionUtils(); final Method touchDown = utils.getControllerMethod("touchDown", int.class, int.class); final Method touchUp = utils.getControllerMethod("touchUp", int.class, int.class); if ((Boolean) touchDown.invoke(utils.getController(), x, y)) { SystemClock.sleep(duration); if ((Boolean) touchUp.invoke(utils.getController(), x, y)) { return true; } } return false; } catch (final Exception e) { Logger.debug("Problem invoking correct long click: " + e); return false; } } @Override protected boolean executeTouchEvent() throws UiObjectNotFoundException { final Object paramDuration = params.get("duration"); int duration = 2000; // two seconds if (paramDuration != null) { duration = Integer.parseInt(paramDuration.toString()); } printEventDebugLine("TouchLongClick", duration); if (correctLongClick(clickX, clickY, duration)) { return true; } // if correctLongClick failed and we have an element // then uiautomator's longClick is used as a fallback. if (isElement) { Logger.debug("Falling back to broken longClick"); return el.longClick(); } return false; } } ~~~ TouchLongClick類繼承于TouchEvent,而TouchEvent繼承于CommandHandler.調用TouchEvent的execute的方法中,調用了executeTouchEvent方法,所以我們來看上面的executeTouchEvent就好了,執行長點擊事件,在uiautomator里有UiObject.longClick()方法,但是寫過case的人知道,有時候這個方法達不到我們的需求,但是我們是自己了反射調用TouchDown和TouchUp兩個個方法,而在appium里幫你解決了,它自己就幫你做到了這一點,如果你傳入到是控件對象,那無可厚非,還是調用UiObject.longClick方法,如果你想根據坐標,時間在點擊的話,那么就調用currectLongClick這個appium給你封裝好的方法。 ~~~ final ReflectionUtils utils = new ReflectionUtils(); final Method touchDown = utils.getControllerMethod("touchDown", int.class, int.class); final Method touchUp = utils.getControllerMethod("touchUp", int.class, int.class); ~~~ 通過反射得到uiautomator里的沒有公開的類,從而我們想要的方法touchDown和touchUp. ~~~ public ReflectionUtils() throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException { final UiDevice device = UiDevice.getInstance(); final Object bridge = enableField(device.getClass(), "mUiAutomationBridge") .get(device); if (API_18) { controller = enableField(bridge.getClass().getSuperclass(), "mInteractionController").get(bridge); } else { controller = enableField(bridge.getClass(), "mInteractionController") .get(bridge); } } ~~~ 因為uiautomator api的改動,在api18以上的版本中,mInteractionController是存在于UiAutomationBridge的父類中的變量,而在18以下的版本中它是存在于本類中的。所以反射時會有一點點小小點差異,但總的來說都是要獲得InteractionController這個類,因為這個類里面存在有我們要但touch類但方法。最后我們就能輕松調用鼠標的TouchUp和TouchDown他們啦。然后再加上時間,長按就實現啦。 # TouchUp ~~~ package io.appium.android.bootstrap.handler; import com.android.uiautomator.common.ReflectionUtils; import com.android.uiautomator.core.UiObjectNotFoundException; import io.appium.android.bootstrap.Logger; import java.lang.reflect.Method; /** * This handler is used to perform a touchDown event on an element in the * Android UI. * */ public class TouchDown extends TouchEvent { @Override protected boolean executeTouchEvent() throws UiObjectNotFoundException { printEventDebugLine("TouchDown"); try { final ReflectionUtils utils = new ReflectionUtils(); final Method touchDown = utils.getControllerMethod("touchDown", int.class, int.class); return (Boolean) touchDown.invoke(utils.getController(), clickX, clickY); } catch (final Exception e) { Logger.debug("Problem invoking touchDown: " + e); return false; } } } ~~~ 有了上面的分析,對TouchUp和TouchDown還有TouchMove的分析就不用再多說了,都是反射的原理 # TouchDown 類同 # TouchMove 類同
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看