Skip to content

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Brais Gabin committed Jan 7, 2013
1 parent e33a9ec commit 89a169e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ActionBarSherlock
## What is it?
TableFixHeaders is an Android widget to display tables width headers.

## Features

* Adapter class to fill the table in a easy way.

* Own scroll.

* Impulse scroll.

* Recycling of views.

* Shadows when there are more info to scroll.

## Sample
You can download the app test from here:

![QR](https://raw.github.com/InQBarna/TableFixHeaders/master/web/qr.png "Sample")

http://adhoc.inqbarna.com/com.inqbarna.tablefixheaders/TableFixHeaders_Samples.apk

## Screenshots
![Screenshot 1](https://raw.github.com/InQBarna/TableFixHeaders/master/web/screen1.png "Screenshot 1")
![Screenshot 2](https://raw.github.com/InQBarna/TableFixHeaders/master/web/screen2.png "Screenshot 2")

## License

Copyright 2012-2013 InQBarna

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Binary file added web/qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/screen1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/screen2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

3 comments on commit 89a169e

@tnawrin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to add a checkbox column(can add other column) , plz help ..i m trying to figure it out how to add a checkbox column, and how to set action listener on a specific row????

@BraisGabin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be a issue but, you only need to return a checkbox at getItem() when the number of column is what you want.

@tnawrin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package com.inqbarna.tablefixheaders.samples;

import java.util.ArrayList;
import java.util.List;

import com.inqbarna.tablefixheaders.TableFixHeaders;
import com.inqbarna.tablefixheaders.adapters.BaseTableAdapter;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;
public class FamilyTable extends Activity {

private class NexusTypes {
    private final String name;
    private final List<Nexus> list;
    private final String loan1;
    private final String loan2;
    private final String savings;
    private final String great;
    private final String less;
    NexusTypes(String name,String loan1, String loan2, String savings, String great, String less) {
        this.name = name;
        this.loan1 = loan1;
        this.loan2 = loan2;
        this.savings = savings;
        this.great = great;
        this.less = less;
        list = new ArrayList<Nexus>();
    }

    public int size() {
        return list.size();
    }

    public Nexus get(int i) {
        return list.get(i);
    }
}

private class Nexus {
    private final String[] data;

    private Nexus(String name, String company, String version, String api, String storage, String inches, String ram, String x , String y, String z, String u, String v) {
        data = new String[] {
                name,
                company,
                version,
                api,
                storage,
                inches,
                ram ,
                x,
                y,
                z,
                u,
                v};
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.table);

    TableFixHeaders tableFixHeaders = (TableFixHeaders) findViewById(R.id.table);
    BaseTableAdapter baseTableAdapter = new FamilyNexusAdapter(this);


    tableFixHeaders.setAdapter(baseTableAdapter);
}

public class TestAdapter extends BaseTableAdapter {

    @Override
    public int getRowCount() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getColumnCount() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int row, int column, View convertView,
            ViewGroup parent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getWidth(int column) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getHeight(int row) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getItemViewType(int row, int column) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getViewTypeCount() {
        // TODO Auto-generated method stub
        return 0;
    }

}
public class FamilyNexusAdapter extends BaseTableAdapter {

    private final NexusTypes familys[];
    private final String headers[] = {
            "Sl",
            "Id",
            "Member",
            "Item",
            "PA",
            "SC",
            "GS",
            "VS",
            "LTS",
            "-",
            "Absent",
            "Confirm",
    };

    private final int[] widths = {
            40,
            120,
            140,
            60,
            70,
            60,
            60,
            60,
            70,
            10,
            70,
            70

    };
    private final float density;

    public FamilyNexusAdapter(Context context) {
        familys = new NexusTypes[] {
                new NexusTypes("-","Loan1","Loan2","Savings",">>","<<"),

        };

        density = context.getResources().getDisplayMetrics().density;

        familys[0].list.add(new Nexus("1", "000000000", "Moshferaa", "10", "11100", "3.7\"", "11100", "77", "10", "11100", "10", "11100"));
        familys[0].list.add(new Nexus("2", "000000000", "Moshferaa", "10", "11100", "4\"", "11100", "77", "10", "11100", "10", "11100"));
        familys[0].list.add(new Nexus("3", "000000000", "Ice cream Sandwich", "11100", "16 GB", "4.65\"", "1 GB", "77", "10", "11100", "10", "512 MB"));
        familys[0].list.add(new Nexus("4", "000000000", "Ice cream Sandwich", "15", "32 GB", "4.65\"", "1 GB", "77", "10", "512 MB", "10", "512 MB"));
        familys[0].list.add(new Nexus("5", "000000000", "Jelly Bean", "17", "8 GB", "4.7\"", "2 GB", "77", "10", "512 MB", "10", "512 MB"));
        familys[0].list.add(new Nexus("6", "000000000", "Jelly Bean", "17", "16 GB", "4.7\"", "2 GB", "77", "10", "512 MB", "10", "512 MB"));
        familys[0].list.add(new Nexus("7", "000000000", "Moshferaa", "10", "11100", "3.7\"", "11100", "77", "10", "11100", "10", "11100"));
        familys[0].list.add(new Nexus("8", "000000000", "Moshferaa", "10", "11100", "4\"", "11100", "77", "10", "11100", "10", "11100"));
        familys[0].list.add(new Nexus("9", "000000000", "Ice cream Sandwich", "11100", "16 GB", "4.65\"", "1 GB", "77", "10", "11100", "10", "512 MB"));
        familys[0].list.add(new Nexus("10", "000000000", "Moshferaa", "10", "11100", "3.7\"", "11100", "77", "10", "11100", "10", "11100"));
        familys[0].list.add(new Nexus("11", "000000000", "Moshferaa", "10", "11100", "4\"", "11100", "77", "10", "11100", "10", "11100"));
        familys[0].list.add(new Nexus("12", "000000000", "Ice cream Sandwich", "11100", "16 GB", "4.65\"", "1 GB", "77", "10", "11100", "10", "512 MB"));

        /*familys[1].list.add(new Nexus("7", "000000000", "Jelly Bean", "16", "16 GB", "7\"", "1 GB", "77", "10", "512 MB", "10", "512 MB"));
        familys[1].list.add(new Nexus("8", "Asus", "Jelly Bean", "16", "32 GB", "7\"", "1 GB", "Gingerbread", "10", "512 MB", "10", "512 MB"));
        familys[1].list.add(new Nexus("9", "Samsung", "Jelly Bean", "17", "16 GB", "10\"", "2 GB", "Gingerbread", "10", "512 MB", "10", "512 MB"));
        familys[1].list.add(new Nexus("10", "Samsung", "Jelly Bean", "17", "32 GB", "10\"", "2 GB", "Gingerbread", "10", "512 MB", "10", "512 MB"));
        familys[2].list.add(new Nexus("11", "--", "Honeycomb", "13", "--", "--", "--", "--", "--", "------", "--", "--"));
*/  }

    @Override
    public int getRowCount() {
        return 13;
    }

    @Override
    public int getColumnCount() {
        return 11;
    }

    @Override
    public View getView(int row, int column, View convertView, ViewGroup parent) {
        View view;
        switch (getItemViewType(row, column)) {
            case 0:
                view = getFirstHeader(row, column, convertView, parent);
            break;
            case 1:
                view = getHeader(row, column, convertView, parent);
            break;
            case 2:
                view = getFirstBody(row, column, convertView, parent);
            break;
            case 3:
                try{
                    view = getBody(row, column, convertView, parent);
                }catch(Exception exp){
                    Toast.makeText(FamilyTable.this, exp+"", 1000);
                    view = null;
                }
            break;
            case 4:
                view = getFamilyView(row, column, convertView, parent);
            break;
            default:
                throw new RuntimeException("wrongg!!");
        }
        return view;
    }

    private View getFirstHeader(int row, int column, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = getLayoutInflater().inflate(R.layout.item_table_header_first, parent, false);
        }
        ((TextView) convertView.findViewById(android.R.id.text1)).setText(headers[0]);
        return convertView;
    }

    private View getHeader(int row, int column, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = getLayoutInflater().inflate(R.layout.item_table_header, parent, false);
        }
        ((TextView) convertView.findViewById(android.R.id.text1)).setText(headers[column + 1]);
        //((CheckBox) convertView.findViewById(android.R.id.text1)).setText(headers[column + 1]);

        return convertView;
    }

    private View getFirstBody(int row, int column, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = getLayoutInflater().inflate(R.layout.item_table_first, parent, false);
        }

        convertView.setBackgroundResource(row % 2 == 0 ? R.drawable.bg_table_color1 : R.drawable.bg_table_color2);
        ((TextView) convertView.findViewById(android.R.id.text1)).setText(getDevice(row).data[column + 1]);
        return convertView;
    }

    private View getBody(int row, int column, View convertView, ViewGroup parent) {


        if(column == 3){
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.item_chkbox, parent, false);
                //((CheckBox) );
            }
            convertView.setBackgroundResource(row % 2 == 0 ? R.drawable.bg_table_color1 : R.drawable.bg_table_color2);

            //((TextView) convertView.findViewById(android.R.id.text1)).setText(getDevice(row).data[column + 1]);
            /*CheckBox cb = new CheckBox(FamilyTable.this);
            convertView.findViewById(id)
            return cb;*/
        }else{
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.item_table, parent, false);
            }

         //  ((CheckBox) convertView.findViewById(android.R.id.text1)).setText(getDevice(row).data[row + 1]);
            convertView.setBackgroundResource(row % 2 == 0 ? R.drawable.bg_table_color1 : R.drawable.bg_table_color2);
            ((TextView) convertView.findViewById(android.R.id.text1)).setText(getDevice(row).data[column + 1]);
        }

        return convertView;
    }

    private View getFamilyView(int row, int column, View convertView, ViewGroup parent) {
        /*if (column == 3 ) {
            //string = getFamily(row).loan1;
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.item_chkbox, parent, false);
            }
            return convertView;
        }*/

        if (convertView == null) {
            convertView = getLayoutInflater().inflate(R.layout.item_table_family, parent, false);
        }
        final String string;
        if (column == -1) {
            string = getFamily(row).name;
        }else if (column == 3 ) {
            string = getFamily(row).loan1;
        }else if (column == 6 ) {
            string = getFamily(row).loan2;
        }else if (column == 9 ) {
            string = getFamily(row).savings;
        }else if (column == 2 || column == 5 || column == 8) {
            string =  getFamily(row).less;
        }else if (column == 4 || column == 7 || column == 10) {
            string =  getFamily(row).great;
        }
        else {
            string = "";
        }
        ((TextView) convertView.findViewById(android.R.id.text1)).setText(string);
        return convertView;
    }

    @Override
    public int getWidth(int column) {
        return Math.round(widths[column + 1] * density);
    }

    @Override
    public int getHeight(int row) {
        final int height;
        if (row == -1) {
            height = 35;
        } else if (isFamily(row)) {
            height = 25;
        } else {
            height = 45;
        }
        return Math.round(height * density);
    }

    @Override
    public int getItemViewType(int row, int column) {
        final int itemViewType;
        if (row == -1 && column == -1) {
            itemViewType = 0;
        } else if (row == -1) {
            itemViewType = 1;
        } else if (isFamily(row)) {
            itemViewType = 4;
        } else if (column == -1) {
            itemViewType = 2;
        }else {
            itemViewType = 3;
        }
        return itemViewType;
    }

    private boolean isFamily(int row) {
        int family = 0;
        while (row > 0) {
            row -= familys[family].size() + 1;
            family++;
        }
        return row == 0;
    }

    private NexusTypes getFamily(int row) {
        int family = 0;
        while (row >= 0) {
            row -= familys[family].size() + 1;
            family++;
        }
        return familys[family - 1];
    }

    private Nexus getDevice(int row) {
        int family = 0;
        while (row >= 0) {
            row -= familys[family].size() + 1;
            family++;
        }
        family--;
        return familys[family].get(row + familys[family].size());
    }

    @Override
    public int getViewTypeCount() {
        return 5;
    }
}

}

this code inserts checkbox, but as scroll to last column it crashes. can u give suggestion?

Please sign in to comment.