====== Android Client ====== For this proyect, we created an app for mobile devices, specifically for android devices. This was developed with the SL4A as we mentioned before. \\ This tutorial will simply explain the code of the android client. This software as the entire proyect was released within the GPLv3 License, therefore the code starts with the header for the license agreement. #Copyright (C) 2013 Fabian Melendez B. fabmelb@gmail.com #https://wiki.arcoslab.eie.ucr.ac.cr/doku.php?id=ie0117_proyectos_2013:way_to_shop #https://github.com/gmocornejos/Way_To_Shop/wiki #This file is part of Way To Shop. #Way To Shop 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. #Way To Shop 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 Way To Shop. If not, see . After this, we needed a couple of imports, in order to create sockets, control the app's timing in some process and of course use the SL4A build-in's functions. Then we create the droid instance and some global variables. import socket, android, time droid = android.Android() # ------------------------------------- Global Variables -------------------------------------- # username = "" password = "" latitude = 00 longitude = 00 ===== Connection with the server ===== We decided to create a function that allows to connect with our server, for this purpose, we try to connect until it's done, because the app cant function without this connection. We try a few times (15) and if the connection it's not established we communicate it to the user. # -----------------------------Stablishing the conection with the server------------------------------------- # #----- A function to create the socket ------ # def connectToServer(): #A boolean that indicates if the connection was successful conection = False #An int that indicates the amount of connection attempts count = 0 while (conection==False): conection = True try: #We add an attempt count += 1 #We define the client instance client = socket.socket(socket.AF_INET, socket.SOCK_STREAM #The address of the server (IP , PORT) server_address = ('192.168.1.111', 10100) #We try to connect to the server client.connect(server_address) droid.makeToast('Socket created') #We return the client instance return client #In case the connection failed except: conection = False #In case we tried to connect several times if(count == 15): droid.makeToast("Connection Error") #We restart the counter count = 1 ===== Screens ===== ==== Log in Screen ==== === Layout === For this screen, the layout was pretty simple, we needed two text fields to receive the inputs of the username and the password (this one is special, is a password-type text-field); and also there's two buttons, one for logging in, and other for sign up. \\ The XML code for this layout looks like this: