Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Book Reader Implementation Notes with Android V...
Search
FUJI Goro
April 16, 2016
Technology
0
2.4k
Book Reader Implementation Notes with Android ViewPager 2016
https://github.com/gfx/TinyPdfReader
の解説です。
FUJI Goro
April 16, 2016
Tweet
Share
More Decks by FUJI Goro
See All by FUJI Goro
How to Boost Your Code with WebAssembly
gfx
2
2.8k
AssemblyScriptでライブラリコードの高速化をしてみる
gfx
5
3k
実践TypeScriptトークバトル
gfx
1
1.1k
歴史的経緯の説明 as code
gfx
7
2.7k
Elasticsearchによる 全文検索の実装 in Rails
gfx
6
9.4k
すばらしきGraphQLのSEKAIへようこそ
gfx
20
9.3k
マルチテナント・ウェブアプリケーションの実践
gfx
14
9.5k
How to choose the ORM on Android
gfx
1
4.2k
How Do We Get Along With Static Types
gfx
5
3.3k
Other Decks in Technology
See All in Technology
SpiderPlus & Co. エンジニア向け会社紹介資料
spiderplus_cb
0
660
Copilotの力を実感!3ヶ月間の生成AI研修の試行錯誤&成功事例をご紹介。果たして得たものとは・・?
ktc_shiori
0
270
「隙間家具OSS」に至る道/Fujiwara Tech Conference 2025
fujiwara3
4
1.2k
comilioとCloudflare、そして未来へと向けて
oliver_diary
5
380
12 Days of OpenAIから読み解く、生成AI 2025年のトレンド
shunsukeono_am
0
1.1k
信頼されるためにやったこと、 やらなかったこと。/What we did to be trusted, What we did not do.
bitkey
PRO
0
1.9k
MasterMemory v3 最速確認会
yucchiy
0
340
スケールし続ける事業とサービスを支える組織とアーキテクチャの生き残り戦略 / The survival strategy for Money Forward’s engineering.
moneyforward
0
250
#TRG24 / David Cuartielles / Post Open Source
tarugoconf
0
500
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
1
5k
テストを書かないためのテスト/ Tests for not writing tests
sinsoku
1
160
Fearsome File Formats
ange
0
580
Featured
See All Featured
Designing on Purpose - Digital PM Summit 2013
jponch
116
7.1k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Writing Fast Ruby
sferik
628
61k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Raft: Consensus for Rubyists
vanstee
137
6.7k
The World Runs on Bad Software
bkeepers
PRO
66
11k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
4 Signs Your Business is Dying
shpigford
182
21k
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
Transcript
ಡॻը໘࣮ͷࣄ݅ ~ Android ViewPagerฤ ~ 2016/4/15 ిࢠॻ੶ษڧձ FUJI Goro (gfx)
ࣗݾհ
ࢀর࣮ • ͜ͷࢿྉͷࢀর࣮ҎԼʹ͋Γ·͢ • https://github.com/gfx/TinyPdfReader • ίΞϩδοΫ200ߦ͘Β͍ • DeploygateͰAPKΛ৴͍ͯ͠·͢ •
https://dply.me/xntdx6
ViewPagerجૅࣝ • AOSPͷҰ෦ (support library) • εϫΠϓͰࠨӈʹҠಈ͢ΔViewGroup • λϒҰൠɺಡॻը໘ͳͲʹ͏ •
ϖʔδͷਐΉํLTR(left-to-right)
ϑΝΠϧ#1 ϖʔδૹΓ͕ͬ͞Γ͢Δ
ϖʔδૹΓ͕͍ • ʮBookʯʢࠓճPDFʣ͔Β1ϖʔδऔΓग़ ͯ͠bitmapΛੜ͢Δͷʹ100 ~ 300sec͔͔ Δ • ͯ͢UIεϨουͰॲཧ͢ΔͱɺϖʔδૹΓ Ͱʮࢦ͕Ҿ͔͔ͬΔʯײ͕͢͡Δ
ViewPagerͷ࣮ • ViewPagerɺʮݱࡏͷϖʔδʯͱʮલޙͷ ϖʔδʯͷ3ϖʔδͷviewΛߏங͢Δ • ʮ࣍ͷϖʔδʯʹҠಈ͢Δલʹͦͷ࣍ͷϖʔ δͷviewΛߏங͢ΔͷͰɺͦ͜ͰඦϛϦ͔ ͔ΔͱʮϖʔδૹΓ͕٧·ΔʯΑ͏ʹײ͡Δ
#1 ͷղܾ • ViewPagerʹҰ୴ۭͷviewΛ͠ɺbitmapੜ όοΫάϥϯυεϨουͰߦ͏ • bitmap͕ੜͰ͖ͨΒviewʹͯ͠ඳը͢ Δɺ͜ͷͱ͖alphaʢಁ໌ʣͰΞχϝʔ γϣϯͯ͠ʮ;Θͬͱʯදࣔ͞ΕΔΑ͏ʹ͢ Δͱࢹ֮తʹ༏ͯ͘͠Α͍
PdfPagerAdapter: 1ทͷॲཧ ϓϨʔεϗϧμ7JFXΛͭ͘Δ ඇಉظͰCJUNBQΛϩʔυ͢Δ ݟ։͖࣌ϖʔδϩʔυ
RenderBitmapTask: bitmapੜ ݟ։͖ରԠͷͨΊͪΐͬͱෳࡶ جຊ1EG3FOEFSFSSFOEFS ΛݺͿ͚ͩ
RenderBitmapTask ϑϨʔϜ͔ͭͬͯ;Θͬͱग़ݱͤ͞Δ
Ͳ͜·Ͱ࠷దԽ͖͔͢ • 3ϖʔδ (දࣔϖʔδ+લޙϖʔδʣͷʮ४උʯ͕1ϑ ϨʔϜ(16ms)ҎԼͳΒेߴ • 1ϑϨʔϜҎԼͰͷ࠷దԽઅిޮՌ͘Β͍ • bitmapੜ30msͱ300msͰUXʹͦΕ΄Ͳҧ͍ͳ͍ •
500msΛ͑ΔΑ͏ͳΒ࠷దԽ͖͚ͩ͢ͲɺͦΕҎ Լʹ͢Δྗ͋·Γҙຯ͕ͳ͍
File #2 طಡཧ͍ͨ͠
طಡཧ • ΞϓϦͷॻ੶͝ͱʹɺͲ͜·ͰಡΜ͔ͩه ͍ͨ͠ • ViewPager#getCurrentItem() ͰҐஔΛऔಘ • 1ը໘1ϖʔδͷ࣌؆୯ɺ1ը໘2ϖʔ δʢݟ։͖ʣͷͱ͖
• ʮॻ੶σʔλͰͷҐஔʯʹม͢Δඞཁ͕͋Δ
ʮҐஔʯʹؔ͢Δ໋໊نଇ • ໋໊نଇΛͭ͘Βͳ͍ͱࢮ͵ • ViewPagerͷݱࡏ: position • ॻ੶σʔλͰͷҐஔ: pageIndex •
Ϧϑϩʔͷ͜ͱߟ͑ͳ͍ͷͱ͢Δ
QPSUSBJUͷͱ͖ͦͷ·· JT1PSUSBJU ͡Όͳ͍ͱ͍͚ͳ͍ͷ 7JFX1BHFSͷόάͱࢥΘΕΔ MBOETDBQF ݟ։͖ ͷͱ͖ ഒͯ͠දࢴͷΛҾ͘ ਖ਼֬ʹٯͷมΛߦ͏ 7JFX1BHFSͷҐஔ͔Βॻ੶Ґஔʹม
ॻ੶Ґஔ͔Β7JFX1BHFSͷҐஔʹม
File #3 ViewPager͕ࢥ͍௨Γʹಈ͍ ͯ͘Εͳ͍ΜͰ͢…
VPΛӈ͔ΒࠨʹҠಈͤ͞Δ • ViewPagerleft-to-rightͳͷͰɺright-to-left ͷॻ੶Λදࣔ͢Δͱ͖ʹͦͷ··͏ͱࢮ͵ • …ͷͰRVPͱ͍͏ϥΠϒϥϦΛ࡞ͬͨ • https://github.com/gfx/ReversibleViewPager • rvp.setReversed(true)
͢Δ͚ͩʂ
ViewPagerͰϐϯνΠϯɾΞτ͢ ΔͱIllegalArgumentException • ViewPagerͷόάͬΆ͍ • https://code.google.com/p/android/issues/detail?id=64553 • ViewPager Λܧঝͯ͠ super.onInterceptTouchEvent()
ͷྫ֎ΛѲΓ௵ ͤʂ • RVP͜ͷରԠ͕ೖ͍ͬͯΔ
VP#onSavedInstanceState() • ը໘ճస࣌ʹঢ়ଶΛอଘ͢Δ࣌ʹݺΕΔ • configuration͔ΒͱΕΔorientation͕ʮݱࡏͷ σόΠεͷํʯͰͳ͘ʮ͜Ε͔Β͔͏ํʯ ʹͳΔ • ͦ͜Ͱલड़ͷ !isPortrait()
ʹͳͬͨ • ͜Εਖ਼͍͠ͷ͔…ಈ͍ͯΔ͚Ͳ…
VP#onCreateView()ͱঢ়ଶ෮ؼ • onSavedInstanceState()Ͱอଘͨ͠ঢ়ଶΛ෮ؼͤ͞Δ • ͔͠͠ɺonCreateView()Ͱ vp.setCurrentItem() ͯ͠ແ ࢹ͞ΕΔʂʂʂ • onCreateView()ͷ͋ͱʹFragment͕view
(VPؚΉ) ͷঢ় ଶΛ෮ؼ͢Δ͔ΒɺΒ͍͠ • onCreateView()Ͱঢ়ଶΛಡΈͩ͠ɺonResume()Ͱ vp.setCurrentItem()͢Δ͜ͱʹͨ͠
RVPͷ՝ • RVPΛᘳʹ࣮͢Δͷ͕͍͠ • v1.0.2࣌Ͱ PagerTitleStrip ͱͷڠௐ͕͏ ·͍͔͘ͳ͍όά͕͋Δ • RTLAOSPଆͰରԠͯ͘͠ΕΔͱخ͍͠
• ໘ͳ͜ͱGoogleͷΤϯδχΞʹ͍ͤͨ
That's all.
https://github.com/gfx/ TinyPdfReader