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

The Fragment Transition

Corey's Prezi
by

Corey Latislaw

on 10 October 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of The Fragment Transition

Android
Magic
Get XML
Form factor?
Tablet
main.xml
ListFragment
DetailFragment
main.xml
ListFragment
MainActivity::
onCreate()
DetailActivity::
onCreate()
MainActivity::
showDetail()
MainActivity::
update()
No
Yes
Phone
Dual pane?
A History
Legacy code
Landscape
Why?
Busine$$ Case
Why not?
Engineering
Case

bit rot
Obsolete
New APIs
Start from here
DetailFragment::
onClick()
Note: Default detail view
Multiple Fragments,
Multiple Activities
Fragments
Home Sweet Home
Fragment
Must have a host
@corey_latislaw
Corey Leigh Latislaw
Comcast Interactive Media
...
<
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

{
@Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(
R.layout.activity_welcome
);
}

public void showDetail()
{

if (isDualPane())
{ ... }
}

public boolean
isDualPane
()
{
// determine and return
}
}
public class WelcomeFragment extends

{
...
@Override
public View
onCreateView
(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState)
{
View layout = inflater.inflate(
R.layout.fragment_welcome
, container, false);

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

return layout;
}
...
}
activity_welcome.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" />
...
activity_welcome.xml
Dual Pane
Single Pane
WelcomeActivity.java
1
2
3
Write
fragment
WelcomeFragment.java
DetailFragment::
onClick()
1
2
1
2.isInLayout()
Config changes
Back stack
Idea
2 fragments
1
Activity
New
Activity
Update
Start
Add
Remove
"Sub activity"
Replace
Transaction
Transition
Record
Honeycomb
Manager
sevaeunplugged.wordpress.com/2011/09/13/ostrich-therapy
Lead or follow?
3.0
API 11
Fragment1
Fragment2
Independent
Modular
Flexible
Combine
Reuse
form factors
Remix
Investment
DialogFragment
ListFragment
PreferenceFragment
...
<TextView
android:id="@+id/welcome_text"
    android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world_string" />
...
fragment_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
Activity
Technical debt
Training
Schedule
New
Refactor
Opportunity
HIGH Risk
Tablets won't catch on
stackoverflow.com/questions/5695408/so-what-are-the-exact-advantages-of-fragments-in-android-3-0
The Fragment
Idea
Top Android Developer
>1 million downloads
Converting
Extend
Activity ||
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 compile
errors &
other issues
-setContentView( R.layout.welcome );
+View layout = 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 views
Integrate support library
Change target SDK
Great time for a refactor!
Prepend getActivity()
Disentangle logic
public class WelcomeActivity extends
FragmentActivity
{
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(
R.layout.activity_welcome
);
}
}
...
<fragment
    android:id="@+id/welcome"
android:name="com.example.WelcomeFragment"
    android:layout_width="match_parent"
android:layout_height="match_parent" />
...
activity_welcome.xml
MyActivity.java
6
Set
activity
view
We are here!
detail.xml
DetailFragment
Start from scratch
Full renovation
Leadership
droiddog.com/android-blog/2011/03/2011-the-year-of-fierce-competition/honeycomb-bee-550x550-e1296765261166/
Action bar + tabs
Action bar + "list"-based navigation
Transition animations
Automatic back stack management
Configuration changes
Code reuse
Manage multiple screens
No monolithic activities
Best Practices
Fragment
mint.com/how-it-works/anywhere/android-tablet/
Approaches
public showDetail() {
    // Update current view
if (isDualPane())
{
update();
}
// Start new activity
else
{
startDetailActivity();
}
}
  public boolean isDualPane()
{
FragmentManager fragmentManager =
Fragment detailFragment = fragmentManager.
findFragmentById
( R.id.detail_fragment );
return detailFragment != null && detailFragment.getVisibility() == View.VISIBLE;
}
ListFragment::
onClick()
MainActivity::
startDetail()
Transition
HowAboutWe
WXPN Radio
94%
Pre-Honeycomb
12%
androidpolice.com/tags/comcast
play.google.com/store/apps/details?id=com.xfinity.tv
Philly ETE
73%
<3
May 2012
Nov 2012
44%
May 2013
28%
Nov 2013
Options
v4 supports API 4+ (Donut, 1.6+)
v13 support API 13+ (Honeycomb, 3.2+)
Framework only API 11+ (Honeycomb, 3.0+)
http://developer.android.com/reference/android/support/v4/app/package-summary.html
http://developer.android.com/reference/android/support/v13/app/package-summary.html
Low Risk
ish


http://marketingland.com/study-android-tablet-users-surpass-ipad-users-by-34m-in-q1-with-tablet-usage-up-282-since-2011-2-4774
Prediction: ~70% global tablet users will be Android by 2016
What + Why?
I heard you liked fragments ....
f1
f2
f2
f3
f5
Activity
{
FragmentActivity
{
Fragment
Master/Detail
Update
Start
Start
Start
Back
getSupportFragmentManager();
{
getFragmentManager();
Update
Back
Repeat
A
form factors
steps->
Music Choice
7 Minute Workout
Forxiga
Sunesys
Training
f6
f6
Life cycle
Code!
https://github.com/xxv/android-lifecycle
1 billion Active Users
113 billion installs
236% more app installs
62% of tablets
46% last year
Market Share
Global Shipments
Source: http://www.idc.com/getdoc.jsp?containerId=prUS24857114
Source: http://www.idc.com/getdoc.jsp?containerId=prUS24857114
http://thenextweb.com/google/2014/06/25/google-activations-io-2014/
http://thenextweb.com/google/2014/06/25/google-activations-io-2014/
You?
?
Full transcript