public void onClick(DialogInterface dialog, int which) { alertDialog.hide(); } });
@Override public void hide() { if(alertDialog!=null) alertDialog.hide(); }
AlertDialog alertDialog = new AlertDialog.Builder(Main.this).create(); ... alertDialog.show(); int valueIamWaitingFor = 5; if (aValue == valueIamWaitingFor){ alertDialog.hide(); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mDatabaseManager.setCategory(position, selected); loadStatements(); mainDialog.hide(); }
public void run() { try { debugDataSource = debugDataSourceBridge.loadDefaultDump(); debugLoadedDump = true; DataSource.override(debugDataSource); dialog.hide(); MountPoint.reset(); makeDialog(); } catch (IOException e) { Log.d("diskusage", "Failed to enable debug", e); Toast.makeText( SelectActivity.this, "Failed to enable debug " + e.getMessage(), Toast.LENGTH_LONG).show(); } } }
public void run() { try { debugLoadedDump = false; debugDataSource = debugDataSourceBridge.initNewDump(SelectActivity.this); DataSource.override(debugDataSource); dialog.hide(); MountPoint.reset(); makeDialog(); } catch (IOException e) { Log.d("diskusage", "Failed to enable debug", e); Toast.makeText( SelectActivity.this, "Failed to enable debug " + e.getMessage(), Toast.LENGTH_LONG).show(); } } }
@Override public void run() { boolean reload = false; try { BufferedReader reader = DataSource.get().getProcReader(); String line; int checksum = 0; while ((line = reader.readLine()) != null) { checksum += line.length(); } reader.close(); if (checksum != RootMountPoint.checksum) { Log.d("diskusage", checksum + " vs " + RootMountPoint.checksum); reload = true; } } catch (Throwable t) {} if (reload) { dialog.hide(); MountPoint.reset(); makeDialog(); } handler.postDelayed(this, 2000); } };
mainDialog.hide(); break; case 2:
@Override public void run() { DataSource.override(new DefaultDataSource()); debugDataSource = null; // debugUnhidden = false; dialog.hide(); MountPoint.reset(); makeDialog(); }
@Test public void coverActivity() { /* Pause/resume should not alter dialog. */ Distribute.getInstance().onActivityPaused(mFirstActivity); Distribute.getInstance().onActivityResumed(mFirstActivity); /* Only once check, and no hiding. */ verify(mDialog).show(); verify(mDialog, never()).hide(); verify(mUnknownSourcesDialog).show(); verify(mUnknownSourcesDialog, never()).hide(); /* Cover activity. Second dialog must be replaced. First one skipped. */ Distribute.getInstance().onActivityPaused(mFirstActivity); Distribute.getInstance().onActivityResumed(mock(Activity.class)); verify(mDialog).show(); verify(mDialog, never()).hide(); verify(mUnknownSourcesDialog, times(2)).show(); verify(mUnknownSourcesDialog).hide(); }
@Test public void clickSettingsGoBackWithoutEnabling() throws Exception { /* Click settings. */ Intent intent = mock(Intent.class); whenNew(Intent.class).withArguments(Settings.ACTION_SECURITY_SETTINGS).thenReturn(intent); ArgumentCaptor<DialogInterface.OnClickListener> clickListener = ArgumentCaptor.forClass(DialogInterface.OnClickListener.class); verify(mDialogBuilder).setPositiveButton(eq(R.string.appcenter_distribute_unknown_sources_dialog_settings), clickListener.capture()); clickListener.getValue().onClick(mUnknownSourcesDialog, DialogInterface.BUTTON_POSITIVE); when(mUnknownSourcesDialog.isShowing()).thenReturn(false); /* Verify navigation. */ verify(mFirstActivity).startActivity(intent); /* Simulate we go back and forth to settings without changing the value. */ Distribute.getInstance().onActivityPaused(mFirstActivity); Distribute.getInstance().onActivityResumed(mFirstActivity); /* Second dialog will be back directly, no update dialog again. */ verify(mDialog).show(); verify(mDialog, never()).hide(); verify(mUnknownSourcesDialog, times(2)).show(); verify(mUnknownSourcesDialog, never()).hide(); }
@Test @PrepareForTest(AsyncTaskUtils.class) public void clickSettingsThenEnableThenBack() throws Exception { /* Click settings. */ Intent intent = mock(Intent.class); whenNew(Intent.class).withArguments(Settings.ACTION_SECURITY_SETTINGS).thenReturn(intent); ArgumentCaptor<DialogInterface.OnClickListener> clickListener = ArgumentCaptor.forClass(DialogInterface.OnClickListener.class); verify(mDialogBuilder).setPositiveButton(eq(R.string.appcenter_distribute_unknown_sources_dialog_settings), clickListener.capture()); clickListener.getValue().onClick(mUnknownSourcesDialog, DialogInterface.BUTTON_POSITIVE); when(mUnknownSourcesDialog.isShowing()).thenReturn(false); /* Verify navigation. */ verify(mFirstActivity).startActivity(intent); /* Simulate we go to settings, change value then go back. */ mockStatic(AsyncTaskUtils.class); Distribute.getInstance().onActivityPaused(mFirstActivity); when(InstallerUtils.isUnknownSourcesEnabled(mContext)).thenReturn(true); Distribute.getInstance().onActivityResumed(mFirstActivity); /* No more dialog, start download. */ verify(mDialog).show(); verify(mDialog, never()).hide(); verify(mUnknownSourcesDialog).show(); verify(mUnknownSourcesDialog, never()).hide(); verifyStatic(); AsyncTaskUtils.execute(anyString(), argThat(new ArgumentMatcher<AsyncTask<Object, ?, ?>>() { @Override public boolean matches(Object argument) { return argument instanceof DownloadTask; } }), anyVararg()); }
return null; }).when(mUnknownSourcesDialog).hide();
return null; }).when(mDialog).hide();
return null; }).when(mDialog).hide();