Created
October 31, 2017 22:03
-
-
Save zizibaloob/e107fe80afa6873301bf234702d4b2b9 to your computer and use it in GitHub Desktop.
Skeleton of an Android app to demonstrate a specific kind of activity transition
This file contains 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" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@color/gray" | |
android:orientation="vertical"> | |
<View | |
android:layout_width="match_parent" | |
android:layout_height="?attr/actionBarSize"/> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:textColor="@color/white" | |
android:textSize="16sp" | |
android:text="Featured Lesson Sets"/> | |
<android.support.v7.widget.CardView | |
android:id="@+id/card" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="10dp" | |
app:cardCornerRadius="4dp"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:background="@color/green"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:padding="12dp" | |
android:lineSpacingMultiplier="1.2" | |
android:textColor="@color/white" | |
android:textSize="40sp" | |
android:text="@string/get_your_business_ready" | |
android:fontFamily="sans-serif-light"/> | |
<android.support.v4.widget.Space | |
android:layout_width="0dp" | |
android:layout_height="100dp"/> | |
</LinearLayout> | |
</android.support.v7.widget.CardView> | |
</LinearLayout> |
This file contains 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"?> | |
<FrameLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@color/gray"> | |
<FrameLayout | |
android:id="@+id/transitionBackground" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@color/green" | |
android:transitionName="@string/transition_name"> | |
<LinearLayout | |
android:id="@+id/transitionContents" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<android.support.v7.widget.Toolbar | |
android:id="@+id/toolbar" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:theme="@style/WhiteToolbar"/> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:padding="24dp" | |
android:lineSpacingMultiplier="1.2" | |
android:textColor="@color/white" | |
android:textSize="40sp" | |
android:text="@string/get_your_business_ready" | |
android:fontFamily="sans-serif-light"/> | |
</LinearLayout> | |
</FrameLayout> | |
</FrameLayout> |
This file contains 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.example.transitionexample; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v4.app.ActivityOptionsCompat; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final View card = findViewById(R.id.card); | |
final String transitionName = getString(R.string.transition_name); | |
card.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Intent intent = new Intent(MainActivity.this, OtherActivity.class); | |
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, card, transitionName).toBundle(); | |
startActivity(intent, bundle); | |
} | |
}); | |
} | |
} |
This file contains 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.example.transitionexample; | |
import android.animation.ObjectAnimator; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.Toolbar; | |
import android.view.View; | |
public class OtherActivity extends AppCompatActivity { | |
private View transitionContents; | |
@Override | |
public void onBackPressed() { | |
ObjectAnimator animator = ObjectAnimator.ofFloat(transitionContents, "alpha", 1f, 0f); | |
animator.setDuration(200); | |
animator.start(); | |
supportFinishAfterTransition(); | |
} | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_other); | |
transitionContents = findViewById(R.id.transitionContents); | |
Toolbar toolbar = findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
getSupportActionBar().setTitle("Featured Lessons"); | |
if (savedInstanceState == null) { | |
transitionContents.setAlpha(0f); | |
ObjectAnimator animator = ObjectAnimator.ofFloat(transitionContents, "alpha", 0f, 1f); | |
animator.setStartDelay(250); | |
animator.setDuration(300); | |
animator.start(); | |
} | |
} | |
} |
This file contains 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
<resources> | |
<style name="AppTheme" parent="Theme.AppCompat"> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="windowActionBar">false</item> | |
<item name="windowNoTitle">true</item> | |
</style> | |
<style name="TransitionTheme" parent="AppTheme"> | |
<item name="android:windowSharedElementEnterTransition">@transition/shared_element_transition</item> | |
<item name="android:background">@color/transparent</item> | |
<item name="android:windowBackground">@color/transparent</item> | |
<item name="android:colorBackgroundCacheHint">@null</item> | |
</style> | |
<style name="WhiteToolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> | |
<item name="colorControlNormal">#fff</item> | |
<item name="android:textColorPrimary">#fff</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment