All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.mobile.android.observation.AndroidTextNoteController Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * blueBill Mobile - Android - open source birding
 * Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * 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.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://bluebill.tidalwave.it/mobile
 * SCM: https://java.net/hg/bluebill-mobile~android-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.observation;

import javax.annotation.Nonnull;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.util.ui.FormProperty;

/***********************************************************************************************************************
 *
 * @stereotype Controller
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
public class AndroidTextNoteController
  {
    @Nonnull
    private final Context context;

//    @CheckForNull
//    private TextNote textNote;
//    
    private FormProperty model;

    public AndroidTextNoteController (final @Nonnull Context context)
      {
        this.context = context;
      }

    public void bind (final @Nonnull FormProperty model)
      {
        this.model = model;
      }

    public void editNote()
      {
        final LayoutInflater inflater = LayoutInflater.from(context);
        final View view = inflater.inflate(R.layout.dialog_observation_note, null);
        final EditText etNote = (EditText)view.findViewById(R.id.etNote);

        etNote.setText(model.getValue());

        new AlertDialog.Builder(context)
            .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)
                  {
                    model.setValue(etNote.getText().toString().trim());
                    showFeedback();
                  }
              })
            .setNegativeButton(android.R.string.no, null)
            .setNeutralButton(R.string.erase, new DialogInterface.OnClickListener()
              {
                public void onClick (final @Nonnull DialogInterface dialog, final int whichButton)
                  {
                    model.setValue(null);
                    showFeedback();
                  }
              })
            .create().show();
      }

    private void showFeedback()
      {
        final int text = (model.getValue() != null) ? R.string.noteUpdated : R.string.noteErased;
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy