public void testcase04_DownloadingCancel() { mPreference.edit().putInt(OTA_PRE_STATUS, STATE_DOWNLOADING).commit(); mPreference.edit().putInt(OTA_PRE_DELTA_ID, PKG_ID_TEST).commit(); mActivity = getActivity(); ProgressBar dlRatioProgressBar = (ProgressBar) mActivity.findViewById(R.id.downloaingProBar); assertTrue(dlRatioProgressBar != null); assertTrue(dlRatioProgressBar.isShown()); if (Util.isSdcardAvailable(mActivity) && Util.isNetWorkAvailable(mActivity, "WIFI")) { if (mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_PAUSEDOWNLOAD) { return; } mInst.invokeMenuActionSync(mActivity, MENU_ID_CANCEL, 0); mInst.waitForIdleSync(); assertTrue(mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_PAUSEDOWNLOAD); sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT); sendKeys(KeyEvent.KEYCODE_DPAD_CENTER); mInst.waitForIdleSync(); assertTrue(mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_QUERYNEWVERSION); } }
@Override public void onDetach() { // All dialogs should be closed before leaving the activity in order to avoid // the: Activity has leaked window com.android.internal.policy... exception if (progressBar != null && progressBar.isShown()) { progressBar.setVisibility(View.GONE); } super.onDetach(); }
public void testcase03_DownloadingPaused() { mPreference.edit().putInt(OTA_PRE_STATUS, STATE_PAUSEDOWNLOAD).commit(); mPreference.edit().putInt(OTA_PRE_DELTA_ID, PKG_ID_TEST).commit(); mActivity = getActivity(); ProgressBar dlRatioProgressBar = (ProgressBar) mActivity.findViewById(R.id.downloaingProBar); assertTrue(dlRatioProgressBar != null); assertTrue(dlRatioProgressBar.isShown()); Xlog.i(TAG, "OTA_PRE_STATUS = " + mPreference.getInt(OTA_PRE_STATUS, -1)); if (Util.isSdcardAvailable(mActivity) && Util.isNetWorkAvailable(mActivity, "WIFI")) { assertTrue(mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_PAUSEDOWNLOAD); } }
/* public void waitOnThrobber() { boolean flag; do { flag = false; ArrayList<ProgressBar> bars = solo.getCurrentProgressBars(); for (ProgressBar b: bars) { if (b.isShown() && b.isIndeterminate()) { Log.d("nofatclips", "Waiting on Progress Bar #" + b.getId()); flag = true; solo.sleep(500); } } } while (flag); } */ public void waitOnThrobber() { int sleepTime = SLEEP_ON_THROBBER; if (sleepTime == 0) return; boolean flag; do { flag = false; ArrayList<ProgressBar> bars = solo.getCurrentProgressBars(); for (ProgressBar b : bars) { if (b.isShown() && b.isIndeterminate()) { Log.d("nofatclips", "Waiting on Progress Bar #" + b.getId()); flag = true; solo.sleep(500); sleepTime -= 500; } } } while (flag && (sleepTime > 0)); sync(); }
/** It handles the result of the DownloadService service. It updates the UI. */ @Override public void onReceiveResult(int resultCode, Bundle resultData) { switch (resultCode) { case 1: if (progressBar.isShown()) dismissProgressBar(); MusicBean bean = resultData.getParcelable(DownloadService.MUSIC_BEAN); // update UI with the music musicAdapter.addItem(bean); break; case 2: showProgressBar(); break; default: dismissProgressBar(); Toast.makeText(context, "Search failed", Toast.LENGTH_LONG).show(); break; } }