Android Open Source - ScreamDroid Drawer Adapter






From Project

Back to project page ScreamDroid.

License

The source code is released under:

GNU General Public License

If you think the Android project ScreamDroid 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 io.lxl.screamdroid.view;
//from  w  ww  .ja va2 s. c om
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import io.lxl.screamdroid.R;

/**
 * Custom ArrayAdapter to be displayed in the NavigationDrawer
 * Created by pschmitt on 11/18/13.
 */
public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
    Context mContext;
    private ArrayList<DrawerItem> mObjects;

    public DrawerAdapter(Context context, int textViewResourceId, ArrayList<DrawerItem> objects) {
        super(context, textViewResourceId, objects);
        mContext = context;
        int mLayoutResourceId = textViewResourceId;
        mObjects = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        DrawerItem currentItem = mObjects.get(position);

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.drawer_element, null);
            viewHolder = new ViewHolder();
            viewHolder.textView = (TextView) convertView.findViewById(R.id.drawer_txt);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (currentItem != null) {
            viewHolder.textView.setText(currentItem.getTitle());
            viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().getDrawable(currentItem.getDrawableResID()), null, null, null);
        }
        return convertView;
    }

    private class ViewHolder {
        TextView textView;
    }
}




Java Source Code List

io.lxl.screamdroid.AboutActivity.java
io.lxl.screamdroid.MainActivity.java
io.lxl.screamdroid.NavigationDrawerFragment.java
io.lxl.screamdroid.ScreamActivity.java
io.lxl.screamdroid.SettingsActivity.java
io.lxl.screamdroid.SettingsFragment.java
io.lxl.screamdroid.SnippetsActivity.java
io.lxl.screamdroid.util.SystemUiHiderBase.java
io.lxl.screamdroid.util.SystemUiHiderHoneycomb.java
io.lxl.screamdroid.util.SystemUiHider.java
io.lxl.screamdroid.view.DrawerAdapter.java
io.lxl.screamdroid.view.DrawerItem.java