PlacemarkActivity.java :  » GPS » etracks » com » etracks » gui » Android Open Source

Android Open Source » GPS » etracks 
etracks » com » etracks » gui » PlacemarkActivity.java
/**
 *   Copyright 2009 Pau Haro
 * 
 *  This file is part of eTracks.
 *
 *  eTracks is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  eTracks is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *  along with eTracks.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.etracks.gui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.etracks.R;
import com.etracks.domini.CtrlPlacemark;

public class PlacemarkActivity extends Activity {
  
  private CtrlPlacemark placemarkCtrl;
  
  private long routeId;
  private long placemarkId;
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        routeId = this.getIntent().getLongExtra("route_id", -1); // XXX valor per defecte?
        placemarkId = this.getIntent().getLongExtra("placemark_id", -1);
        if (placemarkId == -1)
          placemarkCtrl = new CtrlPlacemark(routeId, this);
        else
          placemarkCtrl = new CtrlPlacemark(routeId, placemarkId, this);
        
        // GUI
        setContentView(R.layout.placemark);
        
        // Text inputs initialized
    final EditText markerNameEdit = (EditText) findViewById(R.id.placemark_name);
    markerNameEdit.setText(placemarkCtrl.getName());
    
    final EditText markerDescEdit = (EditText) findViewById(R.id.placemark_desc);
    markerDescEdit.setText(placemarkCtrl.getDesc());
        
        // Buttons
        Button saveButton = (Button)this.findViewById(R.id.save_placemark);
        saveButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        placemarkCtrl.save(
            markerNameEdit.getText().toString(),
            markerDescEdit.getText().toString());
        
          Intent intent = new Intent();
        intent.putExtra("msg", getString(R.string.placemark_saved));
        setResult(RESULT_OK, intent);
        
        finish();
      }
        });
        
        Button deleteButton = (Button)this.findViewById(R.id.delete_placemark);
        deleteButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        placemarkCtrl.delete();
        
          Intent intent = new Intent();
        intent.putExtra("msg", getString(R.string.placemark_deleted));
        setResult(RESULT_OK, intent);
        
        finish();
      }
        });
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.