List of usage examples for android.app Dialog setContentView
public void setContentView(@NonNull View view)
From source file:com.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java
public void displayDialog(String vid) { if (getResources().getIdentifier(vid, "raw", getPackageName()) == 0) { /* TEST if RAW file doesn't exist then do nothing*/ } else {/*from w ww . j a va 2 s. c o m*/ final Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar); dialog.setContentView(R.layout.number_video_view); dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(true); mVideoView = (VideoView) dialog.findViewById(R.id.videoView); mVideoView.setZOrderMediaOverlay(true); String path = "android.resource://" + getPackageName() + "/" + //R.raw.alif; getResources().getIdentifier(vid, "raw", getPackageName()); FrameLayout fl = (FrameLayout) dialog.findViewById(R.id.VideoFrameLayout); ImageButton imageButtonClose = (ImageButton) fl.findViewById(R.id.imageButtonClose); imageButtonClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //dialog.dismiss(); if (v.getId() == R.id.imageButtonClose) { dialog.dismiss(); } } // Perform button logic }); // Set the media controller buttons if (mediaController == null) { mediaController = new MediaController(NumberViewActivity.this); // Set the videoView that acts as the anchor for the MediaController. mediaController.setAnchorView(mVideoView); // Set MediaController for VideoView mVideoView.setMediaController(mediaController); } mVideoView.setVideoURI(Uri.parse(path)); mVideoView.requestFocus(); // When the video file ready for playback. mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { public void onPrepared(MediaPlayer mediaPlayer) { mVideoView.seekTo(position); if (position == 0) { mVideoView.start(); } // When video Screen change size. mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() { @Override public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { // Re-Set the videoView that acts as the anchor for the MediaController mediaController.setAnchorView(mVideoView); } }); } }); dialog.show(); } }
From source file:com.amazonaws.cognito.sync.demo.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); Log.i(TAG, "onCreate"); /**//from w w w. j a v a 2s . co m * Initialize Facebook SDK */ FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); //Twitter if (mOauthConsumer == null) { mOauthProvider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize"); mOauthConsumer = new DefaultOAuthConsumer(getString(R.string.twitter_consumer_key), getString(R.string.twitter_consumer_secret)); } retrieveTwitterCredentials(getIntent()); //If access token is already here, set fb session final AccessToken fbAccessToken = AccessToken.getCurrentAccessToken(); if (fbAccessToken != null) { setFacebookSession(fbAccessToken); btnLoginFacebook.setVisibility(View.GONE); } /** * Initializes the sync client. This must be call before you can use it. */ CognitoSyncClientManager.init(this); btnLoginFacebook = (Button) findViewById(R.id.btnLoginFacebook); btnLoginFacebook.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // start Facebook Login LoginManager.getInstance().logInWithReadPermissions(MainActivity.this, Arrays.asList("public_profile")); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { btnLoginFacebook.setVisibility(View.GONE); new GetFbName(loginResult).execute(); setFacebookSession(loginResult.getAccessToken()); } @Override public void onCancel() { Toast.makeText(MainActivity.this, "Facebook login cancelled", Toast.LENGTH_LONG).show(); } @Override public void onError(FacebookException error) { Toast.makeText(MainActivity.this, "Error in Facebook login " + error.getMessage(), Toast.LENGTH_LONG).show(); } }); } }); btnLoginFacebook.setEnabled(getString(R.string.facebook_app_id) != "facebook_app_id"); try { mAuthManager = new AmazonAuthorizationManager(this, Bundle.EMPTY); } catch (IllegalArgumentException e) { Log.d(TAG, "Login with Amazon isn't configured correctly. " + "Thus it's disabled in this demo."); } btnLoginLWA = (Button) findViewById(R.id.btnLoginLWA); btnLoginLWA.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mAuthManager.authorize(APP_SCOPES, Bundle.EMPTY, new AuthorizeListener()); } }); btnLoginLWA.setEnabled(mAuthManager != null); Button btnWipedata = (Button) findViewById(R.id.btnWipedata); btnWipedata.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(MainActivity.this).setTitle("Wipe data?") .setMessage("This will log off your current session and wipe all user data. " + "Any data not synchronized will be lost.") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // clear login status if (fbAccessToken != null) { LoginManager.getInstance().logOut(); } btnLoginFacebook.setVisibility(View.VISIBLE); if (mAuthManager != null) { mAuthManager.clearAuthorizationState(null); } btnLoginLWA.setVisibility(View.VISIBLE); // wipe data CognitoSyncClientManager.getInstance().wipeData(); // Wipe shared preferences AmazonSharedPreferencesWrapper .wipe(PreferenceManager.getDefaultSharedPreferences(MainActivity.this)); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).show(); } }); findViewById(R.id.btnListDatasets).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, ListDatasetsActivity.class); startActivity(intent); } }); btnLoginDevAuth = (Button) findViewById(R.id.btnLoginDevAuth); if ((CognitoSyncClientManager.credentialsProvider .getIdentityProvider()) instanceof DeveloperAuthenticationProvider) { btnLoginDevAuth.setEnabled(true); Log.w(TAG, "Developer authentication feature configured correctly. "); } else { btnLoginDevAuth.setEnabled(false); Log.w(TAG, "Developer authentication feature configured incorrectly. " + "Thus it's disabled in this demo."); } btnLoginDevAuth.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // username and password dialog final Dialog login = new Dialog(MainActivity.this); login.setContentView(R.layout.login_dialog); login.setTitle("Sample developer login"); final TextView txtUsername = (TextView) login.findViewById(R.id.txtUsername); txtUsername.setHint("Username"); final TextView txtPassword = (TextView) login.findViewById(R.id.txtPassword); txtPassword.setHint("Password"); Button btnLogin = (Button) login.findViewById(R.id.btnLogin); Button btnCancel = (Button) login.findViewById(R.id.btnCancel); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { login.dismiss(); } }); btnLogin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Validate the username and password if (txtUsername.getText().toString().isEmpty() || txtPassword.getText().toString().isEmpty()) { new AlertDialog.Builder(MainActivity.this).setTitle("Login error") .setMessage("Username or password cannot be empty!!").show(); } else { // Clear the existing credentials CognitoSyncClientManager.credentialsProvider.clearCredentials(); // Initiate user authentication against the // developer backend in this case the sample Cognito // developer authentication application. ((DeveloperAuthenticationProvider) CognitoSyncClientManager.credentialsProvider .getIdentityProvider()).login(txtUsername.getText().toString(), txtPassword.getText().toString(), MainActivity.this); } login.dismiss(); } }); login.show(); } }); /** * Button that leaves the app and launches the Twitter site to get an authorization. * If the user grants permissions to our app, it will be redirected to us again through * a callback. */ Button btnLoginTwitter = (Button) findViewById(R.id.btnLoginTwitter); btnLoginTwitter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { try { String callbackUrl = "callback://" + getString(R.string.twitter_callback_url); String authUrl = mOauthProvider.retrieveRequestToken(mOauthConsumer, callbackUrl); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)); startActivity(intent); } catch (Exception e) { Log.w("oauth fail", e); } } }).start(); } }); btnLoginTwitter.setEnabled(getString(R.string.twitter_consumer_secret) != "twitter_consumer_secret"); }
From source file:com.amazon.appstream.fireclient.ConnectDialogFragment.java
/** * Create callback; performs initial set-up. *//*w ww .ja va2s . co m*/ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { mEmpty.setAlpha(0); final Dialog connectDialog = new Dialog(getActivity()); connectDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); connectDialog.setCanceledOnTouchOutside(false); connectDialog.setCancelable(false); connectDialog.setContentView(R.layout.server_address); connectDialog.getWindow().setBackgroundDrawable(mEmpty); mAddressTitle = (TextView) connectDialog.findViewById(R.id.address_title); mAddressField = (TextView) connectDialog.findViewById(R.id.address); mTextEntryFields = connectDialog.findViewById(R.id.text_entry_fields); mProgressBar = (ProgressBar) connectDialog.findViewById(R.id.progress_bar); mUseHardware = (CheckBox) connectDialog.findViewById(R.id.hardware); mUseHardware.setChecked(false); final CheckBox useAppServerBox = (CheckBox) connectDialog.findViewById(R.id.appserver); useAppServerBox.setChecked(mUseAppServer); useAppServerBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (!mUseAppServer) { mDESServerAddress = mAddressField.getText().toString(); } } else { if (mUseAppServer) { mServerAddress = mAddressField.getText().toString(); } } mUseAppServer = isChecked; updateFields(); } }); mAppIdField = (TextView) connectDialog.findViewById(R.id.appid); mSpace1 = connectDialog.findViewById(R.id.space1); mSpace2 = connectDialog.findViewById(R.id.space2); mAppIdTitle = connectDialog.findViewById(R.id.appid_title); mUserIdTitle = connectDialog.findViewById(R.id.userid_title); if (mAppId != null) { mAppIdField.setText(mAppId); } mUserIdField = (TextView) connectDialog.findViewById(R.id.userid); if (mUsername != null) { mUserIdField.setText(mUsername); } mErrorMessageField = (TextView) connectDialog.findViewById(R.id.error_message); mReconnect = connectDialog.findViewById(R.id.reconnect_fields); mReconnectMessage = (TextView) connectDialog.findViewById(R.id.reconnect_message); final Button connectButton = (Button) connectDialog.findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onConnect(); } }); TextView.OnEditorActionListener listener = new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_GO) { InputMethodManager imm = (InputMethodManager) mActivity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mUserIdField.getWindowToken(), 0); onConnect(); } return true; } }; View.OnFocusChangeListener focusListener = new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { connectButton.setFocusableInTouchMode(false); } }; mAppIdField.setOnFocusChangeListener(focusListener); mUserIdField.setOnFocusChangeListener(focusListener); mUserIdField.setOnFocusChangeListener(focusListener); mUserIdField.setOnEditorActionListener(listener); updateFields(); if (mAddressField.getText().length() == 0) { mAddressField.requestFocus(); connectButton.setFocusableInTouchMode(false); } else { connectButton.requestFocus(); } if (mReconnectMessageString != null) { reconnecting(mReconnectMessageString); mReconnectMessageString = null; } return connectDialog; }
From source file:com.gunz.carrental.Fragments.CarsFragment.java
private void addCar(final boolean isAddCar, final int position) { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.custom_dialog_car); dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false);/*w ww . j a va 2s .co m*/ TextView lblTitle = (TextView) dialog.findViewById(R.id.lblTitle); final MaterialEditText txBrand = (MaterialEditText) dialog.findViewById(R.id.txBrand); final MaterialEditText txModel = (MaterialEditText) dialog.findViewById(R.id.txModel); final MaterialEditText txLicense = (MaterialEditText) dialog.findViewById(R.id.txLicense); final MaterialEditText txFare = (MaterialEditText) dialog.findViewById(R.id.txFare); Button btnSave = (Button) dialog.findViewById(R.id.btnSave); ImageView imgClose = (ImageView) dialog.findViewById(R.id.imgClose); dialog.show(); clearErrorMsg(dialog); if (!isAddCar) { lblTitle.setText(getActivity().getResources().getString(R.string.update_car_title)); txBrand.setText(cars.get(position).brand); txModel.setText(cars.get(position).type); txLicense.setText(cars.get(position).licensePlat); txFare.setText(String.valueOf((int) cars.get(position).farePerDay)); } else { lblTitle.setText(getActivity().getResources().getString(R.string.add_new_car_title)); } btnSave.setOnClickListener(new OnOneClickListener() { @Override public void onOneClick(View v) { if (TextUtils.isEmpty(txBrand.getText().toString().trim())) { txBrand.setText(""); txBrand.setError(getActivity().getResources().getString(R.string.validation_required)); txBrand.requestFocus(); } else if (TextUtils.isEmpty(txModel.getText().toString().trim())) { txModel.setText(""); txModel.setError(getActivity().getResources().getString(R.string.validation_required)); txModel.requestFocus(); } else if (TextUtils.isEmpty(txLicense.getText().toString().trim())) { txLicense.setText(""); txLicense.setError(getActivity().getResources().getString(R.string.validation_required)); txLicense.requestFocus(); } else if (TextUtils.isEmpty(txFare.getText().toString().trim())) { txFare.setText(""); txFare.setError(getActivity().getResources().getString(R.string.validation_required)); txFare.requestFocus(); } else { String confirmText; if (isAddCar) { confirmText = getActivity().getResources().getString(R.string.dialog_add_car_question); } else { confirmText = getActivity().getResources().getString(R.string.dialog_update_car_question); } new SweetAlertDialog(getActivity(), SweetAlertDialog.NORMAL_TYPE) .setTitleText(getActivity().getResources().getString(R.string.dialog_confirmation)) .setContentText(confirmText) .setCancelText(getActivity().getResources().getString(R.string.btn_cancel)) .setConfirmText(getActivity().getResources().getString(R.string.btn_save)) .showCancelButton(true) .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sweetAlertDialog) { if (isAddCar) { saveNewCar(dialog, txBrand.getText().toString().trim(), txModel.getText().toString().trim(), Integer.parseInt(txFare.getText().toString().trim()), txLicense.getText().toString().trim()); } else { updateCar(dialog, cars.get(position).id, txBrand.getText().toString().trim(), txModel.getText().toString().trim(), Integer.parseInt(txFare.getText().toString().trim()), txLicense.getText().toString().trim()); } sweetAlertDialog.dismiss(); } }).show(); } } }); imgClose.setOnClickListener(new OnOneClickListener() { @Override public void onOneClick(View v) { Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { dialog.dismiss(); } @Override public void onAnimationRepeat(Animation animation) { } }); v.startAnimation(animation); } }); }
From source file:com.slownet5.pgprootexplorer.filemanager.ui.FileManagerActivity.java
private void showBackupDialog() { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.password_dialog_layout); Button button = (Button) dialog.findViewById(R.id.decrypt_file_button); button.setText("Backup"); ((TextInputLayout) dialog.findViewById(R.id.key_password_layout)).setHint("Application password"); button.setOnClickListener(new View.OnClickListener() { @Override// w w w.j a v a 2 s. c o m public void onClick(View view) { String pass = ((EditText) dialog.findViewById(R.id.key_password)).getText().toString(); if (pass.length() < 1) { Toast.makeText(FileManagerActivity.this, "Please input application password", Toast.LENGTH_LONG) .show(); return; } new BackupKeysTask().execute(pass); dialog.dismiss(); } }); dialog.findViewById(R.id.cancel_decrypt_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); dialog.show(); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to allow user to select which row to add the shortcut. For * TV channels let the user change the channel name. * //from w ww . j a va 2 s .c o m * @see InstallShortcutReceiver * * @param context * @param name * @param icon * @param uri */ public static void displayShortcutsRowSelection(final Launcher context, final String name, final String icon, final String uri) { if (uri == null) { return; } final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); final boolean isChannel = uri.startsWith("tv"); dialog.setContentView(R.layout.select_row); final TextView channelTextView = (TextView) dialog.findViewById(R.id.channelText); final EditText channelNameEditText = (EditText) dialog.findViewById(R.id.channelName); if (isChannel) { channelTextView.setVisibility(View.VISIBLE); channelNameEditText.setVisibility(View.VISIBLE); channelNameEditText.setText(name); } final TextView selectTextView = (TextView) dialog.findViewById(R.id.selectText); selectTextView.setText(context.getString(R.string.dialog_select_row, name)); final Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); spinner.setVisibility(View.GONE); } }); List<String> list = new ArrayList<String>(); final ArrayList<RowInfo> rows = RowsTable.getRows(context); if (rows != null) { for (RowInfo row : rows) { list.add(row.getTitle()); } } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, R.layout.simple_spinner_item, list); dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); Button buttonYes = (Button) dialog.findViewById(R.id.buttonOk); buttonYes.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String shortcutName = name; try { if (isChannel) { String channelName = channelNameEditText.getText().toString().trim(); if (channelName.length() == 0) { channelNameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_channel_name_alert)); return; } shortcutName = channelName; } // if the new row radio button is selected, the user must // enter a name for the new row String rowName = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && rowName.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); int rowId = 0; int rowPosition = 0; if (currentRow) { if (rows != null) { String selectedRow = (String) spinner.getSelectedItem(); for (RowInfo row : rows) { if (row.getTitle().equals(selectedRow)) { rowId = row.getId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row break; } } } } else { rowId = (int) RowsTable.insertRow(context, rowName, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); ItemsTable.insertItem(context, rowId, rowPosition, shortcutName, intent, icon, DatabaseHelper.SHORTCUT_TYPE); Toast.makeText(context, context.getString(R.string.shortcut_installed, shortcutName), Toast.LENGTH_SHORT).show(); context.reloadAllGalleries(); if (currentRow) { Analytics.logEvent(Analytics.ADD_SHORTCUT); } else { Analytics.logEvent(Analytics.ADD_SHORTCUT_WITH_ROW); } } catch (Exception e) { Log.d(LOG_TAG, "onClick", e); } context.showCover(false); dialog.dismiss(); } }); Button buttonNo = (Button) dialog.findViewById(R.id.buttonCancel); buttonNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_SHORTCUT); }
From source file:org.videolan.vlc.gui.MainActivity.java
private void showInfoDialog() { final Dialog infoDialog = new Dialog(this, R.style.info_dialog); infoDialog.setContentView(R.layout.info_dialog); Button okButton = (Button) infoDialog.findViewById(R.id.ok); okButton.setOnClickListener(new OnClickListener() { @Override//from w w w.ja v a 2s . c o m public void onClick(View view) { CheckBox notShowAgain = (CheckBox) infoDialog.findViewById(R.id.not_show_again); if (notShowAgain.isChecked() && mSettings != null) { Editor editor = mSettings.edit(); editor.putInt(PREF_SHOW_INFO, mVersionNumber); editor.commit(); } /* Close the dialog */ infoDialog.dismiss(); /* and finally open the sliding menu if first run */ if (mFirstRun) mMenu.showMenu(); } }); infoDialog.show(); }
From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { setCancelable(isCancelable);// w w w . j a v a2 s . com if (TextUtils.isEmpty(positiveText)) { positiveText = "OK"; Log.d("CHECK", "" + com.commonsdroid.fragmentdialog.R.string.ok); } if (TextUtils.isEmpty(negativeText)) { negativeText = "Cancel"; } switch (type) { case DIALOG_TYPE_OK: /*show dialog with positive button*/ return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(positiveText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onPositiveButtonClick(identifier); } }).create(); case DIALOG_TYPE_YES_NO: /*show dialog with positive and negative button*/ return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(positiveText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onPositiveButtonClick(identifier); } }).setNegativeButton(negativeText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onNegativeButtonClick(identifier); } }).create(); case DATE_DIALOG: /*show date picker dialog*/ return new DatePickerDialog(getActivity(), AlertFragmentDialog.this, sYear, sMonth, sDate); case TIME_DIALOG: /*show time picker dialog*/ return new TimePickerDialog(getActivity(), AlertFragmentDialog.this, sHour, sMinute, true); case SIMPLE_LIST_DIALOG: /** * show simple list dialog */ return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_item).create(); case SINGLE_CHOICE_LIST_DIALOG: /*show single choice list dialog*/ return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_singlechoice).create(); case MULTI_CHOICE_LIST_DIALOG: /*show multichoice list dialog*/ Dialog multipleChoice = new Dialog(getActivity()); multipleChoice.setContentView(R.layout.list_multichoice); multipleChoice.setTitle(title); ListView listView = (ListView) multipleChoice.findViewById(R.id.lstMultichoiceList); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Manage selected items here CheckedTextView textView = (CheckedTextView) view; if (textView.isChecked()) { } else { } Log.e("CHECK", "clicked pos : " + position + " checked : " + textView.isChecked()); } }); final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_multichoice, dialogList); listView.setAdapter(arraySingleChoiceAdapter); multipleChoice.show(); /*multipleChoice.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); multipleChoice.setPositiveButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } });*/ /* multipleChoice.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (alSelectedItem.size() != 0) { sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } } });*/ // multipleChoice.create(); // singleChoiceListDialog.setCancelable(false); /* multipleChoice.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { alSelectedItem.add(items[which]); } else { alSelectedItem.remove(items[which]); } } }); multipleChoice.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); multipleChoice.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (alSelectedItem.size() != 0) { sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } } });*/ return multipleChoice;//.create(); } return null; }
From source file:cs.umass.edu.prepare.view.activities.CalendarActivity.java
/** * Allows the user to set time for adherence data where the time is unknown. * @param medication the medication for which the adherence is being modified. * @param index the index of the adherence being modified, i.e. AM or PM. */// w ww . j a va 2s .co m private void setTimeTaken(final Medication medication, final Calendar dateKey, final int index) { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_set_time); final TimePicker timePicker = (TimePicker) dialog.findViewById(R.id.time_picker); Button cancelButton = (Button) dialog.findViewById(R.id.btn_time_cancel); cancelButton.setOnClickListener(v -> dialog.dismiss()); Button saveButton = (Button) dialog.findViewById(R.id.btn_time_save); saveButton.setOnClickListener(v -> { Calendar time = Utils.getTimeNoInterval(timePicker); // TODO: Store times taken Map<Medication, Adherence[]> dailyAdherence = adherenceData.get(dateKey); Adherence[] adherence = dailyAdherence.get(medication); adherence[index].setTimeTaken(time); Calendar[] schedule = dailySchedule.get(medication); Calendar timeToTake = (Calendar) time.clone(); timeToTake.set(Calendar.HOUR_OF_DAY, schedule[index].get(Calendar.HOUR_OF_DAY)); timeToTake.set(Calendar.MINUTE, schedule[index].get(Calendar.MINUTE)); Calendar upperBound = (Calendar) timeToTake.clone(); upperBound.add(Calendar.HOUR_OF_DAY, 1); Calendar lowerBound = (Calendar) timeToTake.clone(); lowerBound.add(Calendar.HOUR_OF_DAY, -1); if (time.after(upperBound) || time.before(lowerBound)) { adherence[index].setAdherenceType(Adherence.AdherenceType.TAKEN_EARLY_OR_LATE); } else { adherence[index].setAdherenceType(Adherence.AdherenceType.TAKEN); } dialog.dismiss(); refresh(); DataIO preferences = DataIO.getInstance(CalendarActivity.this); preferences.setAdherenceData(this, adherenceData); }); dialog.show(); }
From source file:fr.cph.chicago.activity.MainActivity.java
private void displayUpdatePanel() { try {//ww w . ja va2 s .co m String versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); String versionNamePreferences = sharedPref.getString("version.name", null); if (versionNamePreferences == null || !versionNamePreferences.equals(versionName)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putString("version.name", versionName); editor.commit(); final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.update); dialog.setTitle("Update"); InputStreamReader is = new InputStreamReader( ChicagoTracker.getAppContext().getAssets().open("update.txt")); BufferedReader br = new BufferedReader(is); String read = br.readLine(); StringBuilder sb = new StringBuilder(); while (read != null) { sb.append(read + "\n"); read = br.readLine(); } TextView text = (TextView) dialog.findViewById(R.id.updateText); text.setText(sb.toString()); Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int newWidth = width - (width * 20 / 100); int height = size.y; int newHeight = height - (height * 20 / 100); dialog.getWindow().setLayout(newWidth, newHeight); dialog.show(); } } catch (NameNotFoundException e) { Log.w(TAG, e.getMessage(), e); } catch (IOException e) { Log.w(TAG, e.getMessage(), e); } }