Android Open Source - ExpertAndroid Create A Meaning Activity






From Project

Back to project page ExpertAndroid.

License

The source code is released under:

MIT License

If you think the Android project ExpertAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.androidbook.parse;
//w  w  w . j  a  v a  2 s . c  o m
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.parse.ParseException;
import com.parse.SaveCallback;

/*
 * Given a word create a meaning for it.
 * uses layout: create_word_meaning (cwm_)
 */
public class CreateAMeaningActivity 
extends FormActivity 
{
  //Fields
  TextView word;
  TextView wordDetail;
  EditText meaning;
  Word parceledWord;
  
  public CreateAMeaningActivity()  {
    super("CreateAMeaningActivity");
  }

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    parceledWord = getParceledWordFromIntent();
    
    //Make sure this is one ofthe last calls
    setContentView(R.layout.create_word_meaning);
  }

  @Override
  protected void initializeFormFields() 
  {
    word = (TextView)findViewById(R.id.cwm_tv_word);
    wordDetail = (TextView)findViewById(R.id.cwm_tv_wordDetail);
    meaning = (EditText)findViewById(R.id.cwm_et_meaning);
    
    //Only meaning is a required field
    addValidator(new Field(meaning));
    
    //initialize word
    word.setText("Provide meaning for:" + getWordText(parceledWord));
    
    //initalize wordDetail
    wordDetail.setText(getWordDetail(parceledWord));
  }

  private String getWordText(Word pword)
  {
    return pword.getWord();
  }
  private String getWordDetail(Word pword)
  {
    String by = pword.getCreatedByUser().username;
    Date d = pword.getCreatedAt();
    
    DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
    String datestring =  df.format(d);
    
    return by + "/" + datestring;
  }
  private Word getParceledWordFromIntent()
  {
    Intent i = this.getIntent();
    if (i == null)    {
      throw new RuntimeException("Sorry no intent found");
    }
    //intent is available
    ParseObjectWrapper pow = 
      (ParseObjectWrapper)i.getParcelableExtra(Word.t_tablename);
    
    if (pow == null) {
      throw new RuntimeException("ParceledWord not found");
    }
    Word parceledWord = new Word(pow);
    
    reportTransient("Parcelled word recovered");
    return parceledWord;
  }
  
  public void createMeaning(View v)
  {
    if (validateForm() == false)
    {
      return;
    }
    String meaning = getMeaning();
    //form is valid
    WordMeaning wm = new WordMeaning(meaning, parceledWord);
    turnOnProgressDialog("Saving Word Meaning", "We will be right back");
    wm.po.saveInBackground(new SaveCallback() {
      @Override
      public void done(ParseException e) {
        turnOffProgressDialog();
        if (e == null)  {
          //no exception
          wordMeaningSavedSuccessfully();
        }
        else  {
          wordMeaningSaveFailed(e);
        }
      }
    });
  }
  
  private String getMeaning()
  {
    return this.meaning.getText().toString();
  }
  
  private void wordMeaningSaveFailed(ParseException e)
  {
    String error = e.getMessage();
    alert("Saving word failed", error);
  }
  private void wordMeaningSavedSuccessfully()
  {
    //gotoActivity(WordListActivity.class);
    //Don't finish it as back button is valid
    //finish();
    alert("word meaning saved", "Success");
  }
}//eof-class





Java Source Code List

