|
15 | 15 | import java.util.List; |
16 | 16 |
|
17 | 17 | public class CustomSpinnerAdapter extends ArrayAdapter<RowItem> { |
18 | | - |
19 | | - private int spinner = R.id.spinnerview; |
20 | | - private String TAG = "CustomSpinnerAdapter"; |
21 | | - private LayoutInflater flater; |
22 | | - |
23 | | - CustomSpinnerAdapter(Activity context, int resouceId, int textviewId, List<RowItem> list) { |
24 | | - |
25 | | - super(context, resouceId, textviewId, list); |
26 | | - flater = context.getLayoutInflater(); |
27 | | - } |
28 | | - |
29 | | - @Override |
30 | | - public View getView(int position, View convertView, ViewGroup parent) { |
31 | | - |
32 | | - RowItem rowItem = getItem(position); |
33 | | - |
34 | | - View rowview = flater.inflate(R.layout.listitems_layout, null, true); |
35 | | - |
36 | | - TextView txtTitle = (TextView) rowview.findViewById(spinner); |
37 | | - txtTitle.setText(rowItem.getTitle()); |
38 | | - txtTitle.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); |
39 | | - if (position == 0) return rowview; |
40 | | - try { |
41 | | - //Log.d(TAG, "getView: tf string is " + rowItem.getTitleFont(position)); |
42 | | - //Log.d(TAG, "getView: identifier is " + getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName())); |
43 | | - //Log.d(TAG, "getView: typefont is " + ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName()))); |
44 | | - txtTitle.setTypeface(ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName()))); |
45 | | - } catch (Exception e) { |
46 | | - Log.e(TAG, "getView: error occured while determiting font", e); |
47 | | - } |
48 | | - return rowview; |
49 | | - } |
50 | | - |
51 | | - @Override |
52 | | - public View getDropDownView(int position, View view, ViewGroup parent) { |
53 | | - if (view == null) { |
54 | | - view = flater.inflate(R.layout.listitems_layout, parent, false); |
55 | | - } |
56 | | - RowItem rowItem = getItem(position); |
57 | | - TextView txtTitle = (TextView) view.findViewById(spinner); |
58 | | - txtTitle.setText(rowItem.getTitle()); |
59 | | - txtTitle.setTypeface(rowItem.getTypeface()); |
60 | | - return view; |
61 | | - } |
| 18 | + |
| 19 | + private int spinner = R.id.spinnerview; |
| 20 | + private String TAG = "CustomSpinnerAdapter"; |
| 21 | + private LayoutInflater flater; |
| 22 | + |
| 23 | + CustomSpinnerAdapter(Activity context, int resouceId, int textviewId, List<RowItem> list) { |
| 24 | + |
| 25 | + super(context, resouceId, textviewId, list); |
| 26 | + flater = context.getLayoutInflater(); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public View getView(int position, View convertView, ViewGroup parent) { |
| 31 | + |
| 32 | + RowItem rowItem = getItem(position); |
| 33 | + |
| 34 | + View rowview = flater.inflate(R.layout.listitems_layout, null, true); |
| 35 | + |
| 36 | + TextView txtTitle = rowview.findViewById(spinner); |
| 37 | + txtTitle.setText(rowItem.getTitle()); |
| 38 | + txtTitle.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); |
| 39 | + if (position == 0) return rowview; |
| 40 | + try { |
| 41 | + //Log.d(TAG, "getView: tf string is " + rowItem.getTitleFont(position)); |
| 42 | + //Log.d(TAG, "getView: identifier is " + getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName())); |
| 43 | + //Log.d(TAG, "getView: typefont is " + ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName()))); |
| 44 | + txtTitle.setTypeface(ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName()))); |
| 45 | + } catch (Exception e) { |
| 46 | + Log.e(TAG, "getView: error occured while determiting font", e); |
| 47 | + } |
| 48 | + return rowview; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public View getDropDownView(int position, View view, ViewGroup parent) { |
| 53 | + if (view == null) { |
| 54 | + view = flater.inflate(R.layout.listitems_layout, parent, false); |
| 55 | + } |
| 56 | + RowItem rowItem = getItem(position); |
| 57 | + TextView txtTitle = view.findViewById(spinner); |
| 58 | + txtTitle.setText(rowItem.getTitle()); |
| 59 | + txtTitle.setTypeface(rowItem.getTypeface()); |
| 60 | + return view; |
| 61 | + } |
62 | 62 | } |
63 | 63 |
|
64 | 64 |
|
65 | 65 | class RowItem { |
66 | | - |
67 | | - private final static String TAG = "rowitem"; |
68 | | - private String title; |
69 | | - private Typeface typeface; |
70 | | - private int visibility; |
71 | | - |
72 | | - RowItem(Context context, String title, int position) { |
73 | | - this.title = title; |
74 | | - if (position == 0) { |
75 | | - typeface = Typeface.defaultFromStyle(Typeface.NORMAL); |
76 | | - return; |
77 | | - } |
78 | | - try { |
79 | | - //Log.d(TAG, "getView: tf string is " + rowItem.getTitleFont(position)); |
80 | | - //Log.d(TAG, "getView: identifier is " + getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName())); |
81 | | - //Log.d(TAG, "getView: typefont is " + ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName()))); |
82 | | - typeface = ResourcesCompat.getFont(context, context.getResources().getIdentifier(getTitleFont(position), "font", context.getPackageName())); |
83 | | - } catch (Exception e) { |
84 | | - Log.e(TAG, "getView: error occured while determiting font "+title, e); |
85 | | - //visibility = View.GONE; |
86 | | - visibility = View.INVISIBLE; |
87 | | - } |
88 | | - } |
89 | | - |
90 | | - String getTitle() { |
91 | | - return title; |
92 | | - } |
93 | | - |
94 | | - String getTitleFont(int position) { |
95 | | - return ClockWidgetProvider.fonts.get(position).replace(" ", "_"); |
96 | | - } |
97 | 66 |
|
98 | | - Typeface getTypeface() { |
99 | | - return typeface; |
100 | | - } |
| 67 | + private final static String TAG = "rowitem"; |
| 68 | + private String title; |
| 69 | + private Typeface typeface; |
| 70 | + private int visibility; |
| 71 | + |
| 72 | + RowItem(Context context, String title, int position) { |
| 73 | + this.title = title; |
| 74 | + if (position == 0) { |
| 75 | + typeface = Typeface.defaultFromStyle(Typeface.NORMAL); |
| 76 | + return; |
| 77 | + } |
| 78 | + try { |
| 79 | + //Log.d(TAG, "getView: tf string is " + rowItem.getTitleFont(position)); |
| 80 | + //Log.d(TAG, "getView: identifier is " + getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName())); |
| 81 | + //Log.d(TAG, "getView: typefont is " + ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName()))); |
| 82 | + typeface = ResourcesCompat.getFont(context, context.getResources().getIdentifier(getTitleFont(position), "font", context.getPackageName())); |
| 83 | + } catch (Exception e) { |
| 84 | + Log.e(TAG, "getView: error occured while determiting font " + title, e); |
| 85 | + //visibility = View.GONE; |
| 86 | + visibility = View.INVISIBLE; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + String getTitle() { |
| 91 | + return title; |
| 92 | + } |
| 93 | + |
| 94 | + String getTitleFont(int position) { |
| 95 | + return ClockWidgetProvider.fonts.get(position).replace(" ", "_"); |
| 96 | + } |
| 97 | + |
| 98 | + Typeface getTypeface() { |
| 99 | + return typeface; |
| 100 | + } |
101 | 101 |
|
102 | | - int getVisibility() { |
103 | | - return visibility; |
104 | | - } |
| 102 | + int getVisibility() { |
| 103 | + return visibility; |
| 104 | + } |
105 | 105 |
|
106 | | - @Override |
107 | | - public String toString() { |
108 | | - return title; |
109 | | - } |
| 106 | + @Override |
| 107 | + public String toString() { |
| 108 | + return title; |
| 109 | + } |
110 | 110 | } |
0 commit comments