Added Courses module
This commit is contained in:
parent
e7b7c90d4b
commit
f8ede67282
|
@ -2,7 +2,7 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="es.ugr.swad.swadroid"
|
package="es.ugr.swad.swadroid"
|
||||||
android:installLocation="auto" android:versionCode="5" android:versionName="0.2.2">
|
android:installLocation="auto" android:versionCode="5" android:versionName="0.2.2">
|
||||||
<application android:debuggable="true">
|
<application android:debuggable="true" android:label="@string/app_name" android:icon="@drawable/ic_launcher_swadroid">
|
||||||
<activity android:name=".SWADMain"
|
<activity android:name=".SWADMain"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:icon="@drawable/ic_launcher_swadroid" android:configChanges="keyboard|keyboardHidden|orientation">
|
android:icon="@drawable/ic_launcher_swadroid" android:configChanges="keyboard|keyboardHidden|orientation">
|
||||||
|
@ -19,10 +19,11 @@
|
||||||
android:name=".modules.Login"
|
android:name=".modules.Login"
|
||||||
android:label="@string/loginModuleLabel" android:configChanges="keyboard|keyboardHidden|orientation" android:theme="@android:style/Theme.Dialog">
|
android:label="@string/loginModuleLabel" android:configChanges="keyboard|keyboardHidden|orientation" android:theme="@android:style/Theme.Dialog">
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
<activity android:name=".modules.Courses"></activity>
|
||||||
|
</application>
|
||||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="9"></uses-sdk>
|
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="9"></uses-sdk>
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
|
||||||
<supports-screens android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:anyDensity="true" android:largeScreens="true"></supports-screens>
|
<supports-screens android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:anyDensity="true" android:largeScreens="true" android:xlargeScreens="true"></supports-screens>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -35,6 +35,7 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import es.ugr.swad.swadroid.model.DataBaseHelper;
|
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.modules.Login;
|
||||||
import es.ugr.swad.swadroid.ssl.SecureConnection;
|
import es.ugr.swad.swadroid.ssl.SecureConnection;
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ public class SWADMain extends ListActivity {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.login_menu:
|
case R.id.login_menu:
|
||||||
Intent loginActivity = new Intent(getBaseContext(),
|
Intent loginActivity = new Intent(getBaseContext(),
|
||||||
Login.class);
|
Courses.class);
|
||||||
startActivityForResult(loginActivity, Global.LOGIN_REQUEST_CODE);
|
startActivityForResult(loginActivity, Global.LOGIN_REQUEST_CODE);
|
||||||
return true;
|
return true;
|
||||||
case R.id.preferences_menu:
|
case R.id.preferences_menu:
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package es.ugr.swad.swadroid.model;
|
package es.ugr.swad.swadroid.model;
|
||||||
|
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
import org.ksoap2.serialization.PropertyInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for store a course
|
* Class for store a course
|
||||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||||
|
@ -27,6 +31,13 @@ public class Course extends Model {
|
||||||
* Course name
|
* Course name
|
||||||
*/
|
*/
|
||||||
private String 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
|
* Constructor
|
||||||
|
@ -37,7 +48,7 @@ public class Course extends Model {
|
||||||
super(id);
|
super(id);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets course name
|
* Gets course name
|
||||||
* @return Course name
|
* @return Course name
|
||||||
|
@ -90,6 +101,42 @@ public class Course extends Model {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
98
SWADroid/src/es/ugr/swad/swadroid/modules/Courses.java
Normal file
98
SWADroid/src/es/ugr/swad/swadroid/modules/Courses.java
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* This file is part of SWADroid.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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 <juanmi1982@gmail.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user