Android Open Source - Alfred4Android Match Adapter






From Project

Back to project page Alfred4Android.

License

The source code is released under:

Apache License

If you think the Android project Alfred4Android 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.toraleap.collimator.ui;
/*from w w w.  j a  va2 s  .  c o m*/
import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.toraleap.collimator.R;
import com.toraleap.collimator.data.Match;
import com.toraleap.collimator.util.FileInfo;

/**
 * ???? ListView ?????????????????????
 * @author    uestc.Mobius <mobius@toraleap.com>
 * @version  2010.1104
 */
public final class MatchAdapter extends BaseAdapter {//implements SectionIndexer {
  
  private static final int[] LAYOUT_DEFAULT = { R.layout.listitem_tile_default, R.layout.listitem_icon_default, R.layout.listitem_digest_default };
  private static final int[] LAYOUT_SELECTED = { R.layout.listitem_tile_selected, R.layout.listitem_icon_selected, R.layout.listitem_digest_selected };
  private static final int[] IMAGE_FRAME_THUMBNAIL = { R.drawable.frame_undefined, R.drawable.frame_audio, R.drawable.frame_image, R.drawable.frame_video, R.drawable.frame_text };
  private static final int IMAGE_FRAME_NONE = 0;
  private static final int IMAGE_FRAME_AUDIO = 1;
  private static final int IMAGE_FRAME_IMAGE = 2;
  private static final int IMAGE_FRAME_VIDEO = 3;
  private static final int IMAGE_FRAME_TEXT = 4;
  public static final int LAYOUT_TILE = 0;
  public static final int LAYOUT_ICON = 1;
  public static final int LAYOUT_DIGEST = 2;
  
    private final LayoutInflater mInflater;  
    private final List<Match> mItems;
    private int mSelected = -1;
    private int mLayout = 0;
    
    public MatchAdapter(LayoutInflater inflater, List<Match> items) {
        mInflater = inflater;
        mItems = items;
    }
    
    /**
     * ??????????????????
     * @param layout  ????????(LAYOUT????????)
     */
    public void setLayout(int layout) {
      mLayout = layout;
    }
    
    /**
     * ???????????????????????
     * @param position  ??????
     */
    public void setSelected(int position) {
      mSelected = position;
    }
    
    public boolean areAllItemsEnabled()
    {
        return true;
    }

    public boolean isEnabled(int position)
    {
        return true;
    }
    
  public int getCount() {
    return mItems.size();
  }

  public Object getItem(int position) {
    if (position < mItems.size()) {
      return mItems.get(position);
    } else {
      return null;
    }
  }

  public long getItemId(int position) {
    return position;
  }

  public View getView(int position, View convertView, ViewGroup parent) {
    final Match matchEntry = mItems.get(position);
    View view;
    ViewHolder holder;
    int viewid = position == mSelected ? LAYOUT_SELECTED[mLayout] : LAYOUT_DEFAULT[mLayout]; 
    if (convertView != null && ((ViewHolder)convertView.getTag()).viewId == viewid) {
      view = convertView;
      holder = (ViewHolder)view.getTag();
    } else {
      view = mInflater.inflate(viewid, parent, false);
      holder = new ViewHolder(view, viewid);
      view.setTag(holder);
    }
    holder.updateView(matchEntry);
    return view;
  }
  
//  @Override
//  public int getItemViewType(int position) {
//    return position == mSelected ? 0 : 1; 
//  }
//
//  @Override
//  public int getViewTypeCount() {
//    return 2;
//  }

  private int getFrameType(Match match) {
    String mime = FileInfo.mimeType(match.name());
    if (mime.startsWith("audio/")) return IMAGE_FRAME_AUDIO;
    else if (mime.startsWith("image/")) return IMAGE_FRAME_IMAGE;
    else if (mime.startsWith("video/")) return IMAGE_FRAME_VIDEO;
    else if (mime.startsWith("text/plain")) return IMAGE_FRAME_TEXT;
    else return IMAGE_FRAME_NONE;
  }

//  public int getPositionForSection(int section) {
//    // TODO Auto-generated method stub
//    Log.e("section", String.valueOf(section));
//    return section;
//  }
//
//  public int getSectionForPosition(int position) {
//    Log.e("position", String.valueOf(position));
//    return position;
//  }
//
//  public Object[] getSections() {
//    Log.e("getsections", "getsections");
//    return new Object[]{ "A", "B", "C", "D", "E", "F", "G" };
//  }
//  
  public final class ViewHolder
    {
    public final int viewId;
      public final ImageView thumbnail;
      public final TextView filename;
      public final TextView filepath;
      public final TextView filesize;
      public final TextView filetime;
      public final TextView digest;
      
      public ViewHolder(View v, int viewid) {
      viewId = viewid;
      thumbnail = (ImageView)v.findViewById(R.id.thumbnail);
      filename = (TextView)v.findViewById(R.id.filename);
      filepath = (TextView)v.findViewById(R.id.filepath);
      filesize = (TextView)v.findViewById(R.id.filesize);
      filetime = (TextView)v.findViewById(R.id.filetime);
      digest = (TextView)v.findViewById(R.id.digest);
      }
      
      public void updateView(Match matchEntry) {
      if (null != thumbnail) {
        thumbnail.setImageBitmap(matchEntry.thumbnail());
        thumbnail.setBackgroundResource(IMAGE_FRAME_THUMBNAIL[getFrameType(matchEntry)]);
      }
      if (null != filename) filename.setText(matchEntry.highlightedName());
      if (null != filepath) filepath.setText(matchEntry.path());
      if (null != filesize) filesize.setText(matchEntry.sizeString());
      if (null != filetime) filetime.setText(matchEntry.timeString());
      if (null != digest) digest.setText(matchEntry.digest());        
      }
    }
}




Java Source Code List

android.media.MediaMetadataRetriever.java
com.toraleap.collimator.AppSearchActivity.java
com.toraleap.collimator.GlobalContext.java
com.toraleap.collimator.HelpActivity.java
com.toraleap.collimator.PrefsActivity.java
com.toraleap.collimator.SearchActivity.java
com.toraleap.collimator.ShortcutActivity.java
com.toraleap.collimator.bll.FileScannerService.java
com.toraleap.collimator.bll.TagGenerator.java
com.toraleap.collimator.dal.DBColumns.java
com.toraleap.collimator.dal.DBHelper.java
com.toraleap.collimator.dal.DBOperation.java
com.toraleap.collimator.data.Expression.java
com.toraleap.collimator.data.IndexData.java
com.toraleap.collimator.data.IndexLoader.java
com.toraleap.collimator.data.Index.java
com.toraleap.collimator.data.Match.java
com.toraleap.collimator.data.Matcher.java
com.toraleap.collimator.data.Sorter.java
com.toraleap.collimator.ext.GlobalProvider.java
com.toraleap.collimator.ext.Playlist.java
com.toraleap.collimator.model.BaseTag.java
com.toraleap.collimator.ui.FloatingDialog.java
com.toraleap.collimator.ui.MatchAdapter.java
com.toraleap.collimator.util.DigestUtil.java
com.toraleap.collimator.util.FileInfo.java
com.toraleap.collimator.util.MimeTypeMap.java
com.toraleap.collimator.util.RecursiveFileObserver.java
com.toraleap.collimator.util.ShortcutHelper.java
com.toraleap.collimator.util.SoftCache.java
com.toraleap.collimator.util.ThumbnailUtil.java
com.toraleap.collimator.util.Unicode2Alpha.java