Android Open Source - firstcodeandroid My Adapter






From Project

Back to project page firstcodeandroid.

License

The source code is released under:

MIT License

If you think the Android project firstcodeandroid 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.vjia.hellonote;
/* w w  w  .j ava 2s .  co m*/
import android.annotation.SuppressLint;
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;
  }

  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.getColumnIndex("content"));
    String time = cursor.getString(cursor.getColumnIndex("time"));
    String url = cursor.getString(cursor.getColumnIndex("path"));
    String urlvideo = cursor.getString(cursor.getColumnIndex("video"));
    contenttv.setText(content);
    timetv.setText(time);
    videoiv.setImageBitmap(getVideoThumbnail(urlvideo, 200, 200,
        MediaStore.Images.Thumbnails.MICRO_KIND));
    imgiv.setImageBitmap(getImageThumbnail(url, 200, 200));
    return layout;
  }

  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;
  }

}




Java Source Code List

com.example.activitylifecycletest.DialogActivity.java
com.example.activitylifecycletest.MainActivity.java
com.example.activitylifecycletest.NormalActivity.java
com.example.activitytest.FirstActivity.java
com.example.listviewtest.FruitAdapter.java
com.example.listviewtest.Fruit.java
com.example.listviewtest.MainActivity.java
com.jikexueyuan.counttime.MainActivity.java
com.jikexueyuan.getmyphonenumber.GetNumber.java
com.jikexueyuan.getmyphonenumber.MainActivity.java
com.jikexueyuan.getmyphonenumber.MyAdapter.java
com.jikexueyuan.getmyphonenumber.PhoneInfo.java
com.vjia.bookcollector.MainActivity.java
com.vjia.coolweather.MainActivity.java
com.vjia.coolweather.activity.ChooseAreaActivity.java
com.vjia.coolweather.activity.WeatherActivity.java
com.vjia.coolweather.db.CoolWeatherDB.java
com.vjia.coolweather.db.CoolWeatherOpenHelper.java
com.vjia.coolweather.model.City.java
com.vjia.coolweather.model.County.java
com.vjia.coolweather.model.Province.java
com.vjia.coolweather.util.HttpCallbackListener.java
com.vjia.coolweather.util.HttpUtil.java
com.vjia.coolweather.util.Utility.java
com.vjia.helloandroid.FirstActivity.java
com.vjia.helloandroid.HelloAndroidActivity.java
com.vjia.hellonote.AddContent.java
com.vjia.hellonote.MainActivity.java
com.vjia.hellonote.MyAdapter.java
com.vjia.hellonote.NotesDB.java
com.vjia.hellonote.SelectAct.java
com.vjia.jokeking.GetJoke.java
com.vjia.jokeking.HttpCallbackListener.java
com.vjia.jokeking.HttpUtil.java
com.vjia.jokeking.Joke.java
com.vjia.jokeking.MainActivity.java
com.vjia.jokeking.MyAdapter.java
com.vjia.locationtest.MainActivity.java