Android Open Source - Open-file-manager Grid Adapter






From Project

Back to project page Open-file-manager.

License

The source code is released under:

GNU General Public License

If you think the Android project Open-file-manager 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

/*******************************************************************************
 * Copyright (c) 2013 Michele Corazza.//from  w ww . j  a  v a2  s .com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Credits:
 *   Actionbarsherlock library: for the fragment support
 *   Oxygen team: for the gorgeous icons
 ******************************************************************************/
package com.open.file.manager;

import java.io.File;
import java.util.Arrays;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.ImageView;

import com.open.file.manager.IconLoader.AsyncImgLoad;


public class GridAdapter extends BaseAdapter {
  
  private File[] dirfiles;
    private Context mContext;
    private static final FileComparator compare= new FileComparator();
    private IconLoader loader;

    public GridAdapter(Context c, File curdir) {
        mContext = c;
        loader= new IconLoader(mContext);
        dirfiles=curdir.listFiles();
        Arrays.sort(dirfiles, compare);
    }
    
    public void changepath(File newpath)
    {
      dirfiles=newpath.listFiles();
      Arrays.sort(dirfiles, compare);
      notifyDataSetChanged();
    }
    
    @Override
    public boolean hasStableIds()
    {
      return true;
    }
    
    @Override
    public int getCount() {
      return dirfiles.length;
    }
    @Override
    public File getItem(int position) {
      return dirfiles[position];
    }

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

    @Override
    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
      Gridviewholder holder;
        if ( convertView == null )
        {
           LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           convertView = li.inflate(R.layout.grid_item, null); 
           holder=new Gridviewholder();
           holder.filename=(CheckedTextView)convertView.findViewById(R.id.grid_item_text);
           holder.fileicon=(ImageView)convertView.findViewById(R.id.grid_item_image);
           convertView.setTag(holder);
        }
        else
        {
          holder=(Gridviewholder) convertView.getTag();
          holder.fileicon.setImageResource(R.drawable.unknownfile);
        }
        holder.rootview=convertView;
        holder.associatedfile=dirfiles[position];
        holder.position=position;
        CheckedTextView tv = holder.filename;
        File current=holder.associatedfile;
        tv.setText(current.getName());
        tv.setChecked(MainActivity.selectedfiles.contains(current));
        loader.loadIcon(holder, position);   
        if(tv.isChecked())
        {
          convertView.setBackgroundResource(R.color.cyan);
        }
        else
        {
          convertView.setBackgroundResource(R.color.white);
        }
        
        return convertView;
    }
    

    
    
    static public class Gridviewholder
    {
      CheckedTextView filename;
      ImageView fileicon;
      View rootview;
      Integer position;
      File associatedfile;
      AsyncImgLoad loader;
    }
    
    
}




Java Source Code List

com.open.file.manager.Consts.java
com.open.file.manager.CutCopyService.java
com.open.file.manager.FileComparator.java
com.open.file.manager.FileCopyTree.java
com.open.file.manager.FileOperations.java
com.open.file.manager.FragmentAdapter.java
com.open.file.manager.GridAdapter.java
com.open.file.manager.GridFragment.java
com.open.file.manager.IconLoader.java
com.open.file.manager.ListFileAdapter.java
com.open.file.manager.MainActivity.java
com.open.file.manager.SelectPathAdapter.java
com.open.file.manager.SelectPathFragment.java