com.androidbook.notebad.NoteEditor.java
com.androidbook.notebad.NotePadProvider.java
com.androidbook.notebad.NotePad.java
com.androidbook.notebad.NotesList.java
com.androidbook.notebad.TitleEditor.java
com.androidbook.parse.BaseActivity.java
com.androidbook.parse.BaseListActivity.java
com.androidbook.parse.CreateAMeaningActivity.java
com.androidbook.parse.CreateAWordActivity.java
com.androidbook.parse.Field.java
com.androidbook.parse.FormActivity.java
com.androidbook.parse.IReportBack.java
com.androidbook.parse.IValidator.java
com.androidbook.parse.IValueValidator.java
com.androidbook.parse.LoginActivity.java
com.androidbook.parse.ParseApplication.java
com.androidbook.parse.ParseObjectWrapperOld1.java
com.androidbook.parse.ParseObjectWrapper.java
com.androidbook.parse.ParseStarterProjectActivity.java
com.androidbook.parse.PasswordFieldRule.java
com.androidbook.parse.PasswordResetActivity.java
com.androidbook.parse.PasswordResetSuccessActivity.java
com.androidbook.parse.SignupActivity.java
com.androidbook.parse.SignupSuccessActivity.java
com.androidbook.parse.StringUtils.java
com.androidbook.parse.UserListActivity.java
com.androidbook.parse.WelcomeActivity.java
com.androidbook.parse.WordListActivity.java
com.androidbook.parse.WordListAdapter.java
com.androidbook.parse.WordMeaningListAdapter.java
com.androidbook.parse.WordMeaning.java
com.androidbook.parse.WordMeaningsListActivity.java
com.androidbook.parse.Word.java
com.iuriio.demos.expertandroid.ch10search.MainActivity.java
com.iuriio.demos.expertandroid.ch10search.SearchActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.MainActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.SearchActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.SimpleSuggestionProvider.java
com.iuriio.demos.expertandroid.ch11searchprovider.SuggestUrlProvider.java
com.iuriio.demos.expertandroid.ch13parsesimple.BaseActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.LoginActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.MainActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseApp.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseObjectWrapper.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseStarterProjectActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.PasswordResetSuccessActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.ResetPasswordActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.SignupActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.StringUtils.java
com.iuriio.demos.expertandroid.ch13parsesimple.WordListActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.Word.java
com.iuriio.demos.expertandroid.ch1circleview.AbstractBaseView.java
com.iuriio.demos.expertandroid.ch1circleview.CircleView.java
com.iuriio.demos.expertandroid.ch1circleview.MainActivity.java
com.iuriio.demos.expertandroid.ch2durationcontrol.DatePickerFragment.java
com.iuriio.demos.expertandroid.ch2durationcontrol.DurationControl.java
com.iuriio.demos.expertandroid.ch2durationcontrol.MainActivity.java
com.iuriio.demos.expertandroid.ch3flowlayout.FlowLayout.java
com.iuriio.demos.expertandroid.ch3flowlayout.MainActivity.java
com.iuriio.demos.expertandroid.ch4gsonserialization.ChildObject.java
com.iuriio.demos.expertandroid.ch4gsonserialization.MainActivity.java
com.iuriio.demos.expertandroid.ch4gsonserialization.MainObject.java
com.iuriio.demos.expertandroid.ch6forms.BaseActivity.java
com.iuriio.demos.expertandroid.ch6forms.Field.java
com.iuriio.demos.expertandroid.ch6forms.FormActivity.java
com.iuriio.demos.expertandroid.ch6forms.IValidator.java
com.iuriio.demos.expertandroid.ch6forms.IValueValidator.java
com.iuriio.demos.expertandroid.ch6forms.MainActivity.java
com.iuriio.demos.expertandroid.ch6forms.PasswordFieldRule.java
com.iuriio.demos.expertandroid.ch6forms.StringUtils.java
com.iuriio.demos.expertandroid.ch6forms.WelcomeActivity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.AbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.AnimatedSimpleTriangleRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20AbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20ControlledAnimatedTexturedCubeRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20SimpleTriangleRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20SingleTextureAbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.FrustumDimensions.java
com.iuriio.demos.expertandroid.ch9openglexperiments.MainActivity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.MyApplication.java
com.iuriio.demos.expertandroid.ch9openglexperiments.OpenGLES10Activity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.OpenGLES20Activity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.PolygonRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.RegularPolygon.java
com.iuriio.demos.expertandroid.ch9openglexperiments.Shape.java
com.iuriio.demos.expertandroid.ch9openglexperiments.SimpleTriangleRenderer.java
converters.FieldTransporter.java
converters.IFieldTransport.java
converters.IntegerFieldTransport.java
converters.ParseObjectEssentials.java
converters.StringFieldTransport.java
converters.User.java
converters.ValueField.java