mirror of
https://github.com/balkian/Carrousel-Android.git
synced 2025-09-03 17:02:22 +00:00
Primer commit, no carga la lista de equipos
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package com.onirica.carrousel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ListActivity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ComponentName;
|
||||
@@ -14,10 +12,12 @@ import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
@@ -38,8 +38,9 @@ public class Configuration extends ListActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
intent = new Intent(getBaseContext(), Results.class);
|
||||
startService(intent);
|
||||
startService(intent);
|
||||
setContentView(R.layout.main);
|
||||
this.getWindow().setBackgroundDrawableResource(R.drawable.realmadrid);
|
||||
conn = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
@@ -89,7 +90,33 @@ public class Configuration extends ListActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
private void close() {
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.configuration_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle item selection
|
||||
switch (item.getItemId()) {
|
||||
case R.id.select_team:
|
||||
showSelect();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void showSelect() {
|
||||
//TODO
|
||||
Intent intent = new Intent(this, SelectTeam.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void close() {
|
||||
unbindService(conn);
|
||||
finish();
|
||||
}
|
||||
@@ -114,6 +141,8 @@ public class Configuration extends ListActivity {
|
||||
public MatchView(Context context, String text, boolean isChecked) {
|
||||
super(context);
|
||||
this.setOrientation(HORIZONTAL);
|
||||
this.setBackgroundColor(R.color.transparent);
|
||||
|
||||
mTv = new TextView(context);
|
||||
mTv.setText(text);
|
||||
mCb = new CheckBox(context);
|
||||
@@ -167,7 +196,9 @@ public class Configuration extends ListActivity {
|
||||
MatchView v;
|
||||
Match match = mMatches[pos];
|
||||
boolean isSubscribed = subscribedMatches.contains(match.getId());
|
||||
|
||||
if(match.localTeam.equals("Real Madrid")||match.visitorTeam.equals("Real Madrid")){
|
||||
isSubscribed=true;
|
||||
}
|
||||
if (convertView == null) {
|
||||
; v = new MatchView(parent.getContext(), match.toString(), isSubscribed);
|
||||
v.setOnMatchCheckedChanged(new OnMatchCheckedListener(pos));
|
||||
|
@@ -66,7 +66,7 @@ public class Results extends Service {
|
||||
private HashMap<String, Match> retrieveMatches() {
|
||||
HashMap<String, Match> matches = new HashMap<String, Match>();
|
||||
try {
|
||||
URL url = new URL("http://192.168.1.10/matches.json");
|
||||
URL url = new URL("http://www.eurielec.etsit.upm.es/~fherrera/matches.json");
|
||||
URLConnection urlConnection = url.openConnection();
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
|
142
src/com/onirica/carrousel/SelectTeam.java
Normal file
142
src/com/onirica/carrousel/SelectTeam.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
29
src/com/onirica/carrousel/Team.java
Normal file
29
src/com/onirica/carrousel/Team.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user