Amazon

2012年6月16日土曜日

Titaniumで使えるCalendarモジュール

Titaniumで自分のアプリ用のカレンダーを作りたい場合に使えそうなモジュール

- Appcelerator-Calendar-Module
http://www.mountposition.co.jp/blog/?p=227

- AGCalendar

https://github.com/Appgutta/AGCalendar
[document]
https://github.com/Appgutta/AGCalendar/blob/master/documentation/index.md

- 頑張って書いてみる
http://qiita.com/items/1398

var win = Ti.UI.currentWindow;

//今日という日
var now = new Date();
now.setHours(12);
var Y = now.getYear()+1900;
var M = now.getMonth()+1;

//表示している画面の年と月
var whenLabel = Ti.UI.createLabel({
    font:{
        fontFamily:'Helvetica Neue',
        fontSize:25
    },
    textAlign:'center',
    text:Y+"年"+M+"月",
    top:5, left:'auto', height:25, width:'auto'
});
win.add(whenLabel);

//月を戻すボタン
var backMonthButton = Ti.UI.createLabel({
    backgroundColor:"green",
    top:35, left:30, height:25, width:120,
    textAlign:'center',
    text:'back'
});
backMonthButton.addEventListener('click', function(){
    var date = new Date(Y,parseInt(M)-1-1)
    var Y_ = date.getYear()+1900;
    var M_ = date.getMonth()+1;
    whenLabel.text = Y_+"年"+M_+"月";
    cal(date);
});
win.add(backMonthButton);

//月を進めるボタン
var forwardMonthButton = Ti.UI.createLabel({
    backgroundColor:"green",
    top:35, left:170, height:25, width:120,
    textAlign:'center',
    text:'forward'
});
forwardMonthButton.addEventListener('click', function(){
    var date = new Date(Y,parseInt(M)-1+1)
    var Y_ = date.getYear()+1900;
    var M_ = date.getMonth()+1;
    whenLabel.text = Y_+"年"+M_+"月";
    cal(date);
});
win.add(forwardMonthButton);

//ここにカレンダーの各日付を表示。スクロールさせる。
var scrollView = Titanium.UI.createScrollView({
    contentWidth:'auto',
    contentHeight:'auto',
    top:70,
    height:300,
    width:320,
    backgroundColor:'#fff'
});
win.add(scrollView);

//カレンダー表示関数
var cal = function(date){
    var year = date.getFullYear();
    var month = date.getMonth();

    var leap_year=false;
    if ((year%4 == 0 && year%100 != 0) || (year%400 == 0)) leap_year=true;
    var lom = new Array(31,28+leap_year,31,30,31,30,31,31,30,31,30,31);
    var w = new Array("red","gray","gray","gray","gray","gray","blue"); //曜日の見分けは色のみ
    var days=0;
    for (var i=0; i < month; i++) days+=lom[i];
    var week=Math.floor((year*365.2425+days)%7); //その月の開始曜日を取得
    var cols = 0;
    var rows = 0;
    var width = 80;
    var height = 80;
    for(var i=0; i<lom[month]; i++){
        var top = 0 + height * rows;  //各日付の表示位置制御
        var left = 0 + width * cols;
        var calLabel = Ti.UI.createLabel({
            backgroundColor:w[week],
            borderColor:"black",
            top:top, left:left, height:height, width:width
        });
        scrollView.add(calLabel);
        var dayLabel = Ti.UI.createLabel({
            color:'white',
            font:{fontSize:20},
            width:'auto',
            textAlign:'center',
            height:'auto',
            text:i+1
        });
        calLabel.add(dayLabel);
        if(cols != 3){  //各日付は横4列まで
            cols++;
        } else {
            cols = 0;
            rows++;
        }
        if(week != 6){
            week++;
        } else {
            week = 0;
        }
    }
}

cal(now);

Javascriptのグラフモジュール

Javascriptのグラフモジュールを幾つか

