Android Open Source - Android-ORM Detail Activity






From Project

Back to project page Android-ORM.

License

The source code is released under:

Apache License

If you think the Android project Android-ORM 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

/**
 * //from  ww  w.  j a  v a  2s  . c om
 */
package cn.ieclipse.aorm.example;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;
import cn.ieclipse.aorm.Session;

/**
 * @author Jamling
 * 
 */
public abstract class DetailActivity extends BaseActivity {
    
    protected long id;
    protected EditText etIndex;
    protected Session session;
    
    @Override
    protected void initIntent(Intent intent, Bundle savedInstanceState) {
        id = getIntent().getLongExtra(Intent.EXTRA_UID, 0);
        if (savedInstanceState != null) {
            id = savedInstanceState.getLong(Intent.EXTRA_UID);
        }
    }
    
    @Override
    protected void onResume() {
        super.onResume();
    }
    
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // menu.findItem(R.id.menu_edit).setVisible(true);
        // menu.findItem(R.id.menu_delete).setVisible(true);
        // menu.findItem(R.id.menu_save).setVisible(true);
        if (id == 0) {
            menu.findItem(R.id.menu_edit).setVisible(false);
            menu.findItem(R.id.menu_delete).setVisible(false);
        }
        else {
            menu.findItem(R.id.menu_save).setVisible(false);
        }
        return super.onPrepareOptionsMenu(menu);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.detail_menu, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.menu_save) {
            if (save()) {
                updateOptionMenu();
                etIndex.setText(String.valueOf(id));
                Toast.makeText(this, "Save successfully!", Toast.LENGTH_SHORT)
                        .show();
            }
        }
        else if (item.getItemId() == R.id.menu_edit) {
            if (edit()) {
                updateOptionMenu();
                Toast.makeText(this, "Update successfully!", Toast.LENGTH_SHORT)
                        .show();
            }
        }
        else if (item.getItemId() == R.id.menu_delete) {
            if (delete()) {
                updateOptionMenu();
                id = 0;
                etIndex.setText(String.valueOf(id));
                Toast.makeText(this, "Delete successfully!", Toast.LENGTH_SHORT)
                        .show();
            }
        }
        return super.onOptionsItemSelected(item);
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putLong(Intent.EXTRA_UID, id);
        super.onSaveInstanceState(outState);
    }
    
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    protected void updateOptionMenu() {
        invalidateOptionsMenu();
    }
    
    protected abstract int getLayout();
    
    protected abstract boolean delete();
    
    protected abstract boolean edit();
    
    protected abstract boolean save();
}




Java Source Code List

android.content.ContentResolver.java
android.content.ContentValues.java
android.database.ContentObserver.java
android.database.Cursor.java
android.database.sqlite.SQLiteDatabase.java
android.database.sqlite.SQLiteOpenHelper.java
android.net.Uri.java
android.os.Handler.java
android.util.FastPrintWriter.java
android.util.Log.java
android.util.Printer.java
cn.ieclipse.aorm.Aorm.java
cn.ieclipse.aorm.Criteria.java
cn.ieclipse.aorm.CursorUtils.java
cn.ieclipse.aorm.Mapping.java
cn.ieclipse.aorm.ORMException.java
cn.ieclipse.aorm.Order.java
cn.ieclipse.aorm.Restrictions.java
cn.ieclipse.aorm.SessionObserver.java
cn.ieclipse.aorm.Session.java
cn.ieclipse.aorm.annotation.ColumnWrap.java
cn.ieclipse.aorm.annotation.Column.java
cn.ieclipse.aorm.annotation.TableWrap.java
cn.ieclipse.aorm.annotation.Table.java
cn.ieclipse.aorm.example.AbstractBaseAdapter.java
cn.ieclipse.aorm.example.BaseActivity.java
cn.ieclipse.aorm.example.CourseDetailActivity.java
cn.ieclipse.aorm.example.CourseListActivity.java
cn.ieclipse.aorm.example.DetailActivity.java
cn.ieclipse.aorm.example.ExampleApplication.java
cn.ieclipse.aorm.example.ExampleContentProvider.java
cn.ieclipse.aorm.example.ListActivity.java
cn.ieclipse.aorm.example.MainActivity.java
cn.ieclipse.aorm.example.StudentDetailActivity.java
cn.ieclipse.aorm.example.StudentGradeActivity.java
cn.ieclipse.aorm.example.StudentGradeDetailActivity.java
cn.ieclipse.aorm.example.StudentListActivity.java
cn.ieclipse.aorm.example.bean.Course.java
cn.ieclipse.aorm.example.bean.Grade.java
cn.ieclipse.aorm.example.bean.Student.java