Android/myself2011/08/29 17:01
スライドパズル

幅が 3 マスから 6 マスで、高さが 3 マスから 6 マスのボードが与えられます。 各マスは、パネルが置かれているか、壁があるか、空白であるかのいずれかです。 パネルには 1 から 9 あるいは A から Z のいずれかの文字が書かれており、同じ文字の書かれたパネルは存在しません。 壁は 0 個以上存在し、空白のマスはただ 1 つだけ存在します。 例えば、次のようなボードが与えられます。ここで、壁は = で、空白は 0 で表されています。

40=

215

=86


空白は、上下左右のマスのパネルと入れ替えることができます。上のマスのパネルと入れ替えることを U とよび、同様に、下左右のマスのパネルと入れ替えることをそれぞれ D, L, R とよぶものとします。壁を空白やパネルと入れ替えることはできません。

パズルを解くというのは、与えられたボードの各マスを操作して、ゴール状態に持っていくことです。

ゴール状態とは、上の行から各行順番に、左から右に 1, 2, 3, 4, ..., 9, A, ..., Z という順にパネルが並び、最も右下のマスに空白が配置された状態のことです。壁のあるマスに対応するパネルは存在しません。例えば、左上のマスが壁であれば、ボード上に 1 のパネルは存在しません。

例えば、上で与えられたボードのパズルを解くと以下のようになります。

4 0 =                      1 2 =
2 1 5         ->          4 5 6
= 8 6                      = 8 0

いま、使うことができる L, R, U, D それぞれの総数があたえられます。 この総数は全パズルで共有されています。 例えばあるパズルを解くために L を使い切ってしまった場合、 他のパズルでは L を使うことはできません。 この総数を超えないようにしながら、なるべくたくさんのパズルを解いてください。

得点
パズルをひとつ解くごとに 0.01 点が加算されます。全問解くと 50 点になります。 あるパズルが不正解だった場合、またはスキップした場合は、そのパズルに関する得点は加算されません。L, R, U, D いずれか一つでも使うことができる総数を超えていた場合は、各パズルの正解不正解にかかわらず 0 点となります。

入力と解答
入力フォーマット

LX RX UX DX
N
w1,h1,b1
w2,h2,b2
...
wN,hN,bN


LX, RX, UX, DX: 使うことができる L, R, U, D それぞれの総数
N: 総ボード数 (整数)
wi: ボードの幅 [3-6]
hi: ボードの高さ [3-6]
bi: ボード初期状態 [0-9A-Z=] からなる文字列

ボードは
0: 空白
=: 壁
1-9 A-Z: それぞれのパネル。
ボードは行を上から下の順に一列に並べた文字列として与えられます。すなわち、

40=
215
=86


は、文字列 40=215=86 として与えられます。

ゴールは左上隅が 1。空白は右下隅。壁になっているところに対応するパネルは存在しません。

ゴール例:

1234
5678
9ABC
DEF0

123=
5=78
9=BC
DEF0


こちら から入力データをダウンロードできます

解答フォーマット
各行はそれぞれの問題に対応する LRUD の列。

解答例:

URRD
DDRRRRULLULLDDDRRRR

RRUULLD


- 特定の問題の解答を飛ばしたい場合は、対応する行に空行を出力してください。

Google 번역


저작자 표시 비영리 동일 조건 변경 허락
Posted by mirwing
Android/myself2011/08/29 15:33
一人ゲームをしましょう。

ルール
数がいくつか与えられます。なるべく少ない手数で数を全て取り除いてください。
あなたは 1 手で、
- 全ての数を半分にする(端数は切り捨て)
- 5 の倍数 (0 を含む) を全て取り除く
のどちらかの操作をすることができます。

入力データの形式
1 行目にテストケースの数 T (1 ≤ T ≤ 100) が整数で与えられます。
2 行目からがテストケースです。各テストケースは 2 行から構成されます。

テストケースの 1 行目には、数の個数 N (1 ≤ N ≤ 10) が整数で与えられます。 テストケースの 2 行目には、整数が N 個与えられます。整数同士の間は 1 つの空白で区切られています。 全ての数は 0 以上 1,000,000 以下です。同じ数が複数含まれる場合があります。

入力データは全体として次のような形式になります。

T

N

a1 a2 ... aN

N

a1 a2 ... aN

...


出力データの形式

各テストケースごとに、全ての数を取り除くための最短手数を 1 行で出力します。余計な空白や空行を入れてはいけません。最後のテストケースの行末にも改行が必要です。余計な空白や改行を入れたり、行末の改行がなかった場合は不正解と判定されることがあります。改行コードは CR, LF, CRLF のいずれでもかまいません。

入力例

4

2

10 21

3

0 9 9

4

81 67 83 86

3

11 22 30


入力例に対する回答

2

5

8

4


 1 つめのテストケースでは、まず全ての数を半分にします (10, 21 → 5, 10) 。次に、5 の倍数を全て取り除きます。これで 2 手で全ての数を取り除けます。
2 つめのテストケースでは、全ての数を半分にする操作を 4 回行います。
0, 9, 9 → 0, 4, 4 → 0, 2, 2 → 0, 1, 1 → 0, 0, 0 
その後、5 の倍数を全て取り除きます。これで 5 手で全ての数を取り除けます。

入力と回答
解答フォームの下の入力データに対する回答、およびその回答を出力したソースコードを提出してください。仮にコンピューターに頼らない方法で計算した場合、その方法を記述したテキストファイルをソースコードとして提出してください。

回答:  
ソースコード:  

入力データ

100

2

10 11

3

0 9 9

4

81 67 83 86

3

11 22 30

1

0

1

