Splash Application

From WebOS Internals
Jump to navigation Jump to search

Coming from the Treo 800w (and 3 other windows mobile phones) I am missing the 'Today' screen. I would like to research a build an app that reaches out to other applications data (using the same calls) to pull stuff into one screen.

I have already started trying to pull together how some things work to get the data i want to show. Heres what i have looked into so far:

  • Number of unread Emails - com.palm.app.email
  • Number of unread Text Messages - com.palm.app.messaging
  • Speed Dial (maybe 2,3, and 4 slots, stored as R, T, and D respectively) - com.palm.app.phone/luna-applauncher
  • Upcoming Events - com.palm.app.calendar

I kinda have these milestones inmind:

  • v0.2 Headless App with Blank Cardview (anyone have this already?)
  • v0.6 All 4 data sources pulled
  • v0.9 Launching respective applications (luna-applauncher)
  • v1.0 Refreshing (timer or event, whichever is easiest for now)
  • v2.0 Configurable Visibility/Order

I have left a versioning gap from .6-.9 incase someone else suggests another data source or has some other good ideas.

I really want to focus on building this by example of the existing applications, this should provide a smoother transition into Mojo, and can be packaged and installed on unrooted phones.

Disclaimer

The code listed below as *Existing* is partial versions of existing applications. This code will not be used, it is only for review of how Mojo Methods are called and the data objects that come back. The intention is not to use this code but gain an understanding from it, and be able to write code behind the UI that uses the same data sources. As each data source of the application moves along , and is mostly functional, it will be assumed that this code is understood and no longer needed and it will be removed from this page.

*Existing* Event Assistant Snippet(s)

This is pulled and edited from the com.palm.app.calendar application. It is not intended to function, only demonstrate how it retrieves and stores events. It has been edited to remove the application UI and additional features that wont be required.

var EventAssistant = Class.create({

	initialize: function(appController) {
		this.calendarService = new CalendarMojoService;
	},
	getEvents: function() {
		this.calendarService.getEvents(
			'all', 
			getCurrentDateTime().getTime(), 
			getCurrentDateTime().addDays(3).getTime(), //make configurable
			this.getEventsCallback.bind(this, true), 
			this.controller, 
			this.getEventsFailCallback.bind(this),
		{freeTimes: false}
		);
	},
	getEventsCallback: function(hideFastScroll, response) {
		var numDays = response.days.size();
		for (var i = 0; i < numDays; i++) {
			var day = {};
			day.days = [];
			day.days.push(response.days[i]);
			var dayDate = day.days[0].date;
			this.addToCache(dayDate, day);
		}
	},
 	addToCache: function(dayDate, events) {
		var key = this.keyFromDate(dayDate);
		EventAssistant.dayCache.set(key, events);
		EventAssistant.cacheSize = EventAssistant.dayCache.keys().length;
		while (EventAssistant.cacheSize > EventAssistant.MAX_CACHE_SIZE) {
			// Remove the day that is farthest away from the current day
			var farthestIndex = -1;
			var farthestDiff = 0;
			var keys = EventAssistant.dayCache.keys();
			var currentKey = this.keyFromDate(getCurrentDateTime());
			for (var i = 0; i < keys.length; i++) {
				var diff = Math.abs(currentKey - keys[i]);
				if (diff > farthestDiff) {
					farthestDiff = diff
					farthestIndex = i;
				}
			}
			if (farthestIndex >= 0) {
				EventAssistant.dayCache.unset(keys[farthestIndex]);
				EventAssistant.cacheSize--;
			}
		}
	},
	keyFromDate: function(dayDate) {
		var date = new Date(dayDate);
		return date.clearTime().getTime();
	},
	getEventsFailCallback: function(response) {
	  	Mojo.Log.info("FAILURE IN THE SERVICE **********************************************************");
	}
});
EventAssistant.MIN_EVENT_HEIGHT = 24;
EventAssistant.MAX_CACHE_SIZE = 15;//days
EventAssistant.cacheSize = 0;
EventAssistant.dayCache = new Hash();


*Existing* Speed Dial Assistant Snippet(s)

Again, this isnt functioning code, just some of the code that is used in global search, and specific to returning speed dial contacts.

