Added behaviour for navigation buttons(home, parent and refresh)

This commit is contained in:
Helena Rodriguez 2012-05-17 20:54:08 +02:00
parent fd0f18fc99
commit ace5f326d9
6 changed files with 182 additions and 131 deletions

View File

@ -16,7 +16,9 @@
android:background="@color/title_background"
android:textColor="@android:color/white"
android:textSize="18sp"
android:textStyle="bold" >
android:textStyle="bold"
android:ellipsize="start"
android:singleLine="true">
</TextView>
<include layout="@layout/navigation_bar" />

View File

@ -21,7 +21,7 @@
<string name="userPasswordSummary_preferences">Password</string>
<string name="userPasswordTitle_preferences">Password</string>
<string name="saveMsg_preferences">Preferences have been saved</string>
<string name="saveSummary_preferences">Save actual preferences</string>
<string name="saveSummary_preferences">Save current preferences</string>
<string name="saveTitle_preferences">Save preferences</string>
<string name="preferencesTitle_menu">Preferences</string>
<string name="shareTitle_menu">Share SWADroid</string>

View File

@ -297,18 +297,18 @@ public class Global {
return b ? "Y" : "N";
}
/**
* Gets code of actual course
* return -1 if no course chosen; code of actual course in other case
* Gets code of current course
* return -1 if no course chosen; code of current course in other case
* */
public static long getSelectedCourseCode(){
return selectedCourseCode;
}
/**
* Sets code of actual course
* Sets code of current course
* @param courseCode. Code of the chosen course. It should be courseCode>0. Otherwise nothing will change
* */
public static void setSelectedCourseCode(long actualCourseCode){
if(actualCourseCode >0) selectedCourseCode = actualCourseCode;
public static void setSelectedCourseCode(long currentCourseCode){
if(currentCourseCode >0) selectedCourseCode = currentCourseCode;
}
public static boolean isPreferencesChanged(){
@ -322,12 +322,12 @@ public class Global {
preferencesChanged = newState;
}
public static void setSelectedCourseShortName(String actualCourseShortName){
selectedCourseShortName = actualCourseShortName;
public static void setSelectedCourseShortName(String currentCourseShortName){
selectedCourseShortName = currentCourseShortName;
}
public static void setSelectedCourseFullName(String actualCourseFullName){
selectedCourseFullName = actualCourseFullName;
public static void setSelectedCourseFullName(String currentCourseFullName){
selectedCourseFullName = currentCourseFullName;
}
public static String getSelectedCourseShortName(){

View File

@ -104,7 +104,7 @@ public class SWADMain extends MenuExpandableListActivity {
private boolean firstRun = false;
/**
* Actual role 2 - student 3 - teacher -1 - none role was chosen
* Current role 2 - student 3 - teacher -1 - none role was chosen
* */
private int currentRole = -1;
/**
@ -253,7 +253,7 @@ public class SWADMain extends MenuExpandableListActivity {
createMenu();
}
}else{
getActualCourses();
getCurrentCourses();
Global.setPreferencesChanged(false);
}
}
@ -335,7 +335,7 @@ public class SWADMain extends MenuExpandableListActivity {
Global.setSelectedCourseCode(-1);
Global.setSelectedCourseShortName("");
Global.setSelectedCourseFullName("");
if(!firstRun && Module.connectionAvailable(this)) getActualCourses(); //at the first run, this will be launched after the preferences menu
if(!firstRun && Module.connectionAvailable(this)) getCurrentCourses(); //at the first run, this will be launched after the preferences menu
}
currentRole = -1;
} catch (Exception ex) {
@ -427,7 +427,7 @@ public class SWADMain extends MenuExpandableListActivity {
if(dbHelper.getAllRows(Global.DB_TABLE_COURSES).size()==0){
if(Module.connectionAvailable(getBaseContext()))
getActualCourses();
getCurrentCourses();
//else
}else{
@ -439,7 +439,7 @@ public class SWADMain extends MenuExpandableListActivity {
}
};
private void getActualCourses(){
private void getCurrentCourses(){
Intent activity;
activity = new Intent(getBaseContext(), Courses.class );
Toast.makeText(getBaseContext(), R.string.coursesProgressDescription, Toast.LENGTH_LONG).show();

View File

@ -1,3 +1,21 @@
/*
* This file is part of SWADroid.
*
* Copyright (C) 2012 Helena Rodriguez Gijon <hrgijon@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.downloads;
import java.io.StringReader;
@ -17,12 +35,13 @@ import org.xml.sax.InputSource;
* Class used to navigate around the XML file. That XML file contains the
information of all the directory.
* @author Sergio Ropero Oliver. <sro0000@gmail.com>
* @author Helena Rodríguez Gijón <hrgijon@gmail.com>
* @version 1.0
*/
public class DirectoryNavigator
{
private String XMLinfo;
ArrayList<String> path;
private ArrayList<String> path;
/**
* Constructor.
@ -40,7 +59,7 @@ public class DirectoryNavigator
* @return Return a list of items that are inside the subdirectory.
* @throws InvalidPath When the directory don't exist.
*/
public ArrayList<DirectoryItem> subDirectory(String subDirectory) throws InvalidPath
public ArrayList<DirectoryItem> goToSubDirectory(String subDirectory) throws InvalidPath
{
//We increase the path.
path.add(subDirectory);
@ -58,16 +77,18 @@ public class DirectoryNavigator
* @return Return a list of items that are inside the parent directory.
* @throws InvalidPath When the directory does not exist.
*/
public List<DirectoryItem> parentDirectory() throws InvalidPath
public ArrayList<DirectoryItem> goToParentDirectory() throws InvalidPath
{
//We decrease the path.
path.remove(path.size()-1);
Node node = goToDirectory();
List<DirectoryItem> itemsToShow;
itemsToShow = new ArrayList<DirectoryItem>(getItems(node));
ArrayList<DirectoryItem> itemsToShow;
if(path.size() !=0){
//We decrease the path.
path.remove(path.size()-1);
Node node = goToDirectory();
itemsToShow = new ArrayList<DirectoryItem>(getItems(node));
}else
itemsToShow = goToRoot();
return itemsToShow;
}
@ -76,13 +97,13 @@ public class DirectoryNavigator
* @return Return a list of items in the current directory.
* @throws InvalidPath When the directory don't exist.
*/
public List<DirectoryItem> refresh(String fileXML) throws InvalidPath
public ArrayList<DirectoryItem> refresh(String fileXML) throws InvalidPath
{
this.XMLinfo = fileXML;
Node node = goToDirectory();
List<DirectoryItem> itemsToShow;
ArrayList<DirectoryItem> itemsToShow;
itemsToShow = new ArrayList<DirectoryItem>(getItems(node));
return itemsToShow;
@ -93,13 +114,13 @@ public class DirectoryNavigator
* @return The items of the root directory.
* @throws InvalidPath When the directory don't exist.
*/
public List<DirectoryItem> goToRoot() throws InvalidPath
public ArrayList<DirectoryItem> goToRoot() throws InvalidPath
{
path.clear();
Node node = goToDirectory();
List<DirectoryItem> itemsToShow;
ArrayList<DirectoryItem> itemsToShow;
itemsToShow = new ArrayList<DirectoryItem>(getItems(node));
return itemsToShow;
@ -205,7 +226,7 @@ public class DirectoryNavigator
DocumentBuilder builder;
int directoryLevel = 0;
Node actualNode = null;
Node currentNode = null;
try
{
@ -214,15 +235,15 @@ public class DirectoryNavigator
//We read the entire XML file.
Document dom = builder.parse(new InputSource(new StringReader(XMLinfo)));
//We put the actual node in the root Element.
actualNode = dom.getDocumentElement();
//We put the current node in the root Element.
currentNode = dom.getDocumentElement();
System.out.println("XML: " + XMLinfo);
System.out.println("path size "+path.size());
//We change the current node.
for(int i=0; i<path.size(); i++)
{
//WE GET THE REST OF THE INFO
NodeList childs = actualNode.getChildNodes();
NodeList childs = currentNode.getChildNodes();
System.out.println(childs.getLength());
for(int j=0;j<childs.getLength();j++)
{
@ -232,7 +253,7 @@ public class DirectoryNavigator
System.out.println(path.get(i)+" "+attributes.getNamedItem("name").getNodeValue());
if(path.get(i).equals(attributes.getNamedItem("name").getNodeValue()))
{
actualNode = currentChild;
currentNode = currentChild;
directoryLevel++;
}
}
@ -250,7 +271,7 @@ public class DirectoryNavigator
}
else
{
return actualNode;
return currentNode;
}
}
@ -268,15 +289,15 @@ public class DirectoryNavigator
/**
* Function used for testing.
* @param directory Directory to add to the actual path.
* @param directory Directory to add to the current path.
*/
public void addToPath(String directory)
{
path.add(directory);
}
//TODO List<DirectoryItem> getActual
//public List<DirectoryItem> getActual(){}
//TODO List<DirectoryItem> getcurrent
//public List<DirectoryItem> getcurrent(){}
}
/**

View File

@ -24,149 +24,177 @@ import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import es.ugr.swad.swadroid.Global;
import es.ugr.swad.swadroid.MenuActivity;
import es.ugr.swad.swadroid.R;
import es.ugr.swad.swadroid.model.Course;
/**
* Activity to navigate through the directory tree of documents and to manage the downloads of documents
* Activity to navigate through the directory tree of documents and to manage
* the downloads of documents
*
* @author Helena Rodríguez Gijon <hrgijon@gmail.com>
* */
public class DownloadsManager extends MenuActivity {
/**
* Class that contains the directory tree and gives information of each level
* Class that contains the directory tree and gives information of each
* level
* */
private DirectoryNavigator navigator;
private DirectoryNavigator navigator;
/**
* Specifies whether to display the documents or the shared area of the subject
* 1 specifies documents area
* 2 specifies shared area
* Specifies whether to display the documents or the shared area of the
* subject 1 specifies documents area 2 specifies shared area
* */
private int downloadsCode = 0;
/**
* String that contains the xml files recevied from the web service
* String that contains the xml files recevied from the web service
* */
private String tree;
/**
* Downloads tag name for Logcat
*/
public static final String TAG = Global.APP_TAG + " Downloads";
private GridView grid;
ImageView moduleIcon = null;
TextView moduleText = null;
TextView actualPathText;
/**
* Downloads tag name for Logcat
*/
public static final String TAG = Global.APP_TAG + " Downloads";
/**
* Indicates whether the refresh button was pressed
* */
private boolean refresh = false;
private GridView grid;
private ImageView moduleIcon = null;
private TextView moduleText = null;
private TextView currentPathText;
@Override
protected void onStart() {
super.onStart();
Intent activity;
activity = new Intent(getBaseContext(),DirectoryTreeDownload.class);
activity.putExtra("treeCode",downloadsCode);
startActivityForResult(activity,Global.DIRECTORY_TREE_REQUEST_CODE);
activity = new Intent(getBaseContext(), DirectoryTreeDownload.class);
activity.putExtra("treeCode", downloadsCode);
startActivityForResult(activity, Global.DIRECTORY_TREE_REQUEST_CODE);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigation);
downloadsCode = getIntent().getIntExtra("downloadsCode", Global.DOCUMENTS_AREA_CODE);
downloadsCode = getIntent().getIntExtra("downloadsCode",
Global.DOCUMENTS_AREA_CODE);
grid = (GridView) this.findViewById(R.id.gridview);
grid.setOnItemClickListener((new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
TextView text = (TextView) v.findViewById(R.id.icon_text);
String path = text.getText().toString();
ArrayList<DirectoryItem> newBrowser = navigator.subDirectory(path);
((NodeAdapter)grid.getAdapter()).change(newBrowser);
actualPathText.setText(navigator.getPath());
((NodeAdapter)grid.getAdapter()).change(newBrowser);
}
}));
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
TextView text = (TextView) v.findViewById(R.id.icon_text);
String chosenNodeName = text.getText().toString();
updateView(navigator.goToSubDirectory(chosenNodeName));
}
}));
ImageButton homeButton = (ImageButton) this
.findViewById(R.id.home_button);
homeButton.setOnClickListener((new OnClickListener() {
@Override
public void onClick(View v) {
updateView(navigator.goToRoot());
}
}));
ImageButton parentButton = (ImageButton) this
.findViewById(R.id.parent_button);
parentButton.setOnClickListener((new OnClickListener() {
@Override
public void onClick(View v) {
updateView(navigator.goToParentDirectory());
}
}));
ImageButton refreshButton = (ImageButton) this
.findViewById(R.id.refresh_button);
refreshButton.setOnClickListener((new OnClickListener() {
@Override
public void onClick(View v) {
refresh = true;
Intent activity;
activity = new Intent(getBaseContext(), DirectoryTreeDownload.class);
activity.putExtra("treeCode", downloadsCode);
startActivityForResult(activity, Global.DIRECTORY_TREE_REQUEST_CODE);
}
}));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == Activity.RESULT_OK){
switch(requestCode){
//After get the list of courses, a dialog is launched to choice the course
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
// After get the list of courses, a dialog is launched to choice the
// course
case Global.DIRECTORY_TREE_REQUEST_CODE:
tree = data.getStringExtra("tree");
setMainView();
if (!refresh)
setMainView();
else {
refresh = false;
refresh();
}
break;
}
}
}
private void setMainView(){
if(moduleIcon == null){
if(downloadsCode == Global.DOCUMENTS_AREA_CODE){
moduleIcon = (ImageView)this.findViewById(R.id.moduleIcon);
moduleIcon.setBackgroundResource(R.drawable.folder);
moduleText = (TextView)this.findViewById(R.id.moduleName);
moduleText.setText(R.string.documentsDownloadModuleLabel);
}else{ //SHARE_AREA_CODE
moduleIcon = (ImageView)this.findViewById(R.id.moduleIcon);
private void setMainView() {
if (moduleIcon == null) {
if (downloadsCode == Global.DOCUMENTS_AREA_CODE) {
moduleIcon = (ImageView) this.findViewById(R.id.moduleIcon);
moduleIcon.setBackgroundResource(R.drawable.folder);
moduleText = (TextView) this.findViewById(R.id.moduleName);
moduleText.setText(R.string.documentsDownloadModuleLabel);
} else { // SHARE_AREA_CODE
moduleIcon = (ImageView) this.findViewById(R.id.moduleIcon);
moduleIcon.setBackgroundResource(R.drawable.folderusers);
moduleText = (TextView)this.findViewById(R.id.moduleName);
moduleText.setText(R.string.sharedsDownloadModuleLabel);
moduleText = (TextView) this.findViewById(R.id.moduleName);
moduleText.setText(R.string.sharedsDownloadModuleLabel);
}
}
actualPathText= (TextView) this.findViewById(R.id.path);
currentPathText = (TextView) this.findViewById(R.id.path);
navigator = new DirectoryNavigator(tree);
//GridView
ArrayList<DirectoryItem> r = (ArrayList<DirectoryItem>) navigator.goToRoot();
String path = navigator.getPath() ;
actualPathText.setText(path);
grid.setAdapter(new NodeAdapter(this,r));
// GridView
ArrayList<DirectoryItem> items = (ArrayList<DirectoryItem>) navigator
.goToRoot();
currentPathText.setText(navigator.getPath());
grid.setAdapter(new NodeAdapter(this, items));
}
/*private OnClickListener homeClickListener = new OnClickListener(){
}*/
/* public class GridViewOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
String directoryName = parent.getItemAtPosition(pos).toString();
ArrayList<DirectoryItem> newBrowser = navigator.subDirectory(directoryName);
String path = navigator.getPath();
actualPathText.setText(path);
((NodeAdapter)grid.getAdapter()).change(newBrowser);
}
private void refresh() {
navigator.refresh(tree);
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}*/
}
private void updateView(ArrayList<DirectoryItem> items) {
currentPathText.setText(navigator.getPath());
((NodeAdapter) grid.getAdapter()).change(items);
}
}