5

1

999999

1

1000000

2

5 10

3

0 10 11

5

10 20 21 22 23

5

422808 211404 761062 845625 491519

5

27 13 90 99 64

5

67 2 57 37 67

5

95 37 89 76 64

5

47 14 59 50 87

5

3 40 37 51 96

5

61 31 30 19 18

5

63 35 57 83 17

5

12 28 85 22 29

5

52 14 28 11 19

5

74 77 77 41 76

10

41 19 51 60 19 55 3 12 9 2

10

63 67 77 82 10 68 50 91 77 20

10

30 43 86 79 24 96 9 97 25 51

10

32 61 67 46 94 0 81 3 5 34

10

34 21 11 59 43 14 91 62 79 75

10

9 59 85 91 83 80 86 94 80 40

10

72 19 80 80 1 44 44 37 4 59

10

31 72 24 88 43 70 63 82 49 35

10

100 63 26 82 2 22 7 13 97 24

10

96 64 99 72 38 74 77 22 96 75

5

838606 863240 884690 917147 947645

5

944436 958307 892536 926207 872867

5

818042 954117 845194 881836 807692

5

861881 819526 973015 903444 829313

5

964932 961556 994739 827545 891188

5

947201 901027 890300 808137 850288

5

916398 927746 905525 877027 942644

5

817475 801287 979620 812560 851238

5

925269 885356 886992 890802 821467

5

914386 984849 807953 931696 845089

10

959063 898538 806008 914641 921488 823255 971853 825394 950743 879499

10

846510 935395 929978 964649 909028 967071 910153 995506 840399 923217

10

933391 972663 818940 849680 866777 942892 843302 837110 832555 850715

10

968417 849301 907112 847192 873792 990996 872319 946687 837306 860828

10

995012 812006 923912 948745 974503 949313 830266 895451 885844 954131

10

829784 901004 849926 834557 989986 858349 865154 952798 872702 986919

10

892796 945301 972838 878146 911230 996957 856365 877290 851455 916473

10

815810 846362 858607 993513 941346 895705 842317 974505 960285 857518

10

897627 963518 969827 865499 887420 886326 871944 998834 841347 877372

10

892073 962888 837156 950912 958946 916531 968654 892101 859049 857011

10

40 818985 802242 51 937791 46 825623 77 49 957395

10

93 891589 70 51 836672 937800 9 959161 41 936944

10

3 2 75 60 960721 32 977468 964720 947223 987691

10

944867 93 913044 39 98 891300 884150 76 70 944323

10

55 74 42 915361 972024 10 903628 911328 903671 60

10

70 860007 56 71 954543 74 894096 807336 802322 57

10

33 896967 833568 805290 86 87 6 16 971773 854380

10

975041 930114 41 994624 38 42 855120 31 71 816953

10

23 99 2 803160 820368 948644 25 5 892215 974924

10

12 907919 53 74 13 976344 932887 34 965677 997068

10

54 948398 65 39 955671 52 818315 901897 38 980424

10

820257 53 62 15 955880 813603 36 800360 864340 13

10

943092 30 938550 847328 31 30 97 985092 94 809900

10

960928 875334 100 81 881720 32 77 944446 12 851302

10

859772 914845 30 978192 2 68 892517 851282 71 88

10

921249 955882 9 54 50 79 899608 819673 870838 31

10

989502 8 807937 53 930588 65 982505 979141 100 82

10

997199 43 93 999256 94 918642 70 52 880110 855773

10

995107 100 813495 813816 13 942014 57 66 72 969879

10

35 4 56 57 968608 816584 819850 832314 38 993257

8

400580 282120 309934 253810 73055 865063 767665 114594

10

624507 232765 755604 71310 60135 734041 147300 81030 235552 799816

8

146005 332605 657710 867165 232520 751166 932780 642910

10

399015 640336 592726 418450 611602 561990 559370 760320 397829 364855

8

191330 88892 501744 232625 202090 60990 35865 201450

9

111525 532487 275881 771030 746930 437476 770100 1956 83210

9

222735 109040 352870 508925 155004 481765 828781 658905 211830

7

886660 158255 64902 747155 292560 858110 621305

8

661305 569080 915065 478050 387727 942425 263065 788720

9

854932 699425 448275 94395 48988 636250 857505 309075 65250

8

621595 859799 339425 428835 580190 140800 631610 670875

9

171715 942815 560060 2658 514974 300420 607115 646390 821454

8

515190 330535 884295 54200 511345 659195 970110 525506

10

581005 446990 3157 312725 196020 479085 973845 66875 416745 642405

10

243685 964 713968 734495 666637 593145 466030 311453 978865 113240

8

796908 567985 533610 290410 436625 720535 287745 100540

8

444755 104322 490980 969190 811200 544625 436730 3015

7

83234 917635 490458 779805 972214 971875 489200

8

728450 332810 413540 257970 725680 743460 220108 952770

8

21085 472455 527864 465555 154265 581996 442845 782225

9

920438 242870 423392 585969 819012 561564 353240 777001 879663

10

706657 164998 814087 305742 131170 456185 451735 529939 747761 570299

10

872717 861822 556612 943485 19439 156622 314293 109471 200797 487588

10

594437 515117 966922 977169 455402 524506 190177 562295 594147 819805

4

603616 734195 997899 211769

1

728250

9

656861 598831 137488 254331 768842 621460 416296 832139 804484

9

193806 302987 946788 983666 725308 273332 758047 448855 682564

Google 번역


저작자 표시 비영리 동일 조건 변경 허락
Posted by mirwing
Android/myself2011/08/29 15:24
問題
ある都市(複数)における日別の供給電力と最大消費電力に関する記録が以下のような JSON の形式で与えられます。 この記録を Google SpreadSheets 上に展開してください。

