Primer commit, no carga la lista de equipos
parent
7c1e616981
commit
3be0993d1d
@ -0,0 +1,12 @@
|
||||
#Thu Mar 24 20:11:09 CET 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,37 @@
|
||||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*
|
||||
* This class was automatically generated by the
|
||||
* aapt tool from the resource data it found. It
|
||||
* should not be modified by hand.
|
||||
*/
|
||||
|
||||
package com.onirica.carrousel;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class color {
|
||||
public static final int transparent=0x7f040000;
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int icon=0x7f020000;
|
||||
public static final int realmadrid=0x7f020001;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int quit=0x7f070001;
|
||||
public static final int select_team=0x7f070002;
|
||||
public static final int subscribe=0x7f070000;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int list_item=0x7f030000;
|
||||
public static final int main=0x7f030001;
|
||||
public static final int team_selector=0x7f030002;
|
||||
}
|
||||
public static final class menu {
|
||||
public static final int configuration_menu=0x7f060000;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int app_name=0x7f050001;
|
||||
public static final int hello=0x7f050000;
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1" >
|
||||
<ListView android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:drawSelectorOnTop="false"
|
||||
android:cacheColorHint="#00000000"
|
||||
/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:enabled="true" android:title="Select Team" android:visible="true" android:id="@+id/select_team"></item>
|
||||
</menu>
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="transparent">#fff00000</color>
|
||||
</resources>
|
@ -0,0 +1,142 @@
|
||||
package com.onirica.carrousel;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SelectTeam extends ListActivity{
|
||||
public static String baseURL = "http://www.eurielec.etsit.upm.es/~cathan";
|
||||
private HashMap<String, Team> mTeams = new HashMap<String, Team>();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.team_selector);
|
||||
mTeams = retrieveTeams();
|
||||
populateTeams();
|
||||
Log.d("SelectTeam","My teams are: "+mTeams.toString());
|
||||
}
|
||||
|
||||
private void populateTeams() {
|
||||
TeamAdapter adapter = new TeamAdapter((Team[])mTeams.values().toArray(new Team[0]));
|
||||
Log.d("SelectTeam","POPULATING TEAMS");
|
||||
setListAdapter(adapter);
|
||||
}
|
||||
|
||||
private HashMap<String, Team> retrieveTeams() {
|
||||
HashMap<String, Team> teams = new HashMap<String, Team>();
|
||||
try {
|
||||
URL url = new URL(baseURL+"/teams.json");
|
||||
URLConnection urlConnection = url.openConnection();
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
urlConnection.getInputStream()));
|
||||
String line;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while ((line = in.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
String jString = builder.toString();
|
||||
|
||||
JSONObject jObject;
|
||||
jObject = new JSONObject(jString);
|
||||
JSONArray teamsArray = jObject.getJSONArray("teams");
|
||||
Log.d("SelectTeam","TeamsArray: "+teamsArray.toString());
|
||||
|
||||
if (teamsArray == null)
|
||||
throw new Exception("No teams object in json response");
|
||||
for (int i = 0; i < teamsArray.length(); i++) {
|
||||
JSONObject teamsObject = teamsArray.getJSONObject(i);
|
||||
|
||||
String id = teamsObject.getString("id");
|
||||
String crest = teamsObject.getString("crest");
|
||||
Team team = new Team(id, crest);
|
||||
teams.put(team.getId(), team);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.v("Results", "Cannot parse matches json info: " + e.getMessage());
|
||||
}
|
||||
|
||||
return teams;
|
||||
}
|
||||
|
||||
private class TeamAdapter extends BaseAdapter {
|
||||
private Team aTeams[];
|
||||
|
||||
public TeamAdapter(Team teams[]) {
|
||||
super();
|
||||
aTeams = teams;
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
return aTeams.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int pos) {
|
||||
return (Object)aTeams[pos];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int pos) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
private class TeamView extends LinearLayout {
|
||||
private TextView mTv;
|
||||
|
||||
public TeamView(Context context, String text) {
|
||||
super(context);
|
||||
this.setOrientation(HORIZONTAL);
|
||||
this.setBackgroundColor(R.color.transparent);
|
||||
|
||||
mTv = new TextView(context);
|
||||
mTv.setText(text);
|
||||
this.addView(mTv, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
mTv.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int pos, View convertView, ViewGroup parent) {
|
||||
TeamView v;
|
||||
Team team= aTeams[pos];
|
||||
if (convertView == null) {
|
||||
v = new TeamView(parent.getContext(), team.toString());
|
||||
} else {
|
||||
v = (TeamView)convertView;
|
||||
v.setText(team.toString());
|
||||
// This is tricky: We are reusing the view for a different match.
|
||||
// We need to update the view checkbox state and we use setChecked,
|
||||
// but this would trigger the previous event listener, clearing
|
||||
// the model of the previous item shown with this view.
|
||||
/*v.setOnMatchCheckedChanged(null);
|
||||
v.setChecked(isSubscribed);
|
||||
v.setOnMatchCheckedChanged(new OnMatchCheckedListener(pos));*/
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.onirica.carrousel;
|
||||
|
||||
public class Team {
|
||||
private String id;
|
||||
private String crestURL;
|
||||
|
||||
public Team(String id, String crestURL) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.crestURL = crestURL;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getCrestURL() {
|
||||
return crestURL;
|
||||
}
|
||||
public void setCrestURL(String crestURL) {
|
||||
this.crestURL = crestURL;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return id;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue