Skip to content

Commit

Permalink
support Open Graph Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
naoya committed Oct 19, 2011
1 parent 307f485 commit 7cdf7de
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .settings/com.appcelerator.titanium.mobile.prefs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Tue Oct 18 15:06:09 JST 2011
MOBILE_PROJECT_SDK_VERSION=1.7.2
#Wed Oct 19 15:54:36 JST 2011
MOBILE_PROJECT_SDK_VERSION=1.7.3
eclipse.preferences.version=1
44 changes: 31 additions & 13 deletions Resources/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Ti.include "socket.js"
Ti.UI.setBackgroundColor "#fff"

win = Ti.UI.createWindow
title: "Timeline"
title: "Chrome To iOS"
win.hideTabBar()

dummy = Ti.UI.createTableViewRow
Expand All @@ -19,6 +19,29 @@ table.prependRow = (row) ->
table.insertRowBefore 0, row,
animationStyle:Ti.UI.iPhone.RowAnimationStyle.LEFT

tabGroup =Ti.UI.createTabGroup()
tab = Ti.UI.createTab
window: win
tabGroup.addTab tab
tabGroup.open()

## APN (doesn't work, hmm...)
# Ti.Network.registerForPushNotifications
# types: [
# Ti.Network.NOTIFICATION_TYPE_BADGE,
# Ti.Network.NOTIFICATION_TYPE_ALERT,
# Ti.Network.NOTIFICATION_TYPE_SOUND
# ]
# success: (e) ->
# Ti.API.debug e
# alert e.deviceToken
# error: (e) ->
# alert e.error
# Ti.API.debug e.error
# callback: (e) ->
# alert "incoming push notification!"
# Ti.API.debug e

## events
socket.connect win

Expand All @@ -28,9 +51,10 @@ socket.on "hello", (e) ->

socket.on 'openUrl', (params) ->
table.prependRow $$.ui.createRow
title: 'URLを開く'
title: params.title || params.url
icon: "http://favicon.st-hatena.com/?url=#{params.url}"
message: params.url
message: 'URLを開く'
image: params.image
hasChild: true
click: ->
w = Ti.UI.createWindow()
Expand All @@ -40,9 +64,9 @@ socket.on 'openUrl', (params) ->

socket.on 'openMap', (params) ->
table.prependRow $$.ui.createRow
title: 'マップを開く'
title: "#{params.latitude}, #{params.longitude}"
icon: '/images/gmaps.ico'
message: "#{params.latitude}, #{params.longitude}"
message: 'マップを開く'
hasChild: true
click: ->
w = Ti.UI.createWindow()
Expand All @@ -65,19 +89,13 @@ socket.on 'openMap', (params) ->

socket.on 'pbcopy', (params) ->
table.prependRow $$.ui.createRow
title: 'クリップボードにコピー'
title: params.text
icon: '/images/note_pinned.ico'
message: params.text
message: 'クリップボードにコピー'
hasChild: false
click: ->
Ti.UI.Clipboard.setText params.text

socket.on 'phoneCall', (params) ->
Ti.API.debug params.tel
Ti.Platform.openURL "tel:#{params.tel}"

