List of usage examples for android.widget EditText getText
@Override
public Editable getText()
From source file:fi.mikuz.boarder.gui.internet.Login.java
private void showLoggedOutView() { setContentView(R.layout.internet_login_logged_out); mLogin = (Button) findViewById(R.id.submit); mUsername = (EditText) findViewById(R.id.userName); mPassword = (EditText) findViewById(R.id.userPassword); boolean usernameInDb = false; String dbPassword = null;/*from w w w. jav a2s . co m*/ try { Cursor loginCursor = mDbHelper.fetchLogin(InternetMenu.USERNAME_KEY); startManagingCursor(loginCursor); mUsername.setText(loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA))); usernameInDb = true; } catch (SQLException e) { Log.d(TAG, "Couldn't get database login info", e); } catch (CursorIndexOutOfBoundsException e) { Log.d(TAG, "Couldn't get database login info", e); } dbPassword = getDbPassword(); final CheckBox rememberPassword = (CheckBox) findViewById(R.id.rememberPassword); if (dbPassword == null) { rememberPassword.setChecked(false); } else { rememberPassword.setChecked(true); mPassword.setText(dbPassword); } final CheckBox rememberUsername = (CheckBox) findViewById(R.id.rememberUsername); rememberUsername.setChecked(usernameInDb); mLogin.setOnClickListener(new OnClickListener() { public void onClick(View v) { mWaitDialog = new TimeoutProgressDialog(Login.this, "Waiting for response", TAG, false); String username = mUsername.getText().toString(); String password = mPassword.getText().toString(); Boolean entrancePassword = true; String dbPassword = getDbPassword(); // Password in the Android database is always the same as in the server database // Being an entrance password means that the password is not the same as in the server database if (dbPassword != null) { if (dbPassword.equals(password)) { entrancePassword = false; } } // If the password is now an entrance password then it's plain text and wants to be hashed if (entrancePassword) { try { password = Security.passwordHash(password); } catch (NoSuchAlgorithmException e) { String msg = "Couldn't make a password hash"; Toast.makeText(Login.this, msg, Toast.LENGTH_LONG).show(); Log.e(TAG, msg, e); } } if (rememberUsername.isChecked()) { mDbHelper.putLogin(InternetMenu.USERNAME_KEY, username); } else if (!rememberUsername.isChecked()) { mDbHelper.deleteLogin(InternetMenu.USERNAME_KEY); } if (rememberPassword.isChecked()) { if (!entrancePassword) { mPasswordOperation = PASSWORD_OPERATION_NONE; mDbHelper.putLogin(InternetMenu.PASSWORD_KEY, password); } else { mPasswordOperation = PASSWORD_OPERATION_SAVE; } } else if (!rememberPassword.isChecked()) { mDbHelper.deleteLogin(InternetMenu.PASSWORD_KEY); } mDbHelper.deleteLogin(InternetMenu.USER_ID_KEY); mDbHelper.deleteLogin(InternetMenu.SESSION_TOKEN_KEY); CheckBox rememberSession = (CheckBox) findViewById(R.id.rememberSession); if (rememberSession.isChecked()) { mRememberSession = true; } HashMap<String, String> sendList = new HashMap<String, String>(); sendList.put(InternetMenu.USERNAME_KEY, username); sendList.put(InternetMenu.PASSWORD_KEY, password); sendList.put(InternetMenu.ENTRANCE_PASSWORD_KEY, entrancePassword ? "1" : "0"); new ConnectionManager(Login.this, InternetMenu.mLoginURL, sendList); } }); Button recoverPassword = (Button) findViewById(R.id.recoverPassword); recoverPassword.setOnClickListener(new OnClickListener() { public void onClick(View v) { LayoutInflater inflater = (LayoutInflater) Login.this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.internet_login_alert_recover_password, (ViewGroup) findViewById(R.id.alert_settings_root)); final EditText input = (EditText) layout.findViewById(R.id.input); Button submitButton = (Button) layout.findViewById(R.id.submitButton); AlertDialog.Builder builder = new AlertDialog.Builder(Login.this); builder.setView(layout); builder.setTitle("Password recovery"); submitButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mWaitDialog = new TimeoutProgressDialog(Login.this, "Waiting for response", TAG, false); String inputText = input.getText().toString(); HashMap<String, String> sendList = new HashMap<String, String>(); sendList.put(InternetMenu.EMAIL_KEY, inputText); new ConnectionManager(Login.this, InternetMenu.mRecoverPasswordURL, sendList); } }); builder.show(); } }); }
From source file:cz.zcu.kiv.eeg.mobile.base.ui.scenario.ScenarioAddActivity.java
@Override protected void save() { //obtaining layout elements Spinner group = (Spinner) findViewById(R.id.groupList); EditText scenarioName = (EditText) findViewById(R.id.scenario_name_value); EditText description = (EditText) findViewById(R.id.scenario_description_value); EditText mime = (EditText) findViewById(R.id.scenario_mime_value); TextView fileName = (TextView) findViewById(R.id.fchooserSelectedFile); CompoundButton isPrivate = (CompoundButton) findViewById(R.id.scenario_private); SharedPreferences getOwner = getSharedPreferences(Values.PREFS_TEMP, Context.MODE_PRIVATE); String loggeduserDocID = getOwner.getString("loggedUserDocID", null); String loggeduserName = getOwner.getString("loggedUserName", null); //creating scenario instance Scenario scenario = new Scenario(); scenario.setScenarioName(scenarioName.getText().toString()); scenario.setResearchGroupId(// ww w . ja v a 2 s. c o m group.getSelectedItem() == null ? null : ((ResearchGroup) group.getSelectedItem()).getGroupId()); scenario.setDescription(description.getText().toString()); scenario.setMimeType(mime.getText().toString()); scenario.setFileName(fileName.getText().toString()); scenario.setPrivate(isPrivate.isChecked()); scenario.setFilePath(selectedFile); scenario.setFileLength(String.valueOf(selectedFileLength)); scenario.setOwnerId(loggeduserDocID); scenario.setOwnerUserName(loggeduserName); validateAndRun(scenario); }
From source file:com.cypress.cysmart.RDKEmulatorView.MicrophoneEmulatorFragment.java
/** * Method to display a custom alert./*from w w w . ja va 2 s . co m*/ * Option for entering the google key in the method for voice to * text conversion */ private void showCustumAlert(String storedKey, boolean changeNeeded) { LayoutInflater li = LayoutInflater.from(getActivity()); View promptsView = li.inflate(R.layout.api_key_dialog_alert, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set api_key_dialog_alert.xml to alertdialog builder alertDialogBuilder.setView(promptsView); //User input Edittext final EditText userInput = (EditText) promptsView.findViewById(R.id.custom_alert_user_input); if (changeNeeded) { userInput.setText(storedKey); } // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to sharedpreferecne Logger.i("userInput.getText()--->" + userInput.getText()); Utils.setStringSharedPreference(getActivity(), Constants.PREF_GOOGLE_API_KEY, userInput.getText().toString()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:com.iverson.toby.rhealth.MainActivity.java
public void openMenu() { setContentView(R.layout.open);/*from ww w .j a va2 s . c o m*/ final EditText restSearch = (EditText) findViewById(R.id.editsearch); Button sbtn = (Button) findViewById(R.id.search_button); Button lbtn = (Button) findViewById(R.id.location_button); // search button sbtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String psearch = restSearch.getText().toString(); setContentView(R.layout.httptestlist); //getting rid of special characters psearch = psearch.toUpperCase(); psearch = psearch.replaceAll(" ", "%20"); psearch = psearch.replaceAll("&", "%26"); psearch = psearch.replaceAll("!", "%21"); if (psearch.contains("'")) { psearch = psearch.substring(0, psearch.indexOf("'")); } //creating query queryGoogle = new StringBuilder(); queryGoogle.append("https://maps.googleapis.com/maps/api/place/textsearch/xml?"); queryGoogle.append("location=44.9756997,-93.2664641&"); queryGoogle.append("radius=10000&"); queryGoogle.append("types=" + type + "&"); queryGoogle.append("query=" + psearch + "&"); queryGoogle.append("key=" + APIKEY); new SearchGooglePlaces().execute(queryGoogle.toString()); } }); //location button lbtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { setContentView(R.layout.httptestlist); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener myLocationListener = new MyLocationListener(); locationResult = new MyLocation.LocationResult() { @Override public void gotLocation(Location location) { latitude = String.valueOf(location.getLatitude()); longitude = String.valueOf(location.getLongitude()); progressDialog.dismiss(); new GetCurrentLocation().execute(latitude, longitude); } }; /*****Enter lat lon for testing*****/ //latitude = String.valueOf(44.9157615); //longitude = String.valueOf(-93.2629201); MyRunnable myRun = new MyRunnable(); myRun.run(); progressDialog = ProgressDialog.show(MainActivity.this, "Finding your location", "Please wait...", true); queryGoogle = new StringBuilder(); queryGoogle.append("https://maps.googleapis.com/maps/api/place/nearbysearch/xml?"); queryGoogle.append("location=" + latitude + "," + longitude + "&"); queryGoogle.append("radius=" + radius + "&"); queryGoogle.append("types=" + type + "&"); queryGoogle.append("sensor=true&"); //Must be true if queried from a device with GPS queryGoogle.append("key=" + APIKEY); new QueryGooglePlaces().execute(queryGoogle.toString()); } }); }
From source file:za.co.neilson.alarm.preferences.AlarmPreferencesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.alarm_preferences); pref = getSharedPreferences("AppPref", MODE_PRIVATE); email = getIntent().getStringExtra("email"); Log.d("? ???!!! ", "" + email); Bundle bundle = getIntent().getExtras(); if (bundle != null && bundle.containsKey("alarm")) { setMathAlarm((Alarm) bundle.getSerializable("alarm")); } else {/* w w w .ja v a 2 s. c o m*/ setMathAlarm(new Alarm()); } if (bundle != null && bundle.containsKey("adapter")) { setListAdapter((AlarmPreferenceListAdapter) bundle.getSerializable("adapter")); } else { setListAdapter(new AlarmPreferenceListAdapter(this, getMathAlarm())); } getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> l, View v, int position, long id) { final AlarmPreferenceListAdapter alarmPreferenceListAdapter = (AlarmPreferenceListAdapter) getListAdapter(); final AlarmPreference alarmPreference = (AlarmPreference) alarmPreferenceListAdapter .getItem(position); AlertDialog.Builder alert; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); switch (alarmPreference.getType()) { case BOOLEAN: CheckedTextView checkedTextView = (CheckedTextView) v; boolean checked = !checkedTextView.isChecked(); ((CheckedTextView) v).setChecked(checked); switch (alarmPreference.getKey()) { case ALARM_ACTIVE: alarm.setAlarmActive(checked); break; case ALARM_VIBRATE: alarm.setVibrate(checked); if (checked) { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(1000); } break; } alarmPreference.setValue(checked); break; case STRING: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(AlarmPreferencesActivity.this); input.setText(alarmPreference.getValue().toString()); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { alarmPreference.setValue(input.getText().toString()); if (alarmPreference.getKey() == Key.ALARM_NAME) { alarm.setAlarmName(alarmPreference.getValue().toString()); } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] items = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < items.length; i++) items[i] = alarmPreference.getOptions()[i]; alert.setItems(items, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (alarmPreference.getKey()) { case ALARM_DIFFICULTY: Alarm.Difficulty d = Alarm.Difficulty.values()[which]; alarm.setDifficulty(d); break; case ALARM_TONE: alarm.setAlarmTonePath(alarmPreferenceListAdapter.getAlarmTonePaths()[which]); if (alarm.getAlarmTonePath() != null) { if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } else { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); mediaPlayer.reset(); } try { // mediaPlayer.setVolume(1.0f, 1.0f); mediaPlayer.setVolume(0.2f, 0.2f); mediaPlayer.setDataSource(AlarmPreferencesActivity.this, Uri.parse(alarm.getAlarmTonePath())); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setLooping(false); mediaPlayer.prepare(); mediaPlayer.start(); // Force the mediaPlayer to stop after 3 // seconds... if (alarmToneTimer != null) alarmToneTimer.cancel(); alarmToneTimer = new CountDownTimer(3000, 3000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e) { } } }; alarmToneTimer.start(); } catch (Exception e) { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e2) { } } } break; default: break; } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case MULTIPLE_LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] multiListItems = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < multiListItems.length; i++) multiListItems[i] = alarmPreference.getOptions()[i]; boolean[] checkedItems = new boolean[multiListItems.length]; for (Alarm.Day day : getMathAlarm().getDays()) { checkedItems[day.ordinal()] = true; } alert.setMultiChoiceItems(multiListItems, checkedItems, new OnMultiChoiceClickListener() { @Override public void onClick(final DialogInterface dialog, int which, boolean isChecked) { Alarm.Day thisDay = Alarm.Day.values()[which]; if (isChecked) { alarm.addDay(thisDay); } else { // Only remove the day if there are more than 1 // selected if (alarm.getDays().length > 1) { alarm.removeDay(thisDay); } else { // If the last day was unchecked, re-check // it ((AlertDialog) dialog).getListView().setItemChecked(which, true); } } } }); alert.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case TIME: TimePickerDialog timePickerDialog = new TimePickerDialog(AlarmPreferencesActivity.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int hours, int minutes) { Calendar newAlarmTime = Calendar.getInstance(); newAlarmTime.set(Calendar.HOUR_OF_DAY, hours); newAlarmTime.set(Calendar.MINUTE, minutes); newAlarmTime.set(Calendar.SECOND, 0); alarm.setAlarmTime(newAlarmTime); alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }, alarm.getAlarmTime().get(Calendar.HOUR_OF_DAY), alarm.getAlarmTime().get(Calendar.MINUTE), true); timePickerDialog.setTitle(alarmPreference.getTitle()); timePickerDialog.show(); default: break; } } }); }
From source file:com.autburst.picture.MainActivity.java
@Override protected Dialog onCreateDialog(int id) { final Dialog dialog; final Context mContext = this; switch (id) { case DIALOG_CREATE_ALBUM_ID: AlertDialog.Builder builder2 = new AlertDialog.Builder(this); builder2.setTitle(R.string.new_gallery); View view = getLayoutInflater().inflate(R.layout.create_album, null); final EditText edit = (EditText) view.findViewById(R.id.albumNameEditText); final RadioGroup rg = (RadioGroup) view.findViewById(R.id.formatRadioGroup); builder2.setView(view);//from w ww . j a va2s .c o m builder2.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String name = edit.getText().toString(); Log.d(TAG, "Entered name: " + name); // base64 encode string String encodedName = new String(Base64.encodeBase64(name.getBytes())); Log.d(TAG, "base64 encoded name: " + encodedName); // check if album with the same name already exist if (Utilities.existsAlbumName(encodedName)) { // fehler showDialog(DIALOG_ALBUM_NAME_ALREADY_EXIST); return; } // create folder Utilities.getAlbumDirectory(encodedName); // get format int checkedRadioButtonId = rg.getCheckedRadioButtonId(); final Boolean portrait; if (checkedRadioButtonId == R.id.portraitRB) portrait = true; else portrait = false; SharedPreferences settings = getSharedPreferences(Utilities.PIC_STORE, 0); Editor edit2 = settings.edit(); edit2.putBoolean(encodedName + ".portrait", portrait); edit2.putFloat(encodedName + ".frameRate", Utilities.MEDIUM_FRAME_RATE); edit2.commit(); Log.d(TAG, "portrait: " + portrait + " settingsname: " + encodedName + ".portrait frameRate: " + Utilities.MEDIUM_FRAME_RATE); // reset editView edit.setText(""); // update table adapter.add(encodedName); adapter.sort(Utilities.getAlbumNameComparator()); adapter.notifyDataSetChanged(); dialog.dismiss(); controller.transformGUI(MainActivityController.CREATED_ALBUM); } }); builder2.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); // reset editView edit.setText(""); // showDialog(DIALOG_CREATE_ALBUM_ID); } }); AlertDialog create = builder2.create(); dialog = create; break; case DIALOG_ALBUM_NAME_ALREADY_EXIST: AlertDialog.Builder builder3 = new AlertDialog.Builder(this); builder3.setTitle(R.string.warning); builder3.setMessage(R.string.gallery_exists); builder3.setNegativeButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // dialog.dismiss(); showDialog(DIALOG_CREATE_ALBUM_ID); } }); dialog = builder3.create(); break; default: dialog = null; } return dialog; }
From source file:uk.bowdlerize.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.action_add: { AlertDialog.Builder builder = new AlertDialog.Builder(this); // Get the layout inflater LayoutInflater inflater = getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_add_url, null); final EditText urlET = (EditText) dialogView.findViewById(R.id.urlET); builder.setView(dialogView)/*from w w w. j a v a 2 s . co m*/ .setPositiveButton(R.string.action_add, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { Bundle extras = new Bundle(); Intent receiveURLIntent = new Intent(MainActivity.this, CensorCensusService.class); extras.putString("url", urlET.getText().toString()); extras.putString("hash", MD5(urlET.getText().toString())); extras.putInt("urgency", 0); extras.putBoolean("local", true); //Add our extra info if (getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE) .getBoolean("sendISPMeta", true)) { WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); TelephonyManager telephonyManager = ((TelephonyManager) getSystemService( Context.TELEPHONY_SERVICE)); if (wifiMgr.isWifiEnabled() && null != wifiInfo.getSSID()) { LocalCache lc = null; Pair<Boolean, String> seenBefore = null; try { lc = new LocalCache(MainActivity.this); lc.open(); seenBefore = lc.findSSID(wifiInfo.getSSID().replaceAll("\"", "")); } catch (Exception e) { e.printStackTrace(); } if (null != lc) lc.close(); if (seenBefore.first) { extras.putString("isp", seenBefore.second); } else { extras.putString("isp", "unknown"); } try { extras.putString("sim", telephonyManager.getSimOperatorName()); } catch (Exception e) { e.printStackTrace(); } } else { try { extras.putString("isp", telephonyManager.getNetworkOperatorName()); } catch (Exception e) { e.printStackTrace(); } try { extras.putString("sim", telephonyManager.getSimOperatorName()); } catch (Exception e) { e.printStackTrace(); } } } receiveURLIntent.putExtras(extras); startService(receiveURLIntent); dialog.cancel(); } }).setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.show(); return true; } } return super.onOptionsItemSelected(item); }
From source file:com.chaturs.notepad.NoteEditor.java
private void showDialogForTitle() { View view = LayoutInflater.from(this).inflate(R.layout.dialog_title, null); final EditText edit = (EditText) view.findViewById(R.id.edit); Button okButton = (Button) view.findViewById(R.id.ok); Button cancelButton = (Button) view.findViewById(R.id.cancel); edit.setText(title);/*from w w w . ja va2s . c om*/ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Enter Title"); builder.setView(view); builder.setCancelable(false); okButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { title = edit.getText().toString(); if (title.trim().length() == 0) { edit.setError("Please Enter Some Text !"); return; } saveNote(); setTitle(title); dialog.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); dialog = builder.create(); dialog.show(); }
From source file:org.telegram.ui.myLocationSettingsActivity.java
@Override public View createView(LayoutInflater inflater) { if (fragmentView == null) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle("My Places"); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/* w w w . j a va2s . co m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); listAdapter = new ListAdapter(getParentActivity()); fragmentView = new FrameLayout(getParentActivity()); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(0xfff0f0f0); ListView listView = new ListView(getParentActivity()); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; listView.setLayoutParams(layoutParams); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == homeRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle("Home"); final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(50, 30); final EditText input = new EditText(getParentActivity()); input.setHint("Insert city"); input.setLayoutParams(lparams); builder.setView(input); builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (input.getText().toString().trim().length() > 0) { String city = input.getText().toString().trim(); try { Bundle locationHome = new getCoordinates().execute(city).get(); String latHome = locationHome.getString("lat"); String lonHome = locationHome.getString("lon"); SharedPreferences sharedPreferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("latHome", latHome); editor.putString("longHome", lonHome); editor.commit(); Log.i(TAG, "fine! " + lonHome); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } else { Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT) .show(); } } }); builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show(); } }); showAlertDialog(builder); } else if (i == workRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle("Work"); final EditText input = new EditText(getParentActivity()); input.setHint("Insert city"); builder.setView(input); builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (input.getText().toString().trim().length() > 0) { String city = input.getText().toString().trim(); try { Bundle locationWork = new getCoordinates().execute(city).get(); String latWork = locationWork.getString("lat"); String lonWork = locationWork.getString("lon"); SharedPreferences sharedPreferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("latWork", latWork); editor.putString("longWork", lonWork); editor.commit(); Log.i(TAG, "fine! " + latWork); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } else { Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT) .show(); } } }); builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show(); } }); showAlertDialog(builder); } else if (i == entertainmentRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle("Entertainment"); final EditText input = new EditText(getParentActivity()); input.setHint("Insert city"); builder.setView(input); builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (input.getText().toString().trim().length() > 0) { String city = input.getText().toString().trim(); try { Bundle locationEntertainment = new getCoordinates().execute(city).get(); String latEntertainment = locationEntertainment.getString("lat"); String lonEntertainment = locationEntertainment.getString("lon"); SharedPreferences sharedPreferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("latEntertainment", latEntertainment); editor.putString("longEntertainment", lonEntertainment); editor.commit(); Log.i(TAG, "fine! " + latEntertainment); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } else { Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT) .show(); } } }); builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show(); } }); showAlertDialog(builder); } //TODO find a solution for commuteRow as well!! } }); } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } return fragmentView; }
From source file:com.krayzk9s.imgurholo.ui.MessagingFragment.java
private void buildSendMessage(String username) { ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); final EditText newUsername = new EditText(activity); newUsername.setSingleLine();/*from ww w .j a v a 2s.c om*/ newUsername.setHint(R.string.body_hint_recipient); if (username != null) newUsername.setText(username); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_body); newBody.setLines(5); LinearLayout linearLayout = new LinearLayout(activity); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(newUsername); linearLayout.addView(newBody); new AlertDialog.Builder(activity).setTitle(R.string.dialog_send_message_title).setView(linearLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { MessagingAsync messagingAsync = new MessagingAsync(newBody.getText().toString(), newUsername.getText().toString()); messagingAsync.execute(); } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); }