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
Square Fragmentやめるってよ
Search
ninjinkun
October 22, 2014
Programming
13
3.4k
Square Fragmentやめるってよ
『【翻訳】Android Fragmentへの反対声明』の解説
http://ninjinkun.hatenablog.com/entry/2014/10/16/234611
ninjinkun
October 22, 2014
Tweet
Share
More Decks by ninjinkun
See All by ninjinkun
Designer's and Engineer's Thinking Styles
ninjinkun
0
100
Launchable Webinar テストを効率化して生産性を上げる方法
ninjinkun
2
490
ディープリンクの 設計と実装 - iOSDC2017
ninjinkun
18
9.7k
スマートフォンアプリ開発における共創的な開発チーム
ninjinkun
61
18k
ReSwiftでアプリの状態管理 / Reactive Swift Meetup
ninjinkun
9
16k
フリルのアプリ開発今昔物語
ninjinkun
3
2.1k
プロトタイピング合宿によるデザインリニューアル
ninjinkun
1
3k
デザイナーが仕事をしやすいアプリエンジニアを考える
ninjinkun
4
610
Elevationで影が思ったように出ないとき
ninjinkun
4
12k
Other Decks in Programming
See All in Programming
1人で挑むSwiftコンパイラ 〜型システム入門編〜
s_shimotori
0
320
Scala におけるコンパイラエラーとの付き合い方
chencmd
2
350
これからの時代の新標準!SwiftTestingへの移行とトラブルシューティング
uetyo
0
480
ESLint Rule により事業, 技術ドメインに沿った制約と誓約を敷衍させるアプローチのすゝめ
shinyaigeek
1
2.9k
Desafios e Lições Aprendidas na Migração de Monólitos para Microsserviços em Java
jessilyneh
2
140
Rubyのobject_id
qnighy
6
1.3k
長期運用プロダクトの開発速度を維持し続けるためのリファクタリング実践例
wataruss
8
2.6k
Hono・Prisma・AWSでGeoなAPI開発
nokonoko1203
5
630
Regular Expressions, REXML, Automata Learning
makenowjust
0
190
Meet BrowserEngineKit
swiftty
0
310
私のEbitengineの第一歩
qt_luigi
0
430
Ruby Parser progress report 2024
yui_knk
2
190
Featured
See All Featured
Building Applications with DynamoDB
mza
89
5.9k
Into the Great Unknown - MozCon
thekraken
28
1.4k
Become a Pro
speakerdeck
PRO
22
4.9k
Side Projects
sachag
451
42k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
363
22k
The Illustrated Children's Guide to Kubernetes
chrisshort
46
48k
A Tale of Four Properties
chriscoyier
155
22k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Building Your Own Lightsaber
phodgson
101
6k
Thoughts on Productivity
jonyablonski
66
4.2k
How to name files
jennybc
75
98k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Transcript
4RVBSF 'SBHNFOUΊΔͬͯΑ OJOKJOLVO
ʲ༁ʳ"OESPJE'SBHNFOUͷ ର໌ w "EWPDBUJOH"HBJOTU"OESPJE'SBHNFOUT w 4RVBSF͕'SBHNFOUΛΊͨ w ษڧ͕ͯΒ༁ͨ͠ͷͰɺղઆ͠·͢ w !IPUDIFNJ͞Μʹ༁νΣοΫ͖ͯ͠·ͨ͠
IUUQOJOKJOLVOIBUFOBCMPHDPNFOUSZ
'SBHNFOUͷ w ϥΠϑαΠΫϧ͕ෳࡶ w σόοά͕͍͠ w 7JFXͱϏδωεϩδοΫͷ͕ͮ͠Β͍ w ࠶ੜ͕ࠇຐज़
ϥΠϑαΠΫϧ͕ෳࡶ w "DUJWJUZ͔Βड͚ܧ͍ͩϥΠϑαΠΫϧ w "DUJWJUZͱ࿈ܞ͢ΔҝͷϥΠϑαΠΫϧ w 'SBHNFOU5SBOTBDUJPOͱ࿈ܞ͢ΔͨΊ ͷϥΠϑαΠΫϧ
σόοάͷ͠͞ w ελοΫΛ͍ͬͯ͘ͱ'SBHNFOU.BOBHFS*NQM ʹͿ͔ͭͬͯࢮ͵
7JFX$POUSPMMFSͨΓಘΔ͔ w 'SBHNFOU7JFXʹؔ͢ΔϩδοΫ͍ͩͿ࣋ͬͯ ͍Δ w ϏδωεϩδοΫͱ྆ํࠞࡏͯ͠͠·͏
'SBHNFOU5SBOTBDUJPO w DPNNJU͕ඇಉظ w ϝΠϯεϨουͷϋϯυϥΩϡʔͷ͋ͱͰ·ͱΊͯ ࣮ߦ͞ΕΔ w ͙͢ʹ݁ՌΛ͍͍ͨͳΒ FYFDVUF1FOEJOH5SBOTBDUJPOT
'SBHNFOUΛੜ͢Δຐ๏ w 'SBHNFOUϦϑϨΫγϣϯΛͬͯ࠶ੜ͞ΕΔ w ಗ໊ΫϥεͰ'SBHNFOUΛ࡞Δͱɺ0VUFS$MBTTͷ ࢀর͕ͳͯ͘࠶ੜ࣌ʹࢮ͵ w +BWBͷϥΠϑαΠΫϧͱ'SBHNFOUͷϥΠϑαΠΫ ϧ͕ϛεϚον DialogFragment
dialogFragment = new DialogFragment() { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { ... } }; dialogFragment.show(fragmentManager, tag);
ʢิʣ'SBHNFOUΛੜ͢Δຐ๏ w -JTUFOFSอ࣋Ͱ͖ͳ͍ w ͱ௨৴͠Α͏ͱࢥͬͨΒɺʹ-JTUFOFSΛ࣮͢ Δඞཁ͕͋Δ w 'SBHNFOU͔Β"DUJWJUZʹίʔϧόοΫ͢Δํ๏ IUUQZBO[NCMPHTQPUKQGSBHNFOUBDUJWJUZIUNM
public class MainFragment extends Fragment { public interface OnOkBtnClickListener {
public void onOkClicked(); } private OnOkBtnClickListener mListener; public void setOnOkBtnClickListener(OnOkBtnClickListener l) { mListener = l; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Button okBtn = new Button(inflater.getContext()); okBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(mListener != null) { mListener.onOkClicked(); } } }); return okBtn; } } ࠶ੜ࣌ʹ-JTUFOFS͕ফ͑Δ IUUQZBO[NCMPHTQPUKQGSBHNFOUBDUJWJUZIUNM
public class MainFragment2 extends Fragment { public interface OnOkBtnClickListener {
public void onOkClicked(); } private OnOkBtnClickListener mListener; @Override public void onAttach(Activity activity) { super.onAttach(activity); if (activity instanceof OnOkBtnClickListener == false) { throw new ClassCastException("activity ͕ OnOkBtnClickListener Λ࣮͍ͯ͠·ͤΜ."); } mListener = ((OnOkBtnClickListener) activity); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Button okBtn = new Button(inflater.getContext()); okBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mListener != null) { mListener.onOkClicked(); } } }); return okBtn; } }
'SBHNFOU͔ΒֶΜͩ͜ͱ w ୯Ұͷ"DUJWJUZ w ը໘ຖʹ"DUJWJUZΛ͚Δඞཁແ͍ w ΞχϝʔγϣϯͱϥΠϑαΠΫϧ͕؆୯ʹͳΔ
'SBHNFOU͔ΒֶΜͩ͜ͱ w όοΫελοΫ"DUJWJUZಛ༗ͷ֓೦Ͱͳ͍ w "DUJWJUZͷதʹ࣮Ͱ͖Δ
'SBHNFOU͔ΒֶΜͩ͜ͱ w ඞཁͳͷશ෦ॳΊ͔Βἧ͍ͬͯͨ w "DUJWJUZ 7JFX -BZPVU*OqBUPS
ΧελϜϏϡʔ w $POUBJOFSͷಋೖ w ຕͷը໘Λ7JFXͰදݱ͢Δ w 7JFXPS-BZPVUͷαϒΫϥε w 7JFXͱͯ͠ͷׂ όοΫૢ࡞ͷཧ
public class DualPaneContainer extends LinearLayout implements Container { private MyDetailView
detailView; ! public DualPaneContainer(Context context, AttributeSet attrs) { super(context, attrs); } ! @Override protected void onFinishInflate() { super.onFinishInflate(); detailView = (MyDetailView) getChildAt(1); } ! public boolean onBackPressed() { return false; } ! @Override public void showItem(String item) { detailView.setItem(item); } }
public class MainActivity extends Activity { private Container container; !
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); container = (Container) findViewById(R.id.container); } ! public Container getContainer() { return container; } ! @Override public void onBackPressed() { boolean handled = container.onBackPressed(); if (!handled) { finish(); } } }
7JFXͱ1SFTFOUFS w ϏδωεϩδοΫͱ$POUSPMMFSͷ w 1SFTFOUFS w .PEFMΛૢ࡞͢Δ w 7JFXΛૢ࡞͢Δ
ʢิʣ.71ύλʔϯ w .7$ͱͷҧ͍ w $POUSPMMFS͕ϢʔβʔೖྗΛड͚ͱΒͳ͍ w ड͚ͱΔͷ7JFX
public class MyDetailView extends LinearLayout { TextView textView; DetailPresenter presenter;
! public MyDetailView(Context context, AttributeSet attrs) { super(context, attrs); presenter = new DetailPresenter(); } ! @Override protected void onFinishInflate() { super.onFinishInflate(); presenter.setView(this); textView = (TextView) findViewById(R.id.text); findViewById(R.id.button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { presenter.buttonClicked(); } }); } ! public void setItem(String item) { textView.setText(item); } }
class EditDiscountPresenter { // ... public void saveDiscount() { EditDiscountView
view = getView(); String name = view.getName(); if (isBlank(name)) { view.showNameRequiredWarning(); return; } if (isNewDiscount()) { createNewDiscountAsync(name, view.getAmount(), view.isPercentage()); } else { updateNewDiscountAsync(discountId, name, view.getAmount(), view.isPercentage()); } close(); } }
OJOKJOLVOࢲݟ w "DUJWJUZͷܽؕʢͱ͍͏͔χʔζʹ߹͍ͬͯͳ͔ͬ ͨͱ͜Ζʣ w "DUJWJUZؒͷૄ݁߹ઃܭ w ը໘લఏ
OJOKJOLVOࢲݟ w "DUJWJUZͷܽΛิ͢ΔͨΊͷ'SBHNFOU w "DUJWJUZͱͷ߹ੑΛऔΖ͏ͱ͗ͯ͢͠ઃܭ͕ෳ ࡶʹͳͬͯ͠·͍ͬͯΔ w 4RVBSF߹ੑΛࣺͯͯɺಠࣗͷεςʔτϑϧੈ քΛߏங͢ΔΞϓϩʔν
OJOKJOLVOࢲݟ w ϖʔδભҠ͢Δ8FCΞϓϦͱ4JOHMF1BHF "QQMJDBUJPOͷؔʹࣅͯΔ w ͳͷͰࢀߟʹͳΔ͜ͱ͋Δ͔
OJOKJOLVOࢲݟ w ฐࣾͰ'SBHNFOUࣺͯͳ͍ w ಠࣗͰੈք؍Λ࡞Δ༨༟ͳ͍ w ͔͠͠'SBHNFOUͷਏ͞ೝ͓͖ࣝͯͩ͘͠ͱࢥ ͏
ձσΟεΧογϣϯ w #BDLTUBDLʹ٧Έ͍ͨͱ͖͚ͩ'SBHNFOUΛ͏ύ λʔϯΛࢼ͍ͯ͠Δํ͕͍Βͬ͠Όͬͨ w $VTUPN7JFXΛͬͱ͏Α͏ʹ͢Ε'SBHNFOU ґଘݮΒͤΔ w 'SBHNFOUʹԿͰॻ͘ͷԿʹͤΑΞϯνύλʔ ϯ
w 1SFTFOUFS'SBHNFOUΛ͍ͬͯͯ༗༻ͦ͏
ձσΟεΧογϣϯ w Ͱ͖Δ͚ͩ"DUJWJUZ͚ͩͰ࡞Δͷํ w "DUJWJUZʹ͍ͭͯ͋·Γέ͕ྑ͘ͳ͔ͬͨ
ձσΟεΧογϣϯ w 'SBHNFOUͷਏ͞ʹ͍ͭͯ݁ߏίϯηϯαε͕औ Εͨͱࢥ͏ w ͦͷลΓΛཧղ্ͨ͠Ͱ͍͖ͬͯ·͠ΐ͏