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

Primer commit, no carga la lista de equipos

This commit is contained in:
Fernando Sánchez 2011-03-30 17:26:20 +02:00
parent 7c1e616981
commit 3be0993d1d
42 changed files with 290 additions and 13 deletions

View File

@ -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

View File

@ -15,6 +15,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<service android:name="Results"></service> <service android:name="Results"></service>
<activity android:name="SelectTeam"></activity>
</application> </application>
</manifest> </manifest>

BIN
bin/Carrousel.apk Normal file

Binary file not shown.

BIN
bin/classes.dex Normal file

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.

BIN
bin/resources.ap_ Normal file

Binary file not shown.

View File

@ -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

View File

@ -10,16 +10,14 @@
<ListView android:id="@android:id/list" <ListView android:id="@android:id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:drawSelectorOnTop="false"/> android:drawSelectorOnTop="false"
android:cacheColorHint="#00000000"
/>
</FrameLayout> </FrameLayout>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_height="wrap_content" android:layout_width="match_parent"> android:layout_height="wrap_content" android:layout_width="match_parent">
<Button android:layout_width="wrap_content" android:text="Subscribe to selected matches" android:layout_height="wrap_content" android:id="@+id/subscribe"></Button>
<Button android:id="@+id/subscribe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subscribe to selected matches"/>
<Button android:id="@+id/quit" <Button android:id="@+id/quit"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -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>

View File

@ -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>

4
res/values/colors.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#fff00000</color>
</resources>

View File

@ -1,10 +1,8 @@
package com.onirica.carrousel; package com.onirica.carrousel;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import android.app.Activity;
import android.app.ListActivity; import android.app.ListActivity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.ComponentName; import android.content.ComponentName;
@ -14,10 +12,12 @@ import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
@ -38,8 +38,9 @@ public class Configuration extends ListActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
intent = new Intent(getBaseContext(), Results.class); intent = new Intent(getBaseContext(), Results.class);
startService(intent); startService(intent);
setContentView(R.layout.main); setContentView(R.layout.main);
this.getWindow().setBackgroundDrawableResource(R.drawable.realmadrid);
conn = new ServiceConnection() { conn = new ServiceConnection() {
@Override @Override
public void onServiceConnected(ComponentName className, IBinder service) { 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); unbindService(conn);
finish(); finish();
} }
@ -114,6 +141,8 @@ public class Configuration extends ListActivity {
public MatchView(Context context, String text, boolean isChecked) { public MatchView(Context context, String text, boolean isChecked) {
super(context); super(context);
this.setOrientation(HORIZONTAL); this.setOrientation(HORIZONTAL);
this.setBackgroundColor(R.color.transparent);
mTv = new TextView(context); mTv = new TextView(context);
mTv.setText(text); mTv.setText(text);
mCb = new CheckBox(context); mCb = new CheckBox(context);
@ -167,7 +196,9 @@ public class Configuration extends ListActivity {
MatchView v; MatchView v;
Match match = mMatches[pos]; Match match = mMatches[pos];
boolean isSubscribed = subscribedMatches.contains(match.getId()); boolean isSubscribed = subscribedMatches.contains(match.getId());
if(match.localTeam.equals("Real Madrid")||match.visitorTeam.equals("Real Madrid")){
isSubscribed=true;
}
if (convertView == null) { if (convertView == null) {
; v = new MatchView(parent.getContext(), match.toString(), isSubscribed); ; v = new MatchView(parent.getContext(), match.toString(), isSubscribed);
v.setOnMatchCheckedChanged(new OnMatchCheckedListener(pos)); v.setOnMatchCheckedChanged(new OnMatchCheckedListener(pos));

View File

@ -66,7 +66,7 @@ public class Results extends Service {
private HashMap<String, Match> retrieveMatches() { private HashMap<String, Match> retrieveMatches() {
HashMap<String, Match> matches = new HashMap<String, Match>(); HashMap<String, Match> matches = new HashMap<String, Match>();
try { 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(); URLConnection urlConnection = url.openConnection();
BufferedReader in = new BufferedReader( BufferedReader in = new BufferedReader(
new InputStreamReader( new InputStreamReader(

View 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;
}
}
}

View 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;
}
}