1 |
|
package com.dreamcatcher.bicycle.adapter; |
2 |
|
|
3 |
|
import android.view.LayoutInflater; |
4 |
|
import android.view.View; |
5 |
|
import android.view.View.OnClickListener; |
6 |
|
import android.view.ViewGroup; |
7 |
|
import android.widget.BaseAdapter; |
8 |
|
import android.widget.ImageView; |
9 |
|
import android.widget.TextView; |
10 |
|
|
11 |
|
import com.dreamcatcher.bicycle.BicycleApp; |
12 |
|
import com.dreamcatcher.bicycle.R; |
13 |
|
import com.dreamcatcher.bicycle.util.Constants; |
14 |
|
import com.dreamcatcher.bicycle.util.Utils; |
15 |
|
|
|
|
| 82,5% |
Uncovered Elements: 7 (40) |
Complexity: 10 |
Complexity Density: 0,37 |
|
16 |
|
public class CityListAdapter extends BaseAdapter { |
17 |
|
private LayoutInflater mLayoutInflater = null; |
18 |
|
private int[] cityNameResIdArray = null; |
19 |
|
private ViewHolder mSelectedViewHolder = null; |
20 |
|
private ICityListEvent mCityListEvent; |
21 |
|
private int mDefaultSelection = -1; |
22 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
23 |
4
|
public CityListAdapter(ICityListEvent cityListEvent, int defaultSelectiono){... |
24 |
4
|
cityNameResIdArray = Constants.CitySetting.CITY_NAME_RESID; |
25 |
4
|
mLayoutInflater = LayoutInflater.from(BicycleApp.getInstance()); |
26 |
4
|
mCityListEvent = cityListEvent; |
27 |
4
|
mDefaultSelection = defaultSelectiono; |
28 |
|
} |
29 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
30 |
44
|
public int getCount() {... |
31 |
44
|
return cityNameResIdArray.length; |
32 |
|
} |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
34 |
0
|
public String getItem(int position) {... |
35 |
0
|
return Utils.getText(cityNameResIdArray[position]).toString(); |
36 |
|
} |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0
|
public long getItemId(int position) {... |
39 |
0
|
return position; |
40 |
|
} |
41 |
|
|
|
|
| 88,9% |
Uncovered Elements: 2 (18) |
Complexity: 3 |
Complexity Density: 0,21 |
|
42 |
44
|
public View getView(int position, View convertView, ViewGroup parent) {... |
43 |
44
|
ViewHolder holder = null; |
44 |
44
|
if(convertView == null){ |
45 |
44
|
convertView = mLayoutInflater.inflate(R.layout.select_city_item, parent, false); |
46 |
44
|
holder = new ViewHolder(convertView); |
47 |
44
|
convertView.setTag(holder); |
48 |
|
}else{ |
49 |
0
|
holder = (ViewHolder) convertView.getTag(); |
50 |
|
} |
51 |
|
|
52 |
44
|
holder.cityTextView.setText(Utils.getText(cityNameResIdArray[position])); |
53 |
44
|
if(position == mDefaultSelection){ |
54 |
4
|
holder.selectImageView.setSelected(true); |
55 |
4
|
mSelectedViewHolder = holder; |
56 |
|
|
57 |
|
}else { |
58 |
40
|
holder.selectImageView.setSelected(false); |
59 |
|
} |
60 |
|
|
61 |
44
|
final int index = position; |
62 |
44
|
convertView.setOnClickListener(new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
4
|
public void onClick(View v) {... |
64 |
4
|
CityListAdapter.this.onItemClicked(v, index); |
65 |
|
} |
66 |
|
}); |
67 |
|
|
68 |
44
|
return convertView; |
69 |
|
} |
70 |
|
|
|
|
| 85,7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
71 |
4
|
private void onItemClicked(View view, int index){... |
72 |
4
|
if(mSelectedViewHolder != null){ |
73 |
4
|
mSelectedViewHolder.selectImageView.setSelected(false); |
74 |
|
} |
75 |
4
|
mSelectedViewHolder = (ViewHolder)view.getTag(); |
76 |
4
|
mSelectedViewHolder.selectImageView.setSelected(true); |
77 |
|
|
78 |
4
|
mCityListEvent.onCityItemClicked(index); |
79 |
|
} |
80 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
81 |
|
public interface ICityListEvent{ |
82 |
|
void onCityItemClicked(int index); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,5 |
|
85 |
|
private static class ViewHolder{ |
86 |
|
public TextView cityTextView; |
87 |
|
public ImageView selectImageView; |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
89 |
44
|
public ViewHolder(View parent){... |
90 |
44
|
cityTextView = (TextView) parent.findViewById(R.id.select_city_item_name); |
91 |
44
|
selectImageView = (ImageView) parent.findViewById(R.id.select_city_item_check); |
92 |
|
} |
93 |
|
} |
94 |
|
} |