[

  {

    "city_name": "Oykot",

    "data": [

      {

        "capacity": 1000,

        "usage": 750,

      },

      {

        "capacity": 1200,

        "usage": 1000,

      },

      ...

    ]

  },

  {

    "city_name": "Akaso",

    "data": [

      {

        "capacity": 1000,

        "usage": 800,

      },

      ...

    ]

  },

  ...

]

上の例では、最初のオブジェクトには Oykot という都市における記録が含まれています。1 日目には 1000W の供給能力があり、ピーク時に 750W が消費されました。
実際のデータはこちらから取得できます。

以下の条件に従って、ひとつの Google Spreadsheets を作ってください。JSON 内の各都市ごとにシートを分けて生成していただくことになります。 条件は以下の通りです。

シートの名前は都市名にしてください。上の例では、最左のシートの名称は「Oykot」とします。
データは 1 行目の A 列目から順番に埋めます。ヘッダ(タイトル行)は付けないでください。
n 行目の A 列に n 日目の供給電力(capacity)を入れます。
n 行目の B 列に n 日目の消費電力(usage)を入れます。
n 行目の C 列に n 日目の電力の消費割合を入れます。上の例の 1 日目では 1000W の供給力のうち 750W が消費されたので、セル C1 の値は 75.00% とします。 同様にセル C2 の値は 83.33%(1000 / 1200 = 0.8333...)になります。 小数点以下の桁数は問いませんが、値の誤差が 0.01 以内となるようにしてください。 たとえば、75.00% を 75% としたり、83.33% を 83.33333% としても差し支えありませんが、 83.33% を丸めて 83% とはしないでください。
作成したスプレッドシートは、gdd2011jp@gmail.com のアカウントと共有してください。


解答例
この問題例 からデータを取得した場合、作成する Google Spreadsheets は この解答例 のようになります。

解答
作成した Google Spreadsheets の URL を入力してください。


ヒント
Google Apps Script を使うと、Google Spreadsheets を操作する事ができます。 詳しくは http://code.google.com/intl/ja/googleapps/appsscript/guide.html をご覧ください。

Google 번역


 
저작자 표시 비영리 동일 조건 변경 허락
Posted by mirwing
Android/myself2011/08/29 15:18
以下の AIDL で定義されるサービスを持つ Android アプリケーションを配布します。インターフェースを利用し、解答コードを手に入れてください。

1. 以下の Android アプリケーションを Android エミュレータあるいは、お手持ちの Android 携帯にインストールしてください。
2. Google Developer Day 2011 に登録したeメールアドレス XXXX@XXXXXXXX と、 パスコードとして XXXXXXXXXX をアプリに入力して保存してください。
3. サービスにアクセスするアプリケーションを作成し、解答コードを手に入れ、サーバーに登録してください。

AIDL

package com.google.android.apps.gddquiz;

interface IQuizService {
  String getCode();
}


アプリケーションはこちらからダウンロードして下さい。

解答
以下の入力欄に解答コードを入れて、提出ボタンを押してください。
解答コード: 

Google 번역

 
저작자 표시 비영리 동일 조건 변경 허락
Posted by mirwing
Android/myself2011/08/29 15:09
Go 言語で、PNG 画像を入力として受け取り、その画像が何色使っているかを返す関数
func CountColor(png io.Reader) int
を実装してください。PNG 画像は io.Reader 型で与えられます。
なお、入力の画像は R G B の各色の値が 0 から 255 までの 256 段階のいずれかであり、不透明(アルファチャンネルの値が常に 255)であることが保証されています。

サンプル画像


サンプルの答え
5

Go言語のドキュメント
注)日本語版は非公式サイトであり、情報が最新でない場合や不正確である可能性があります。

package main


import (

    "fmt"

    "io"

    "strings"

    /* add more */

)


func CountColor(png io.Reader) int {

    /* modify here */

    return 0

}



/* これらの関数は提出時に自動挿入されます。 */

func main() {

    png := GetPngBinary()

    cnt := CountColor(png)

    fmt.Println(cnt)

}


func GetPngBinary() io.Reader {

    // img_strの中身は提出するたびに変化します。

    img_str := "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x18\x00\x00\x00\x08\x08\x06\x00\x00\x00\xe3\xa1?c\x00\x00\x02\xeeiCCPICC Profile\x00\x00x\x01\x85T\xcfk\x13A\x14\xfe6n\xa9\xd0\"\x08Zk\x0e\xb2x\x90\"IY\xabhE\xd46\xfd\x11bk\x0c\xdb\x1f\xb6E\x90d3I\xd6n6\xeb\xee&\xb5\xa5\x88\xe4\xe2\xd1*\xdeE\xed\xa1\x07\xff\x80\x1ez\xf0d/J\x85ZE(\xde\xab(b\xa1\x17-\xf1\xcdnL\xb6\xa5\xea\xc0\xce~\xf3\xde7\xef}ov\xdf\x00\rr\xd24\xf5\x80\x04\xe4\r\xc7R\xa2\x11il|Bj\xfc\x88\x00\x8e\xa2\tA4%U\xdb\xecN$\x06A\x83s\xf9{\xe7\xd8z\x0f\x81[V\xc3{\xfbw\xb2w\xad\x9a\xd2\xb6\x9a\x07\x84\xfd@\xe0G\x9a\xd9*\xb0\xef\x17q\nY\x12\x02\x88<\xdf\xa1)\xc7t\x08\xdf\xe3\xd8\xf2\xec\x8f9Nyx\xc1\xb5\x0f+=\xc4Y\"|@5-\xce\x7fM\xb8S\xcd%\xd3@\x83H8\x94\xf5qR>\x9c\xd7\x8b\x94\xd7\x1d\x07inf\xc6\xc8\x10\xbdO\x90\xa6\xbb\xcc\xee\xabb\xa1\x9cN\xf6\x0e\x90\xbd\x9d\xf4~N\xb3\xde>\xc2!\xc2\x0b\x19\xad?F\xb8\x8d\x9e\xf5\x8c\xd5?\xe2a\xe1\xa4\xe6\xc4\x86=\x1c\x185\xf4\xf8`\x15\xb7\x1a\xa9\xf85\xc2\x14_\x10M'\xa2Tq\xd9.\r\xf1\x98\xae\xfdV\xf2J\x82p\x908\xcada\x80sZHO\xd7Ln\xf8\xba\x87\x05}&\xd7\x13\xaf\xe2wVQ\xe1y\x8f\x13g\xde\xd4\xdd\xefE\xda\x02\xaf0\x0e\x1d\x0c\x1a\x0c\x9a\rHP\x10E\x04a\x98\xb0P@\x86<\x1a14\xb2r?#\xab\x06\x1b\x93{2u$j\xbbtbD\xb1A{6\xdc=\xb7Q\xa4\xdd<\xfe(\"q\x94C\xb5\x08\x92\xfcA\xfe*\xaf\xc9O\xe5y\xf9\xcb\\\xb0\xd8V\xf7\x94\xad\x9b\x9a\xba\xf2\xe0;\xc5\xe5\x99\xb9\x1a\x1e\xd7\xd3\xc8\xe3sM^|\x95\xd4v\x93WG\x96\xacyz\xbc\x9a\xec\x1a?\xecW\x971\xe6\x825\x8f\xc4s\xb0\xfb\xf1-_\x95\xcc\x97)\x8c\x14\xc5\xe3U\xf3\xeaK\x84uZ17\xdf\x9fl\x7f;=\xe2.\xcf.\xb5\xd6s\xad\x89\x8b7V\x9b\x97g\xfdjH\xfb\xee\xaa\xbc\x93\xe6U\xf9O^\xf5\xf1\xfcg\xcd\xc4c\xe2)1&v\x8a\xe7!\x89\x97\xc5.\xf1\x92\xd8K\xab\x0b\xe2`m\xc7\x08\x9d\x95\x86)\xd2m\x91\xfa$\xd5``\x9a\xbc\xf5/]?[x\xbdF\x7f\x0c\xf5Q\x94\x19\xcc\xd2T\x89\xf7\x7f\xc2*d4\x9d\xb9\x0eo\xfa\x8f\xdb\xc7\xfc\x17\xe4\xf7\x8a\xe7\x9f(\x02/l\xe0\xc8\x99\xbamSq\xef\x10\xa1e\xa5ns\xae\x02\x17\xbf\xd1}\xf0\xb6nk\xa3~8\xfc\x04X<\xab\x16\xadR5\x9f \xbc\x01\x1cv\x87z\x1e\xe8)\x98\xd3\x96\x96\xcd9R\x87,\x9f\x93\xba\xe9\xcabR\xccP\xdbCRR\xd7%\xd7eK\x16\xb3\x99Ub\xe9v\xd8\x99\xd3\x1dn\x1c\xa19B\xf7\xc4\xa7Je\x93\xfa\xaf\xf1\x11\xb0\xfd\xb0R\xf9\xf9\xacR\xd9~N\x1a\xd6\x81\x97\xfao\xc0\xbc\xfdE\xc0x\x8b\x89\x00\x00\x00\x97IDAT(\x15\x9d\x92\x81\x0e\x80 \x08D\xa5\xf9m\xf5Y\xad\xcf\xaa\x9f#nz$\xba\xb9\xca\xad\x85\xc1\xbd\x03S\xd4\x96H\xf2\xa5\xea\xe1\xeb@\x8e\x02\xd0}\x14/\x80\x03\xca\xa75{\xeb0\x80\x01\xa9\xa0\xdcC|\x02:\xf1\xc3U\xc7\\K\x97}\xda9HPcq0pQ\x8aE\xe94y\x05'3\x92M[\x86\xc7\xc1\xa4n\x82\x01\x8ci\xe2\xc5\x7f\x02N`\xda\xdcCK\xaeqbqsD\xbd\x86=\xe0g\xdb\x9dy\xba\xb4Xp\x8bX\xf0\xe7\x8d\x89g\x84pD_\x0cx\x9438x7\xa4yC\r7\x04z\xae\x00\x00\x00\x00IEND\xaeB`\x82"

    return strings.NewReader(img_str)

}


Google 번역

저작자 표시 비영리 동일 조건 변경 허락
Posted by mirwing
Android/myself2011/08/29 14:56
ゲームを始める

ルール
シンプルな神経衰弱ゲームです。カードはクリックすることでめくることができます。全 64 セットを解くことで問題クリアとなります。

ヒント
1 枚目のカードを開いてその色を取得する Chrome Extension の サンプルをダウンロード できます。 (もちろん、Chrome Extension 以外の方法を使って解いてもかまいません。)
 

バックグラウンド
Web アプリケーションを使っていて、自分向けにカスタマイズしたいと思ったことはありませんか? そんな時、Chrome Extension が力になります。例えば、入力を補完する、特定のテキストをハイライトする、といったことも思いのままです。

この神経衰弱ゲームでは、人間が到底解けないような枚数の神経衰弱が与えられますが、 Chrome Extension を作ればそれらを迅速に処理することができます。

