Android Open Source - android-furk-app Files Adapter






From Project

Back to project page android-furk-app.

License

The source code is released under:

Apache License

If you think the Android project android-furk-app 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.simple.furk.adapter;
// ww  w.j a va2s.co  m
import android.content.Context;
import android.widget.BaseAdapter;

import com.simple.furk.APIClient;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;


public abstract class FilesAdapter extends BaseAdapter implements APIClient.APICallback {

    protected final Context context;
    protected JSONArrayChain jArrayChain;


    public FilesAdapter(Context context) {
        super();
        this.context = context;
        jArrayChain = new JSONArrayChain();
    }

    public abstract void Execute(Object... args);


    public JSONObject getJSONObject(int index) throws JSONException {
        return jArrayChain.getJSONObject(index);
    }

    @Override
    public int getCount() {
        return jArrayChain.length();
    }



public class JSONArrayChain {
    private ArrayList<JSONArray> innerList;

    public JSONArrayChain() {
        this.innerList = new ArrayList<JSONArray>();
    }
    public JSONArrayChain(JSONArray jArray) {
        this.innerList = new ArrayList<JSONArray>();
        innerList.add(jArray);
    }

    public void addJSONArray(JSONArray jarray)
    {
        innerList.add(jarray);
    }

    public JSONArray getJSONArray(int index)
    {
        return innerList.get(index);
    }

    public JSONObject getJSONObject(int index) throws JSONException {
        int offset = index;
        JSONArray itemContainer = null;
        Iterator<JSONArray> arrayIterator = innerList.iterator();
        while (arrayIterator.hasNext())
        {
            itemContainer = arrayIterator.next();
            if(offset >= itemContainer.length())
                offset -= itemContainer.length();
            else
                break;
        }

        if(itemContainer != null)
        {
            return itemContainer.getJSONObject(offset);
        }
        else
            throw new JSONException("index out of bounds");
    }

    public int length()
    {
        int l = 0;
        for(JSONArray item : innerList)
        {
            l += item.length();
        }
        return l;
    }

    public void clear()
    {
        innerList.clear();
    }
}
}




Java Source Code List

com.simple.furk.APIClient.java
com.simple.furk.APIUtils.java
com.simple.furk.FileActivity.java
com.simple.furk.FurkServiceGuideExtension.java
com.simple.furk.Furk.java
com.simple.furk.LogExceptionHandler.java
com.simple.furk.LoginActivity.java
com.simple.furk.MainActivity.java
com.simple.furk.NavigationDrawerFragment.java
com.simple.furk.SearchActivity.java
com.simple.furk.SettingsActivity.java
com.simple.furk.adapter.ActiveFilesAdapter.java
com.simple.furk.adapter.FilesAdapter.java
com.simple.furk.adapter.MyFilesAdapter.java
com.simple.furk.adapter.SearchFilesAdapter.java
com.simple.furk.adapter.TFilesAdapter.java