Android Open Source - Langleo Words






From Project

Back to project page Langleo.

License

The source code is released under:

Apache License

If you think the Android project Langleo 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.atteo.langleo_trial.activities;
/*w ww. j av  a  2 s . co  m*/
import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;

import com.atteo.langleo_trial.R;
import com.atteo.langleo_trial.models.List;
import com.atteo.langleo_trial.models.Word;

public class Words extends ListActivity {
  private SimpleCursorAdapter adapter;
  private List list;

  private Cursor cursor;

  private final int REQUEST_NEW_WORD = 1;
  private final int REQUEST_EDIT_WORD = 2;

  ArrayList<HashMap<String, String>> datalist;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.words_list);

    list = new List();
    list.loadBundle(getIntent().getBundleExtra("list"));

    ListView list = getListView();

    list.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
        editWord((int) id);
      }

    });

    registerForContextMenu(list);

  }

  @Override
  public void onResume() {
    super.onResume();
    refreshList();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.words, menu);
    return true;
  }

  @Override
  public void onCreateContextMenu(ContextMenu menu, View v,
      ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.word, menu);
  }

  @Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
        .getMenuInfo();
    switch (item.getItemId()) {
    case R.id.delete_word:
      deleteWord((int) info.id);
      return true;
    case R.id.edit_word:
      editWord((int) info.id);
      return true;
    default:
      return super.onContextItemSelected(item);
    }

  }

  @Override
  public boolean onOptionsItemSelected(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.new_word:
      Intent intent = new Intent(getApplicationContext(), EditWord.class);
      Word word = new Word();
      word.setList(list);

      intent.putExtra("word", word.toBundle());
      startActivityForResult(intent, REQUEST_NEW_WORD);
      break;
    }
    return true;
  }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == RESULT_CANCELED)
      return;
    Bundle b;
    switch (requestCode) {
    case REQUEST_NEW_WORD:
    case REQUEST_EDIT_WORD:
      b = intent.getBundleExtra("word");
      Word word = new Word();
      word.loadBundle(b);
      word.save();
      refreshList();
      break;

    }
  }

  public void editWord(int id) {
    Intent intent = new Intent(getApplicationContext(), EditWord.class);
    intent.putExtra("word", new Word(id).toBundle());
    startActivityForResult(intent, REQUEST_EDIT_WORD);

  }

  public void deleteWord(int id) {
    new Word(id).delete();
    refreshList();
  }

  public void refreshList() {
    ListView list = getListView();
    datalist = new ArrayList<HashMap<String, String>>();

    this.list.load();
    this.cursor = this.list.getWords().orderByInPlace("word").getCursor();
    adapter = new SimpleCursorAdapter(this, R.layout.word_item,
        this.cursor, new String[] { "word", "translation" }, new int[] {
            R.id.word_word, R.id.word_translation });
    list.setAdapter(adapter);
  }
}




Java Source Code List

com.atteo.langleo_trial.CollectionProgress.java
com.atteo.langleo_trial.ImportData.java
com.atteo.langleo_trial.ImportFile.java
com.atteo.langleo_trial.Langleo.java
com.atteo.langleo_trial.LearningAlgorithm.java
com.atteo.langleo_trial.TaskInfo.java
com.atteo.langleo_trial.TaskManager.java
com.atteo.langleo_trial.activities.Collections.java
com.atteo.langleo_trial.activities.Download.java
com.atteo.langleo_trial.activities.EditCollection.java
com.atteo.langleo_trial.activities.EditList.java
com.atteo.langleo_trial.activities.EditWord.java
com.atteo.langleo_trial.activities.Help.java
com.atteo.langleo_trial.activities.ImportFromFile.java
com.atteo.langleo_trial.activities.Lists.java
com.atteo.langleo_trial.activities.Main.java
com.atteo.langleo_trial.activities.Preferences.java
com.atteo.langleo_trial.activities.SelectFile.java
com.atteo.langleo_trial.activities.SelectList.java
com.atteo.langleo_trial.activities.StackDetails.java
com.atteo.langleo_trial.activities.Study.java
com.atteo.langleo_trial.activities.Updates.java
com.atteo.langleo_trial.activities.Words.java
com.atteo.langleo_trial.algorithms.Olli.java
com.atteo.langleo_trial.models.Collection.java
com.atteo.langleo_trial.models.Language.java
com.atteo.langleo_trial.models.List.java
com.atteo.langleo_trial.models.OlliAnswer.java
com.atteo.langleo_trial.models.OlliFactor.java
com.atteo.langleo_trial.models.Question.java
com.atteo.langleo_trial.models.StudyDay.java
com.atteo.langleo_trial.models.StudySession.java
com.atteo.langleo_trial.models.Word.java
com.atteo.langleo_trial.util.BetterAsyncTask.java
com.atteo.langleo_trial.util.ProgressHandler.java
com.atteo.langleo_trial.views.MainMenuButton.java
com.atteo.langleo_trial.views.NumberPickerButton.java
com.atteo.langleo_trial.views.NumberPicker.java
com.atteo.langleo_trial.views.SelectLimitDialog.java