ResourceAdapter.java
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.upc.pbe.upcnews;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
//Modificacio de l'Adapter d'Adnroid, creat al nostre gust per donar estil als elements de la ListView de directoris i arxius
public class ResourceAdapter extends ArrayAdapter<String> {
Context context;
int layoutResourceId;
String[] entries = null;
public ResourceAdapter(Context context, int layoutResourceId, String[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
entries = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView row;
if (convertView == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = (TextView) inflater.inflate(R.layout.rowlayout, parent, false);
}
else {
row = (TextView) convertView;
}
final String text = entries[position];
row.setText(text);
//Si es un m3u8, posem el text en verd
if(text.endsWith(".m3u8")) {
row.setTextColor(Color.parseColor("#5FB404"));
}
//Si no, posem el text en blau
else{
row.setTypeface(null,Typeface.NORMAL);
row.setTextColor(((Activity)context).getResources().getColor(R.color.BlueAndroid));
}
return row;
}
}