@Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; int viewType = getItemViewType(position); if (v == null) { if (viewType == HEADER_TYPE) v = LayoutInflater.from(getContext()).inflate(R.layout.list_drawer_header, null, false); else if (viewType == ITEM_TYPE) v = LayoutInflater.from(getContext()).inflate(R.layout.list_drawer_item, null, false); } if (viewType == HEADER_TYPE) { DrawerHeader header = (DrawerHeader) getItem(position); TextView title = (TextView) v.findViewById(R.id.drawer_header_title); switch ((int) getItemId(position)) { case HEADER_CONNECTED_SERVER: if (mProvider.isConnected()) { title.setText(mProvider.getConnectedServerName()); break; } default: title.setText(header.title); break; } } else if (viewType == ITEM_TYPE) { DrawerItem item = (DrawerItem) getItem(position); TextView title = (TextView) v.findViewById(R.id.drawer_item_title); ImageView icon = (ImageView) v.findViewById(R.id.drawer_item_icon); title.setText(item.title); icon.setImageResource(item.icon); boolean enabled = isEnabled(position); // Set text and icon color+alpha based on enabled/disabled state int textColor = title.getCurrentTextColor(); textColor &= 0x00FFFFFF; // Clear alpha bits textColor |= enabled ? 0xFF000000 : 0x55000000; // Set alpha bits depending on whether the state is enabled or disabled title.setTextColor(textColor); icon.setColorFilter(textColor, PorterDuff.Mode.MULTIPLY); } return v; }
@Override public boolean isEnabled(int position) { int viewType = getItemViewType(position); if (viewType == ITEM_TYPE) { switch ((int) getItemId(position)) { case ITEM_SERVER: case ITEM_INFO: case ITEM_ACCESS_TOKENS: case ITEM_PINNED_CHANNELS: return mProvider.isConnected(); case ITEM_LAN: return false; default: return true; } } return false; // Default false for headers }