数据库功能实现
NotesDB(全)?
package com.dj.notepad;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class NotesDB extends SQLiteOpenHelper {
public static final String TABLE_NAME = "notes";
public static final String CONTENT = "content";
public static final String PATH = "path";
public static final String VIDEO = "video";
public static final String ID = "_id";
public static final String TIME = "time";
public NotesDB(Context context) {
super(context, "notes", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT," + CONTENT
+ " TEXT NOT NULL," + PATH + " TEXT NOT NULL," + VIDEO
+ " TEXT NOT NULL," + TIME + " TEXT NOT NULL)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
}
自定义功能实现
Myadapter(全)
package com.dj.notepad;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MyAdapter extends BaseAdapter {
private Context context;
private Cursor cursor;
private LinearLayout layout;
public MyAdapter(Context context, Cursor cursor) {
this.context = context;
this.cursor = cursor;
}
@Override
public int getCount() {
return cursor.getCount();
}
@Override
public Object getItem(int position) {
return cursor.getPosition();
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
layout = (LinearLayout) inflater.inflate(R.layout.cell, null);
//控件按钮
TextView contenttv = (TextView) layout.findViewById(R.id.list_content);
TextView timetv = (TextView) layout.findViewById(R.id.list_time);
ImageView imgiv = (ImageView) layout.findViewById(R.id.list_img);
ImageView videoiv = (ImageView) layout.findViewById(R.id.list_video);
cursor.moveToPosition(position);
String content = cursor.getString(cursor.getColumnIndexOrThrow("content"));
String time = cursor.getString(cursor.getColumnIndexOrThrow("time"));
String url = cursor.getString(cursor.getColumnIndexOrThrow("path"));
String urlvideo = cursor.getString(cursor.getColumnIndexOrThrow("video"));
//set功能
contenttv.setText(content);
timetv.setText(time);
imgiv.setImageBitmap(getImageThumbnail(url, 100, 100));
videoiv.setImageBitmap(getVideoThumbnail(urlvideo, 100, 100,
MediaStore.Images.Thumbnails.MICRO_KIND));
return layout;
}
/** ListView 显示图片*/
public Bitmap getImageThumbnail(String uri, int width, int height) {
Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inJustDecodeBounds = true;
//bitmap = BitmapFactory.decodeFile(uri, options);
options.inJustDecodeBounds = false;
int beWidth = options.outWidth / width;
int beHeight = options.outHeight / height;
int be = 1;
if (beWidth < beHeight) {
be = beWidth;
} else {
be = beHeight;
}
if (be <= 0) {
be = 1;
}
options.inSampleSize = be;
bitmap = BitmapFactory.decodeFile(uri, options);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
/**视频缩略图*/
private Bitmap getVideoThumbnail(String uri, int width, int height, int kind) {
Bitmap bitmap = null;
bitmap = ThumbnailUtils.createVideoThumbnail(uri, kind);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
}
添加信息功能实现
AddContent(全)
先不整了,等我12月27号考完试之后我再把剩下的代码一次性分享上来吧,有缘人耐心等待。
|