Android Open Source - TechDissected Nav Drawer Adapter






From Project

Back to project page TechDissected.

License

The source code is released under:

Apache License

If you think the Android project TechDissected 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.pkmmte.techdissected.adapter;
//from w w  w .  j a va 2 s  .  c om
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.pkmmte.pkrss.Category;
import com.pkmmte.techdissected.R;
import java.util.ArrayList;
import java.util.List;

public class NavDrawerAdapter extends BaseAdapter {
  // Essential Resources
  private final List<Category> mDrawerItems;
  private final Context mContext;

  // Current index and custom fonts
  private int currentPage;
  private int highlightColor;

  public NavDrawerAdapter(Context context) {
    this(context, new ArrayList<Category>());
  }

  public NavDrawerAdapter(Context context, List<Category> drawerItems) {
    this.mDrawerItems = drawerItems;
    this.mContext = context;
    this.currentPage = 0;
    this.highlightColor = context.getResources().getColor(R.color.action_overlay);
  }

  public void addItem(Category drawerItem) {
    mDrawerItems.add(drawerItem);
  }

  public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
    notifyDataSetChanged();
  }

  @Override
  public int getCount() {
    return mDrawerItems.size();
  }

  @Override
  public Category getItem(int position) {
    return mDrawerItems.get(position);
  }

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

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if (convertView == null) {
      LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = mInflater.inflate(R.layout.drawer_item, parent, false);

      holder = new ViewHolder();
      holder.txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);

      convertView.setTag(holder);
    }
    else {
      holder = (ViewHolder) convertView.getTag();
    }

    // Set text
    holder.txtTitle.setText(mDrawerItems.get(position).getName());

    // Highlight if selected
    holder.txtTitle.setBackgroundColor((currentPage == position) ? highlightColor : Color.TRANSPARENT);

    return convertView;
  }

  private class ViewHolder {
    public TextView txtTitle;
  }
}




Java Source Code List

com.pkmmte.techdissected.ApplicationTest.java
com.pkmmte.techdissected.activity.ArticleActivity.java
com.pkmmte.techdissected.activity.MainActivity.java
com.pkmmte.techdissected.activity.SearchActivity.java
com.pkmmte.techdissected.adapter.AuthorAdapter.java
com.pkmmte.techdissected.adapter.CreditsLibraryAdapter.java
com.pkmmte.techdissected.adapter.FeedAdapter.java
com.pkmmte.techdissected.adapter.NavDrawerAdapter.java
com.pkmmte.techdissected.adapter.SettingsAdapter.java
com.pkmmte.techdissected.fragment.AboutFragment.java
com.pkmmte.techdissected.fragment.ArticleFragment.java
com.pkmmte.techdissected.fragment.FavoritesFragment.java
com.pkmmte.techdissected.fragment.FeedFragment.java
com.pkmmte.techdissected.fragment.SettingsFragment.java
com.pkmmte.techdissected.model.Author.java
com.pkmmte.techdissected.model.CreditsLibraryItem.java
com.pkmmte.techdissected.model.ListBuilder.java
com.pkmmte.techdissected.model.SettingsItem.java
com.pkmmte.techdissected.util.Base64DecoderException.java
com.pkmmte.techdissected.util.Base64.java
com.pkmmte.techdissected.util.Constants.java
com.pkmmte.techdissected.util.Dialogs.java
com.pkmmte.techdissected.util.IabException.java
com.pkmmte.techdissected.util.IabHelper.java
com.pkmmte.techdissected.util.IabResult.java
com.pkmmte.techdissected.util.Inventory.java
com.pkmmte.techdissected.util.Purchase.java
com.pkmmte.techdissected.util.RoundTransform.java
com.pkmmte.techdissected.util.Security.java
com.pkmmte.techdissected.util.SkuDetails.java
com.pkmmte.techdissected.util.Utils.java
com.pkmmte.techdissected.view.BakedBezierInterpolator.java
com.pkmmte.techdissected.view.CustomShareActionProvider.java
com.pkmmte.techdissected.view.FlowLayout.java
com.pkmmte.techdissected.view.HeaderGridView.java
com.pkmmte.techdissected.view.PkDrawerLayout.java
com.pkmmte.techdissected.view.PkScrollView.java
com.pkmmte.techdissected.view.PkSwipeRefreshLayout.java
com.pkmmte.techdissected.view.StickyScrollView.java
com.pkmmte.techdissected.view.SwipeProgressBar.java