#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 . import socket, android, time droid = android.Android() # ------------------------------------- Global Variables -------------------------------------- # username = "" password = "" latitude = 00 longitude = 00 # -----------------------------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 METHODS --------------------------------------------------------------# #--------LOG IN SCREEN --------# # --DECIDER -- # def login(client): while (True): #Waits for an event event=droid.eventWait().result print event #If a button is clicked if event["name"]=="click": #Gets the id of the clicked button id=event["data"]["id"] #If it was the login button: if (id=="login"): username = droid.fullQueryDetail("username").result["text"] password = droid.fullQueryDetail("password").result["text"] #Comunication with the server message = "login<>"+username+"<>"+password #For checking client.sendall(message) #Waits for an answer answer = client.recv(100) #The response depends on the server's answer if (answer == "login<>success"): droid.makeToast("Logged In") droid.fullDismiss() droid.fullShow(menulayout) #We execute the menu screen decider menu(client) else: droid.makeToast("Invalid Username or Password, Try Again, or SignUp") #If it was the sign up button elif (id=="signup"): #We close the actual screen droid.fullDismiss() #We show the sign screen droid.fullShow(signlayout) #Trigger the decider for this screen sign(client) # XML code for the graphical layout of the LOGIN SCREEN loginlayout = """