この機会に Chrome Extension の書き方を学んで、日々のタスクの改善に生かしてみませんか?

Google 번역

 
저작자 표시 비영리 동일 조건 변경 허락

'Android > myself' 카테고리의 다른 글

GDD 2011 Japan 분야별 퀴즈 - Android  (0) 2011/08/29
GDD 2011 Japan 분야별 퀴즈 - GO!  (0) 2011/08/29
GDD 2011 Japan 분야별 퀴즈 - Web Game  (0) 2011/08/29
GDD 2011 Japan 워밍업 퀴즈  (0) 2011/08/29
GDD 2011 Japan 도전 시작!...  (0) 2011/08/29
Implementing IPC Using AIDL  (0) 2009/06/09
Posted by mirwing
Android/myself2011/08/29 14:47

우선 제일 처음 저를 맞이 해주던 워밍업 퀴즈 입니다.

Google Web Font API
Google Web Font API に text= パラメータを指定すると何が起こるでしょうか?
パラメータの内容に応じてフォントをサジェストして返してくれる
何も起こらない
必要なグリフのみを含むフォントを返してくれる

Google 번역



gmail
Google Chrome、Firefox、Safari において、Gmail のメール作成画面など文字修飾が可能な編集領域で、 修飾を無視してテキストだけをペーストするにはどのようにすればよいでしょうか?
Alt + V (Option + V) を押す
Ctrl + Shift + V (Command + Shift + V) を押す
Ctrl + X を押してから Ctrl + V (Command + X Command + V) を押す

Google 번역



Android
Android 3.x (Honeycomb)についての次の記述のうち、間違っているものはどれでしょう?
Fragment, Action Bar などの考え方は今後 一般の携帯電話用にもリリースされる Ice Cream Sandwich のアプリケーション開発においてもそのまま継承される
ドラッグ & ドロップ(ドラッグ中の半透明 UI 表示など)の実装が簡単にできる API が提供されている
画面描画を高速化するハードウェアアクセラレーションを活用するには Java では足りず、C/C++ を活用した JNI プログラミングが必要である

Google 번역



Google Apps Script
Google Apps Script で、できないものはどれでしょうか? ただし、Google が提供するものを除き、外部の Web API やサービス等は使わないものとします。
Google Docs の表計算で使える関数を追加する
表計算に地図を表示して、セルにある住所にマーカーを表示する
OAuth 認証を使って GData API にアクセスする
30KB のファイルを添付したメールを送信する

Google 번역



maps API
Google Maps JavaScript API V3 にて以下のコードのように定義した gddMapType では、 通常の地図と比べてどのように見た目が変化するでしょうか? 間違っているものを選択してください。

var map = new google.maps.Map(document.getElementById("map_canvas"),

  { center: new google.maps.LatLng(35.660482, 139.729217),

    zoom: 13,

    mapTypeControlOptions: {

      mapTypeIds: [ google.maps.MapTypeId.ROADMAP, "gdd" ]

    }

  });

var gddMapType = new google.maps.StyledMapType(

  [ {

      featureType: "road",

      elementType: "all",

      stylers: [ { saturation: -100 } ]

    },{

      featureType: "poi.school",

      elementType: "geometry",

      stylers: [ { hue: "#ff0000" } ]

    },{

      featureType: "transit.line",

      elementType: "all",

      stylers: [ { visibility: "off" } ]

    },{

      featureType: "administrative.locality",

      elementType: "labels",

      stylers: [ { invert_lightness: true } ]

    } ], { name: "GDD" });

map.mapTypes.set("gdd", gddMapType);

map.setMapTypeId("gdd");

学校の敷地が赤っぽい色になる。
市区町村名が白抜き文字になる。
鉄道の線路が地図上から消える。
全ての道路が黒く塗りつぶされる。 

Google 번역



저작자 표시 비영리 동일 조건 변경 허락

'Android > myself' 카테고리의 다른 글

GDD 2011 Japan 분야별 퀴즈 - GO!  (0) 2011/08/29
GDD 2011 Japan 분야별 퀴즈 - Web Game  (0) 2011/08/29
GDD 2011 Japan 워밍업 퀴즈  (0) 2011/08/29
GDD 2011 Japan 도전 시작!...  (0) 2011/08/29
Implementing IPC Using AIDL  (0) 2009/06/09
Calling an IPC Method  (8) 2009/06/09
Posted by mirwing
Android/myself2011/08/29 14:35
Google Developer Day 2011 Japan은 11월 1일 요코하마에서 있습니다.

자세한 내용은 http://www.google.com/events/developerday/2011/ 를 참조 바랍니다.

한국어 이외에는 어리버리한 저에게는 GDD Japan을 등록 신청 하는 것 조차 어렵게....모두 일본어 질문이더군요.ㅠ

한국어로 번역한 뒤에 영어로 적어뒀습니다.


얼마 지나지 않아 메일을 받았습니다.

GDD 2011 Japan에 참여를 하려면 퀴즈를 풀어 점수로 참가증을 보내준다는 내용의 메일...

뭐...참가를 기대하지는 않지만!

퀴즈라니!....막막 풀어 보고 싶어 지네요.... 차례차례 시작하겠습니다!.ㅋ

 


위의 사진 처럼 워밍업 퀴즈로 시작하여 분야별 퀴즈(Web Game, GO!, Android, Apps Script, 一人ゲーム), 도전 퀴즈 항목이 있습니다.

각각 항목별 퀴즈는 별도로 만들어 알려 드리겠습니다. 

저작자 표시 비영리 동일 조건 변경 허락

'Android > myself' 카테고리의 다른 글

