def handle_event(event): """ This should handle events one at a time. It should return a manager.EVENT_* constant. """ if event["name"] == "key": id = event["data"]["key"] #BACK_BUTTON = '4' if id == '4': #the back button was pressed print "BACK BUTTON PRESSED!!!" manager.pop_view(); elif event["name"]=="screen": if event["data"]=="destroy": pass #manager.close_app() #return manager.EVENT_CONSUME elif event["name"] == "EXIT_APP": droid.stopLocating() manager.close_app() elif event["name"] == "SAVE_SETTINGS": save_settings() else: print "Unused event in about." return manager.EVENT_UNUSED
def handle_event(event): """ This should handle events one at a time. It should return a manager.EVENT_* constant. """ if event["name"] == "key": id = event["data"]["key"] #BACK_BUTTON = '4' if id == '4': #the back button was pressed manager.pop_view(); return manager.EVENT_CONSUME elif event["name"]=="screen": if event["data"]=="destroy": pass #manager.close_app() return manager.EVENT_USED elif event["name"] == "EXIT_APP": manager.close_app() return manager.EVENT_CONSUME elif event["name"] == "GET_LOW": droid.webViewShow("http://107.20.202.68:5052/static/bad.html") return manager.EVENT_CONSUME elif event["name"] == "GET_MED": droid.webViewShow("http://107.20.202.68:5052/static/medium.html") return manager.EVENT_CONSUME elif event["name"] == "GET_HIGH": droid.webViewShow("http://107.20.202.68:5052/static/good.html") return manager.EVENT_CONSUME else: print "Unused event in collectData." return manager.EVENT_UNUSED
def handle_event(event): """ This should handle events one at a time. It should return a manager.EVENT_* constant. """ if event["name"] == "click": id = event["data"]["id"] if id == "openScanSlider": print settings print type(settings) print settings["scan_interval"] droid.dialogCreateSeekBar( settings["scan_interval"], 120, "Scan Interval", "How many seconds should the phone wait in between WiFi Scans? A smaller interval will decrease battery life but increase data collection.", ) droid.dialogSetPositiveButtonText("Update Interval") droid.dialogShow() sliderResp = droid.dialogGetResponse().result valToSet = sliderResp["progress"] if valToSet <= MINIMUM_UPDATE: valToSet = MINIMUM_UPDATE settings["scan_interval"] = valToSet save_settings() return manager.EVENT_CONSUME elif id == "minimumBattery": droid.dialogCreateSeekBar( str(settings["minimum_battery"]), 80, "Minimum Battery Level", "This app can be configured to stop scanning when battery level is below a certain level. Choose the minimum battery level.", ) droid.dialogSetPositiveButtonText("Update Minimum battery level") droid.dialogShow() sliderResp = droid.dialogGetResponse().result valToSet = sliderResp["progress"] if valToSet == 0: valToSet = 1 settings["minimum_battery"] = valToSet save_settings() return manager.EVENT_CONSUME elif id == "bufferSizeSlider": droid.dialogCreateSeekBar( str(settings["buffer_size"]), 50, "Buffer Size", "How often should the app send its collected data to the server? Decreasing this size will send data to the server more often (though the same amount of total data will be sent).", ) droid.dialogSetPositiveButtonText("Update Buffer Limit") droid.dialogShow() sliderResp = droid.dialogGetResponse().result valToSet = sliderResp["progress"] if valToSet == 0: valToSet = 1 settings["buffer_size"] = valToSet save_settings() return manager.EVENT_CONSUME elif event["name"] == "key": id = event["data"]["key"] # BACK_BUTTON = '4' if id == "4": # the back button was pressed print "BACK BUTTON PRESSED!!!" manager.pop_view() elif event["name"] == "screen": if event["data"] == "destroy": pass # manager.close_app() # return manager.EVENT_CONSUME elif event["name"] == "EXIT_APP": droid.stopLocating() manager.close_app() elif event["name"] == "SAVE_SETTINGS": save_settings() else: print "Unused event in settings." return manager.EVENT_UNUSED
def handle_event(event): """ This should handle events one at a time. It should return a manager.EVENT_* constant. """ if event["name"] == "click": id = event["data"]["id"] if id == "openScanSlider": print settings print type(settings) print settings['scan_interval'] droid.dialogCreateSeekBar( settings['scan_interval'], 120, "Scan Interval", "How many seconds should the phone wait in between WiFi Scans? A smaller interval will decrease battery life but increase data collection." ) droid.dialogSetPositiveButtonText("Update Interval") droid.dialogShow() sliderResp = droid.dialogGetResponse().result valToSet = sliderResp['progress'] if valToSet <= MINIMUM_UPDATE: valToSet = MINIMUM_UPDATE settings['scan_interval'] = valToSet save_settings() return manager.EVENT_CONSUME elif id == "minimumBattery": droid.dialogCreateSeekBar( str(settings['minimum_battery']), 80, "Minimum Battery Level", "This app can be configured to stop scanning when battery level is below a certain level. Choose the minimum battery level." ) droid.dialogSetPositiveButtonText("Update Minimum battery level") droid.dialogShow() sliderResp = droid.dialogGetResponse().result valToSet = sliderResp['progress'] if valToSet == 0: valToSet = 1 settings['minimum_battery'] = valToSet save_settings() return manager.EVENT_CONSUME elif id == "bufferSizeSlider": droid.dialogCreateSeekBar( str(settings['buffer_size']), 50, "Buffer Size", "How often should the app send its collected data to the server? Decreasing this size will send data to the server more often (though the same amount of total data will be sent)." ) droid.dialogSetPositiveButtonText("Update Buffer Limit") droid.dialogShow() sliderResp = droid.dialogGetResponse().result valToSet = sliderResp['progress'] if valToSet == 0: valToSet = 1 settings['buffer_size'] = valToSet save_settings() return manager.EVENT_CONSUME elif event["name"] == "key": id = event["data"]["key"] #BACK_BUTTON = '4' if id == '4': #the back button was pressed print "BACK BUTTON PRESSED!!!" manager.pop_view() elif event["name"] == "screen": if event["data"] == "destroy": pass #manager.close_app() #return manager.EVENT_CONSUME elif event["name"] == "EXIT_APP": droid.stopLocating() manager.close_app() elif event["name"] == "SAVE_SETTINGS": save_settings() else: print "Unused event in settings." return manager.EVENT_UNUSED
def handle_event(event): """ This should handle events one at a time. It should return a manager.EVENT_* constant. """ if event["name"] == "key": id = event["data"]["key"] #BACK_BUTTON = '4' if id == '4': #the back button was pressed droid.stopLocating() manager.pop_view() return manager.EVENT_CONSUME elif event["name"] == "screen": if event["data"] == "destroy": pass #manager.close_app() return manager.EVENT_USED elif event["name"] == "EXIT_APP": droid.stopLocating() manager.close_app() return manager.EVENT_CONSUME elif event["name"] == "SAVE_SETTINGS": save_settings() return manager.EVENT_USED elif event["name"] == "battery": #if battery level is below the minimum, then stop locating and set the low battery warning! prefs = droid.prefGetValue('settings', 'clairvoyance').result if prefs is not None: settings = json.loads( droid.prefGetValue('settings', 'clairvoyance').result) else: settings = common.default_settings if (droid.batteryGetLevel().result < int(settings['minimum_battery'])): droid.stopLocating() droid.fullSetProperty( "status", "text", "Battery level too low. Please charge the device and try again (or change the minimum battery level in settings)." ) elif event["name"] == "location": loc_data = droid.readLocation().result try: myLat = loc_data['gps']['latitude'] myLong = loc_data['gps']['longitude'] accuracy = loc_data['gps']['accuracy'] if droid.checkWifiState().result == False: droid.makeToast("WiFi was not enabled. Enabling WiFi...") droid.toggleWifiState(True) myID = droid.getDeviceId().result networks = droid.wifiGetScanResults().result if networks != None and handle_event.odd == False: handle_event.odd = True for singleNetwork in networks: if singleNetwork['ssid'] in common.SSIDS_TO_TRACK: handle_event.totalPointsCollected += 1 handle_event.bufferCounter = handle_event.bufferCounter + 1 handle_event.location.append( checkin.create_checkin( phone_id=myID, latitude=myLat, longitude=myLong, bssid=singleNetwork['bssid'], ssid=singleNetwork['ssid'], signal=singleNetwork['level'], performance=accuracy)) elif networks != None: handle_event.odd = False settings = json.loads( droid.prefGetValue('settings', 'clairvoyance').result) if (handle_event.bufferCounter >= settings['buffer_size'] and handle_event.odd == True): try: checkin.send_checkins(handle_event.location) handle_event.location = [] handle_event.bufferCounter = 0 handle_event.JSON_sends += 1 except Exception, e: droid.makeToast("Error: " + str(e)) droid.fullSetProperty( "status", "text", "Total number of data points collected: " + str(handle_event.totalPointsCollected) + "\nCurrent buffer size: " + str(handle_event.bufferCounter) + "\nNumber of JSON sends to server: " + str(handle_event.JSON_sends)) except Exception: droid.fullSetProperty("status", "text", "NO GPS LOCK")
def handle_event(event): """ This should handle events one at a time. It should return a manager.EVENT_* constant. """ if event["name"] == "key": id = event["data"]["key"] #BACK_BUTTON = '4' if id == '4': #the back button was pressed droid.stopLocating() manager.pop_view(); return manager.EVENT_CONSUME elif event["name"]=="screen": if event["data"]=="destroy": pass #manager.close_app() return manager.EVENT_USED elif event["name"] == "EXIT_APP": droid.stopLocating() manager.close_app() return manager.EVENT_CONSUME elif event["name"] == "SAVE_SETTINGS": save_settings() return manager.EVENT_USED elif event["name"] == "battery": #if battery level is below the minimum, then stop locating and set the low battery warning! prefs = droid.prefGetValue('settings', 'clairvoyance').result if prefs is not None: settings = json.loads(droid.prefGetValue('settings','clairvoyance').result) else: settings = common.default_settings if (droid.batteryGetLevel().result < int(settings['minimum_battery'])): droid.stopLocating() droid.fullSetProperty("status", "text", "Battery level too low. Please charge the device and try again (or change the minimum battery level in settings)." ) elif event["name"] == "location": loc_data = droid.readLocation().result try: myLat = loc_data['gps']['latitude'] myLong = loc_data['gps']['longitude'] accuracy = loc_data['gps']['accuracy'] if droid.checkWifiState().result == False: droid.makeToast("WiFi was not enabled. Enabling WiFi...") droid.toggleWifiState(True) myID = droid.getDeviceId().result networks = droid.wifiGetScanResults().result if networks != None and handle_event.odd == False: handle_event.odd = True for singleNetwork in networks: if singleNetwork['ssid'] in common.SSIDS_TO_TRACK: handle_event.totalPointsCollected += 1 handle_event.bufferCounter = handle_event.bufferCounter + 1 handle_event.location.append(checkin.create_checkin(phone_id = myID , latitude = myLat , longitude = myLong, bssid = singleNetwork['bssid'], ssid = singleNetwork['ssid'] , signal = singleNetwork['level'] , performance = accuracy)) elif networks != None: handle_event.odd = False settings = json.loads(droid.prefGetValue('settings','clairvoyance').result) if (handle_event.bufferCounter >= settings['buffer_size'] and handle_event.odd == True): try: checkin.send_checkins(handle_event.location) handle_event.location = [] handle_event.bufferCounter = 0 handle_event.JSON_sends += 1 except Exception,e: droid.makeToast("Error: " + str(e)) droid.fullSetProperty("status", "text", "Total number of data points collected: " + str(handle_event.totalPointsCollected) + "\nCurrent buffer size: " + str(handle_event.bufferCounter) + "\nNumber of JSON sends to server: " + str(handle_event.JSON_sends) ) except Exception: droid.fullSetProperty("status", "text", "NO GPS LOCK")