List of usage examples for android.app Dialog Dialog
public Dialog(@NonNull Context context)
From source file:de.j4velin.mapsmeasure.Dialogs.java
/** * @param m the Map/* w ww . ja v a 2s . c o m*/ * @param distance the current distance * @param area the current area * @return the units dialog */ public static Dialog getUnits(final Map m, float distance, double area) { final Dialog d = new Dialog(m); d.requestWindowFeature(Window.FEATURE_NO_TITLE); d.setContentView(R.layout.dialog_unit); CheckBox metricCb = (CheckBox) d.findViewById(R.id.metric); metricCb.setChecked(m.metric); metricCb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { m.metric = !m.metric; m.getSharedPreferences("settings", Context.MODE_PRIVATE).edit().putBoolean("metric", isChecked) .commit(); m.updateValueText(); } }); ((TextView) d.findViewById(R.id.distance)).setText(Map.formatter_two_dec.format(Math.max(0, distance)) + " m\n" + Map.formatter_two_dec.format(distance / 1000) + " km\n\n" + Map.formatter_two_dec.format(Math.max(0, distance / 0.3048f)) + " ft\n" + Map.formatter_two_dec.format(Math.max(0, distance / 0.9144)) + " yd\n" + Map.formatter_two_dec.format(distance / 1609.344f) + " mi\n" + Map.formatter_two_dec.format(distance / 1852f) + " nautical miles"); ((TextView) d.findViewById(R.id.area)).setText(Map.formatter_two_dec.format(Math.max(0, area)) + " m\n" + Map.formatter_two_dec.format(area / 10000) + " ha\n" + Map.formatter_two_dec.format(area / 1000000) + " km\n\n" + Map.formatter_two_dec.format(Math.max(0, area / 0.09290304d)) + " ft\n" + Map.formatter_two_dec.format(area / 4046.8726099d) + " ac (U.S. Survey)\n" + Map.formatter_two_dec.format(area / 2589988.110336d) + " mi"); d.findViewById(R.id.close).setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { d.dismiss(); } }); return d; }
From source file:com.vk.sdk.dialogs.VKShareDialog.java
@NonNull @Override//from w w w.ja va 2 s . c o m public Dialog onCreateDialog(Bundle savedInstanceState) { Context context = getActivity(); View mInternalView = LayoutInflater.from(context).inflate(R.layout.vk_share_dialog, null); assert mInternalView != null; mSendButton = (Button) mInternalView.findViewById(R.id.sendButton); mSendProgress = (ProgressBar) mInternalView.findViewById(R.id.sendProgress); mPhotoLayout = (LinearLayout) mInternalView.findViewById(R.id.imagesContainer); mShareTextField = (EditText) mInternalView.findViewById(R.id.shareText); mPhotoScroll = (HorizontalScrollView) mInternalView.findViewById(R.id.imagesScrollView); LinearLayout mAttachmentLinkLayout = (LinearLayout) mInternalView.findViewById(R.id.attachmentLinkLayout); mSendButton.setOnClickListener(sendButtonPress); //Attachment text if (savedInstanceState != null) { mShareTextField.setText(savedInstanceState.getString(SHARE_TEXT_KEY)); mAttachmentLink = savedInstanceState.getParcelable(SHARE_LINK_KEY); mAttachmentImages = (VKUploadImage[]) savedInstanceState.getParcelableArray(SHARE_IMAGES_KEY); mExistingPhotos = savedInstanceState.getParcelable(SHARE_UPLOADED_IMAGES_KEY); } else if (mAttachmentText != null) { mShareTextField.setText(mAttachmentText); } //Attachment photos mPhotoLayout.removeAllViews(); if (mAttachmentImages != null) { for (VKUploadImage mAttachmentImage : mAttachmentImages) { addBitmapToPreview(mAttachmentImage.mImageData); } mPhotoLayout.setVisibility(View.VISIBLE); } if (mExistingPhotos != null) { processExistingPhotos(); } if (mExistingPhotos == null && mAttachmentImages == null) { mPhotoLayout.setVisibility(View.GONE); } //Attachment link if (mAttachmentLink != null) { TextView linkTitle = (TextView) mAttachmentLinkLayout.findViewById(R.id.linkTitle), linkHost = (TextView) mAttachmentLinkLayout.findViewById(R.id.linkHost); linkTitle.setText(mAttachmentLink.linkTitle); linkHost.setText(VKUtil.getHost(mAttachmentLink.linkUrl)); mAttachmentLinkLayout.setVisibility(View.VISIBLE); } else { mAttachmentLinkLayout.setVisibility(View.GONE); } Dialog result = new Dialog(context); result.requestWindowFeature(Window.FEATURE_NO_TITLE); result.setContentView(mInternalView); result.setCancelable(true); result.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { if (mListener != null) { mListener.onVkShareCancel(); } VKShareDialog.this.dismiss(); } }); return result; }
From source file:com.example.gemswin.screencastrecevertest.MainActivity_Reciever.java
protected void DoubtBox () { // TODO Auto-generated method stub dialogDoubt = new Dialog(MainActivity_Reciever.this); dialogDoubt.requestWindowFeature(Window.FEATURE_NO_TITLE); dialogDoubt.setContentView(R.layout.activity_doubt_reciever); // name1 = (EditText)dialogDoubt.findViewById(R.id.name_reg1); class1 = (EditText)dialogDoubt.findViewById(R.id.class_reg1); doubt1 = (EditText)dialogDoubt.findViewById(R.id.doubt_reg1); submit1 = (Button) dialogDoubt.findViewById(R.id.doubtsubmit); submit1.setOnClickListener(new View.OnClickListener() { @Override/* w w w .j a v a2s.c o m*/ public void onClick(View v) { doubtstring = doubt1.getText().toString(); //username //password = pass.getText().toString(); // nameString = name1.getText().toString(); classget = class1.getText().toString(); new login().execute(); dialogDoubt.dismiss(); } }); dialogDoubt.show(); }
From source file:com.PPRZonDroid.MainActivity.java
/** * Bound UI items//from ww w. ja v a 2 s .c o m */ private void set_up_app() { //if ( Debug.isDebuggerConnected() ) DEBUG= true; //else DEBUG=false; //Get app settings AppSettings = PreferenceManager.getDefaultSharedPreferences(this); AppSettings.registerOnSharedPreferenceChangeListener(this); AppPassword = (AppSettings.getString("app_password", "")); DisableScreenDim = AppSettings.getBoolean("disable_screen_dim", true); /* Setup waypoint dialog */ WpDialog = new Dialog(this); WpDialog.setContentView(R.layout.wp_modified); DialogTextWpName = (TextView) WpDialog.findViewById(R.id.textViewWpName); DialogButtonConfirm = (Button) WpDialog.findViewById(R.id.buttonConfirm); DialogWpAltitude = (EditText) WpDialog.findViewById(R.id.editTextAltitude); DialogTextWpLat = (TextView) WpDialog.findViewById(R.id.textViewLatitude); DialogTextWpLon = (TextView) WpDialog.findViewById(R.id.textViewLongitude); DialogAltUp = (Button) WpDialog.findViewById(R.id.buttonplust); DialogAltDown = (Button) WpDialog.findViewById(R.id.buttonmint); DialogAltDown.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Double alt = parseDouble(DialogWpAltitude.getText().toString()) - 10; DialogWpAltitude.setText(alt.toString()); } }); DialogAltUp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Double alt = parseDouble(DialogWpAltitude.getText().toString()) + 10; DialogWpAltitude.setText(alt.toString()); } }); DialogButtonConfirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SendStringBuf = "PPRZonDroid MOVE_WAYPOINT " + DialogAcId + " " + DialogWpId + " " + DialogTextWpLat.getText() + " " + DialogTextWpLon.getText() + " " + DialogWpAltitude.getText(); send_to_server(SendStringBuf, true); WpDialog.dismiss(); } }); /* Setup altitude dialog */ AltDialog = new Dialog(this); AltDialog.setContentView(R.layout.alt_modified); Alt_DialogButtonConfirm = (Button) AltDialog.findViewById(R.id.buttonConfAlt); Alt_DialogButtonConfirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String DlAlt = ""; DlAlt = DlAlt + mNumberPickerThus.getValue(); DlAlt = DlAlt + mNumberPickerHuns.getValue(); DlAlt = DlAlt + mNumberPickerTens.getValue(); DlAlt = DlAlt + mNumberPickerOnes.getValue(); SendStringBuf = "dl DL_SETTING " + AC_DATA.AircraftData[AC_DATA.SelAcInd].AC_Id + " " + AC_DATA.AircraftData[AC_DATA.SelAcInd].AC_AltID + " " + DlAlt; //Log.d("PPRZ_info", SendStringBuf ); send_to_server(SendStringBuf, true); AltDialog.dismiss(); } }); Alt_ResToDlAlt = (Button) AltDialog.findViewById(R.id.buttonResToDlAlt); Alt_ResToDlAlt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fill_alt(AC_DATA.AircraftData[AC_DATA.SelAcInd].AC_DlAlt); } }); Alt_ResToDesAlt = (Button) AltDialog.findViewById(R.id.buttonResToAcAlt); Alt_ResToDesAlt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fill_alt(AC_DATA.AircraftData[AC_DATA.SelAcInd].Altitude); } }); mNumberPickerThus = (NumberPicker) AltDialog.findViewById(R.id.numberPickerThus); mNumberPickerThus.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); mNumberPickerThus.setMinValue(0); mNumberPickerThus.setMaxValue(9); mNumberPickerHuns = (NumberPicker) AltDialog.findViewById(R.id.numberPickerHuns); mNumberPickerHuns.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); mNumberPickerHuns.setMinValue(0); mNumberPickerHuns.setMaxValue(9); mNumberPickerTens = (NumberPicker) AltDialog.findViewById(R.id.numberPickerTens); mNumberPickerTens.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); mNumberPickerTens.setMinValue(0); mNumberPickerTens.setMaxValue(9); mNumberPickerOnes = (NumberPicker) AltDialog.findViewById(R.id.numberPickerOnes); mNumberPickerOnes.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); mNumberPickerOnes.setMinValue(0); mNumberPickerOnes.setMaxValue(9); //Setup left drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); //Setup AC List setup_ac_list(); //Setup Block list setup_block_list(); //Set map zoom level variable (if any); if (AppSettings.contains("MapZoomLevel")) { MapZoomLevel = AppSettings.getFloat("MapZoomLevel", 17.0f); } //continue to bound UI items MapAlt = (TextView) findViewById(R.id.Alt_On_Map); MapThrottle = (TextView) findViewById(R.id.ThrottleText); Pfd = (ImageView) findViewById(R.id.imageView_Pfd); //mToolTip = (ImageView) findViewById(R.id.imageFeedBack ); Button_ConnectToServer = (Button) findViewById(R.id.Button_ConnectToServer); setup_map_ifneeded(); LockToAcSwitch = (ToggleButton) findViewById(R.id.toggleButton_TraceAircraft); //LockToAcSwitch.setSelected(true); ChangeVisibleAcButon = (ToggleButton) findViewById(R.id.toggleButtonVisibleAc); ChangeVisibleAcButon.setSelected(false); TextViewApMode = (TextView) findViewById(R.id.Ap_Status_On_Map); TextViewGpsMode = (TextView) findViewById(R.id.Gps_Status_On_Map); TextViewFlightTime = (TextView) findViewById(R.id.Flight_Time_On_Map); TextViewBattery = (TextView) findViewById(R.id.Bat_Vol_On_Map); TextViewStateFilterMode = (TextView) findViewById(R.id.State_Filter_On_Map); TextViewSpeed = (TextView) findViewById(R.id.SpeedText); TextViewAirspeed = (TextView) findViewById(R.id.AirSpeed_On_Map); TextViewAirspeed.setVisibility(View.INVISIBLE); }
From source file:com.aware.ui.ESM_UI.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // getActivity().getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); builder = new AlertDialog.Builder(getActivity()); inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); TAG = Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0 ? Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG) : TAG;/*from w w w . j av a 2 s. c o m*/ Cursor visible_esm = getActivity().getContentResolver().query(ESM_Data.CONTENT_URI, null, ESM_Data.STATUS + "=" + ESM.STATUS_NEW, null, ESM_Data.TIMESTAMP + " ASC LIMIT 1"); if (visible_esm != null && visible_esm.moveToFirst()) { esm_id = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data._ID)); //Fixed: set the esm as not new anymore, to avoid displaying the same ESM twice due to changes in orientation ContentValues update_state = new ContentValues(); update_state.put(ESM_Data.STATUS, ESM.STATUS_VISIBLE); getActivity().getContentResolver().update(ESM_Data.CONTENT_URI, update_state, ESM_Data._ID + "=" + esm_id, null); esm_type = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.TYPE)); expires_seconds = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.EXPIRATION_THREASHOLD)); builder.setTitle(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.TITLE))); View ui = null; switch (esm_type) { case ESM.TYPE_ESM_TEXT: ui = inflater.inflate(R.layout.esm_text, null); break; case ESM.TYPE_ESM_RADIO: ui = inflater.inflate(R.layout.esm_radio, null); break; case ESM.TYPE_ESM_CHECKBOX: ui = inflater.inflate(R.layout.esm_checkbox, null); break; case ESM.TYPE_ESM_LIKERT: ui = inflater.inflate(R.layout.esm_likert, null); break; case ESM.TYPE_ESM_QUICK_ANSWERS: ui = inflater.inflate(R.layout.esm_quick, null); break; } final View layout = ui; builder.setView(layout); current_dialog = builder.create(); sContext = current_dialog.getContext(); TextView esm_instructions = (TextView) layout.findViewById(R.id.esm_instructions); esm_instructions.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.INSTRUCTIONS))); switch (esm_type) { case ESM.TYPE_ESM_TEXT: final EditText feedback = (EditText) layout.findViewById(R.id.esm_feedback); Button cancel_text = (Button) layout.findViewById(R.id.esm_cancel); cancel_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); current_dialog.cancel(); } }); Button submit_text = (Button) layout.findViewById(R.id.esm_submit); submit_text.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, feedback.getText().toString()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_RADIO: try { final RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); final JSONArray radios = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.RADIOS))); for (int i = 0; i < radios.length(); i++) { final RadioButton radioOption = new RadioButton(getActivity()); radioOption.setId(i); radioOption.setText(radios.getString(i)); radioOptions.addView(radioOption); if (radios.getString(i).equals("Other")) { radioOption.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) radioOption.setText(otherText.getText()); inputManager.hideSoftInputFromWindow(otherText.getWindowToken(), 0); editOther.dismiss(); } }); editor.addView(confirm); } }); } } Button cancel_radio = (Button) layout.findViewById(R.id.esm_cancel); cancel_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_radio = (Button) layout.findViewById(R.id.esm_submit); submit_radio.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); if (radioOptions.getCheckedRadioButtonId() != -1) { RadioButton selected = (RadioButton) radioOptions .getChildAt(radioOptions.getCheckedRadioButtonId()); rowData.put(ESM_Data.ANSWER, selected.getText().toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_CHECKBOX: try { final LinearLayout checkboxes = (LinearLayout) layout.findViewById(R.id.esm_checkboxes); final JSONArray checks = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.CHECKBOXES))); for (int i = 0; i < checks.length(); i++) { final CheckBox checked = new CheckBox(getActivity()); checked.setText(checks.getString(i)); checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (buttonView.getText().equals("Other")) { checked.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow() .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) { inputManager.hideSoftInputFromWindow( otherText.getWindowToken(), 0); selected_options .remove(buttonView.getText().toString()); checked.setText(otherText.getText()); selected_options.add(otherText.getText().toString()); } editOther.dismiss(); } }); editor.addView(confirm); } }); } else { selected_options.add(buttonView.getText().toString()); } } else { selected_options.remove(buttonView.getText().toString()); } } }); checkboxes.addView(checked); } Button cancel_checkbox = (Button) layout.findViewById(R.id.esm_cancel); cancel_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_checkbox = (Button) layout.findViewById(R.id.esm_submit); submit_checkbox.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); if (selected_options.size() > 0) { rowData.put(ESM_Data.ANSWER, selected_options.toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_LIKERT: final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.esm_likert); ratingBar.setMax(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); ratingBar.setStepSize( (float) visible_esm.getDouble(visible_esm.getColumnIndex(ESM_Data.LIKERT_STEP))); ratingBar.setNumStars(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); TextView min_label = (TextView) layout.findViewById(R.id.esm_min); min_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MIN_LABEL))); TextView max_label = (TextView) layout.findViewById(R.id.esm_max); max_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX_LABEL))); Button cancel = (Button) layout.findViewById(R.id.esm_cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit = (Button) layout.findViewById(R.id.esm_submit); submit.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, ratingBar.getRating()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_QUICK_ANSWERS: try { final JSONArray answers = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.QUICK_ANSWERS))); final LinearLayout answersHolder = (LinearLayout) layout.findViewById(R.id.esm_answers); //If we have more than 3 possibilities, better that the UI is vertical for UX if (answers.length() > 3) { answersHolder.setOrientation(LinearLayout.VERTICAL); } for (int i = 0; i < answers.length(); i++) { final Button answer = new Button(getActivity()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f); answer.setLayoutParams(params); answer.setText(answers.getString(i)); answer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); rowData.put(ESM_Data.ANSWER, (String) answer.getText()); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); answersHolder.addView(answer); } } catch (JSONException e) { e.printStackTrace(); } break; } } if (visible_esm != null && !visible_esm.isClosed()) visible_esm.close(); //Start dialog visibility threshold if (expires_seconds > 0) { expire_monitor = new ESMExpireMonitor(System.currentTimeMillis(), expires_seconds, esm_id); expire_monitor.execute(); } //Fixed: doesn't dismiss the dialog if touched outside or ghost touches current_dialog.setCanceledOnTouchOutside(false); return current_dialog; }
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 ww w . j ava 2 s. c o 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.xxjwd.sjbg.MainActivity.java
private void doShowDownloadDialog() { Dialog builder = new Dialog(this); //builder.requestWindowFeature(Window.FEATURE_NO_TITLE); builder.setTitle("???"); builder.getWindow().setBackgroundDrawable( new ColorDrawable(android.graphics.Color.TRANSPARENT)); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override/*from w ww. j ava 2s. com*/ public void onDismiss(DialogInterface dialogInterface) { //nothing; } }); ImageView imageView = new ImageView(this); imageView.setImageResource(R.drawable.erweima); imageView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("http://61.163.45.215:808/sjbg/download.html"); intent.setData(content_url); startActivity(intent); return true; } } ); builder.addContentView(imageView, new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); builder.show(); }
From source file:com.z3r0byte.magistify.DashboardActivity.java
private void relogin() { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.fragment_login); dialog.setTitle(R.string.msg_relogin); Button button = (Button) dialog.findViewById(R.id.button_login); button.setOnClickListener(new View.OnClickListener() { @Override//w w w. ja v a 2s . com public void onClick(View view) { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); EditText usertxt = (EditText) dialog.findViewById(R.id.edit_text_username); EditText passwordtxt = (EditText) dialog.findViewById(R.id.edit_text_password); String username = usertxt.getText().toString(); String password = passwordtxt.getText().toString(); School school = new Gson().fromJson(configUtil.getString("School"), School.class); try { Magister magister = Magister.login(school, username, password); } catch (final IOException | NullPointerException e) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(DashboardActivity.this, R.string.err_no_connection, Toast.LENGTH_SHORT).show(); } }); return; } catch (ParseException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(DashboardActivity.this, R.string.err_unknown, Toast.LENGTH_SHORT) .show(); } }); return; } catch (InvalidParameterException e) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(DashboardActivity.this, R.string.err_wrong_username_or_password, Toast.LENGTH_SHORT).show(); } }); return; } Log.d(TAG, "onClick: login succeeded!"); User user = new User(username, password, false); configUtil.setString("User", new Gson().toJson(user)); configUtil.setInteger("failed_auth", 0); GlobalAccount.USER = user; dialog.dismiss(); } }).start(); } }); dialog.show(); }
From source file:com.mitre.holdshort.MainActivity.java
private void showDisclaimer() { final Dialog dialog = new Dialog(MainActivity.this); OnClickListener disclaimerBtnClick;//from w ww . j ava2 s. c om dialog.setContentView(R.layout.legal_stuff_dialog); dialog.setTitle("RIPPLE - Informed Consent"); dialog.setCancelable(false); dialog.getWindow().setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); TextView consent = (TextView) dialog.findViewById(R.id.disclaimerAccept); TextView reject = (TextView) dialog.findViewById(R.id.disclaimerReject); disclaimerBtnClick = new OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.disclaimerAccept) { settings.edit().putBoolean("consent", true).commit(); dialog.dismiss(); waiverAccept = true; startUp(); } else { finish(); } } }; consent.setOnClickListener(disclaimerBtnClick); reject.setOnClickListener(disclaimerBtnClick); dialog.show(); }
From source file:com.jinrustar.sky.main.MainActivity.java
private void itemClick(final VideoInfo info) { if (prelongTim == 0) {//??? prelongTim = System.currentTimeMillis(); } else {//w ww . jav a2s .c o m long curTime = System.currentTimeMillis(); ;//? jiangeTime = curTime - prelongTim; prelongTim = curTime;//??? } if (jiangeTime > 5000 || firstClick) { firstClick = false; if (!TextUtils.isEmpty(content) && isConnect) { Log.i("ip", "ip_address:" + content); if (dialog == null) dialog = new Dialog(context); dialog.getContext().setTheme(R.style.custom); dialog.setContentView(R.layout.layout_dialog_downloadtips); dialog.getWindow().setGravity(Gravity.CENTER); dialog.getWindow().setLayout( dialog.getWindow().getWindowManager().getDefaultDisplay().getWidth() - 200, WindowUtils.getScreenWidthAndHeight()[1] / 3); dialog.findViewById(R.id.tv_downloadcancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.findViewById(R.id.tv_download).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // search_layout.setVisibility(View.GONE); // scan.setEnabled(true); downloadVideoInfo = new DownloadVideoInfo(); downloadVideoInfo.setId(info.getId()); downloadid = info.getId(); downloadVideoInfo.setName(info.getName()); if (!isAdd(downloadVideoInfo.getId())) { downloadVideoInfos.add(downloadVideoInfo); } else { dialog.dismiss(); return; } count++; // Toast.makeText(context, "??id=" +info.getId()+info.getName(), Toast.LENGTH_SHORT).show(); sendmessage(info.getId() + ""); dialog.dismiss(); } }); dialog.show(); // showDownLoadDialog(videoInfos.get(position).getId() + ""); } else { showDilogTips(); Toast.makeText(context, "?????", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(context, "????", Toast.LENGTH_SHORT).show(); } }