Code example for Instrumentation

Methods: sendKeyDownUpSyncwaitForIdleSync

0
 
    private void enterRecordingMode() { 
        if (View.INVISIBLE == mButtonRecord.getVisibility()) {
            makeFMPowerUp(); 
        } 
        mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
        mInstrumentation.waitForIdleSync();
        mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
        mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_LEFT);
        mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
        mInstrumentation.waitForIdleSync();
    } 
 
    private boolean isExistInChannelList(int station) {
        boolean find = false;
        float frequency = 0;
        int stationInList = 0;
        ListView listView = (ListView) mFMRadioFavorite.findViewById(R.id.station_list);
        assertNotNull(listView);
        for (int i = 0; i < listView.getChildCount(); i++) {
            View view = listView.getChildAt(i);
            TextView textView = (TextView) view.findViewById(R.id.lv_station_freq);
            String frequencyStr = textView.getText().toString();
            try { 
                frequency = Float.parseFloat(frequencyStr);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } 
            stationInList = (int) (frequency * CONVERT_RATE);
            if (station == stationInList) {
                return true; 
            } 
        } 
        return false; 
 
    } 
 
    private int getStationFromUI() { 
        int station = 0;
        float frequency = 0;
        mTextViewFrequency = (TextView) mFMRadioActivity.findViewById(R.id.station_value);
        String frequencyStr = mTextViewFrequency.getText().toString();
        try { 
            frequency = Float.parseFloat(frequencyStr);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } 
        station = (int) (frequency * CONVERT_RATE);
        return station;
 
    } 
 
    private void switchEarphone() { 
        if (!mButtonEarLoud.isEnabled()) {
            makeFMPowerUp(); 
        } 
        boolean isEarphoneUsed = false;
        isEarphoneUsed = getBooleanFromMethod(mFMRadioActivity, "isEarphoneUsed");
        if (!isEarphoneUsed) {
            clickView(mButtonEarLoud);
            mInstrumentation.waitForIdleSync();
        } 
    } 
 
    private void switchSpeaker() { 
        if (!mButtonEarLoud.isEnabled()) {
            makeFMPowerUp(); 
        } 
        boolean isEarphoneUsed = true;
        isEarphoneUsed = getBooleanFromMethod(mFMRadioActivity, "isEarphoneUsed");
        if (isEarphoneUsed) {
            clickView(mButtonEarLoud);
            mInstrumentation.waitForIdleSync();
        } 
 
    } 
 
    private void deleteChannelFromFavorite(int station) {
        if (FMRadioStation.isFavoriteStation(mFMRadioActivity, station)) {
            clickView(mButtonAddToFavorite);
            mInstrumentation.waitForIdleSync();
            sleep(SHORT_TIME);
        } 
    } 
 
    private void addChannelAsFavorite(int station) {
        if (!FMRadioStation.isFavoriteStation(mFMRadioActivity, station)) {
            clickView(mButtonAddToFavorite);
            mInstrumentation.waitForIdleSync();
            sleep(SHORT_TIME);
        } 
 
    } 
 
    private void makeFMPowerUp() { 
        boolean isPlaying = false;
        isPlaying = getBooleanFromVariable(mFMRadioActivity, "mbPlaying");
        if (!isPlaying) {
            clickView(mButtonPlayStop);
        } 
        mInstrumentation.waitForIdleSync();
        
    } 
 
    private void makeFMPowerDown() { 
        boolean isPlaying = true;
Contextual code suggestions in your IDE  Get Codota for Java