tabGroup =Ti.UI.createTabGroup()
tab = Ti.UI.createTab
window: win
tabGroup.addTab tab
tabGroup.open()
29 changes: 15 additions & 14 deletions Resources/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Ti.include("ui.js");
Ti.include("socket.js");
Ti.UI.setBackgroundColor("#fff");
win = Ti.UI.createWindow({
title: "Timeline"
title: "Chrome To iOS"
});
win.hideTabBar();
dummy = Ti.UI.createTableViewRow({
Expand All @@ -19,15 +19,22 @@ table.prependRow = function(row) {
animationStyle: Ti.UI.iPhone.RowAnimationStyle.LEFT
});
};
tabGroup = Ti.UI.createTabGroup();
tab = Ti.UI.createTab({
window: win
});
tabGroup.addTab(tab);
tabGroup.open();
socket.connect(win);
socket.on("hello", function(e) {
return alert("hello!");
});
socket.on('openUrl', function(params) {
return table.prependRow($$.ui.createRow({
title: 'URLを開く',
title: params.title || params.url,
icon: "http://favicon.st-hatena.com/?url=" + params.url,
message: params.url,
message: 'URLを開く',
image: params.image,
hasChild: true,
click: function() {
var w;
Expand All @@ -41,9 +48,9 @@ socket.on('openUrl', function(params) {
});
socket.on('openMap', function(params) {
return table.prependRow($$.ui.createRow({
title: 'マップを開く',
title: "" + params.latitude + ", " + params.longitude,
icon: '/images/gmaps.ico',
message: "" + params.latitude + ", " + params.longitude,
message: 'マップを開く',
hasChild: true,
click: function() {
var anno, w;
Expand Down Expand Up @@ -72,9 +79,9 @@ socket.on('openMap', function(params) {
});
socket.on('pbcopy', function(params) {
return table.prependRow($$.ui.createRow({
title: 'クリップボードにコピー',
title: params.text,
icon: '/images/note_pinned.ico',
message: params.text,
message: 'クリップボードにコピー',
hasChild: false,
click: function() {
return Ti.UI.Clipboard.setText(params.text);
Expand All @@ -84,10 +91,4 @@ socket.on('pbcopy', function(params) {
socket.on('phoneCall', function(params) {
Ti.API.debug(params.tel);
return Ti.Platform.openURL("tel:" + params.tel);
});
tabGroup = Ti.UI.createTabGroup();
tab = Ti.UI.createTab({
window: win
});
tabGroup.addTab(tab);
tabGroup.open();
});
53 changes: 27 additions & 26 deletions Resources/ui.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,21 @@ $$.ui =
container = Ti.UI.createView
top: 10
left: 10
width: 300
width: 290
height: 'auto'
layout: 'vertical'

title = Ti.UI.createLabel
text: params.title
color: "#000"
top: 0
bottom: 5
left: 0
width: 'auto'
height: 'auto'
font:
fontSize: 16

# date = Ti.UI.createLabel
# text: params.date
# width: 'auto'
# height: 'auto'
# top: 10
# right: 10
# color: '#999'
# font:
# fontSize: 14
if params.image
Ti.API.debug params.image
container.add Ti.UI.createImageView
image: params.image
width: 100
height: 100
top: 0
bottom: 3
left: 5

messageContainer = Ti.UI.createView
titleContainer = Ti.UI.createView
top: 0
left: 0
height: 'auto'
Expand All @@ -45,8 +34,20 @@ $$.ui =
image: params.icon
width: 16
height: 16
top: 2
left: 0

title = Ti.UI.createLabel
text: params.title
color: "#000"
top: 0
bottom: 5
left: 3
width: 'auto'
height: 'auto'
font:
fontSize: 16

message = Ti.UI.createLabel
text: params.message
color: "#666"
Expand All @@ -58,10 +59,10 @@ $$.ui =
font:
fontSize: 14

messageContainer.add favicon
messageContainer.add message
container.add title
container.add messageContainer
titleContainer.add favicon
titleContainer.add title
container.add titleContainer
container.add message
row.add container
# row.add date

Expand Down
50 changes: 31 additions & 19 deletions Resources/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if (typeof $$ === "undefined" || $$ === null) {
}
$$.ui = {
createRow: function(params) {
var container, favicon, message, messageContainer, row, title;
var container, favicon, message, row, title, titleContainer;
row = Ti.UI.createTableViewRow({
height: 'auto',
layout: 'absolute',
Expand All @@ -12,23 +12,22 @@ $$.ui = {
container = Ti.UI.createView({
top: 10,
left: 10,
width: 300,
width: 290,
height: 'auto',
layout: 'vertical'
});
title = Ti.UI.createLabel({
text: params.title,
color: "#000",
top: 0,
bottom: 5,
left: 0,
width: 'auto',
height: 'auto',
font: {
fontSize: 16
}
});
messageContainer = Ti.UI.createView({
if (params.image) {
Ti.API.debug(params.image);
container.add(Ti.UI.createImageView({
image: params.image,
width: 100,
height: 100,
top: 0,
bottom: 3,
left: 5
}));
}
titleContainer = Ti.UI.createView({
top: 0,
left: 0,
height: 'auto',
Expand All @@ -39,8 +38,21 @@ $$.ui = {
image: params.icon,
width: 16,
height: 16,
top: 2,
left: 0
});
title = Ti.UI.createLabel({
text: params.title,
color: "#000",
top: 0,
bottom: 5,
left: 3,
width: 'auto',
height: 'auto',
font: {
fontSize: 16
}
});
message = Ti.UI.createLabel({
text: params.message,
color: "#666",
Expand All @@ -53,10 +65,10 @@ $$.ui = {
fontSize: 14
}
});
messageContainer.add(favicon);
messageContainer.add(message);
container.add(title);
container.add(messageContainer);
titleContainer.add(favicon);
titleContainer.add(title);
container.add(titleContainer);
container.add(message);
row.add(container);
row.addEventListener('click', params.click);
return row;
Expand Down
15 changes: 15 additions & 0 deletions Resources/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if (typeof $$ === "undefined" || $$ === null) {
$$ = {};
}
$$.util = {
prettyDate: function(time) {
var date, day_diff, diff;
date = new Date((time || "").replace(/-/g, "/").replace(/[TZ]/g, " "));
diff = ((new Date()).getTime() - date.getTime()) / 1000;
day_diff = Math.floor(diff / 86400);
if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) {
return;
}
return day_diff === 0 && (diff < 60 && "たった今" || diff < 120 && "1分前" || diff < 3600 && Math.floor(diff / 60) + "分前" || diff < 7200 && "1時間前" || diff < 86400 && Math.floor(diff / 3600) + "時間前") || day_diff === 1 && "昨日" || day_diff < 7 && day_diff + "日前" || day_diff < 31 && Math.ceil(day_diff / 7) + "週間前";
}
};

0 comments on commit 7cdf7de

Please sign in to comment.