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

Revision 19298, 32.9 kB (checked in by kan, 5 years ago)

イイネの処理がfeedCanvas決めうちになっててバグってた。修正

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