Hi Guys,
I've gone back to try and fix my watch - manual data entry problems, of trying to enter or modify a few GPS positions ( the name and latitude or longitude ) That will be saved in the app Storage.set data
I thought using the Picker factory would suit the name entry seeing as it may be letter or numbers, however when I implemented the sample factory,
I cannot figure out how to exit the picker screen and save the string I have created. all the buttons are being used for up / down, enter value or cancel value and there does not seem to be a way to stop adding to the string and exit the page...
Any ideas?
using Toybox.Application; using Toybox.Graphics; using Toybox.WatchUi; class StringPicker extends WatchUi.Picker { const mCharacterSet = " ABCDEFGHIJKLMNOPQRSTUVWXYZ -0123456789"; hidden var mTitleText; hidden var mFactory; function initialize() { mFactory = new CharacterFactory(mCharacterSet, {:addOk=>true}); mTitleText = ""; var string = Application.getApp().getProperty("string"); var defaults = null; var titleText = Rez.Strings.stringPickerTitle; if(string != null) { mTitleText = string; titleText = string; defaults = [mFactory.getIndex(string.substring(string.length()-1, string.length()))]; } mTitle = new WatchUi.Text({:text=>titleText, :locX =>WatchUi.LAYOUT_HALIGN_CENTER, :locY=>WatchUi.LAYOUT_VALIGN_BOTTOM, :color=>Graphics.COLOR_WHITE}); Picker.initialize({:title=>mTitle, :pattern=>[mFactory], :defaults=>defaults}); } function onUpdate(dc) { dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK); dc.clear(); Picker.onUpdate(dc); } function addCharacter(character) { mTitleText += character; mTitle.setText(mTitleText); } function removeCharacter() { mTitleText = mTitleText.substring(0, mTitleText.length() - 1); if(0 == mTitleText.length()) { mTitle.setText(WatchUi.loadResource(Rez.Strings.stringPickerTitle)); } else { mTitle.setText(mTitleText); } } function getTitle() { return mTitleText.toString(); } function getTitleLength() { return mTitleText.length(); } function isDone(value) { return mFactory.isDone(value); } } class StringPickerDelegate extends WatchUi.PickerDelegate { hidden var mPicker; function initialize(picker) { PickerDelegate.initialize(); mPicker = picker; } function onCancel() { if(0 == mPicker.getTitleLength()) { WatchUi.popView(WatchUi.SLIDE_IMMEDIATE); } else { mPicker.removeCharacter(); } } function onAccept(values) { if(!mPicker.isDone(values[0])) { mPicker.addCharacter(values[0]); } else { if(mPicker.getTitle().length() == 0) { Application.getApp().deleteProperty("string"); } else { Application.getApp().setProperty("string", mPicker.getTitle()); } WatchUi.popView(WatchUi.SLIDE_IMMEDIATE); } } }