○グラフ
- Raphaeljs
動きのあるグラフを作れるモジュール。かなり素敵なグラフが作れるが、もっぱら上級者向け

- flot (jQuery)
jQuery.jsを使ってグラフが作れる。
使い方はこちらを参照

Prototype.jsを使ってグラフが作れる。

- JSCharts (JavaScriptオンリーだけど有料)
他のモジュールなしのJavaScriptでグラフが作れる。が有料


2012年6月9日土曜日

Graph APIで写真にタグ付けする


FacebookのGraph APIで写真にタグ付けをする場合のパラメータは以下

Photo #tag


ParameterDescriptionTypeRequired
toUSER_ID of the User to tag; can also be provided in URL path (see above).stringOne of to ortag_text
tag_textA text string to tag.stringOne of to ortag_text
xx coordinate of tag, as a percentage offset from the left edge of the picturenumberno
yy coordinate of tag, as a percentage offset from the top edge of the picturenumberno

If the write is successful, you get the following return.
DescriptionType
If the update succeededboolean

2012年6月3日日曜日

Titaniumで別Window間で変数を渡す場合の注意点

TabGroupを使っている場合各Windowは
var tabGroup = Titanium.UI.currentWindow.tabGroup;
tabGroup.tabs[1].window
でアクセスできる。
#tabs[n]は追加したタブの数

そこで、window A -> tabGroup -> window Bでそれぞれにローカル変数を定義して、渡してあげる方法が一般的
tabGroup.tabs[1].hogeValue = tabGroup.tabs[1].window.hogehogeValue;
tabGroup.tabs[2].window.hogehogehogeValue = tabGroup.tabs[1].hogeValue;

もっとお手軽にやるならば、Titaniumのグローバル変数を使う。
Ti.Appにグローバル変数を定義する
Ti.App._hogeValue = "hoge";

ここで一つ気をつける事がある。
このグローバル変数、基本的に追記ができないようです。
例えば、配列のグローバル変数を作りたいとき
Ti.App._anArray = [];
Ti.App._anArray.push(['hoge']);
としてもTi.Appは更新されない。
#Ti.App._anArray=[]のまま。
そこでTi.App._anArray=['hoge'];
としてあげると更新される。
つまり別オブジェクトを割り当てることは可能だが、該当オブジェクトを追記(上書き)はできないため、一度ローカル変数で追記したい配列なり連想配列を作った上で、Ti.App._anArrayに割当てあげる。

もし配列に要素を追加したい場合は
var currentWithFriends = Ti.App._withFriends;
var ids = {
    name : e.source.text,
    id : e.source.id,
};
currentWithFriends.push(ids);
Ti.App._withFriends = currentWithFriends;

という感じ。

Facebook GraphAPIで友達と一緒にいることを伝えるAPI

*****今のところ、Facebookのbugらしく、Graph APIからのwith_tagsは投稿できない様子。with_tagsやtoを投稿しても消えてしまうみたい。
http://developers.facebook.com/bugs/334390446603278***


FacebookのGraphAPIを使って、"○○さんと一緒にいます"というような投稿をする場合、実際にFacebookにpostする際には"with_tags"というパラメーターをつける。

Graph APIのドキュメントによれば

with_tagsObjects (Users, Pages, etc) tagged as being with the publisher of the post ("Who are you with?" on Facebook)read_streamobjects containing id and name fields, encapsulated in a data[] array
とのことなので
Titaniumでのリクエストの書き方としては、paramatersという連想配列を定義して、
 Ti.Facebook.requestWithGraphPathの第二引数に指定するのが、汎用的な方法


function postFB(parameters) {
    if(!Ti.Facebook.loggedIn) {
        Ti.Facebook.authorize();
    }
    var paramater = {
        message : "with Friend, xxx",
        with_tags : {
            data : [{
                id : id,
                name : name
            }]
        }
    };


    Ti.Facebook.requestWithGraphPath('me/feed', parameters, "POST", function(e) {
        if(e.success) {
            alert("Success" + e.result);
        }
    });
}



Amazon3