GDD 2011 Japan 분야별 퀴즈 - Web Game  (0) 2011/08/29
GDD 2011 Japan 워밍업 퀴즈  (0) 2011/08/29
GDD 2011 Japan 도전 시작!...  (0) 2011/08/29
Implementing IPC Using AIDL  (0) 2009/06/09
Calling an IPC Method  (8) 2009/06/09
Android Study 1  (0) 2009/04/24
Posted by mirwing
Android/myself2009/06/09 19:05

Follow these steps to implement an IPC service using AIDL.

  1. Create your .aidl file - This file defines an interface (YourInterface.aidl) that defines the methods and fields available to a client.
  2. Add the .aidl file to your makefile - (the ADT Plugin for Eclipse manages this for you). Android includes the compiler, called AIDL, in the tools/ directory.
  3. Implement your interface methods - The AIDL compiler creates an interface in the Java programming language from your AIDL interface. This interface has an inner abstract class named Stub that inherits the interface (and implements a few additional methods necessary for the IPC call). You must create a class that extends YourInterface.Stub and implements the methods you declared in your .aidl file.
  4. Expose your interface to clients - If you're writing a service, you should extend Service and overrideService.onBind(Intent) to return an instance of your class that implements your interface.

Create an .aidl File

AIDL is a simple syntax that lets you declare an interface with one or more methods, that can take parameters and return values. These parameters and return values can be of any type, even other AIDL-generated interfaces. However, it is important to note that you must import all non-built-in types, even if they are defined in the same package as your interface. Here are the data types that AIDL can support:

  • Primitive Java programming language types (int, boolean, etc) — No import statement is needed.
  • One of the following classes (no import statements needed):
    • String
    • List - All elements in the List must be one of the types in this list, including other AIDL-generated interfaces and parcelables. List may optionally be used as a "generic" class (e.g. List<String>). The actual concrete class that the other side will receive will always be an ArrayList, although the method will be generated to use the List interface.
    • Map - All elements in the Map must be of one of the types in this list, including other AIDL-generated interfaces and parcelables. Generic maps, (e.g. of the form Map<String,Integer> are not supported. The actual concrete class that the other side will receive will always be a HashMap, although the method will be generated to use the Map interface.
    • CharSequence - This is useful for the CharSequence types used by TextView and other widget objects.
  • Other AIDL-generated interfaces, which are always passed by reference. An import statement is always needed for these.
  • Custom classes that implement the Parcelable protocol and are passed by value. An import statement is always needed for these.

Here is the basic AIDL syntax:

// My AIDL file, named SomeClass.aidl
// Note that standard comment syntax is respected.
// Comments before the import or package statements are not bubbled up
// to the generated interface, but comments above interface/method/field
// declarations are added to the generated interface.

// Include your fully-qualified package statement.
package com.android.sample;

// See the list above for which classes need
// import statements (hint--most of them)
import com.android.sample.IAtmService;

// Declare the interface.
interface IBankAccountService {
    
    // Methods can take 0 or more parameters, and
    // return a value or void.
    int getAccountBalance();
    void setOwnerNames(in List<String> names);
    
    // Methods can even take other AIDL-defined parameters.
    BankAccount createAccount(in String name, int startingDeposit, in IAtmService atmService);

    // All non-Java primitive parameters (e.g., int, bool, etc) require
    // a directional tag indicating which way the data will go. Available
    // values are in, out, inout. (Primitives are in by default, and cannot be otherwise).
    // Limit the direction to what is truly needed, because marshalling parameters
    // is expensive.
    int getCustomerList(in String branch, out String[] customerList);
}

Implementing the Interface

AIDL generates an interface file for you with the same name as your .aidl file. If you are using the Eclipse plugin, AIDL will automatically be run as part of the build process (you don't need to run AIDL first and then build your project). If you are not using the plugin, you should run AIDL first.

The generated interface includes an abstract inner class named Stub that declares all the methods that you declared in your .aidl file. Stub also defines a few helper methods, most notably asInterface(), which takes an IBinder (passed to a client's onServiceConnected() implementation when applicationContext.bindService() succeeds), and returns an instance of the interface used to call the IPC methods. See the section Calling an IPC Method for more details on how to make this cast.

To implement your interface, extend YourInterface.Stub, and implement the methods. (You can create the .aidl file and implement the stub methods without building between--the Android build process will process .aidl files before .java files.)

Here is an example of implementing an interface called IRemoteService, which exposes a single method, getPid(), using an anonymous instance:

// No need to import IRemoteService if it's in the same project.
private final IRemoteService.Stub mBinder = new IRemoteService.Stub(){
    public int getPid(){
        return Process.myPid();
    }
}

A few rules about implementing your interface:

  • No exceptions that you throw will be sent back to the caller.
  • IPC calls are synchronous. If you know that an IPC service takes more than a few milliseconds to complete, you should not call it in the Activity/View thread, because it might hang the application (Android might display an "Application is Not Responding" dialog). Try to call them in a separate thread.
  • Only methods are supported; you cannot declare static fields in an AIDL interface.

Exposing Your Interface to Clients

Now that you've got your interface implementation, you need to expose it to clients. This is known as "publishing your service." To publish a service, inherit Service and implement Service.onBind(Intent) to return an instance of the class that implements your interface. Here's a code snippet of a service that exposes the IRemoteService interface to clients.

public class RemoteService extends Service {
...
    @Override
    public IBinder onBind(Intent intent) {
        // Select the interface to return.  If your service only implements
        // a single interface, you can just return it here without checking
        // the Intent.
        if (IRemoteService.class.getName().equals(intent.getAction())) {
            return mBinder;
        }
        if (ISecondary.class.getName().equals(intent.getAction())) {
            return mSecondaryBinder;
        }
        return null;
    }

    /**
     * The IRemoteInterface is defined through IDL
     */
    private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {
        public void registerCallback(IRemoteServiceCallback cb) {
            if (cb != null) mCallbacks.register(cb);
        }
        public void unregisterCallback(IRemoteServiceCallback cb) {
            if (cb != null) mCallbacks.unregister(cb);
        }
    };

    /**
     * A secondary interface to the service.
     */
    private final ISecondary.Stub mSecondaryBinder = new ISecondary.Stub() {
        public int getPid() {
            return Process.myPid();
        }
        public void basicTypes(int anInt, long aLong, boolean aBoolean,
                float aFloat, double aDouble, String aString) {
        }
    };

}

Pass by value Parameters using Parcelables

If you have a class that you would like to send from one process to another through an AIDL interface, you can do that. You must ensure that the code for your class is available to the other side of the IPC. Generally, that means that you're talking to a service that you started.

There are five parts to making a class support the Parcelable protocol:

  1. Make your class implement the Parcelable interface.
  2. Implement the method public void writeToParcel(Parcel out) that takes the current state of the object and writes it to a parcel.
  3. Implement the method public void readFromParcel(Parcel in) that reads the value in a parcel into your object.
  4. Add a static field called CREATOR to your class which is an object implementing the Parcelable.Creator interface.
  5. Last but not least, create an aidl file that declares your parcelable class (as shown below). If you are using a custom build process, do not add the aidl file to your build. Similar to a header file in C, the aidl file isn't compiled.

AIDL will use these methods and fields in the code it generates to marshall and unmarshall your objects.

Here is an example of how the Rect class implements the Parcelable protocol.

import android.os.Parcel;
import android.os.Parcelable;

public final class Rect implements Parcelable {
    public int left;
    public int top;
    public int right;
    public int bottom;

    public static final Parcelable.Creator<Rect> CREATOR = new Parcelable.Creator<Rect>() {
        public Rect createFromParcel(Parcel in) {
            return new Rect(in);
        }

        public Rect[] newArray(int size) {
            return new Rect[size];
        }
    };

    public Rect() {
    }

    private Rect(Parcel in) {
        readFromParcel(in);
    }

    public void writeToParcel(Parcel out) {
        out.writeInt(left);
        out.writeInt(top);
        out.writeInt(right);
        out.writeInt(bottom);
    }

    public void readFromParcel(Parcel in) {
        left = in.readInt();
        top = in.readInt();
        right = in.readInt();
        bottom = in.readInt();
    }
}

Here is Rect.aidl for this example

package android.graphics;

// Declare Rect so AIDL can find it and knows that it implements
// the parcelable protocol.
parcelable Rect;

The marshalling in the Rect class is pretty simple. Take a look at the other methods on Parcel to see the other kinds of values you can write to a Parcel.

Warning: Don't forget the security implications of receiving data from other processes. In this case, the rect will read four numbers from the parcel, but it is up to you to ensure that these are within the acceptable range of values for whatever the caller is trying to do. See Security and Permissions for more on how to keep your application secure from malware.

'Android > myself' 카테고리의 다른 글

GDD 2011 Japan 워밍업 퀴즈  (0) 2011/08/29
GDD 2011 Japan 도전 시작!...  (0) 2011/08/29
Implementing IPC Using AIDL  (0) 2009/06/09
Calling an IPC Method  (8) 2009/06/09
Android Study 1  (0) 2009/04/24
Android 구글 강좌  (1) 2009/04/23
Posted by mirwing
TAG aidl, Android, IPC
Android/myself2009/06/09 17:09

Here are the steps a calling class should make to call your remote interface:

  1. Declare a variable of the interface type that your .aidl file defined.
  2. Implement ServiceConnection.
  3. Call Context.bindService(), passing in your ServiceConnection implementation.
  4. In your implementation of ServiceConnection.onServiceConnected(), you will receive an IBinder instance (called service). Call YourInterfaceName.Stub.asInterface((IBinder)service) to cast the returned parameter to YourInterface type.
  5. Call the methods that you defined on your interface. You should always trap DeadObjectException exceptions, which are thrown when the connection has broken; this will be the only exception thrown by remote methods.
  6. To disconnect, call Context.unbindService() with the instance of your interface.

A few comments on calling an IPC service:

  • Objects are reference counted across processes.
  • You can send anonymous objects as method arguments.

Here is some sample code demonstrating calling an AIDL-created service, taken from the Remote Activity sample in the ApiDemos project.

/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.apis.app;

import com.example.android.apis.R;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Process;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class RemoteServiceBinding extends Activity {
    /** The primary interface we will be calling on the service. */
    IRemoteService mService = null;
    /** Another interface we use on the service. */
    ISecondary mSecondaryService = null;

    Button mKillButton;
    TextView mCallbackText;

    private boolean mIsBound;

    /**
     * Standard initialization of this activity.  Set up the UI, then wait
     * for the user to poke it before doing anything.
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.remote_service_binding);

        // Watch for button clicks.
        Button button = (Button)findViewById(R.id.bind);
        button.setOnClickListener(mBindListener);
        button = (Button)findViewById(R.id.unbind);
        button.setOnClickListener(mUnbindListener);
        mKillButton = (Button)findViewById(R.id.kill);
        mKillButton.setOnClickListener(mKillListener);
        mKillButton.setEnabled(false);

        mCallbackText = (TextView)findViewById(R.id.callback);
        mCallbackText.setText("Not attached.");
    }

    /**
     * Class for interacting with the main interface of the service.
     */
    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className,
                IBinder service) {
            // This is called when the connection with the service has been
            // established, giving us the service object we can use to
            // interact with the service.  We are communicating with our
            // service through an IDL interface, so get a client-side
            // representation of that from the raw service object.
            mService = IRemoteService.Stub.asInterface(service);
            mKillButton.setEnabled(true);
            mCallbackText.setText("Attached.");

            // We want to monitor the service for as long as we are
            // connected to it.
            try {
                mService.registerCallback(mCallback);
            } catch (RemoteException e) {
                // In this case the service has crashed before we could even
                // do anything with it; we can count on soon being
                // disconnected (and then reconnected if it can be restarted)
                // so there is no need to do anything here.
            }

            // As part of the sample, tell the user what happened.
            Toast.makeText(RemoteServiceBinding.this, R.string.remote_service_connected,
                    Toast.LENGTH_SHORT).show();
        }

        public void onServiceDisconnected(ComponentName className) {
            // This is called when the connection with the service has been
            // unexpectedly disconnected -- that is, its process crashed.
            mService = null;
            mKillButton.setEnabled(false);
            mCallbackText.setText("Disconnected.");

            // As part of the sample, tell the user what happened.
            Toast.makeText(RemoteServiceBinding.this, R.string.remote_service_disconnected,
                    Toast.LENGTH_SHORT).show();
        }
    };

    /**
     * Class for interacting with the secondary interface of the service.
     */
    private ServiceConnection mSecondaryConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className,
                IBinder service) {
            // Connecting to a secondary interface is the same as any
            // other interface.
            mSecondaryService = ISecondary.Stub.asInterface(service);
            mKillButton.setEnabled(true);
        }

        public void onServiceDisconnected(ComponentName className) {
            mSecondaryService = null;
            mKillButton.setEnabled(false);
        }
    };

    private OnClickListener mBindListener = new OnClickListener() {
        public void onClick(View v) {
            // Establish a couple connections with the service, binding
            // by interface names.  This allows other applications to be
            // installed that replace the remote service by implementing
            // the same interface.
            bindService(new Intent(IRemoteService.class.getName()),
                    mConnection, Context.BIND_AUTO_CREATE);
            bindService(new Intent(ISecondary.class.getName()),
                    mSecondaryConnection, Context.BIND_AUTO_CREATE);
            mIsBound = true;
            mCallbackText.setText("Binding.");
        }
    };

    private OnClickListener mUnbindListener = new OnClickListener() {
        public void onClick(View v) {
            if (mIsBound) {
                // If we have received the service, and hence registered with
                // it, then now is the time to unregister.
                if (mService != null) {
                    try {
                        mService.unregisterCallback(mCallback);
                    } catch (RemoteException e) {
                        // There is nothing special we need to do if the service
                        // has crashed.
                    }
                }

                // Detach our existing connection.
                unbindService(mConnection);
                unbindService(mSecondaryConnection);
                mKillButton.setEnabled(false);
                mIsBound = false;
                mCallbackText.setText("Unbinding.");
            }
        }
    };

    private OnClickListener mKillListener = new OnClickListener() {
        public void onClick(View v) {
            // To kill the process hosting our service, we need to know its
            // PID.  Conveniently our service has a call that will return
            // to us that information.
            if (mSecondaryService != null) {
                try {
                    int pid = mSecondaryService.getPid();
                    // Note that, though this API allows us to request to
                    // kill any process based on its PID, the kernel will
                    // still impose standard restrictions on which PIDs you
                    // are actually able to kill.  Typically this means only
                    // the process running your application and any additional
                    // processes created by that app as shown here; packages
                    // sharing a common UID will also be able to kill each
                    // other's processes.
                    Process.killProcess(pid);
                    mCallbackText.setText("Killed service process.");
                } catch (RemoteException ex) {
                    // Recover gracefully from the process hosting the
                    // server dying.
                    // Just for purposes of the sample, put up a notification.
                    Toast.makeText(RemoteServiceBinding.this,
                            R.string.remote_call_failed,
                            Toast.LENGTH_SHORT).show();
                }
            }
        }
    };

    // ----------------------------------------------------------------------
    // Code showing how to deal with callbacks.
    // ----------------------------------------------------------------------

    /**
     * This implementation is used to receive callbacks from the remote
     * service.
     */
    private IRemoteServiceCallback mCallback = new IRemoteServiceCallback.Stub() {
        /**
         * This is called by the remote service regularly to tell us about
         * new values.  Note that IPC calls are dispatched through a thread
         * pool running in each process, so the code executing here will
         * NOT be running in our main thread like most other things -- so,
         * to update the UI, we need to use a Handler to hop over there.
         */
        public void valueChanged(int value) {
            mHandler.sendMessage(mHandler.obtainMessage(BUMP_MSG, value, 0));
        }
    };

    private static final int BUMP_MSG = 1;

    private Handler mHandler = new Handler() {
        @Override public void handleMessage(Message msg) {
            switch (msg.what) {
                case BUMP_MSG:
                    mCallbackText.setText("Received from service: " + msg.arg1);
                    break;
                default:
                    super.handleMessage(msg);
            }
        }

    };
}

'Android > myself' 카테고리의 다른 글

GDD 2011 Japan 도전 시작!...  (0) 2011/08/29
Implementing IPC Using AIDL  (0) 2009/06/09
Calling an IPC Method  (8) 2009/06/09
Android Study 1  (0) 2009/04/24
Android 구글 강좌  (1) 2009/04/23
Android 뭐 부터 공부 해야 할지 모르겠다...  (0) 2009/04/13
Posted by mirwing
TAG aidl, Android, IPC