<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之旅 廣告
                # Flick ~~~ package io.appium.android.bootstrap.handler; import com.android.uiautomator.core.UiDevice; import io.appium.android.bootstrap.*; import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException; import io.appium.android.bootstrap.utils.Point; import org.json.JSONException; import java.util.Hashtable; /** * This handler is used to flick elements in the Android UI. * * Based on the element Id, flick that element. * */ public class Flick extends CommandHandler { private Point calculateEndPoint(final Point start, final Integer xSpeed, final Integer ySpeed) { final UiDevice d = UiDevice.getInstance(); final Point end = new Point(); final double speedRatio = (double) xSpeed / ySpeed; double xOff; double yOff; final double value = Math.min(d.getDisplayHeight(), d.getDisplayWidth()); if (speedRatio < 1) { yOff = value / 4; xOff = value / 4 * speedRatio; } else { xOff = value / 4; yOff = value / 4 / speedRatio; } xOff = Integer.signum(xSpeed) * xOff; yOff = Integer.signum(ySpeed) * yOff; end.x = start.x + xOff; end.y = start.y + yOff; return end; } /* * @param command The {@link AndroidCommand} used for this handler. * * @return {@link AndroidCommandResult} * * @throws JSONException * * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android. * bootstrap.AndroidCommand) */ @Override public AndroidCommandResult execute(final AndroidCommand command) throws JSONException { Point start = new Point(0.5, 0.5); Point end = new Point(); Double steps; final Hashtable<String, Object> params = command.params(); final UiDevice d = UiDevice.getInstance(); if (command.isElementCommand()) { AndroidElement el; try { el = command.getElement(); start = el.getAbsolutePosition(start); final Integer xoffset = (Integer) params.get("xoffset"); final Integer yoffset = (Integer) params.get("yoffset"); final Integer speed = (Integer) params.get("speed"); steps = 1250.0 / speed + 1; end.x = start.x + xoffset; end.y = start.y + yoffset; } catch (final Exception e) { return getErrorResult(e.getMessage()); } } else { try { final Integer xSpeed = (Integer) params.get("xSpeed"); final Integer ySpeed = (Integer) params.get("ySpeed"); final Double speed = Math.min(1250.0, Math.sqrt(xSpeed * xSpeed + ySpeed * ySpeed)); steps = 1250.0 / speed + 1; start = getDeviceAbsPos(start); end = calculateEndPoint(start, xSpeed, ySpeed); } catch (final InvalidCoordinatesException e) { return getErrorResult(e.getMessage()); } } steps = Math.abs(steps); Logger.debug("Flicking from " + start.toString() + " to " + end.toString() + " with steps: " + steps.intValue()); final boolean res = d.swipe(start.x.intValue(), start.y.intValue(), end.x.intValue(), end.y.intValue(), steps.intValue()); if (res) { return getSuccessResult(res); } else { return getErrorResult("Flick did not complete successfully"); } } } ~~~ 代碼的步驟和swipe類似,而且最終調用的也是UiDevice.swipe方法,那么我們來看看到底區別在什么地方。首先它也分控件和坐標,分別分析: # 控件 首先將控件的中心點作為起始坐標,然后根據提供的參數xoffset和yoffset來獲取位移數據,speed參數用來計算步驟。 ~~~ steps = 1250.0 / speed + 1; end.x = start.x + xoffset; end.y = start.y + yoffset; ~~~ 起始坐標加上位移就是結束坐標,這個steps的設置還是有點讓人摸不著頭腦的,我這個1250我且認為是最大位移吧,speed代表每一步走的路程。用1250/speed得到使用多少步到結束點,再加上初始值的那個點就得到steps的值啦。至此起始點坐標、結束點坐標、步驟的值都設置完畢。 # 坐標 嚴格來說,不能說成坐標,應該算坐標位移,因為才傳入的參數其實坐標系的速度xSpeed和ySpeed。x軸移動xSpeed距離,y軸移動ySpeed坐標。然后獲取坐標值和steps值。 其中它用1250和位移的平方做了一次比較,取出最小值來計算steps。起始坐標點定位屏幕的中心點坐標。然后再調用end = calculateEndPoint(start, xSpeed, ySpeed);方法獲取結束點坐標。 ~~~ private Point calculateEndPoint(final Point start, final Integer xSpeed, final Integer ySpeed) { final UiDevice d = UiDevice.getInstance(); final Point end = new Point(); final double speedRatio = (double) xSpeed / ySpeed; double xOff; double yOff; final double value = Math.min(d.getDisplayHeight(), d.getDisplayWidth()); if (speedRatio < 1) { yOff = value / 4; xOff = value / 4 * speedRatio; } else { xOff = value / 4; yOff = value / 4 / speedRatio; } xOff = Integer.signum(xSpeed) * xOff; yOff = Integer.signum(ySpeed) * yOff; end.x = start.x + xOff; end.y = start.y + yOff; return end; } ~~~ 首先計算位移比speedRatio(x的位移/y的位移),然后獲取屏幕寬和高中最小的一個數復制給value.如果speedRatio 最后調用UiDevice.swipe和Swipe中是一樣的啦。沒什么特別的 # 總結 特別想知道1250代表的是什么。不然老覺得還沒理解這個方法的意思。哎
                  <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>

                              哎呀哎呀视频在线观看