1
0
mirror of https://github.com/balkian/Carrousel-Android.git synced 2024-12-22 13:08:14 +00:00

I12: Enviar lista de partidos subscritos

This commit is contained in:
Fernando Herrera 2011-03-10 01:04:54 +01:00
parent ee90d55080
commit a1b30d37e9
3 changed files with 78 additions and 17 deletions

View File

@ -1,6 +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;
@ -13,9 +15,11 @@ import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
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;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
@ -24,7 +28,11 @@ import android.widget.TextView;
public class Configuration extends ListActivity {
private Results mResults;
private Intent intent;
private ServiceConnection conn;
private ProgressDialog progressDialog;
private HashSet<String> subscribedMatches = new HashSet<String>();
private Button mSubscribeButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
@ -32,7 +40,7 @@ public class Configuration extends ListActivity {
intent = new Intent(getBaseContext(), Results.class);
startService(intent);
setContentView(R.layout.main);
ServiceConnection conn = new ServiceConnection() {
conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
mResults = ((Results.LocalBinder)service).getService();
@ -60,12 +68,36 @@ public class Configuration extends ListActivity {
}
});
progressDialog.show();
Button b = (Button) findViewById(R.id.quit);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
stopService(intent);
quit();
}
});
mSubscribeButton = (Button) findViewById(R.id.subscribe);
mSubscribeButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mResults.updateSubscriptions(subscribedMatches);
close();
}
});
}
private void close() {
unbindService(conn);
finish();
}
private void quit() {
unbindService(conn);
stopService(intent);
finish();
}
private void populateMatches() {
ArrayList<Match> matches = mResults.getMatches();
Match[] ms = new Match[matches.size()];
matches.toArray(ms);
MatchAdapter adapter = new MatchAdapter(ms);
HashMap<String, Match> matches = mResults.getMatches();
MatchAdapter adapter = new MatchAdapter((Match[])matches.values().toArray(new Match[0]));
setListAdapter(adapter);
}
@ -138,7 +170,13 @@ public class Configuration extends ListActivity {
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Do the real stuff here.
Match m = (Match)getItem(mPosition);
if (m != null) {
if (isChecked)
subscribedMatches.remove(mMatches[mPosition].getId());
else
subscribedMatches.add(mMatches[mPosition].getId());
}
}
}

View File

@ -25,9 +25,11 @@ public class Match {
public String visitorTeam;
public State state;
public int min;
public String id;
public ArrayList<Goal> goals;
public Match(String localTeam, String visitorTeam) {
public Match(String id, String localTeam, String visitorTeam) {
this.id = id;
this.localTeam = localTeam;
this.visitorTeam = visitorTeam;
state = State.MATCH_NO_STARTED;
@ -35,7 +37,8 @@ public class Match {
goals = new ArrayList<Goal>();
}
public Match(String localTeam, String visitorTeam, State state, int min) {
public Match(String id, String localTeam, String visitorTeam, State state, int min) {
this.id = id;
this.localTeam = localTeam;
this.visitorTeam = visitorTeam;
this.state = state;
@ -67,4 +70,8 @@ public class Match {
return localTeam + " " + getLocalGoals() + " - " + getVisitorGoals() + " " + visitorTeam;
}
public String getId() {
return id;
}
}

View File

@ -1,6 +1,8 @@
package com.onirica.carrousel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Timer;
import java.util.TimerTask;
@ -11,6 +13,16 @@ import android.os.IBinder;
public class Results extends Service {
private final IBinder mBinder = new LocalBinder();
private HashMap<String, Match> mMatches = new HashMap<String, Match>();
private HashSet<String> mSubscriptions = null;
public HashMap<String, Match> getMatches() {
return mMatches;
}
public void updateSubscriptions(HashSet<String> subscriptions) {
mSubscriptions = subscriptions;
}
public class LocalBinder extends Binder {
Results getService() {
@ -19,6 +31,8 @@ public class Results extends Service {
}
@Override
public IBinder onBind(Intent arg0) {
if (mMatches.isEmpty())
mMatches = retrieveMatches();
return mBinder;
}
@Override
@ -28,22 +42,24 @@ public class Results extends Service {
timer.scheduleAtFixedRate(task, 0, 60000);
}
public ArrayList<Match> getMatches() {
ArrayList<Match> matches = new ArrayList<Match>();
private HashMap<String, Match> retrieveMatches() {
HashMap<String, Match> matches = new HashMap<String, Match>();
Match match = new Match("Deportivo", "Atelico de Madrid");
matches.add(match);
Match match = new Match("bbva1", "Deportivo", "Atelico de Madrid");
matches.put(match.getId(), match);
match = new Match("Betis", "Sevilla");
matches.add(match);
match = new Match("bbva2", "Betis", "Sevilla");
matches.put(match.getId(), match);
match = new Match("Madrid", "Barcelona", Match.State.MATCH_FIRST_ROUND, 13);
match = new Match("bbva3", "Oviedo", "Sporting", Match.State.MATCH_SECOND_ROUND, 84);
match = new Match("bbva13", "Madrid", "Barcelona", Match.State.MATCH_FIRST_ROUND, 13);
Match.Goal goal = match.new Goal(12, true, "Cristiano Ronaldo");
match.addGoal(goal);
matches.add(match);
matches.put(match.getId(), match);
return matches;
}
}
private class pollingTask extends TimerTask {
@Override