List of usage examples for android.app Dialog getWindow
public @Nullable Window getWindow()
From source file:com.inductivebiblestudyapp.ui.dialogs.SimpleTooltipDialog.java
/** Adjusts the location of the dialog and positions the arrow. * /* w ww.jav a 2 s. c o m*/ * @param dialog The dialog * @param rootView The rootView of the dialog * @param anchorLocation An X =0, Y=1 array of the anchor location via getLocationOnScreen. * @param anchorDimens An X =0, Y=1 array of anchor size in pixels * @param centered Whether to center the dialog or not. */ protected void adjustView(Dialog dialog, View rootView, int[] anchorLocation, int[] anchorDimens, boolean centered) { final int X_INDEX = 0; final int Y_INDEX = 1; try { int[] screenSize = new int[2]; getScreenDimens(screenSize); rootView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); final int rootWidth = rootView.getMeasuredWidth(); final int rootHeight = rootView.getMeasuredHeight(); final int[] screenCenter = new int[] { screenSize[X_INDEX] / 2, screenSize[Y_INDEX] / 2 }; //we have not displayed it yet, so we cannot measure location. //Instead, we will estimate based on Gravity.CENTER x and y final int[] estRootLocation = new int[] { screenCenter[X_INDEX] - rootWidth / 2, screenCenter[Y_INDEX] - rootHeight / 2 }; //if not left, right final boolean anchorToLeft = screenCenter[X_INDEX] >= anchorLocation[X_INDEX]; //if not top, bottom final boolean anchorToTop = screenCenter[Y_INDEX] >= anchorLocation[Y_INDEX]; WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); // lets start by calculating our midpoint //the horizontal center of the anchor relative to left side of screen final int anchorMidpointX = anchorLocation[X_INDEX] + anchorDimens[X_INDEX] / 2; //were the arrow margin should go. int arrowMarginLeft = 0; if (centered) { wmlp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; arrowMarginLeft = anchorMidpointX - estRootLocation[X_INDEX]; } else { //LEFT required if manually positioning. wmlp.gravity = Gravity.TOP | Gravity.LEFT; //center our dialog under our anchor as best as possible int dialogPosFromLeft = anchorMidpointX - rootWidth / 2; //check our values are sane. if (dialogPosFromLeft + rootWidth >= screenSize[X_INDEX]) { dialogPosFromLeft = screenSize[X_INDEX] - rootWidth; } else if (dialogPosFromLeft <= 0) { dialogPosFromLeft = 1; } wmlp.x = dialogPosFromLeft; arrowMarginLeft = anchorMidpointX - dialogPosFromLeft; } //horizontal positions are now calculated, now let's align our dialog vertically to be directly above our view. //the position from the top of the screen, to place the dialog. int desiredPosFromTop = 0; //the arrow params LinearLayout.LayoutParams arrowParams = null; if (anchorToTop) { //position ourself above. desiredPosFromTop = anchorLocation[Y_INDEX] + anchorDimens[Y_INDEX] - getStatusBarHeight(); mDownArrow.setVisibility(View.GONE); arrowParams = (LinearLayout.LayoutParams) mUpArrow.getLayoutParams(); } else { desiredPosFromTop = anchorLocation[Y_INDEX] - rootHeight - getStatusBarHeight(); mUpArrow.setVisibility(View.GONE); arrowParams = (LinearLayout.LayoutParams) mDownArrow.getLayoutParams(); } arrowParams.leftMargin = arrowMarginLeft; if (desiredPosFromTop >= screenSize[Y_INDEX]) { wmlp.y = screenSize[Y_INDEX] - 1; } else if (desiredPosFromTop <= 0) { wmlp.y = 1; } else { wmlp.y = desiredPosFromTop; } dialog.getWindow().setAttributes(wmlp); //force change, even at runtime. } catch (Exception e) { e.printStackTrace(); } }
From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java
private Dialog showSingleChoiceDialog(final Context mContext) { View convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_single_choice, null); final Dialog dialog = new Dialog(mContext, R.style.CustomDialog); View.OnClickListener listener = new View.OnClickListener() { @Override/*www . j a v a 2 s . co m*/ public void onClick(View v) { switch (v.getId()) { case R.id.tv_confirm: onDialogClickLisenter.viewClick("tv_confirm"); dismiss(); break; } } }; TextView tv_confirm = (TextView) convertView.findViewById(R.id.tv_confirm); TextView tv_explain = (TextView) convertView.findViewById(R.id.tv_explain); tv_explain.setText(StringConstant.TEXT_SHOW_AFTER_CALL_POLICE_SUCCESS); if (onDialogClickLisenter != null) { onDialogClickLisenter.controlView(tv_confirm, null, null, tv_explain); } tv_confirm.setOnClickListener(listener); dialog.setContentView(convertView); dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style); return dialog; }
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
/** * Creates the help dialog for this activity. *///from w ww .j a v a 2 s. c o m private Dialog createHelpDialog() { AlertDialog.Builder adb = new AlertDialog.Builder(this).setMessage(R.string.input_mode_help_text) .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // We don't have to do anything. } }); Dialog d = adb.setView(new ListView(this)).create(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(d.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; d.show(); d.getWindow().setAttributes(lp); return d; }
From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java
private void showSettings() { final SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE); int selfReportIntervalSpinnerPosition = sharedPref.getInt("selfReportIntervalSpinnerPosition", 2); int selfReportVarianceSpinnerPosition = sharedPref.getInt("selfReportVarianceSpinnerPosition", 0); int questionnaireSpinnerPosition = sharedPref.getInt("questionnaireSpinnerPosition", 0); //int baselineQuestionnaireSpinnerPosition = sharedPref.getInt("baselineQuestionnaireSpinnerPosition", 0); String activityName = sharedPref.getString("activityName", ""); String participantFirstName = sharedPref.getString("participantFirstName", ""); String participantLastName = sharedPref.getString("participantLastName", ""); boolean configureInterval = sharedPref.getBoolean("configureInterval", false); final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.settings); dialog.setTitle(getString(R.string.action_settings)); dialog.setCancelable(true);/*from ww w. j a v a 2 s . c om*/ WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.getWindow().setAttributes(lp); selfReportIntervalSpinner = (Spinner) dialog.findViewById(R.id.self_report_interval_spinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.study_protocol_settings_self_report_interval_values, android.R.layout.simple_spinner_item); selfReportIntervalSpinner.setAdapter(adapter); selfReportIntervalSpinner.setSelection(selfReportIntervalSpinnerPosition); selfReportVarianceSpinner = (Spinner) dialog.findViewById(R.id.self_report_variance_spinner); ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.study_protocol_settings_self_report_variance_values, android.R.layout.simple_spinner_item); selfReportVarianceSpinner.setAdapter(adapter2); selfReportVarianceSpinner.setSelection(selfReportVarianceSpinnerPosition); questionnaireSpinner = (Spinner) dialog.findViewById(R.id.questionnaireSpinner); //baselineQuestionnaireSpinner = (Spinner) dialog.findViewById(R.id.baseline_questionnaireSpinner); String[] questionnaireTitles = new String[0]; try { questionnaireTitles = new String[questionnaireCount]; for (int i = 0; i < questionnaireCount; i++) { String questionnaireFilename = questionnaireFilenames[i]; String questionnairePath = "questionnaires/" + localeString + "/" + questionnaireFilename; try { JSONObject questionnaire = Utils .getJSONObjectFromInputStream(getAssets().open(questionnairePath)); String questionnaireTitle = questionnaire.getJSONObject("questionnaire").getString("title"); questionnaireTitles[i] = questionnaireTitle; } catch (JSONException e) { e.printStackTrace(); } } } catch (IOException e) { e.printStackTrace(); } ArrayAdapter<String> qSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, questionnaireTitles); questionnaireSpinner.setAdapter(qSpinnerAdapter); questionnaireSpinner.setSelection(questionnaireSpinnerPosition); //baselineQuestionnaireSpinner.setAdapter(qSpinnerAdapter); //baselineQuestionnaireSpinner.setSelection(baselineQuestionnaireSpinnerPosition); final EditText participantFirstNameEditText = (EditText) dialog .findViewById(R.id.participant_first_name_edit_text); final EditText participantLastNameEditText = (EditText) dialog .findViewById(R.id.participant_last_name_edit_text); final EditText activityNameEditText = (EditText) dialog.findViewById(R.id.activity_name_edit_text); participantFirstNameEditText.setText(participantFirstName); participantLastNameEditText.setText(participantLastName); activityNameEditText.setText(activityName); final Switch configureIntervalSwitch = (Switch) dialog.findViewById(R.id.configure_interval_switch); configureIntervalSwitch.setChecked(configureInterval); if (configureInterval) { dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE); dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE); } else { dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE); dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE); } Button saveButton = (Button) dialog.findViewById(R.id.saveButton); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selfReportInterval = Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString()); selfReportVariance = Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString()); MainActivity.this.participantFirstName = participantFirstNameEditText.getText().toString().trim(); MainActivity.this.participantLastName = participantLastNameEditText.getText().toString().trim(); MainActivity.this.activityName = activityNameEditText.getText().toString().trim(); MainActivity.this.intervalConfigured = configureIntervalSwitch.isChecked(); SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("selfReportIntervalSpinnerPosition", selfReportIntervalSpinner.getSelectedItemPosition()); editor.putInt("selfReportVarianceSpinnerPosition", selfReportVarianceSpinner.getSelectedItemPosition()); editor.putInt("questionnaireSpinnerPosition", questionnaireSpinner.getSelectedItemPosition()); //editor.putInt("baselineQuestionnaireSpinnerPosition", baselineQuestionnaireSpinner.getSelectedItemPosition()); editor.putInt("selfReportInterval", Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString())); editor.putInt("selfReportVariance", Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString())); editor.putString("participantFirstName", participantFirstNameEditText.getText().toString().trim()); editor.putString("participantLastName", participantLastNameEditText.getText().toString().trim()); editor.putString("activityName", activityNameEditText.getText().toString().trim()); editor.putBoolean("configureInterval", configureIntervalSwitch.isChecked()); editor.apply(); dialog.dismiss(); } }); configureIntervalSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE); dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE); } else { dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE); dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE); } } }); dialog.show(); }
From source file:com.fbartnitzek.tasteemall.filter.EntityFilterDialogFragment.java
@NonNull @Override/*from w ww . ja va 2 s. com*/ public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); Bundle bundle = getArguments(); if (bundle == null) { bundle = savedInstanceState; } if (bundle == null) { throw new RuntimeException("neither args nor savedInstance - should never happen..."); } mBaseEntity = bundle.getString(BASE_ENTITY); if (bundle.containsKey(FILTER_JSON)) { try { mFilterJson = new JSONObject(bundle.getString(FILTER_JSON)); } catch (JSONException e) { // conversion did not work ... use new Object, but log error Log.e(LOG_TAG, "onCreateDialog: json could not be restored: " + mFilterJson, e); e.printStackTrace(); } } if (mFilterJson == null) { mFilterJson = new JSONObject(); try { mFilterJson.put(mBaseEntity, new JSONObject()); } catch (JSONException e) { e.printStackTrace();// ignore... } } // TODO: restore position //dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW)); dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); return dialog; }
From source file:org.opendatakit.tables.activities.TableDisplayActivity.java
private void showDialogLocNuoc() { final ViewFragmentType fage = this.mCurrentFragmentType; final Dialog dialog = new Dialog(context); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); View layout = inflater.inflate(R.layout.dialog_loc, null); dialog.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dialog.setContentView(R.layout.dialog_loc); final ListView lv = (ListView) dialog.findViewById(R.id.list_loc); TextView title = (TextView) dialog.findViewById(R.id.title); List<Model> list = new ArrayList<Model>(); if (this.getTableId().equals("kdv_dnn_hogiadinh")) { list = SqliteLoc.getThonNuoc();//ww w .j a v a2s. c om } if (this.getTableId().equals("kdv_vs_hogiadinh")) { list = SqliteLoc.getThonGiaDinh(); } if (this.getTableId().equals("kdv_vs_congtrinhcongcong")) { list = SqliteLoc.getThonCongCong(); } if (loc_position >= 0 && list.size() > 0) { Model m = new Model(list.get(loc_position).getName(), true); list.set(loc_position, m); } if (list.size() == 0) { title.setText(getString(R.string.dialogloc)); } adapter = new Adapter(this, list); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Model model = (Model) (lv.getItemAtPosition(position)); String selectedFromList = model.getName(); Intent intent = getIntent(); intent.putExtra("loc", selectedFromList); intent.putExtra("loc_position", String.valueOf(position)); intent.putExtra("all", "0"); intent.putExtra("timkiem", "null"); switch (fage) { case SPREADSHEET: intent.putExtra("page", "SPREADSHEET"); break; case LIST: intent.putExtra("page", "LIST"); break; case MAP: intent.putExtra("page", "MAP"); break; case DETAIL: intent.putExtra("page", "DETAIL"); break; default: break; } finish(); startActivity(intent); } }); dialog.show(); }
From source file:org.opendatakit.tables.activities.TableDisplayActivity.java
private void showDialogOder() { int i, j = 0, n; int k = 0;//from ww w.j av a 2s .c o m final List<String[]> tile = readCsv(context); for (n = 0; n < tile.size(); n++) { if ("sort".equals(tile.get(n)[0])) { j++; } } String[] name = new String[j]; final ViewFragmentType fage = this.mCurrentFragmentType; final Dialog dialog = new Dialog(context); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); View layout = inflater.inflate(R.layout.dialog_sapxep, null); dialog.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dialog.setContentView(R.layout.dialog_sapxep); final ListView lv = (ListView) dialog.findViewById(R.id.list_oder); TextView title = (TextView) dialog.findViewById(R.id.title); title.setText("Sp xp theo"); for (i = 0; i < tile.size(); i++) { if ("sort".equals(tile.get(i)[0])) { name[k] = tile.get(i)[1].toString(); k++; } } List<Model> list = new ArrayList<Model>(); for (String elementKey : name) { list.add(new Model(elementKey)); } if (oder_position >= 0) { Model m = new Model(name[oder_position], true); list.set(oder_position, m); } adapter = new Adapter(this, list); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Model model = (Model) (lv.getItemAtPosition(position)); String selectedFromList = model.getName(); for (int n = 0; n < tile.size(); n++) { if (selectedFromList.equals(tile.get(n)[1])) { String oder_key = tile.get(n)[2].toString(); Intent intent = getIntent(); intent.putExtra("oder", oder_key); intent.putExtra("oder_position", String.valueOf(position)); intent.putExtra("all", "0"); switch (fage) { case SPREADSHEET: intent.putExtra("page", "SPREADSHEET"); break; case LIST: intent.putExtra("page", "LIST"); break; case MAP: intent.putExtra("page", "MAP"); break; case DETAIL: intent.putExtra("page", "DETAIL"); break; default: break; } finish(); startActivity(intent); } } } }); dialog.show(); }
From source file:org.opendatakit.tables.activities.TableDisplayActivity.java
private void showDialogTimkiem() { int i, j = 0, n; int k = 0;//from w w w. j a va2s. c om final List<String[]> tile = readCsv(context); final ViewFragmentType fage = this.mCurrentFragmentType; for (n = 0; n < tile.size(); n++) { if ("filter".equals(tile.get(n)[0])) { j++; } } String[] name = new String[j]; final Dialog dialog = new Dialog(context); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); View layout = inflater.inflate(R.layout.dialog_sapxep, null); dialog.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dialog.setContentView(R.layout.dialog_sapxep); final ListView lv = (ListView) dialog.findViewById(R.id.list_oder); TextView title = (TextView) dialog.findViewById(R.id.title); title.setText("L?c theo trng thi"); for (i = 0; i < tile.size(); i++) { if ("filter".equals(tile.get(i)[0])) { name[k] = tile.get(i)[1].toString(); k++; } } List<Model> list = new ArrayList<Model>(); for (String elementKey : name) { list.add(new Model(elementKey)); } if (position_check >= 0) { Model m = new Model(name[position_check], true); list.set(position_check, m); } adapter = new Adapter(this, list); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { RadioButton checkbox = (RadioButton) view.getTag(R.id.radioBT); checkbox.setChecked(true); Model model = (Model) (lv.getItemAtPosition(position)); String selectedFromList = model.getName(); for (int n = 0; n < tile.size(); n++) { if (selectedFromList.equals(tile.get(n)[1])) { String mj = tile.get(n)[2].toString(); Intent intent = getIntent(); StringBuilder s = new StringBuilder(); s.append(mj); intent.putExtra("timkiem", s.toString()); intent.putExtra("vitri", String.valueOf(position)); intent.putExtra("all", "0"); switch (fage) { case SPREADSHEET: intent.putExtra("page", "SPREADSHEET"); break; case LIST: intent.putExtra("page", "LIST"); break; case MAP: intent.putExtra("page", "MAP"); break; case DETAIL: intent.putExtra("page", "DETAIL"); break; default: break; } finish(); startActivity(intent); } } } }); dialog.show(); }
From source file:co.taqat.call.CallActivity.java
private void showAcceptCallUpdateDialog() { final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorC)); d.setAlpha(200);//from w w w. j av a2s .c o m dialog.setContentView(R.layout.dialog); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); dialog.getWindow().setBackgroundDrawable(d); TextView customText = (TextView) dialog.findViewById(R.id.customText); customText.setText(getResources().getString(R.string.add_video_dialog)); Button delete = (Button) dialog.findViewById(R.id.delete_button); delete.setText(R.string.accept); Button cancel = (Button) dialog.findViewById(R.id.cancel); cancel.setText(R.string.decline); delete.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { int camera = getPackageManager().checkPermission(Manifest.permission.CAMERA, getPackageName()); Log.i("[Permission] Camera permission is " + (camera == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); if (camera == PackageManager.PERMISSION_GRANTED) { CallActivity.instance().acceptCallUpdate(true); } else { checkAndRequestPermission(Manifest.permission.CAMERA, PERMISSIONS_REQUEST_CAMERA); } dialog.dismiss(); } }); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (CallActivity.isInstanciated()) { CallActivity.instance().acceptCallUpdate(false); } dialog.dismiss(); } }); dialog.show(); }
From source file:org.csp.everyaware.offline.Map.java
private void insertAnnDialog(final ExtendedLatLng annLatLng) { final Dialog insertDialog = new Dialog(Map.this); insertDialog.setContentView(R.layout.insert_dialog); insertDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); insertDialog.setTitle(R.string.annotation_insertion); insertDialog.setCancelable(false);/*from w ww . j a va 2 s .c o m*/ //get reference to send button final Button sendButton = (Button) insertDialog.findViewById(R.id.send_button); sendButton.setEnabled(false); //active only if there's text //get reference to cancel/close window button final Button cancelButton = (Button) insertDialog.findViewById(R.id.cancel_button); cancelButton.setEnabled(true); //active all time cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { insertDialog.dismiss(); } }); //get reference to edittext in which user writes annotation final EditText editText = (EditText) insertDialog.findViewById(R.id.annotation_editText); editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { //if modified text length is more than 0, activate send button if (s.length() > 0) sendButton.setEnabled(true); else sendButton.setEnabled(false); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); //get checkbox references CheckBox facebookChBox = (CheckBox) insertDialog.findViewById(R.id.facebook_checkBox); CheckBox twitterChBox = (CheckBox) insertDialog.findViewById(R.id.twitter_checkBox); //activate check boxes depends from log in facebook/twitter boolean[] logs = new boolean[2]; logs[0] = Utils.getValidFbSession(getApplicationContext()); logs[1] = Utils.getValidTwSession(getApplicationContext()); facebookChBox.setEnabled(logs[0]); twitterChBox.setEnabled(logs[1]); //checked on check boxes final boolean[] checkeds = Utils.getShareCheckedOn(getApplicationContext()); if (checkeds[0] == true) facebookChBox.setChecked(true); else facebookChBox.setChecked(false); if (checkeds[1] == true) twitterChBox.setChecked(true); else twitterChBox.setChecked(false); facebookChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean checked) { Utils.setShareCheckedOn(checked, checkeds[1], getApplicationContext()); checkeds[0] = checked; } }); twitterChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean checked) { Utils.setShareCheckedOn(checkeds[0], checked, getApplicationContext()); checkeds[1] = checked; } }); //send annotation to server and on facebook/twitter if user is logged on sendButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //1 - read inserted annotation String annotation = editText.getText().toString(); //2 - update record on db with annotation and save recordId double recordId = annLatLng.mRecordId; int result = mDbManager.updateRecordAnnotation(recordId, annotation); if (result == 1) Toast.makeText(getApplicationContext(), "Updated record", Toast.LENGTH_LONG).show(); else Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_LONG).show(); boolean[] checks = Utils.getShareCheckedOn(getApplicationContext()); //3 - share on facebook is user wants and internet is active now if (checks[0] == true) { Record annotatedRecord = mDbManager.loadRecordById(recordId); try { FacebookManager fb = FacebookManager.getInstance(null, null); if (fb != null) fb.postMessageOnWall(annotatedRecord); } catch (Exception e) { e.printStackTrace(); } } //4 - share on twitter is user wants and internet is active now if (checks[1] == true) { Record annotatedRecord = mDbManager.loadRecordById(recordId); try { TwitterManager twManager = TwitterManager.getInstance(null); twManager.postMessage(annotatedRecord); } catch (Exception e) { e.printStackTrace(); } } //5 - show marker for annotated record Record annotatedRecord = mDbManager.loadRecordById(recordId); String userAnn = annotatedRecord.mUserData1; if (!userAnn.equals("") && (annotatedRecord.mValues[0] != 0)) { BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.annotation_marker); Marker marker = mGoogleMap.addMarker(new MarkerOptions() .position(new LatLng(annotatedRecord.mValues[0], annotatedRecord.mValues[1])) .title("BC: " + String.valueOf(annotatedRecord.mBcMobile) + " " + getResources().getString(R.string.micrograms)) .snippet("Annotation: " + userAnn).icon(icon).anchor(0f, 1f)); } insertDialog.dismiss(); } }); insertDialog.show(); }