/walkytalky/src/com/googlecode/eyesfree/walkytalky/LocationBookmarker.java
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 17package com.googlecode.eyesfree.walkytalky; 18 19import android.app.Activity; 20import android.content.SharedPreferences; 21import android.content.SharedPreferences.Editor; 22import android.os.Bundle; 23import android.preference.PreferenceManager; 24import android.view.View; 25import android.view.View.OnClickListener; 26import android.widget.Button; 27import android.widget.EditText; 28 29import java.util.ArrayList; 30 31/** 32 * Enables the user to bookmark their current location 33 * 34 * @author clchen@google.com (Charles L. Chen) 35 */ 36 37public class LocationBookmarker extends Activity { 38 private static final String FAVORITE_DESTINATIONS_PREFS_KEY = "FAVORITE_DESTINATIONS"; 39 40 private EditText addressEditText; 41 42 private Button saveButton; 43 44 private ArrayList<String> favoriteDestinations; 45 46 private SharedPreferences prefs; 47 48 @Override 49 public void onCreate(Bundle savedInstanceState) { 50 super.onCreate(savedInstanceState); 51 52 String address = getIntent().getExtras().getString("LOCATION"); 53 54 favoriteDestinations = new ArrayList<String>(); 55 prefs = PreferenceManager.getDefaultSharedPreferences(this); 56 String[] savedDests = prefs.getString(FAVORITE_DESTINATIONS_PREFS_KEY, "").split("\n"); 57 for (int i = 0; i < savedDests.length; i++) { 58 favoriteDestinations.add(savedDests[i]); 59 } 60 61 setContentView(R.layout.locationbookmarker); 62 63 addressEditText = (EditText) findViewById(R.id.location_EditText); 64 addressEditText.setText(address); 65 66 saveButton = (Button) findViewById(R.id.saveLocation_Button); 67 saveButton.setOnClickListener(new OnClickListener() { 68 @Override 69 public void onClick(View arg0) { 70 favoriteDestinations.add(0, addressEditText.getText().toString()); 71 String savedDests = ""; 72 for (int i = 0; i < favoriteDestinations.size(); i++) { 73 savedDests = savedDests + favoriteDestinations.get(i) + "\n"; 74 } 75 Editor editor = prefs.edit(); 76 editor.putString(FAVORITE_DESTINATIONS_PREFS_KEY, savedDests); 77 editor.commit(); 78 finish(); 79 } 80 }); 81 } 82 83}