If you think the Android project caddisfly-app-camera 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
/*
* Copyright (C) TernUp Research Labs/*www.java2s.com*/
*
* This file is part of Caddisfly
*
* Caddisfly is free software: you can redistribute it and modify it under the terms of
* the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
* either version 3 of the License or any later version.
*
* Caddisfly is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License included below for more details.
*
* The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
*/package com.ternup.caddisfly.adapter;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.ternup.caddisfly.R;
import com.ternup.caddisfly.app.MainApp;
import com.ternup.caddisfly.model.NavigationDrawerItem;
import java.util.ArrayList;
publicclass NavDrawerListAdapter extends BaseAdapter {
privatefinal Context context;
privatefinal ArrayList<NavigationDrawerItem> navigationDrawerItems;
public NavDrawerListAdapter(Context context,
ArrayList<NavigationDrawerItem> navigationDrawerItems) {
this.context = context;
this.navigationDrawerItems = navigationDrawerItems;
}
@Override
publicint getCount() {
return navigationDrawerItems.size();
}
@Override
public Object getItem(int position) {
return navigationDrawerItems.get(position);
}
@Override
publiclong getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.row_drawer, parent, false);
}
assert convertView != null;
ImageView iconImage = (ImageView) convertView.findViewById(R.id.icon);
TextView titleText = (TextView) convertView.findViewById(R.id.title);
View lineView = convertView.findViewById(R.id.lineView);
//TODO : hardcoded position to be fixed
if (position == 3) {
lineView.setVisibility(View.VISIBLE);
}
assert context.getApplicationContext() != null;
MainApp mainApp = (MainApp) context.getApplicationContext();
try {
TypedArray a = context.getTheme().obtainStyledAttributes(
mainApp.CurrentTheme, newint[]{R.attr.drawerText});
assert a != null;
int attributeResourceId = a.getResourceId(0, 0);
titleText.setTextColor(context.getResources().getColor(attributeResourceId));
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
try {
TypedArray a = context.getTheme().obtainStyledAttributes(
mainApp.CurrentTheme, newint[]{R.attr.drawerSelector});
assert a != null;
int attributeResourceId = a.getResourceId(0, 0);
convertView.setBackgroundResource(attributeResourceId);
//convertView.setBackground(context.getResources().getDrawable(attributeResourceId));
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
iconImage.setImageResource(navigationDrawerItems.get(position).getIcon());
titleText.setText(navigationDrawerItems.get(position).getTitle());
//Drawable drawable = context.getResources().getDrawable(navigationDrawerItems.get(position).getIcon());
//titleText.setCompoundDrawables(drawable, null, null, null);
return convertView;
}
}