/walkytalky/src/com/googlecode/eyesfree/walkytalky/LocationBookmarker.java

http://eyes-free.googlecode.com/ · Java · 83 lines · 47 code · 16 blank · 20 comment · 2 complexity · b186780b7dabf314a01c259df6dfcb67 MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.googlecode.eyesfree.walkytalky;
  17. import android.app.Activity;
  18. import android.content.SharedPreferences;
  19. import android.content.SharedPreferences.Editor;
  20. import android.os.Bundle;
  21. import android.preference.PreferenceManager;
  22. import android.view.View;
  23. import android.view.View.OnClickListener;
  24. import android.widget.Button;
  25. import android.widget.EditText;
  26. import java.util.ArrayList;
  27. /**
  28. * Enables the user to bookmark their current location
  29. *
  30. * @author clchen@google.com (Charles L. Chen)
  31. */
  32. public class LocationBookmarker extends Activity {
  33. private static final String FAVORITE_DESTINATIONS_PREFS_KEY = "FAVORITE_DESTINATIONS";
  34. private EditText addressEditText;
  35. private Button saveButton;
  36. private ArrayList<String> favoriteDestinations;
  37. private SharedPreferences prefs;
  38. @Override
  39. public void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. String address = getIntent().getExtras().getString("LOCATION");
  42. favoriteDestinations = new ArrayList<String>();
  43. prefs = PreferenceManager.getDefaultSharedPreferences(this);
  44. String[] savedDests = prefs.getString(FAVORITE_DESTINATIONS_PREFS_KEY, "").split("\n");
  45. for (int i = 0; i < savedDests.length; i++) {
  46. favoriteDestinations.add(savedDests[i]);
  47. }
  48. setContentView(R.layout.locationbookmarker);
  49. addressEditText = (EditText) findViewById(R.id.location_EditText);
  50. addressEditText.setText(address);
  51. saveButton = (Button) findViewById(R.id.saveLocation_Button);
  52. saveButton.setOnClickListener(new OnClickListener() {
  53. @Override
  54. public void onClick(View arg0) {
  55. favoriteDestinations.add(0, addressEditText.getText().toString());
  56. String savedDests = "";
  57. for (int i = 0; i < favoriteDestinations.size(); i++) {
  58. savedDests = savedDests + favoriteDestinations.get(i) + "\n";
  59. }
  60. Editor editor = prefs.edit();
  61. editor.putString(FAVORITE_DESTINATIONS_PREFS_KEY, savedDests);
  62. editor.commit();
  63. finish();
  64. }
  65. });
  66. }
  67. }