Android Open Source - storm-gen Contact Activity






From Project

Back to project page storm-gen.

License

The source code is released under:

Apache License

If you think the Android project storm-gen 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.turbomanage.storm.sample.activity;
/*from   w  w  w  . j a  va2 s  .  c  om*/
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.turbomanage.storm.sample.R;
import com.turbomanage.storm.sample.adapter.ContactAdapter;
import com.turbomanage.storm.sample.loader.ContactLoader;
import com.turbomanage.storm.sample.model.Contact;
import com.turbomanage.storm.sample.model.dao.ContactDao;

import java.util.List;

import de.timroes.android.listview.EnhancedListView;


public class ContactActivity extends ActionBarActivity implements LoaderManager.LoaderCallbacks<List<Contact>> {

    private static final int REQUEST_CODE = 101;

    private EnhancedListView mListView;
  private ContactAdapter mAdapter;
    private ContactDao mContactDao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_contact);
        mListView = (EnhancedListView) findViewById(android.R.id.list);

        mContactDao = new ContactDao(this);

        mListView.setDismissCallback(new EnhancedListView.OnDismissCallback() {
            @Override
            public EnhancedListView.Undoable onDismiss(EnhancedListView enhancedListView, int i) {

                Contact contact = mAdapter.getItem(i);
                mContactDao.delete(contact.getId());
                mAdapter.remove(i);
                return null;
            }
        });

        mListView.enableSwipeToDismiss();
        getSupportLoaderManager().initLoader(1, null, this);
    }
  
  /**
     * The default content for this Activity has a TextView that is shown when
     * the list is empty. If you would like to change the text, call this method
     * to supply the text it should use.
     */
    public void setEmptyText(CharSequence emptyText) {
    if (mListView != null){
      View emptyView = mListView.getEmptyView();

      if (emptyText instanceof TextView) {
        ((TextView) emptyView).setText(emptyText);
      }
    }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.contact, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if(item.getItemId() == R.id.action_add) {

            startActivityForResult(new Intent(this, NewContactActivity.class), REQUEST_CODE);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if(resultCode == NewContactActivity.RESULT_CODE_CREATED){

            getSupportLoaderManager().restartLoader(1, null, this);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public Loader<List<Contact>> onCreateLoader(int id, Bundle args) {
        return new ContactLoader(this);
    }

    @Override
    public void onLoadFinished(Loader<List<Contact>> loader, List<Contact> data) {

        mAdapter = new ContactAdapter(this, data);
        mListView.setAdapter(mAdapter);
    }

    @Override
    public void onLoaderReset(Loader<List<Contact>> loader) {

        setEmptyText("No data");
    }
}




Java Source Code List

com.turbomanage.storm.DatabaseHelper.java
com.turbomanage.storm.ModelBase.java
com.turbomanage.storm.SQLiteDao.java
com.turbomanage.storm.TableHelper.java
com.turbomanage.storm.api.Converter.java
com.turbomanage.storm.api.DatabaseFactory.java
com.turbomanage.storm.api.Database.java
com.turbomanage.storm.api.Entity.java
com.turbomanage.storm.api.Id.java
com.turbomanage.storm.api.Syncable.java
com.turbomanage.storm.api.package-info.java
com.turbomanage.storm.apt.BaseDaoModel.java
com.turbomanage.storm.apt.ClassModel.java
com.turbomanage.storm.apt.ClassProcessor.java
com.turbomanage.storm.apt.ClassTemplate.java
com.turbomanage.storm.apt.MainProcessor.java
com.turbomanage.storm.apt.ProcessorLogger.java
com.turbomanage.storm.apt.SqlUtil.java
com.turbomanage.storm.apt.StormAnnotationException.java
com.turbomanage.storm.apt.StormEnvironment.java
com.turbomanage.storm.apt.converter.ConverterModel.java
com.turbomanage.storm.apt.converter.ConverterProcessor.java
com.turbomanage.storm.apt.converter.ConverterTypeAnnotationValueVisitor.java
com.turbomanage.storm.apt.converter.ConverterTypeAnnotationValuesVisitor.java
com.turbomanage.storm.apt.converter.package-info.java
com.turbomanage.storm.apt.database.DatabaseFactoryTemplate.java
com.turbomanage.storm.apt.database.DatabaseModel.java
com.turbomanage.storm.apt.database.DatabaseProcessor.java
com.turbomanage.storm.apt.database.package-info.java
com.turbomanage.storm.apt.entity.EntityDaoTemplate.java
com.turbomanage.storm.apt.entity.EntityModel.java
com.turbomanage.storm.apt.entity.EntityProcessor.java
com.turbomanage.storm.apt.entity.FieldModel.java
com.turbomanage.storm.apt.entity.TableHelperTemplate.java
com.turbomanage.storm.apt.entity.package-info.java
com.turbomanage.storm.csv.CsvTableReader.java
com.turbomanage.storm.csv.CsvTableWriter.java
com.turbomanage.storm.csv.CsvUtils.java
com.turbomanage.storm.csv.package-info.java
com.turbomanage.storm.exception.TooManyResultsException.java
com.turbomanage.storm.exception.TypeNotSupportedException.java
com.turbomanage.storm.exception.package-info.java
com.turbomanage.storm.query.Query.java
com.turbomanage.storm.query.package-info.java
com.turbomanage.storm.sample.activity.ContactActivity.java
com.turbomanage.storm.sample.activity.NewContactActivity.java
com.turbomanage.storm.sample.adapter.ContactAdapter.java
com.turbomanage.storm.sample.database.SampleDatabaseHelper.java
com.turbomanage.storm.sample.loader.AbstractAsyncTaskLoader.java
com.turbomanage.storm.sample.loader.ContactLoader.java
com.turbomanage.storm.sample.model.Contact.java
com.turbomanage.storm.types.BlobConverter.java
com.turbomanage.storm.types.BooleanConverter.java
com.turbomanage.storm.types.ByteConverter.java
com.turbomanage.storm.types.CharConverter.java
com.turbomanage.storm.types.DateConverter.java
com.turbomanage.storm.types.DoubleConverter.java
com.turbomanage.storm.types.EnumConverter.java
com.turbomanage.storm.types.FloatConverter.java
com.turbomanage.storm.types.IntegerConverter.java
com.turbomanage.storm.types.LongConverter.java
com.turbomanage.storm.types.PrimitiveConverter.java
com.turbomanage.storm.types.ShortConverter.java
com.turbomanage.storm.types.StringConverter.java
com.turbomanage.storm.types.TypeConverter.java
com.turbomanage.storm.types.package-info.java
com.turbomanage.storm.package-info.java