Created
May 30, 2013 22:55
-
-
Save colabug/5681920 to your computer and use it in GitHub Desktop.
Final code for Fragment Transition Workshop, Labs 1 & 2. Note: Package names differ for each lab. If using these snippets for Lab 1, make sure to change the name to match the project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<fragment | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/outside_fragment" | |
android:name="com.colabug.TardisNoFragments.OutsideTardisFragment" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent"> | |
<fragment | |
android:id="@+id/outside_fragment" | |
android:name="com.colabug.TardisNoFragments.OutsideTardisFragment" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_weight="1"/> | |
<fragment | |
android:id="@+id/inside_fragment" | |
android:name="com.colabug.TardisNoFragments.InsideTardisFragment" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_weight="1"/> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.colabug.TardisNoFragments; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentActivity; | |
import android.view.View; | |
import android.widget.Toast; | |
public class HelloTardisActivity extends FragmentActivity | |
{ | |
@Override | |
public void onCreate( Bundle savedInstanceState ) | |
{ | |
super.onCreate( savedInstanceState ); | |
setContentView( R.layout.hello_tardis ); | |
Fragment fragment = getSupportFragmentManager().findFragmentById( R.id.outside_fragment ); | |
fragment.getView().setOnClickListener( generateOutsideClickListener() ); | |
} | |
private View.OnClickListener generateOutsideClickListener() | |
{ | |
return new View.OnClickListener() | |
{ | |
@Override | |
public void onClick( View view ) | |
{ | |
// "Tablet" | |
if ( isMultiPaneLayout() ) | |
{ | |
Toast.makeText( HelloTardisActivity.this, | |
"PARADOX", | |
Toast.LENGTH_SHORT ).show(); | |
} | |
// "Phone" | |
else | |
{ | |
startActivity( InsideTardisActivity.createIntent( | |
HelloTardisActivity.this ) ); | |
} | |
} | |
}; | |
} | |
private boolean isMultiPaneLayout() | |
{ | |
Fragment insideFragment = getSupportFragmentManager().findFragmentById( R.id.inside_fragment ); | |
return insideFragment != null && | |
insideFragment.isInLayout() && | |
insideFragment.isVisible(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<ImageView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:src="@drawable/inside_tardis"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<fragment | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/inside_fragment" | |
android:name="com.colabug.TardisNoFragments.InsideTardisFragment" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.colabug.TardisNoFragments; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v4.app.FragmentActivity; | |
/** | |
* Author: Corey Leigh Latislaw | |
* Date: 5/11/13 | |
* Purpose: | |
*/ | |
public class InsideTardisActivity extends FragmentActivity | |
{ | |
@Override | |
public void onCreate( Bundle savedInstanceState ) | |
{ | |
super.onCreate( savedInstanceState ); | |
setContentView( R.layout.inside_tardis_single_pane ); | |
} | |
public static Intent createIntent( Context context ) | |
{ | |
return new Intent( context, InsideTardisActivity.class ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.colabug.TardisNoFragments; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
/** | |
* Author: Corey Leigh Latislaw | |
* Date: 5/30/13 | |
* Purpose: | |
*/ | |
public class InsideTardisFragment extends Fragment | |
{ | |
@Override | |
public View onCreateView( LayoutInflater inflater, | |
ViewGroup container, | |
Bundle savedInstanceState ) | |
{ | |
View layout = inflater.inflate( R.layout.inside_tardis, | |
container, | |
false ); | |
return layout; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<ImageView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:src="@drawable/outside_tardis"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.colabug.TardisNoFragments; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
/** | |
* Author: Corey Leigh Latislaw | |
* Date: 5/30/13 | |
* Purpose: | |
*/ | |
public class OutsideTardisFragment extends Fragment | |
{ | |
@Override | |
public View onCreateView( LayoutInflater inflater, | |
ViewGroup container, | |
Bundle savedInstanceState ) | |
{ | |
View layout = inflater.inflate( R.layout.outside_tardis, | |
container, | |
false ); | |
return layout; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment