Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Fragments Are Cool

Corey's Prezi
by

Corey Latislaw

on 28 August 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Fragments Are Cool

A History
Almost as cool as bowties
Legacy code
Landscape
Why?
Community
Busine$$ Case
Why not?
Engineering
Case
bit rot
Obselete
New APIs
Start from here
Shiny!
Fragments
@corey_latislaw
Corey Leigh Latislaw
...
<
fragment
    android:id="@+id/welcome"
android:name="com.example.WelcomeFragment"
    android:layout_width="300dp"
android:layout_height="match_parent" />
Code!
Declare
layout
Show
layout
public class WelcomeActivity
extends FragmentActivity
{
@Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(
R.layout.main
);
}
...
}
public static class WelcomeFragment
extends Fragment
{
...
@Override
public View onCreateView (LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState)
{
View layout = inflater.inflate(
R.layout.welcome
, container, false);

      TextView welcomeText = (TextView)
layout
.findViewById(R.id.welcome_text);

return layout;
}
...
}
main.xml
<
fragment
    android:id="@+id/hello"
android:name="com.example.HelloFragment" 
 
android:layout_width="600dp"
android:layout_height="match_parent" />
...
...
<
fragment
    android:id="@+id/welcome"
android:name="com.example.WelcomeFragment"
    android:layout_width="match_parent"
android:layout_height="match_parent" />
...
main.xml
Dual Pane
Single Pane
MyActivity.java
1
2
3
Write
fragment
WelcomeFragment.java
Where's the code?
Honeycomb
sevaeunplugged.wordpress.com/2011/09/13/ostrich-therapy
Lead or follow?
3.0
API 11
Modular
Flexible
Combine
Reuse
form factors
Remix
Investment
...
<TextView
android:id="@+id/welcome_text"
    android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world_string" />
...
welcome.xml
setContentView(R.layout.main);
main.xml
MyActivity.java
WelcomeFragment.java
welcome.xml
inflater.inflate(R.layout.welcome, container, false);
<TextView/>
<fragment
android:name="com.example.WelcomeFragment"/>
Fragments
165,375
864
Android
Fragments
<1%
stackoverflow questions
Technical debt
Training
Schedule
New
Refactor
Opportunity
HIGH Risk
It ain't broke
million devices
thousands apps
300
450
informationweek.com/news/mobility/smart_phones/232601613
Tablets won't catch on
Idea
Upgrading
Extend
FragmentActivity
Move activity code
into fragment
1
2
3
onCreate() ->
onCreateView()
4
5
7
-import android.app.Activity;
+import android.support.v4.app.FragmentActivity;

-public class MyActivity extends Activity {
+public class MyActivity extends FragmentActivity {
MyActivity.java
...
public class WelcomeFragment extends Fragment {
// Activity's code
}
WelcomeFragment.java
-public void onCreate( Bundle bundle )
+public View onCreateView( LayoutInflater inflater,
+ ViewGroup container,
+ Bundle savedInstanceState )
{
- super.onCreate( bundle );
+ super.onCreateView( inflater, container, savedInstanceState );
WelcomeFragment.java
Fix complie
errors &
other issues
-setContentView( R.layout.welcome );
+LinearLayout layout = (LinearLayout) inflater.inflate( R.layout.welcome,
+ container,
+ false );
Inflate
XML
WelcomeFragment.java
- welcomeText = (TextView) findViewById( R.id.welcome_text );
+ welcomeText = (TextView) layout.findViewById( R.id.welcome_text );
WelcomeFragment.java
Use layout
to find ids
Prepend getActivity()
Disentangle logic
Great time for a refactor!
Change target SDK
public class WelcomeActivity extends FragmentActivity
{
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(
R.layout.main
);
}
}
...
<fragment
    android:id="@+id/welcome"
android:name="com.example.WelcomeFragment"
    android:layout_width="match_parent"
android:layout_height="match_parent" />
...
main.xml
MyActivity.java
6
Set
main
view
We are
here!
Start from scratch
Full renovation
850
thousand devices
activated daily
Leadership
droiddog.com/android-blog/2011/03/2011-the-year-of-fierce-competition/honeycomb-bee-550x550-e1296765261166/
Best Practices
mint.com/how-it-works/anywhere/android-tablet/
Approaches
93.8%
Pre-Honeycomb
Support library
coreylatislaw.com
<3
Reward
Full transcript