diff --git a/SWADroid/AndroidManifest.xml b/SWADroid/AndroidManifest.xml index 5e06db2b..317a75a8 100644 --- a/SWADroid/AndroidManifest.xml +++ b/SWADroid/AndroidManifest.xml @@ -2,7 +2,7 @@ - + @@ -19,10 +19,11 @@ android:name=".modules.Login" android:label="@string/loginModuleLabel" android:configChanges="keyboard|keyboardHidden|orientation" android:theme="@android:style/Theme.Dialog"> - + + - + diff --git a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java index a5bb3bdc..bdb475e9 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java +++ b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java @@ -35,6 +35,7 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import es.ugr.swad.swadroid.model.DataBaseHelper; +import es.ugr.swad.swadroid.modules.Courses; import es.ugr.swad.swadroid.modules.Login; import es.ugr.swad.swadroid.ssl.SecureConnection; @@ -105,7 +106,7 @@ public class SWADMain extends ListActivity { switch (item.getItemId()) { case R.id.login_menu: Intent loginActivity = new Intent(getBaseContext(), - Login.class); + Courses.class); startActivityForResult(loginActivity, Global.LOGIN_REQUEST_CODE); return true; case R.id.preferences_menu: diff --git a/SWADroid/src/es/ugr/swad/swadroid/model/Course.java b/SWADroid/src/es/ugr/swad/swadroid/model/Course.java index d255b821..b1542fcb 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/model/Course.java +++ b/SWADroid/src/es/ugr/swad/swadroid/model/Course.java @@ -18,6 +18,10 @@ */ package es.ugr.swad.swadroid.model; +import java.util.Hashtable; + +import org.ksoap2.serialization.PropertyInfo; + /** * Class for store a course * @author Juan Miguel Boyero Corral @@ -27,6 +31,13 @@ public class Course extends Model { * Course name */ private String name; + private static PropertyInfo PI_id = new PropertyInfo(); + private static PropertyInfo PI_name = new PropertyInfo(); + private static PropertyInfo[] PI_PROP_ARRAY = + { + PI_id, + PI_name + }; /** * Constructor @@ -37,7 +48,7 @@ public class Course extends Model { super(id); this.name = name; } - + /** * Gets course name * @return Course name @@ -90,6 +101,42 @@ public class Course extends Model { */ @Override public String toString() { - return "Course [name=" + name + "]"; + return "Course [name=" + name + ", getId()=" + getId() + "]"; + } + + public Object getProperty(int param) { + Object object = null; + switch(param) + { + case 0 : object = this.getId();break; + case 1 : object = name;break; + } + + return object; + } + + public int getPropertyCount() { + return 2; + } + + public void getPropertyInfo(int param, Hashtable arg1, PropertyInfo propertyInfo) { + switch(param){ + case 0: + propertyInfo.type = PropertyInfo.INTEGER_CLASS; + propertyInfo.name = "id"; + break; + case 1: + propertyInfo.type = PropertyInfo.STRING_CLASS; + propertyInfo.name = "name"; + break; + } + } + + public void setProperty(int param, Object obj) { + switch(param) + { + case 0 : this.setId((Integer)obj); break; + case 1 : name = (String)obj; break; + } } } \ No newline at end of file diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/Courses.java b/SWADroid/src/es/ugr/swad/swadroid/modules/Courses.java new file mode 100644 index 00000000..0f487376 --- /dev/null +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/Courses.java @@ -0,0 +1,98 @@ +/* + * This file is part of SWADroid. + * + * Copyright (C) 2010 Juan Miguel Boyero Corral + * + * SWADroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SWADroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SWADroid. If not, see . + */ +package es.ugr.swad.swadroid.modules; + +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import java.util.Vector; + +import org.ksoap2.SoapFault; +import org.ksoap2.serialization.SoapObject; +import org.xmlpull.v1.XmlPullParserException; + +import android.os.Bundle; +import android.util.Log; +import es.ugr.swad.swadroid.R; +import es.ugr.swad.swadroid.model.Course; +import es.ugr.swad.swadroid.model.User; + +/** + * @author Juan Miguel Boyero Corral + * + */ +public class Courses extends Module { + /* (non-Javadoc) + * @see android.app.Activity#onCreate() + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setMETHOD_NAME("getCourses"); + connect(); + } + + /** + * Launches courses action in a separate thread while shows a progress dialog + * in UI thread. + */ + private void connect() { + String progressDescription = "Asignaturas"; + int progressTitle = R.string.loginProgressTitle; + + new Connect(progressDescription, progressTitle).execute(); + } + + /** + * Connects to SWAD and gets courses data. + * @throws NoSuchAlgorithmException + * @throws IOException + * @throws XmlPullParserException + * @throws SoapFault + * @throws InstantiationException + * @throws IllegalAccessException + */ + protected void requestService() + throws NoSuchAlgorithmException, IOException, XmlPullParserException, SoapFault, IllegalAccessException, InstantiationException { + + //Creates webservice request, adds required params and sends request to webservice + createRequest(); + addParam("wsKey", User.getWsKey()); + sendRequest(Course.class, false); + + if (result != null) { + //Stores courses data returned by webservice response + Vector res = (Vector) result; + SoapObject soap = (SoapObject) res.get(1); + Course[] cs = new Course[soap.getPropertyCount()]; + for (int i = 0; i < cs.length; i++) { + SoapObject pii = (SoapObject)soap.getProperty(i); + int id = Integer.parseInt(pii.getProperty(0).toString()); + String name = pii.getProperty(1).toString(); + Course c = new Course(id, name); + cs[i] = c; + Log.d("Courses", c.toString()); + } + + //Request finalized without errors + setResult(RESULT_OK); + } + + finish(); + } +}