var SpeedDialAssistant = Class.create({

	initialize: function(appController) {
		getContactBySpeeddial('r');//2
		getContactBySpeeddial('t');//3
		getContactBySpeeddial('d');//4
	},
	getContactBySpeeddial: function(digit){
		if (this.getQuickDialsReq){
			this.getQuickDialsReq.cancel();
			delete this.getQuickDialsReq;
		}
		this.getQuickDialsReq = new Mojo.Service.Request(
			'palm://com.palm.contacts', {
			      	method: 'getQuickDials',
			      	parameters: {  },
			      	onSuccess: this.onGetContactBySpeeddial.bind(this, digit),
			      	onFailure: this.onGetContactBySpeeddial.bind(this, digit),
				onComplete: function(){delete this.getQuickDialsReq;}.bind(this)
    			}
		);		
	},

	onGetContactBySpeeddial:function(digit, response){
		if(response.list && response.list.length>0)
			this.showSpeeddial.bind(this, digit, response);
	},
	
	showSpeeddial:function(digit, response){
		if (this.currentFilter.length == 1) {
			if (digit == 'e') {
				this.hasSpeedDial = true;
				var contactName = $L("Voicemail");
				if (this.toPhoneNumber(digit)) 
					digit = this.toPhoneNumber(digit);
				var filterTextModel = {
					'filterText': 1,
					'speedDialText': contactName,
					'digit': digit
				};
				if (!this.dialDiv.visible()) {
					this.dialDiv.show();
					this.dialDiv.update(Mojo.View.render({
						template: 'global-search/dial-div'
					}));
				}
				
				$('dial-div-msg').update(Mojo.View.render({
					template: 'global-search/dial-div-msg',
					object: filterTextModel
				}));
				if ($('contactname')) {
					$('contactname').addClassName("voicemail")
				}
			}
			else {
				for (var i = 0; i < response.list.length; i++) {
					if (digit.toUpperCase() === response.list[i].quickDial || (this.toPhoneNumber(digit) && this.toPhoneNumber(digit) === response.list[i].quickDial)) {
						var labelName;
						if(response.list[i].label ==2 && response.list[i].customLabel)
							labelName = response.list[i].customLabel;
						else
							labelName = this.phoneLabel[response.list[i].label];
						var contactLabel = labelName;
						var patternStr = "^" + labelName;
						var beginPattern = new RegExp(patternStr, 'ig');
						var matchTemplate = Mojo.View.render({
							object: {
								match: 'ZZZZ'
							},
							template: 'global-search/quickdial-div-highlight'
						});
						labelName = labelName.replace(beginPattern, function(match, offset, whole){
							return matchTemplate.replace('ZZZZ', match);
						});
						var contactName = (response.list[i].firstName ? response.list[i].firstName + " " : "") + (response.list[i].middleName ? response.list[i].middleName + " " : "") + (response.list[i].lastName ? response.list[i].lastName + " " : "");
						
						if (this.toPhoneNumber(digit)) 
							digit = this.toPhoneNumber(digit);
						var filterTextModel = {
							'filterText': response.list[i].value,
							'speedDialText': contactName,
							'speedDialLabel': "<br />"+labelName,
							'digit': digit,
							'contactLabel':contactLabel,
							'id':response.list[i].Person_id
						};
						if (!this.dialDiv.visible()) {
							this.dialDiv.show();
							this.dialDiv.update(Mojo.View.render({
								template: 'global-search/dial-div'
							}));
						}
						
						$('dial-div-msg').update(Mojo.View.render({
							template: 'global-search/dial-div-msg',
							object: filterTextModel
						}));
						break;
					}
				}
			}
		}
	},
	toPhoneNumber: function(str) {
		var is = true;
		var numChar = '-1';
		var numberStr ='';
		for (var i = 0; i< str.length; i++) {
			numChar = this.translateToDigit(str.charAt(i));
			if (numChar == '-1') {
				is = false;
				break;
			} else {
				if (i > 0 && (numChar == '+'||numChar == '*'||numChar == '#')) {
					is = false;
					break;
				}
				else
					numberStr += numChar;
			}
		}
	
		if (is) {
			return numberStr;
		} else {
			return null;
		}
	},

	translateToDigit: function(letter) {
		var number = -1;
		if ((letter >= "0") && (letter <= "9")||(letter =="+")||(letter =="#")||(letter =="*")) {
			return letter;
		}
		var keymapping = {'@':0, 'e':1, 'r':2, 't':3, 'd':4, 'f':5, 'g':6, 'x':7, 'c':8, 'v':9, 'w':'+', 'z':'*', 'b':'#'};

		if (keymapping[letter.toLowerCase()] || keymapping[letter.toLowerCase()]=="0")
			return keymapping[letter.toLowerCase()];
		else
			return number;
	}
});