it.tidalwave.bluebill.mobile.android.observation.AndroidTextNoteController Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* $Id: AndroidTextNoteController.java,v 0cdcb7a9f34b 2010/05/29 23:26:46 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.observation;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import it.tidalwave.bluebill.observation.TextNote;
import it.tidalwave.bluebill.mobile.android.R;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class AndroidTextNoteController
{
@Nonnull
private final Activity activity;
@CheckForNull
private TextNote textNote;
public AndroidTextNoteController (final @Nonnull Activity Activity)
{
this.activity = Activity;
}
public void editNote()
{
final LayoutInflater inflater = LayoutInflater.from(activity);
final View view = inflater.inflate(R.layout.observation_note_dialog, null);
final EditText etNote = (EditText)view.findViewById(R.id.etNote);
if (textNote != null)
{
etNote.setText(textNote.stringValue());
}
new AlertDialog.Builder(activity)
.setIcon(android.R.drawable.ic_dialog_info)
.setTitle(R.string.noteHeader)
.setView(view)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener()
{
public void onClick (final @Nonnull DialogInterface dialog, final int whichButton)
{
final String noteText = etNote.getText().toString().trim();
textNote = "".equals(noteText) ? null : new TextNote(noteText);
showFeedback();
}
})
.setNegativeButton(android.R.string.no, null)
.setNeutralButton(R.string.erase, new DialogInterface.OnClickListener()
{
public void onClick (final @Nonnull DialogInterface dialog, final int whichButton)
{
textNote = null;
showFeedback();
}
})
.create().show();
}
@CheckForNull
public TextNote getTextNote()
{
return textNote;
}
private void showFeedback()
{
final int text = (textNote != null) ? R.string.noteUpdated : R.string.noteErased;
Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
}
}