Android Open Source - rtwong-notes Archive Activity






From Project

Back to project page rtwong-notes.

License

The source code is released under:

GNU General Public License

If you think the Android project rtwong-notes 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 ca.ualberta.cs.rtwong_notes;
// ww w.j a  va 2s  . c om
import android.app.Activity;
import android.content.Intent;
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.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.AdapterContextMenuInfo;

// controller of the Archive Activity, separated activity for simplicity
public class ArchiveActivity extends Activity {
  
  private ToDoList todoList;
  
  private ArrayAdapter<ToDo> archiveViewAdapter;
  
  private ListView archiveListView;
  
  private DataManager dataManager;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_archive);
        archiveListView = (ListView) findViewById(R.id.ArchivedTodoList);
  }
  
    @Override
    protected void onStart() {
      super.onStart();
      dataManager = new DataManager(getApplicationContext());
      todoList = this.loadToDoList();
      archiveViewAdapter = new ArrayAdapter<ToDo>(this, R.layout.list_item, todoList.getArchived());
      archiveListView.setAdapter(archiveViewAdapter);
      registerForContextMenu(archiveListView);
    }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.archive, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();    
        // sets the option menu, and starts that activity if it is clicked
        switch (id) {
        case R.id.switchToDo:
          Intent todoIntent = new Intent(this, MainActivity.class);
          saveToDoList(todoList);
          startActivity(todoIntent);
          return true;
        case R.id.switchSummary:
          Intent summaryIntent = new Intent(this, SummaryActivity.class);
          saveToDoList(todoList);
          startActivity(summaryIntent);
          return true;
        case R.id.switchEmail:
          Intent emailIntent = new Intent(this, EmailActivity.class);
          saveToDoList(todoList);
          startActivity(emailIntent);
          return true;
        default:
          return super.onOptionsItemSelected(item);
        }
  }
  
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
      super.onCreateContextMenu(menu, v, menuInfo);  
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.archivepopupmenu, menu);
    }
    
    @Override
    public boolean onContextItemSelected(MenuItem item) {
      AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
      switch(item.getItemId()) {
      case R.id.sendtotodo:
        moveToDo(info);
        return true;
      case R.id.archivepopupremove:
        deleteToDo(info);
        return true;
      default:
        return super.onContextItemSelected(item);
      }
    }
  
    // moves selected item from archive to current
    public void moveToDo(AdapterContextMenuInfo id) {
      ToDo todo = archiveViewAdapter.getItem(id.position);
      todoList.unarchiveToDo(todo);
      this.saveToDoList(todoList);
      archiveViewAdapter.notifyDataSetChanged();
    }
    // deletes selected item from archive
    public void deleteToDo(AdapterContextMenuInfo id) {
      ToDo todo = (ToDo) archiveListView.getItemAtPosition(id.position);
      todoList.removeArchived(todo);
      this.saveToDoList(todoList);
      archiveViewAdapter.notifyDataSetChanged();
    }
  
  public ToDoList loadToDoList() {
    return dataManager.load();
  }
  
  public void saveToDoList(ToDoList todoList) {
    dataManager.save(todoList);
  }
  
  
  
  
  
  
  
  
}




Java Source Code List

ca.ualberta.cs.rtwong_notes.ArchiveActivity.java
ca.ualberta.cs.rtwong_notes.DataManager.java
ca.ualberta.cs.rtwong_notes.EmailActivity.java
ca.ualberta.cs.rtwong_notes.EmailArchived.java
ca.ualberta.cs.rtwong_notes.EmailCurrent.java
ca.ualberta.cs.rtwong_notes.MainActivity.java
ca.ualberta.cs.rtwong_notes.SummaryActivity.java
ca.ualberta.cs.rtwong_notes.ToDoList.java
ca.ualberta.cs.rtwong_notes.ToDo.java