Commit 849af421 authored by Robert Hitt's avatar Robert Hitt

Added transition animation to detail view

-I didn't really like how the shared content transition looked,
unfortunately. Mainly because the two text views had different
font colors, so it looked really off.
-I also found that animating the RecyclerView is pretty much unfeasible.
There's currently an issue on RealmRecyclerViewAdapter that's been open
for months regarding this problem, so oh well.
parent 6db9bd7b
Pipeline #892 passed with stages
in 5 minutes and 8 seconds
......@@ -3,6 +3,7 @@ package srct.whatsopen.views.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
......@@ -12,8 +13,11 @@ import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.transition.Slide;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
......@@ -57,6 +61,7 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
setUpAnimations();
getFacility(getIntent().getStringExtra("name"));
......@@ -72,6 +77,15 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
setNotificationStatus();
}
private void setUpAnimations() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Slide slide = new Slide();
slide.setSlideEdge(Gravity.LEFT);
slide.setDuration(300);
getWindow().setEnterTransition(slide);
}
}
@Override
protected void onResume() {
super.onResume();
......@@ -97,6 +111,13 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAfterTransition();
} else {
finish();
}
return true;
case R.id.action_favorite:
mPresenter.toggleFavorite(mFacility);
return true;
......@@ -143,11 +164,28 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
getSupportActionBar().setTitle(mFacility.getName());
// Set shared content name for transitions if Api >= 21
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getTextViewTitle(toolbar).setTransitionName("facility_name");
}
// Display back button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
public static TextView getTextViewTitle(Toolbar toolbar){
TextView textViewTitle = null;
for(int i = 0; i<toolbar.getChildCount(); i++) {
View view = toolbar.getChildAt(i);
if(view instanceof TextView) {
textViewTitle = (TextView) view;
break;
}
}
return textViewTitle;
}
// Display the content to the text views
private void fillTextViews() {
String statusText = mFacility.isOpen() ? "Open" : "Closed";
......
package srct.whatsopen.views.adapters;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.Pair;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
......@@ -46,15 +50,18 @@ public class FacilityListAdapter extends
private String mMode;
private Realm mRealm;
private Activity mActivity; // this is pretty much just for transition animations
// Mode describes the filtering for the elements to be displayed
public FacilityListAdapter(Context context,
OrderedRealmCollection<Facility> data, String mode, Realm realm) {
OrderedRealmCollection<Facility> data,
String mode, Realm realm, Activity activity) {
super(context, data, true);
mMode = mode;
mRealm = realm;
mActivity = activity;
}
@Override
......@@ -226,7 +233,12 @@ public class FacilityListAdapter extends
Intent intent = new Intent(context, DetailActivity.class);
intent.putExtra("name", data.getName());
context.startActivity(intent);
// for some reason I need this for the transition to work
Pair<View, String> p1 = Pair.create((View) nameTextView, "");
ActivityOptionsCompat transitionActivityOptions =
ActivityOptionsCompat.makeSceneTransitionAnimation(mActivity, p1);
context.startActivity(intent, transitionActivityOptions.toBundle());
}
// toggles favorite status
......
......@@ -92,28 +92,28 @@ public class FacilityListFragment extends android.support.v4.app.Fragment implem
mRecyclerView.setAdapter(new FacilityListAdapter(view.getContext(),
mRealm.where(Facility.class)
.findAllSortedAsync("isOpen", Sort.DESCENDING),
mMode, mRealm));
mMode, mRealm, getActivity()));
break;
case "Favorites":
mRecyclerView.setAdapter(new FacilityListAdapter(view.getContext(),
mRealm.where(Facility.class)
.equalTo("isFavorited", true)
.findAllSortedAsync("isOpen", Sort.DESCENDING),
mMode, mRealm));
mMode, mRealm, getActivity()));
break;
case "Open":
mRecyclerView.setAdapter(new FacilityListAdapter(view.getContext(),
mRealm.where(Facility.class)
.equalTo("isOpen", true)
.findAllSortedAsync("isOpen", Sort.DESCENDING),
mMode, mRealm));
mMode, mRealm, getActivity()));
break;
case "Closed":
mRecyclerView.setAdapter(new FacilityListAdapter(view.getContext(),
mRealm.where(Facility.class)
.equalTo("isOpen", false)
.findAllSortedAsync("isOpen", Sort.DESCENDING),
mMode, mRealm));
mMode, mRealm, getActivity()));
break;
}
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_detail"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include
layout="@layout/toolbar_main"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<Button
android:id="@+id/notification_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Set Notifications"
android:textColor="#FFFFFF"
android:background="@color/cardview_dark_background"
android:layout_margin="8dp"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="1dp"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:paddingTop="4dp"
android:paddingLeft="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:text="Status: "
android:textSize="30sp"
/>
<TextView
android:id="@+id/open_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="TextView"
android:textSize="26sp"
/>
</LinearLayout>
<TextView
android:id="@+id/open_duration"
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingBottom="12dp"
android:textSize="16sp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="1dp"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location: "
android:textColor="@color/colorPrimary"
android:textSize="26sp"/>
<TextView
android:id="@+id/location_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:textSize="20sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="1dp"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:paddingBottom="12dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schedule: "
android:textColor="@color/colorPrimary"
android:textSize="26sp"/>
<TextView
android:id="@+id/schedule_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/text_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/facility_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Facility Name"
android:transitionName="facility_name"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:id="@+id/facility_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Facility Duration"
android:textColor="@color/facilityText"
android:textSize="16sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/favorite_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#00FFFFFF"
android:elevation="2dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:src="@drawable/ic_fav_button_off_24dp" />
</RelativeLayout>
</LinearLayout>
......@@ -10,6 +10,8 @@
<item name="android:colorControlHighlight">@color/tabButtonPressed</item>
<item name="android:homeAsUpIndicator">@drawable/ic_arrow_back_white</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
<item name="android:windowContentTransitions">true</item>
</style>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment