root/platform/air/wasaco/src/wasaco.mxml @ 18545

Revision 18545, 28.2 kB (checked in by kan, 5 years ago)

TODOの閲覧、追加、完了、削除に対応。タグによる絞り込みもできる

Line 
1<?xml version="1.0" encoding="utf-8"?>
2<mx:Application
3        xmlns:mx="http://www.adobe.com/2006/mxml"
4        layout="absolute"
5        height="504"
6        width="400"
7        cornerRadius="4"
8        applicationComplete="init()"
9         xmlns:ns1="*">
10    <mx:Script>
11    <![CDATA[
12        import mx.events.IndexChangedEvent;
13        import vc.kan.util.Template;
14        import mx.events.CloseEvent;
15        import flash.net.URLRequestDefaults;
16        import mx.events.ResizeEvent;
17        import mx.managers.SystemManager;
18        import mx.controls.Alert;
19                import mx.controls.Text;
20                import mx.controls.Image;
21                import mx.containers.TitleWindow;
22        import mx.managers.PopUpManager;
23        import vc.kan.net.Wassr;
24        import vc.kan.data.DBObject;
25            import mx.formatters.DateFormatter;
26           
27            [Embed(source="assets/feed.tt", mimeType="application/octet-stream")]
28            private var feedTmpl:Class;
29           
30            [Embed(source="assets/feed_channel.tt", mimeType="application/octet-stream")]
31            private var feedChannelTmpl:Class;
32       
33            [Embed(source="assets/todo.tt", mimeType="application/octet-stream")]
34            private var todoListTmpl:Class;
35       
36            [Embed(source="assets/style.tt", mimeType="application/octet-stream")]
37            private var feedStyleTmpl:Class;
38           
39            [Embed(source="assets/help.txt", mimeType="application/octet-stream")]
40            private var helpDocument:Class;
41       
42                public var timer:Timer = new Timer(60000);
43               
44                private var feed_view:Array = new Array(20);
45               
46                private var wassr:Wassr;
47               
48                public var user_id:String;
49                public var password:String;
50               
51                public var feed_item:Object;
52                private var iine_map:Object;
53                public var selected_feed:int = -1;
54               
55                private var verXML:XML;
56
57                private var settingDb:DBObject = new DBObject(Setting);
58                private var setting:Object;
59               
60                private var last_chack_wasaco_status_rid:String = "";
61               
62                private function init():void
63                {
64                        URLRequestDefaults.userAgent = "wasaco/"+version()+"; http://fushihara.net/wasaco.html";
65                       
66                        this.panel.title = "wasaco ver " + version();
67                        this.panel.addEventListener( MouseEvent.MOUSE_DOWN, doDrag );
68                        this.panel.addEventListener( MouseEvent.MOUSE_UP, savePosition );
69                        this.minimizeBtn.addEventListener( MouseEvent.MOUSE_UP, onMinimize );
70                        this.closeBtn.addEventListener( MouseEvent.MOUSE_UP, onClose );
71                        this.resizeBtn.addEventListener( MouseEvent.MOUSE_DOWN, startResize );
72                        this.resizeBtn.addEventListener( MouseEvent.MOUSE_UP, saveWindowSize );
73                        stage.addEventListener(Event.RESIZE, onResize);
74                        this.feedCanvas.addEventListener( Event.COMPLETE, feedLinkHook );
75                        this.feedCanvas.htmlLoader.paintsDefaultBackground = false;
76                        this.feedCanvas.htmlLoader.navigateInSystemBrowser = true;
77                        stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDown );
78                        stage.addEventListener( KeyboardEvent.KEY_UP, keyUp );
79                        XML.prettyPrinting = false;
80                        iine_map = {};
81                       
82                        var mine:wasaco = this;
83                        settingDb.find(function (settings:Array):void {
84                                setting = {
85                                        backColor: 0,
86                                        backAlpha: 0.8,
87                                        fontColor: "FFFFFF",
88                                        selectedBackColor: "330066",
89                                        fontSize: 10,
90                                        windowWidth: 400,
91                                        windowHeight: 500,
92                                        windowX: 100,
93                                        windowY: 100,
94                                        alwaysFront: "off"
95                                };
96                                settings.forEach(function(conf:*, idx:Number, arr:Array):void {
97                                        setting[conf.key] = conf.value;
98                                });
99                                panel.setStyle("backgroundColor", setting.backColor);
100                                panel.setStyle("backgroundAlpha", setting.backAlpha);
101                                panel.setStyle("color", Number("0x"+setting.fontColor));
102                                alwaysFrontChk.setStyle("color", Number("0x"+setting.fontColor));
103                                if (setting.alwaysFront == "on") {
104                                        alwaysFrontChk.selected = true;
105                                        stage.nativeWindow.alwaysInFront = true;
106                                }
107                                message.setStyle("color", Number("0x"+setting.fontColor));
108                                stage.nativeWindow.width = setting.windowWidth;
109                                stage.nativeWindow.height = setting.windowHeight;
110                                stage.nativeWindow.x = setting.windowX;
111                                stage.nativeWindow.y = setting.windowY;
112                        });
113                        showLoginWindow();
114                }
115               
116                private function keyDown(evt:KeyboardEvent):void {
117                        trace(evt.keyCode);
118                        switch (evt.keyCode) {
119                                case 72: // h
120                                        if ( evt.controlKey ) {
121                                                if ( tabNavi.selectedIndex == 0) {
122                                                        tabNavi.selectedIndex = 4;
123                                                } else {
124                                                        tabNavi.selectedIndex--;
125                                                }
126                                        }
127                                        break;
128                                case 76: // l
129                                        if ( evt.controlKey ) {
130                                                if ( tabNavi.selectedIndex == 4) {
131                                                        tabNavi.selectedIndex = 0;
132                                                } else {
133                                                        tabNavi.selectedIndex++;
134                                                }
135                                        }
136                                        break;
137                                case 74: // j
138                                        unHighlightFeed();
139                                        selected_feed++;
140                                        selected_feed = highlightFeed();
141                                        break;
142                                case 75: // k
143                                        unHighlightFeed();
144                                        selected_feed--;
145                                        selected_feed = highlightFeed();
146                                        break;
147                        }
148                }
149               
150                private function keyUp(evt:KeyboardEvent):void {
151                        switch (evt.keyCode) {
152                                case 118: // F7
153                                        if (evt.altKey) {
154                                                selected_feed = -1;
155                                                stat.setFocus();
156                                        }
157                                        break;
158                                case 73: // i
159                                        if (evt.controlKey) {
160                                                if (selected_feed>=0) {
161                                                        iine(feed_item[selected_feed].rid);
162                                                }
163                                        }
164                                        break;
165                                case 116: // F5
166                                        statusUpdate();
167                                        break;
168                                case 82: // r
169                                        if (evt.controlKey) {
170                                                if (selected_feed>=0) {
171                                                        reply(feed_item[selected_feed].rid);
172                                                        selected_feed = -1;
173                                                }
174                                        }
175                        }
176                }
177
178                private function highlightFeed():int {
179                        var feed:* = feedCanvas.htmlLoader.window.document.getElementById("feed" + selected_feed);
180                        if ( feed ) {
181                                var top:int = 0, element:* = feed;
182                                do {
183                                        top += element.offsetTop || 0;
184                                        element = element.offsetParent;
185                                } while (element);
186                                trace(setting.selectedBackColor);
187                                feedCanvas.htmlLoader.window.scrollTo(0, top);
188                                feed.style.background = '#'+setting.selectedBackColor;
189                                var feed_stat:* = feedCanvas.htmlLoader.window.document.getElementById("feed_stat" + selected_feed);
190                                feed_stat.style.background = '#'+setting.selectedBackColor;
191                                return selected_feed;
192                        } else {
193                                return -1;
194                        }
195                }
196               
197                private function unHighlightFeed():void {
198                        var feed:* = feedCanvas.htmlLoader.window.document.getElementById("feed" + selected_feed);
199                        if ( feed ) {
200                                feed.style.background = '';
201                                var feed_stat:* = feedCanvas.htmlLoader.window.document.getElementById("feed_stat" + selected_feed);
202                                feed_stat.style.background = '';
203                        }
204                }
205               
206                private function initReplies():void {
207                        this.repliesCanvas.addEventListener( Event.COMPLETE, feedLinkHook );
208                        this.repliesCanvas.htmlLoader.paintsDefaultBackground = false;
209                        this.repliesCanvas.htmlLoader.navigateInSystemBrowser = true;
210                        get_feed();
211                }
212               
213                private function initChannel():void {
214                        this.channelCanvas.addEventListener( Event.COMPLETE, feedLinkHook );
215                        this.channelCanvas.htmlLoader.paintsDefaultBackground = false;
216                        this.channelCanvas.htmlLoader.navigateInSystemBrowser = true;
217                        get_channel_list();
218                }
219               
220                private function initTodo():void {
221                        this.todoCanvas.addEventListener( Event.COMPLETE, todoButtonHook );
222                        this.todoCanvas.htmlLoader.paintsDefaultBackground = false;
223                        this.todoCanvas.htmlLoader.navigateInSystemBrowser = true;
224                        this.todoBody.width = this.width - 210;
225                        wassr.getTodoTags(function(todo:Array, tags:Object):void {
226                                var tag_list:Array = new Array({ label:"全て", value: null });
227                                for (var t:String in tags) {
228                                        tag_list.push({ label: t, tag:t });
229                                }
230                                todoTagList.dataProvider = tag_list;
231                                displayTodo(todo);
232                        });
233                }
234
235                private function initManual():void {
236                        this.manual.text = String(new helpDocument());
237                }
238               
239                private function doDrag(event:MouseEvent):void {
240                        if ( this.panel.contains(event.target as DisplayObject) ) return;
241                        applicationDragHandler(event);
242                }
243               
244                private function feedLinkHook(event:Event):void {
245                        var links:Object = event.target.htmlLoader.window.document.links;
246                        for (var i:uint=0; i < links.length; i++) {
247                                if ( links[i].className == "comment" ) {
248                                        links[i].addEventListener("click", replyClick);
249                                } else if ( links[i].className == "iine" ) {
250                                        links[i].addEventListener("click", iineClick);
251                                } else {
252                                        links[i].addEventListener("mouseover", overLink);
253                                }
254                        }
255                }
256
257                private function todoButtonHook(event:Event):void {
258                        var buttons:Object = event.target.htmlLoader.window.document.getElementsByTagName('input');
259                        for (var i:uint=0; i < buttons.length; i++) {
260                                if ( buttons[i].className == "fix" ) {
261                                        buttons[i].addEventListener("click", function (e:Object):void {
262                                                wassr.doneTodo(e.target.alt, function ():void { get_todo(); });
263                                        } );
264                                } else {
265                                        buttons[i].addEventListener("click", function (e:Object):void {
266                                                wassr.deleteTodo(e.target.alt, function ():void { get_todo(); });
267                                        } );
268                                }
269                        }
270                }
271
272                private function overLink(evt:Object):void {
273                        var url:String = evt.target.href;
274                        if (url == null) return;
275                        message.text = url.replace(/http:\/\/wassr\.jp/, "");
276                }
277
278                private function replyClick(evt:Object):void {
279                        reply(evt.target.title);
280                }
281               
282                public function reply(status_rid:String):void {
283                        var comment:commentWindow = commentWindow(
284                                PopUpManager.createPopUp(this, commentWindow, true)
285                        );
286                        comment.target = this;
287                        comment.res_rid = status_rid;
288                        PopUpManager.centerPopUp(comment);
289                }
290
291                private function iineClick(evt:Object):void {
292                        iine(evt.target.title);
293                }
294               
295                public function iine(status_rid:String):void {
296                        var btn:* = feedCanvas.htmlLoader.window.document.getElementById("iine" + status_rid);
297                        if ( iine_map[status_rid] == 1 ) {
298                                wassr.unFavStatus(status_rid, function():void{
299                                        iine_map[status_rid] = 0;
300                                        btn.src = "app:/assets/normal.png";
301                                });
302                        } else {
303                                wassr.favStatus(status_rid, function():void{
304                                        iine_map[status_rid] = 1;
305                                        btn.src = "app:/assets/good.png";
306                                });
307                        }
308                }
309
310                public function saveSetting(key:String, value:*):void
311                {
312                        settingDb.find(function(settings:Array):void{
313                                if ( settings[0] ) {
314                                        settings[0].update({
315                                                "value": value
316                                        });
317                                }
318                        }, { "key": key }, null,
319                        function():void {
320                                settingDb.create({
321                                        "key": key,
322                                        "value": value
323                                }, function ():void {});
324                        });
325                }
326               
327                public function startAutoGetFeed():void
328                {
329                        updateCheck();
330                        timer.addEventListener(TimerEvent.TIMER, timerHandler);
331                        timer.start();
332                }
333               
334                private function showLoginWindow():void
335                {
336                        var login:loginWindow = loginWindow(
337                                PopUpManager.createPopUp(this, loginWindow, true)
338                        );
339                        login.target = this;
340                        login.loadProfile();
341                        PopUpManager.centerPopUp(login);
342                }
343               
344                public function get_feed():void
345                {
346                        if (!wassr) {
347                                wassr = new Wassr(user_id, password, URLRequestDefaults.userAgent);
348                                wassr.addEventListener(IOErrorEvent.IO_ERROR, function (evt:IOErrorEvent):void { });
349                        }
350                        message.text = "データ取得開始……";
351                        wassr.getFeed(displayFeed);
352                        wassr.getReplies(displayReplies);
353                }
354               
355                public function get_channel_list():void
356                {
357                        if (!wassr) {
358                                wassr = new Wassr(user_id, password, URLRequestDefaults.userAgent);
359                                wassr.addEventListener(IOErrorEvent.IO_ERROR, function (evt:IOErrorEvent):void { });
360                        }
361                        message.text = "チャンネルデータ取得開始……";
362                        wassr.getUserChannelList(function(channels:Array):void{
363                                channelList.dataProvider = channels;
364                                var channel:String = channelList.selectedItem.name_en;
365                                wassr.channelStatusUpdate(channel, stat.text, function ():void {
366                                        wassr.getChannelFeed(channel, displayChannel);
367                                });
368                                message.text = "";
369                        });
370                }
371               
372                public function get_todo():void
373                {
374                        if (!wassr) {
375                                wassr = new Wassr(user_id, password, URLRequestDefaults.userAgent);
376                                wassr.addEventListener(IOErrorEvent.IO_ERROR, function (evt:IOErrorEvent):void { });
377                        }
378                        message.text = "TODOデータ取得開始……";
379                        var tag:String = todoTagList.selectedItem.tag;
380                        if ( tag ) todoBody.text = "[" + tag + "]";
381                        wassr.getTodo(displayTodo, tag);
382                }
383               
384                public function timerHandler(evt:TimerEvent):void
385                {
386                        get_feed();
387                }
388               
389                private function displayFeed(feed_item:Object):void
390                {
391                        message.text = "データ取得完了";
392                        this.feed_item = feed_item;
393                        feedCanvas.htmlText = makeFeedHTML(feed_item);
394                        message.text = "";
395                }
396               
397                private function displayReplies(feed_item:Object):void
398                {
399                        message.text = "返信データ取得完了";
400                        if ( repliesCanvas ) {
401                                repliesCanvas.htmlText = makeFeedHTML(feed_item);
402                        }
403                        message.text = "";
404                }
405               
406                private function displayChannel(feed_item:Object):void
407                {
408                        message.text = "チャンネルデータ取得完了";
409                        if ( channelCanvas ) {
410                                channelCanvas.htmlText = makeChannelFeedHTML(feed_item);
411                        }
412                        message.text = "";
413                }
414
415                private function displayTodo(todo_item:Object):void
416                {
417                        message.text = "TODOデータ取得完了";
418                        if ( todoCanvas ) {
419                                todoCanvas.htmlText = makeTodoListHTML(todo_item);
420                        }
421                        message.text = "";
422                }
423               
424                private function getFeedStyle():String
425                {
426                        var template:Template = new Template();
427                        this.setting.replyFontSize = int(setting.fontSize * 0.9);
428                        return template.process(String(new feedStyleTmpl()), this.setting);
429                }
430               
431                private function makeFeedHTML(feed_item:Object, type:String="feed"):String
432                {
433                        var template:Template = new Template();
434                        var html:String = getFeedStyle();
435                        var pattern:RegExp = /(?<!src=")https?:\/\/[-_.!~*'()\w;\/?:@&=+$,%#]+/g;
436                        html += "<table>";
437                        for (var j:int=0; j<20; j++) {
438                                if (feed_item[j]) {
439                                        // UpdateCheck
440                                        if ( feed_item[j].user_login_id == "wasaco" && last_chack_wasaco_status_rid != feed_item[j].rid ){
441                                                last_chack_wasaco_status_rid = feed_item[j].rid;
442                                                updateCheck();
443                                        }
444                                        var vars:Object = feed_item[j];
445                                        vars.cnt = j;
446                                        if (feed_item[j].reply_user_nick) {
447                                                if ( feed_item[j].reply_message ) {
448                                                        vars.reply_message = feed_item[j].reply_message.replace(pattern, "[URL]");
449                                                } else {
450                                                        vars.reply_message = feed_item[j].reply_user_nick + "さんのメッセージは友達のみに公開です";
451                                                }
452                                        }
453                                        vars.html = feed_item[j].html.replace(pattern, replaceURL);
454                                        vars.profile_url = feed_item[j].user.profile_image_url;
455                                        vars.user_screen_name = feed_item[j].user.screen_name;
456                                        var fmt:DateFormatter = new DateFormatter();
457                                        fmt.formatString = "YYYY/MM/DD JJ:NN";
458                                        vars.time = fmt.format(new Date(int(feed_item[j].epoch) * 1000));
459                                        if (feed_item[j].user.protected) {
460                                                vars.iine_icon = "app:/assets/secret.png";
461                                        } else {
462                                                if ( iine_map[feed_item[j].rid] == 1 ) {
463                                                        vars.iine_icon = "app:/assets/good.png";
464                                                } else {
465                                                        vars.iine_icon = "app:/assets/normal.png";
466                                                }
467                                        }
468                                        html += template.process(String(new feedTmpl()), vars);
469                                }
470                        }
471                        trace(html);
472                        return html + "</table>";
473                }
474
475                private function makeChannelFeedHTML(feed_item:Object):String
476                {
477                        var template:Template = new Template();
478                        var html:String = getFeedStyle();
479                        var pattern:RegExp = /(?<!src=")https?:\/\/[-_.!~*'()\w;\/?:@&=+$,%#]+/g;
480                        html += "<table>";
481                        for (var j:int=0; j<20; j++) {
482                                if (feed_item[j]) {
483                                        var vars:Object = feed_item[j];
484                                        vars.html = feed_item[j].body.replace(pattern, replaceURL);
485                                        vars.profile_url = feed_item[j].user.profile_image_url;
486                                        vars.user_login_id = feed_item[j].user.login_id;
487                                        vars.user_nick = feed_item[j].user.nick;
488                                        var fmt:DateFormatter = new DateFormatter();
489                                        fmt.formatString = "YYYY/MM/DD JJ:NN";
490                                        vars.time = fmt.format(new Date(int(feed_item[j].epoch) * 1000));
491                                        vars.favorites = vars.favorites.map(function(item:Object, idx:Number, array:Array):Object {
492                                                return "<a href=\"http://wassr.jp/user/"+item+"\"><img src=\"app:/assets/good.png\" /></a>";
493                                        });
494                                        html += template.process(String(new feedChannelTmpl()), vars);
495                                }
496                        }
497                        trace(html);
498                        return html + "</table>";
499                }
500               
501                private function makeTodoListHTML(todo_item:Object):String
502                {
503                        var template:Template = new Template();
504                        var html:String = getFeedStyle();
505                        html += '<table class="todo">';
506                        for (var j:int=0; j<30; j++) {
507                                if (todo_item[j]) {
508                                        var vars:Object = todo_item[j];
509                                        html += template.process(String(new todoListTmpl()), vars);
510                                }
511                        }
512                        trace(html);
513                        return html + "</table>";
514                }
515
516                private function replaceURL():String
517                {
518                        var url:String = arguments[0];
519                        var nico:RegExp = /http:\/\/www\.nicovideo\.jp\/watch\/(.+)\/?/;
520                        var youtube:RegExp = /http:\/\/(?:jp\.)youtube\.com\/watch\?v=(.+)\/?/;
521                        var amazon:RegExp = /(?:http:\/\/(?:www\.)?amazon\.(?:co\.)?jp\/[a-z0-9\/-_]+\/|asin:|isbn:)([0-9A-Z]{10,13})/;
522                       
523                        var result:Object = nico.exec(url);
524                       
525                        if ( result ) {
526                                return '<br /><iframe width="312" height="176" src="http://ext.nicovideo.jp/thumb/' +
527                                                        result[1] +
528                                                        '" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"><a href="' +
529                                                        result[0] +
530                                                        '">video</a></iframe><br />';
531                        } else {
532                                result = youtube.exec(url);
533                                if ( result ) {
534                                        return '<br /><a href="'+url+'" target="_blank"><img src="http://img.youtube.com/vi/'+result[1]+'/1.jpg" />[YouTube]</a><br />';
535                                } else {
536                                        result = amazon.exec(url);
537                                        if ( result ) {
538                                                return '<br /><a href="'+url+'/" target="_blank"><img src="http://images-jp.amazon.com/images/P/'+result[1]+'.09.MZZZZZZZ.jpg" />[amazon]</a><br />';
539                                        } else {
540                                                return '<a href="'+url+'" target="_blank">[URL]</a>';
541                                        }
542                                }
543                        }
544                }
545               
546                private function displayParentComment(evt:Event):void
547                {
548                        Alert.show(evt.currentTarget.data);
549                }
550
551                public function applicationDragHandler(event:MouseEvent):void
552                {
553                        stage.nativeWindow.startMove();
554                }
555                   
556                private function onClose(evt:MouseEvent):void
557                {
558                        stage.nativeWindow.close();
559                }
560               
561                private function onMinimize(evt:MouseEvent):void
562                {
563                        stage.nativeWindow.minimize();
564                }
565               
566                private function showPictWindow(evt:MouseEvent):void
567                {
568                        var pict:pictWindow = pictWindow(
569                                PopUpManager.createPopUp(this, pictWindow, true)
570                        );
571                        pict.load(stat);
572                        PopUpManager.centerPopUp(pict);
573                }
574
575                public function statusUpdate(res_rid:String=null):void
576                {
577                        if ( tabNavi.selectedIndex == 2 ) {
578                                var channel:String = channelList.selectedItem.name_en;
579                                if (stat.text == "") {
580                                        wassr.getChannelFeed(channel, displayChannel);
581                                        return;
582                                }
583                                wassr.channelStatusUpdate(channel, stat.text, function ():void {
584                                        wassr.getChannelFeed(channel, displayChannel);
585                                });
586                        } else {
587                                if (stat.text == "") {
588                                        get_feed();
589                                        return;
590                                }
591                                wassr.statusUpdate(stat.text, function ():void {get_feed();}, res_rid);
592                        }
593                        stat.text = "";
594                }
595               
596                private function addTodo():void
597                {
598                        wassr.addTodo(todoBody.text, function ():void { get_todo(); });
599                }
600               
601                private function selectChannel():void
602                {
603                        channelImage.source = channelList.selectedItem.image_url;
604                        wassr.getChannelFeed(channelList.selectedItem.name_en, displayChannel);
605                }
606               
607                public function startResize(event:MouseEvent):void
608                {
609                        stage.nativeWindow.startResize(NativeWindowResize.BOTTOM_RIGHT);
610                }
611               
612                public function onResize(event:Event):void
613                {
614                        this.height = stage.nativeWindow.height;
615                        this.width = stage.nativeWindow.width;
616                        this.panel.height = stage.nativeWindow.height;
617                        this.panel.width = stage.nativeWindow.width;
618                        this.ControlArea.width = this.panel.width - 20;
619                        this.tabNavi.width = this.panel.width - 20;
620                        this.tabNavi.height = this.height - 120;
621                        this.stat.width = this.width - 115;
622                        this.message.width = this.width - 200;
623                        if ( this.todoBody ) {
624                                this.todoBody.width = this.width - 210;
625                        }
626                }
627               
628                public function alwaysFront(event:Event):void
629                {
630                        if (this.alwaysFrontChk.selected == true) {
631                                stage.nativeWindow.alwaysInFront = true;
632                                saveSetting("alwaysFront", "on");
633                        } else {
634                                stage.nativeWindow.alwaysInFront = false;
635                                saveSetting("alwaysFront", "off");
636                        }
637                }
638               
639                private function saveWindowSize(event:Event):void
640                {
641                        saveSetting("windowWidth", stage.nativeWindow.width);
642                        saveSetting("windowHeight", stage.nativeWindow.height);
643                }
644
645                private function savePosition(event:MouseEvent):void {
646                        if ( this.panel.contains(event.target as DisplayObject) ) return;
647                        saveSetting("windowX", stage.nativeWindow.x);
648                        saveSetting("windowY", stage.nativeWindow.y);
649                }
650
651                public function settingTab():void {
652                        bcolorSel.selectedColor = panel.getStyle("backgroundColor");
653                        alphaSel.value = panel.getStyle("backgroundAlpha");
654                        fcolorSel.selectedColor = Number("0x"+setting.fontColor);
655                        sbcolorSel.selectedColor = Number("0x"+setting.selectedBackColor);
656                        fsizeSel.value = setting.fontSize;
657                        label1.setStyle("color", fcolorSel.selectedColor);
658                        label2.setStyle("color", fcolorSel.selectedColor);
659                        label3.setStyle("color", fcolorSel.selectedColor);
660                        label4.setStyle("color", fcolorSel.selectedColor);
661                        label5.setStyle("color", fcolorSel.selectedColor);
662                }
663
664                private function doSetting():void
665                {
666                        saveSetting("backColor", bcolorSel.selectedColor);
667                        saveSetting("backAlpha", alphaSel.value);
668                        saveSetting("fontColor", fcolorSel.selectedColor.toString(16));
669                        saveSetting("selectedBackColor", sbcolorSel.selectedColor.toString(16));
670                        saveSetting("fontSize", fsizeSel.value);
671                        setting.fontColor = fcolorSel.selectedColor.toString(16);
672                        setting.selectedBackColor = sbcolorSel.selectedColor.toString(16);
673                        setting.fontSize = fsizeSel.value;
674                        panel.setStyle("backgroundColor", bcolorSel.selectedColor);
675                        panel.setStyle("color", fcolorSel.selectedColor);
676                        alwaysFrontChk.setStyle("color", fcolorSel.selectedColor);
677                        message.setStyle("color", fcolorSel.selectedColor);
678                        label1.setStyle("color", fcolorSel.selectedColor);
679                        label2.setStyle("color", fcolorSel.selectedColor);
680                        label3.setStyle("color", fcolorSel.selectedColor);
681                        label4.setStyle("color", fcolorSel.selectedColor);
682                        label5.setStyle("color", fcolorSel.selectedColor);
683                        panel.setStyle("backgroundAlpha", alphaSel.value);
684                        get_feed();
685                }
686               
687                private function version():String
688                {
689                        default xml namespace = new Namespace('http://ns.adobe.com/air/application/1.1');
690                        return NativeApplication.nativeApplication.applicationDescriptor.version;
691                }
692               
693                private function updateCheck(notify:Boolean = false):void
694                {
695                        var versionLoader:URLLoader = new URLLoader();
696                        versionLoader.addEventListener(Event.COMPLETE, function (evt:Event):void {
697                                verXML = new XML(evt.target.data);
698                                var localVer:String = version();
699                                var remoteVer:String = verXML.version;
700                                if ( remoteVer != localVer ) {
701                                        Alert.show("新しいwasacoがリリースされています。\n" +
702                                                   "更新しますか?\n\n" +
703                                                   "現在のバージョン:" + localVer + "\n" +
704                                                   "新しいバージョン:" + remoteVer,
705                                                   "確認", Alert.YES | Alert.NO, null, updateConfirm);
706                                } else {
707                                        if ( notify ) {
708                                                Alert.show("ご利用のwasacoは最新版です。", "確認", Alert.OK, null, null);
709                                        }
710                                }
711                        });
712                        versionLoader.load(new URLRequest("http://fushihara.net/wasaco/version.xml"));
713                }
714               
715                private function updateConfirm(evt:CloseEvent): void
716                {
717                        if (evt.detail == Alert.YES) {
718                                var archiveLoader:URLLoader = new URLLoader();
719                                archiveLoader.dataFormat = URLLoaderDataFormat.BINARY;
720                                archiveLoader.addEventListener(Event.COMPLETE, function (evt:Event):void {
721                                        var airFile:File = File.createTempFile();
722                                        var fs:FileStream = new FileStream();
723                                        var data:ByteArray = evt.target.data as ByteArray;
724                                        fs.open(airFile, FileMode.WRITE);
725                                        fs.writeBytes(data);
726                                        fs.close();
727                                       
728                                        var updater:Updater = new Updater();
729                                        updater.update(airFile, verXML.version);
730                                });
731                                archiveLoader.load(new URLRequest(verXML.archive));
732                                updateProgress.source = archiveLoader;
733                                updateProgress.visible = true;
734                        }
735                }
736
737        ]]>
738        </mx:Script>
739        <mx:Style>
740                Application {
741                        background-image: "";
742                        background-color: "";
743                        background-alpha: 0;
744                }
745                Panel {
746                        color: #ffffff;
747                        borderStyle: solid;
748                        roundedBottomCorners: true;
749                        cornerRadius: 15;
750                        shadowDirection: right;
751                        backgroundColor: #000000;
752                        backgroundAlpha: 0.8;
753                        width: 400px;
754                        height: 500px;
755                }
756        </mx:Style>
757        <mx:Panel id="panel" x="0" y="0" title="wasaco" titleIcon="@Embed(source='assets/wasaco.png')" width="374">
758                <mx:Canvas x="0" y="0" width="100%" height="45" id="ControlArea">
759                        <mx:TextInput x="10" y="10" width="254" id="stat" color="#111111" enter="statusUpdate();"  height="22"/>
760                        <mx:Button right="60" y="10" width="22" click="showPictWindow(event);" icon="@Embed('assets/heart.png')" fontSize="9" toolTip="絵文字入力"/>
761                        <mx:Button right="35" y="10" click="statusUpdate();" width="22" icon="@Embed('assets/action_refresh_blue.gif')" fontSize="9" toolTip="ヒトコト投稿/更新"/>
762                        <mx:Image id="minimizeBtn" source="assets/minimize_icon.png" width="16" height="16" right="16" y="0"/>
763                        <mx:Image id="closeBtn" source="assets/close_icon.png" width="16" height="16" right="0" y="0"/>
764                </mx:Canvas>
765                <mx:TabNavigator id="tabNavi" width="100%" height="380" color="#000000" backgroundAlpha="0.0">
766                        <mx:Canvas label="timeline">
767                                <mx:HTML x="0" y="0" width="100%" height="100%" id="feedCanvas" backgroundAlpha="0.0" />
768                        </mx:Canvas>
769                        <mx:Canvas label="replies" width="100%" height="100%" backgroundAlpha="0.0">
770                                <mx:HTML x="0" y="0" width="100%" height="100%" id="repliesCanvas" backgroundAlpha="0.0" creationComplete="initReplies()" />
771                        </mx:Canvas>
772                        <mx:Canvas label="channel" width="100%" height="100%" backgroundAlpha="0.0">
773                                <mx:ComboBox x="10" y="10" width="257" id="channelList" labelField="title" change="selectChannel()"></mx:ComboBox>
774                                <mx:HTML x="0" y="100" width="100%" height="100%" id="channelCanvas" backgroundAlpha="0.0" creationComplete="initChannel()" />
775                                <mx:Image x="275" y="10" id="channelImage"/>
776                        </mx:Canvas>
777                        <mx:Canvas label="todo" creationComplete="initTodo()">
778                                <mx:ComboBox id="todoTagList" x="10" y="10" width="91" change="get_todo()"></mx:ComboBox>
779                                <mx:TextInput x="110" y="10" width="177" id="todoBody" enter="addTodo()" />
780                                <mx:Button y="10" right="10" label="追加" click="addTodo()" />
781                                <mx:HTML x="0" y="50" width="100%" height="100%" id="todoCanvas" backgroundAlpha="0.0" />
782                        </mx:Canvas>
783                        <mx:Canvas label="Setting" width="100%" height="100%" color="#010101" creationComplete="settingTab()">
784                                <mx:Label id="label1" x="14" y="10" text="背景色"  color="#FEFEFE"/>
785                                <mx:ColorPicker x="27" y="36" id="bcolorSel" selectedColor="#277100"/>
786                                <mx:Label id="label2" x="96.5" y="10" text="透過度"  color="#FEFEFE"/>
787                                <mx:HSlider x="94" y="39" width="121" id="alphaSel" minimum="0" maximum="1" snapInterval="0.01"/>
788                                <mx:Button x="10" y="209" label="設定する" width="99" id="okBtn" click="doSetting()" />
789                                <mx:Button x="10" y="252" label="アップデートチェック" width="122" click="updateCheck(true)" />
790                                <mx:ProgressBar x="141" y="263" height="11" id="updateProgress" visible="false"/>
791                                <mx:Label id="label3" x="14" y="76" text="文字色"  color="#FEFEFE"/>
792                                <mx:ColorPicker x="27" y="102" id="fcolorSel" selectedColor="#277100"/>
793                                <mx:Label id="label4" x="96.5" y="77" text="文字のサイズ"  color="#FEFEFE"/>
794                                <mx:HSlider x="94" y="106" width="121" id="fsizeSel" minimum="8" maximum="40" snapInterval="1"/>
795                                <mx:Label id="label5" x="237" y="77" text="選択中の背景色"  color="#FEFEFE"/>
796                                <mx:ColorPicker x="250" y="103" id="sbcolorSel" selectedColor="#277100"/>
797                        </mx:Canvas>
798                        <mx:Canvas label="help" width="100%" height="100%" backgroundAlpha="0.0" creationComplete="initManual()">
799                                <mx:Text id="manual" x="10" y="10" text="" width="279" height="256" color="#FFFFFF"/>
800                        </mx:Canvas>
801                </mx:TabNavigator>
802                <mx:Canvas bottom="0" width="100%" height="20" color="#ffffff" id="statusBar" backgroundAlpha="0.0">
803                        <mx:Image id="resizeBtn" source="assets/resize_icon.png" width="16" height="16" right="0" bottom="0" />
804                        <mx:CheckBox id="alwaysFrontChk" x="0" y="0" label="常に最前面に表示する" click="alwaysFront(event)" />
805                        <mx:Label id="message" x="130" width="200" height="20"  y="2"/>
806                </mx:Canvas>
807        </mx:Panel>
808</mx:Application>
Note: See TracBrowser for help on using the browser.