Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Spannable芸 〜郵便番号編〜
Search
HiroYUKI Seto
March 13, 2018
Programming
2.5k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Spannable芸 〜郵便番号編〜
2018/3/13
potatotips #49
Sample project
https://github.com/hiroyuki-seto/PostalCodeSample
HiroYUKI Seto
March 13, 2018
More Decks by HiroYUKI Seto
See All by HiroYUKI Seto
Androidアプリの 安全なリファクタリングを行うパターン集
seto_hi
2
5k
UI TestやVisual Regression Testを コスパ良くやる
seto_hi
3
2k
事業支援というお仕事
seto_hi
0
470
MDCの内部実装から学ぶ 表現力の高いViewの作り方
seto_hi
5
1.9k
CoordinatorLayoutのBehaviorを使い倒す
seto_hi
1
480
Jetpack Compose
seto_hi
2
900
UI改善に繋がるエンジニアの立ち回り
seto_hi
2
4.9k
MDCのButtonのCorner Family
seto_hi
1
270
MDCのBottomAppBarのShadowの実現方法
seto_hi
0
1.1k
Other Decks in Programming
See All in Programming
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
810
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.6k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.3k
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
AWSに止められる覚悟してますか?
morizo_1984
2
540
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
520
Domain-Driven Transformation
hschwentner
2
2.3k
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
3.9k
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Design in an AI World
tapps
1
350
Agile that works and the tools we love
rasmusluckow
331
22k
Faster Mobile Websites
deanohume
310
32k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Color Theory Basics | Prateek | Gurzu
gurzu
1
490
Making the Leap to Tech Lead
cromwellryan
135
10k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Abbi's Birthday
coloredviolet
4
10k
Transcript
Spannable芸 〜郵便番号編〜 potatotips #49 株式会社ノハナ 瀬戸優之 @seto_hi
自己紹介 • 瀬戸優之 Seto HiroYUKI @seto_hi • Androidエンジニア & アプリデザイン
• 株式会社ノハナ ◦ 一組でも多くの家族に笑顔を届ける ◦ 絶賛採用中 • Material Design大好き • 好きなAPIはCanvas#saveとViewGroup#layout
最高の 郵便番号入力欄を 作りたい
最高の郵便番号入力欄 要件 • 3桁目と4桁目の間にハイフンを表示したい • 3桁目を打ったらハイフンの後にカーソルが移動 ◦ ハイフンは入力させたくない ◦ アプリ側で入力したくもない
◦ inputType=numberでやりたい • 上3桁と下4桁をシームレスに移動したい ◦ カーソル、文字削除、ペースト
郵便番号入力欄問題 • EditText2つ ◦ 2つのEditText間のカーソル移動問題 ◦ 削除、ペースト問題 • EditText1つ ◦
ハイフンが表示できない ◦ or ハイフンが文字として入力される • 恐らくクレカ番号入力欄でも同じ課題がある
簡単!写真1枚で 子どもの成長を届ける カレンダー付き ポストカードアプリ
Spannableで解決
Spannable • 文字列のデコレーションのinterface • SpannableStringBuilderなどが対応 • 文字(列)に対してSpanを設定する ◦ URLSpan, StyleSpan,
TypefaceSpan, etc.. • 未確定文字列の色や下線もSpan
ReplacementSpan
ReplacementSpan • TextViewの文字列を置換するSpan • 独自絵文字やデコ絵文字などに使われている • 文字列の描画幅を任意に変更できる • 文字列と描画を異なるものにできる
実装
サンプル https://github.com/hiroyuki-seto/PostalCodeSample
カスタムEditText+カスタムSpan • EditText ◦ 3文字目にカスタムSpanを設定 ◦ onDrawでハイフンを描画 • Span ◦
ReplacementSpanを継承 ◦ getSizeで対象の文字の幅+ハイフンの幅を返す ◦ drawで対象の文字を描画
罠
罠 • 0文字の際はReplacementSpanが効かない →仕様 • 未確定文字列の背景の描画 →サンプル見てね! • SurrogatePairを考慮したSpan →気合
かなり地道に実装する必要がある
Have a nice Spannable!