<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # MultiPointerGesture ~~~ package io.appium.android.bootstrap.handler; import android.view.MotionEvent.PointerCoords; import com.android.uiautomator.common.ReflectionUtils; import io.appium.android.bootstrap.*; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.lang.reflect.Method; import static io.appium.android.bootstrap.utils.API.API_18; public class MultiPointerGesture extends CommandHandler { private double computeLongestTime(final JSONArray actions) throws JSONException { double max = 0.0; for (int i = 0; i < actions.length(); i++) { final JSONArray gestures = actions.getJSONArray(i); final double endTime = gestures.getJSONObject(gestures.length() - 1) .getDouble("time"); if (endTime > max) { max = endTime; } } return max; } private PointerCoords createPointerCoords(final JSONObject obj) throws JSONException { final JSONObject o = obj.getJSONObject("touch"); final int x = o.getInt("x"); final int y = o.getInt("y"); final PointerCoords p = new PointerCoords(); p.size = 1; p.pressure = 1; p.x = x; p.y = y; return p; } @Override public AndroidCommandResult execute(final AndroidCommand command) throws JSONException { try { final PointerCoords[][] pcs = parsePointerCoords(command); if (command.isElementCommand()) { final AndroidElement el = command.getElement(); if (el.performMultiPointerGesture(pcs)) { return getSuccessResult("OK"); } else { return getErrorResult("Unable to perform multi pointer gesture"); } } else { if (API_18) { final ReflectionUtils utils = new ReflectionUtils(); final Method pmpg = utils.getControllerMethod("performMultiPointerGesture", PointerCoords[][].class); final Boolean rt = (Boolean) pmpg.invoke(utils.getController(), (Object) pcs); if (rt) { return getSuccessResult("OK"); } else { return getErrorResult("Unable to perform multi pointer gesture"); } } else { Logger.error("Device does not support API < 18!"); return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, "Cannot perform multi pointer gesture on device below API level 18"); } } } catch (final Exception e) { Logger.debug("Exception: " + e); e.printStackTrace(); return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage()); } } private PointerCoords[] gesturesToPointerCoords(final double maxTime, final JSONArray gestures) throws JSONException { // gestures, e.g.: // [ // {"touch":{"y":529.5,"x":120},"time":0.2}, // {"touch":{"y":529.5,"x":130},"time":0.4}, // {"touch":{"y":454.5,"x":140},"time":0.6}, // {"touch":{"y":304.5,"x":150},"time":0.8} // ] // From the docs: // "Steps are injected about 5 milliseconds apart, so 100 steps may take // around 0.5 seconds to complete." final int steps = (int) (maxTime * 200) + 2; final PointerCoords[] pc = new PointerCoords[steps]; int i = 1; JSONObject current = gestures.getJSONObject(0); double currentTime = current.getDouble("time"); double runningTime = 0.0; final int gesturesLength = gestures.length(); for (int j = 0; j < steps; j++) { if (runningTime > currentTime && i < gesturesLength) { current = gestures.getJSONObject(i++); currentTime = current.getDouble("time"); } pc[j] = createPointerCoords(current); runningTime += 0.005; } return pc; } private PointerCoords[][] parsePointerCoords(final AndroidCommand command) throws JSONException { final JSONArray actions = (org.json.JSONArray) command.params().get( "actions"); final double time = computeLongestTime(actions); final PointerCoords[][] pcs = new PointerCoords[actions.length()][]; for (int i = 0; i < actions.length(); i++) { final JSONArray gestures = actions.getJSONArray(i); pcs[i] = gesturesToPointerCoords(time, gestures); } return pcs; } } ~~~ 多點觸控根據你傳遞過來的參數決定,如果參數是一個控件元素,那么就要調用performMultiPointerGesture方法,如果參數是一系列的點,那么就要調用反射。那么具體來看看2個方法細節。 ## 控件 performMultiPointerGesture ~~~ public boolean performMultiPointerGesture(PointerCoords[] ...touches) { try { if (API_18) { // The compile-time SDK expects the wrong arguments, but the runtime // version in the emulator is correct. So we cannot do: // `return el.performMultiPointerGesture(touches);` // Instead we need to use Reflection to do it all at runtime. Method method = this.el.getClass().getMethod("performMultiPointerGesture", PointerCoords[][].class); Boolean rt = (Boolean)method.invoke(this.el, (Object)touches); return rt; } else { Logger.error("Device does not support API < 18!"); return false; } } catch (final Exception e) { Logger.error("Exception: " + e + " (" + e.getMessage() + ")"); return false; } } ~~~ UiObject中有直接可以調用的performMultiPointerGesture方法,為什么還要用反射呢。上面的方法里的注釋是這樣解釋的:編譯的時候sdk會認為參數是錯誤的,但是運行時卻認為是正確的,所以只有在運行時調用才能保證正確性。反射調用的就是運行時的環境,所以它使用了反射調用了performMultiPointerGesture。 ## 點組 在api18以上的版本中才有傳點組的方法可調用,所以先判斷sdk的版本。如果api在18以上,那么就要調用InteractionController..performMultiPointerGesture的方法來執行
                  <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>

                              哎呀哎呀视频在线观看