summaryrefslogtreecommitdiffstats
path: root/samples/browseable/ActivitySceneTransitionBasic
diff options
context:
space:
mode:
authorTrevor Johns <trevorjohns@google.com>2014-12-09 18:47:59 -0800
committerTrevor Johns <trevorjohns@google.com>2014-12-09 18:49:04 -0800
commitabededd8f7014bb4af9e0e203b71633cd72e9c20 (patch)
treeb895cb281d829774fea1bd4089729359287f428a /samples/browseable/ActivitySceneTransitionBasic
parent1ccf8350d52bd8d7f480c2c4d46c666356f4a220 (diff)
downloadandroid_development-abededd8f7014bb4af9e0e203b71633cd72e9c20.tar.gz
android_development-abededd8f7014bb4af9e0e203b71633cd72e9c20.tar.bz2
android_development-abededd8f7014bb4af9e0e203b71633cd72e9c20.zip
Docs: Sync browseable samples for lmp-docs
Synced to developers/samples/android commit bc036ecdf44cd03163c206096172299f3940b057. Change-Id: Ib68230d79ca300e7db906aff2ebfc2cb6c6968f7
Diffstat (limited to 'samples/browseable/ActivitySceneTransitionBasic')
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/_index.jd6
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/layout/details.xml2
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/layout/grid_item.xml2
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/transition/grid_detail_transition.xml28
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/values-v21/base-colors.xml20
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/values-v21/base-template-styles.xml23
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/values-v21/styles.xml3
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/values-v21/template-styles.xml22
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/values/base-strings.xml6
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/res/values/strings.xml15
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java118
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/ImageMemoryCache.java96
-rw-r--r--samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java44
13 files changed, 176 insertions, 209 deletions
diff --git a/samples/browseable/ActivitySceneTransitionBasic/_index.jd b/samples/browseable/ActivitySceneTransitionBasic/_index.jd
index 1053a7d5b..fd2e0c79d 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/_index.jd
+++ b/samples/browseable/ActivitySceneTransitionBasic/_index.jd
@@ -5,8 +5,8 @@ sample.group=UI
<p>
Demonstrates how to the use Activity scene transitions when transitions
- from one Activity to another. Uses a combination of moveImage and changeBounds
- to nicely transition a grid of images to an Activity with a large image and detail
- text.
+ from one Activity to another. Uses a combination of changeImageTransform and
+ changeBounds to nicely transition a grid of images to an Activity with a large image
+ and detail text.
</p>
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/layout/details.xml b/samples/browseable/ActivitySceneTransitionBasic/res/layout/details.xml
index e61212ed2..8ca463482 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/res/layout/details.xml
+++ b/samples/browseable/ActivitySceneTransitionBasic/res/layout/details.xml
@@ -27,7 +27,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
- <com.android.volley.toolbox.NetworkImageView
+ <ImageView
android:id="@+id/imageview_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/layout/grid_item.xml b/samples/browseable/ActivitySceneTransitionBasic/res/layout/grid_item.xml
index 1d28dbada..e79f0eb30 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/res/layout/grid_item.xml
+++ b/samples/browseable/ActivitySceneTransitionBasic/res/layout/grid_item.xml
@@ -23,7 +23,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
- <com.android.volley.toolbox.NetworkImageView
+ <ImageView
android:id="@+id/imageview_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/transition/grid_detail_transition.xml b/samples/browseable/ActivitySceneTransitionBasic/res/transition/grid_detail_transition.xml
index 40be3d468..3091cd266 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/res/transition/grid_detail_transition.xml
+++ b/samples/browseable/ActivitySceneTransitionBasic/res/transition/grid_detail_transition.xml
@@ -16,33 +16,15 @@
<!--
The transitions which us used for the entrance and exit of shared elements. Here we declare
- two different transitions which are targeting to specific views.
+ two different transitions which are targeting specific views.
-->
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<!-- changeBounds is used for the TextViews which are shared -->
- <changeBounds>
- <!--
- Set this transitions target IDs to be those which point to the TextViews in both the
- starting and result Activities
- -->
- <targets>
- <target android:targetId="@id/textview_name" />
- <target android:targetId="@id/textview_title" />
- </targets>
- </changeBounds>
-
- <!-- moveImage is used for the ImageViews which are shared -->
- <moveImage>
- <!--
- Set this transitions target IDs to be those which point to the ImageViews in both the
- starting and result Activities
- -->
- <targets>
- <target android:targetId="@id/imageview_header" />
- <target android:targetId="@id/imageview_item" />
- </targets>
- </moveImage>
+ <changeBounds />
+
+ <!-- changeImageTransform is used for the ImageViews which are shared -->
+ <changeImageTransform />
</transitionSet>
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/base-colors.xml b/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/base-colors.xml
new file mode 100644
index 000000000..34c9cd138
--- /dev/null
+++ b/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/base-colors.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+
+
+</resources>
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/base-template-styles.xml b/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/base-template-styles.xml
new file mode 100644
index 000000000..0b2948f7e
--- /dev/null
+++ b/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/base-template-styles.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Material.Light">
+ </style>
+
+</resources>
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/styles.xml b/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/styles.xml
index fd212b395..4fee48dd8 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/styles.xml
+++ b/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/styles.xml
@@ -17,9 +17,6 @@
<resources>
<style name="Theme.Sample" parent="Theme.Base">
- <!-- Set the windowContentTransitions flag to enable Activity scene transitions -->
- <item name="android:windowContentTransitions">true</item>
-
<!-- Set the transitions which are used for the entrance and exit of shared elements -->
<item name="android:windowSharedElementEnterTransition">
@transition/grid_detail_transition
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/template-styles.xml b/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/template-styles.xml
deleted file mode 100644
index 134fcd9d3..000000000
--- a/samples/browseable/ActivitySceneTransitionBasic/res/values-v21/template-styles.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<!--
- Copyright 2014 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<resources>
-
- <!-- Activity themes -->
- <style name="Theme.Base" parent="android:Theme.Material.Light" />
-
-</resources>
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/values/base-strings.xml b/samples/browseable/ActivitySceneTransitionBasic/res/values/base-strings.xml
index 989fe00d7..35860cb2d 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/res/values/base-strings.xml
+++ b/samples/browseable/ActivitySceneTransitionBasic/res/values/base-strings.xml
@@ -21,9 +21,9 @@
Demonstrates how to the use Activity scene transitions when transitions
- from one Activity to another. Uses a combination of moveImage and changeBounds
- to nicely transition a grid of images to an Activity with a large image and detail
- text.
+ from one Activity to another. Uses a combination of changeImageTransform and
+ changeBounds to nicely transition a grid of images to an Activity with a large image
+ and detail text.
]]>
diff --git a/samples/browseable/ActivitySceneTransitionBasic/res/values/strings.xml b/samples/browseable/ActivitySceneTransitionBasic/res/values/strings.xml
index 2aa0d3b5f..669c1270e 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/res/values/strings.xml
+++ b/samples/browseable/ActivitySceneTransitionBasic/res/values/strings.xml
@@ -1,4 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
<resources>
<string name="bacon_ipsum">
diff --git a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java
index 958900890..17d1b2a7b 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java
+++ b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java
@@ -16,13 +16,14 @@
package com.example.android.activityscenetransitionbasic;
-import com.android.volley.toolbox.ImageLoader;
-import com.android.volley.toolbox.NetworkImageView;
-import com.android.volley.toolbox.Volley;
+import com.squareup.picasso.Picasso;
import android.app.Activity;
-import android.graphics.Bitmap;
+import android.os.Build;
import android.os.Bundle;
+import android.support.v4.view.ViewCompat;
+import android.transition.Transition;
+import android.widget.ImageView;
import android.widget.TextView;
/**
@@ -40,23 +41,20 @@ public class DetailActivity extends Activity {
// View name of the header title. Used for activity scene transitions
public static final String VIEW_NAME_HEADER_TITLE = "detail:header:title";
- private NetworkImageView mHeaderImageView;
+ private ImageView mHeaderImageView;
private TextView mHeaderTitle;
- private ImageLoader mImageLoader;
+ private Item mItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
- // Construct an ImageLoader instance so that we can load images from the network
- mImageLoader = new ImageLoader(Volley.newRequestQueue(this), ImageMemoryCache.INSTANCE);
-
// Retrieve the correct Item instance, using the ID provided in the Intent
- Item item = Item.getItem(getIntent().getIntExtra(EXTRA_PARAM_ID, 0));
+ mItem = Item.getItem(getIntent().getIntExtra(EXTRA_PARAM_ID, 0));
- mHeaderImageView = (NetworkImageView) findViewById(R.id.imageview_header);
+ mHeaderImageView = (ImageView) findViewById(R.id.imageview_header);
mHeaderTitle = (TextView) findViewById(R.id.textview_title);
// BEGIN_INCLUDE(detail_set_view_name)
@@ -65,31 +63,97 @@ public class DetailActivity extends Activity {
* This could be done in the layout XML, but exposing it via static variables allows easy
* querying from other Activities
*/
- mHeaderImageView.setTransitionName(VIEW_NAME_HEADER_IMAGE);
- mHeaderTitle.setTransitionName(VIEW_NAME_HEADER_TITLE);
+ ViewCompat.setTransitionName(mHeaderImageView, VIEW_NAME_HEADER_IMAGE);
+ ViewCompat.setTransitionName(mHeaderTitle, VIEW_NAME_HEADER_TITLE);
// END_INCLUDE(detail_set_view_name)
- loadItem(item);
+ loadItem();
}
- private void loadItem(Item item) {
+ private void loadItem() {
// Set the title TextView to the item's name and author
- mHeaderTitle.setText(getString(R.string.image_header, item.getName(), item.getAuthor()));
+ mHeaderTitle.setText(getString(R.string.image_header, mItem.getName(), mItem.getAuthor()));
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && addTransitionListener()) {
+ // If we're running on Lollipop and we have added a listener to the shared element
+ // transition, load the thumbnail. The listener will load the full-size image when
+ // the transition is complete.
+ loadThumbnail();
+ } else {
+ // If all other cases we should just load the full-size image now
+ loadFullSizeImage();
+ }
+ }
- final ImageMemoryCache cache = ImageMemoryCache.INSTANCE;
- Bitmap thumbnailImage = cache.getBitmapFromUrl(item.getThumbnailUrl());
+ /**
+ * Load the item's thumbnail image into our {@link ImageView}.
+ */
+ private void loadThumbnail() {
+ Picasso.with(mHeaderImageView.getContext())
+ .load(mItem.getThumbnailUrl())
+ .noFade()
+ .into(mHeaderImageView);
+ }
+
+ /**
+ * Load the item's full-size image into our {@link ImageView}.
+ */
+ private void loadFullSizeImage() {
+ Picasso.with(mHeaderImageView.getContext())
+ .load(mItem.getPhotoUrl())
+ .noFade()
+ .noPlaceholder()
+ .into(mHeaderImageView);
+ }
- // Check to see if we already have the thumbnail sized image in the cache. If so, start
- // loading the full size image and display the thumbnail as a placeholder.
- if (thumbnailImage != null) {
- mHeaderImageView.setImageUrl(item.getPhotoUrl(), mImageLoader);
- mHeaderImageView.setImageBitmap(thumbnailImage);
- return;
+ /**
+ * Try and add a {@link Transition.TransitionListener} to the entering shared element
+ * {@link Transition}. We do this so that we can load the full-size image after the transition
+ * has completed.
+ *
+ * @return true if we were successful in adding a listener to the enter transition
+ */
+ private boolean addTransitionListener() {
+ final Transition transition = getWindow().getSharedElementEnterTransition();
+
+ if (transition != null) {
+ // There is an entering shared element transition so add a listener to it
+ transition.addListener(new Transition.TransitionListener() {
+ @Override
+ public void onTransitionEnd(Transition transition) {
+ // As the transition has ended, we can now load the full-size image
+ loadFullSizeImage();
+
+ // Make sure we remove ourselves as a listener
+ transition.removeListener(this);
+ }
+
+ @Override
+ public void onTransitionStart(Transition transition) {
+ // No-op
+ }
+
+ @Override
+ public void onTransitionCancel(Transition transition) {
+ // Make sure we remove ourselves as a listener
+ transition.removeListener(this);
+ }
+
+ @Override
+ public void onTransitionPause(Transition transition) {
+ // No-op
+ }
+
+ @Override
+ public void onTransitionResume(Transition transition) {
+ // No-op
+ }
+ });
+ return true;
}
- // If we get here then we do not have either the full size or the thumbnail in the cache.
- // Here we just load the full size and make do.
- mHeaderImageView.setImageUrl(item.getPhotoUrl(), mImageLoader);
+ // If we reach here then we have not added a listener
+ return false;
}
}
diff --git a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/ImageMemoryCache.java b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/ImageMemoryCache.java
deleted file mode 100644
index 53d47bae1..000000000
--- a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/ImageMemoryCache.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.activityscenetransitionbasic;
-
-import com.android.volley.toolbox.ImageLoader;
-
-import android.graphics.Bitmap;
-import android.util.LruCache;
-
-import java.util.Map;
-
-/**
- * An image memory cache implementation for Volley which allows the retrieval of entires via a URL.
- * Volley internally inserts items with a key which is a combination of a the size of the image,
- * and the url.
- *
- * This class provide the method {@link #getBitmapFromUrl(String)} which allows the retrieval of
- * a bitmap solely on the URL.
- */
-public class ImageMemoryCache extends LruCache<String, Bitmap> implements ImageLoader.ImageCache {
-
- /**
- * Singleton instance which has it's maximum size set to be 1/8th of the allowed memory size.
- */
- public static final ImageMemoryCache INSTANCE = new ImageMemoryCache(
- (int) (Runtime.getRuntime().maxMemory() / 8));
-
- // Cache the last created snapshot
- private Map<String, Bitmap> mLastSnapshot;
-
- private ImageMemoryCache(int maxSize) {
- super(maxSize);
- }
-
- public Bitmap getBitmapFromUrl(String url) {
- // If we do not have a snapshot to use, generate one
- if (mLastSnapshot == null) {
- mLastSnapshot = snapshot();
- }
-
- // Iterate through the snapshot to find any entries which match our url
- for (Map.Entry<String, Bitmap> entry : mLastSnapshot.entrySet()) {
- if (url.equals(extractUrl(entry.getKey()))) {
- // We've found an entry with the same url, return the bitmap
- return entry.getValue();
- }
- }
-
- // We didn't find an entry, so return null
- return null;
- }
-
- @Override
- public Bitmap getBitmap(String key) {
- return get(key);
- }
-
- @Override
- public void putBitmap(String key, Bitmap bitmap) {
- put(key, bitmap);
-
- // An entry has been added, so invalidate the snapshot
- mLastSnapshot = null;
- }
-
- @Override
- protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
- super.entryRemoved(evicted, key, oldValue, newValue);
-
- // An entry has been removed, so invalidate the snapshot
- mLastSnapshot = null;
- }
-
- private static String extractUrl(String key) {
- return key.substring(key.indexOf("http"));
- }
-
- @Override
- protected int sizeOf(String key, Bitmap value) {
- return value.getAllocationByteCount();
- }
-}
diff --git a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java
index 9c51789db..9eed44a3d 100644
--- a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java
+++ b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java
@@ -16,20 +16,20 @@
package com.example.android.activityscenetransitionbasic;
-import com.android.volley.toolbox.ImageLoader;
-import com.android.volley.toolbox.NetworkImageView;
-import com.android.volley.toolbox.Volley;
+import com.squareup.picasso.Picasso;
import android.app.Activity;
-import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
-import android.util.Pair;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.app.ActivityOptionsCompat;
+import android.support.v4.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
+import android.widget.ImageView;
import android.widget.TextView;
/**
@@ -42,16 +42,11 @@ public class MainActivity extends Activity implements AdapterView.OnItemClickLis
private GridView mGridView;
private GridAdapter mAdapter;
- private ImageLoader mImageLoader;
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid);
- // Retrieve the ImageLoader we are going to use for NetworkImageView
- mImageLoader = new ImageLoader(Volley.newRequestQueue(this), ImageMemoryCache.INSTANCE);
-
// Setup the GridView and set the adapter
mGridView = (GridView) findViewById(R.id.grid);
mGridView.setOnItemClickListener(this);
@@ -74,23 +69,21 @@ public class MainActivity extends Activity implements AdapterView.OnItemClickLis
// BEGIN_INCLUDE(start_activity)
/**
* Now create an {@link android.app.ActivityOptions} instance using the
- * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity, android.util.Pair[])} factory method.
+ * {@link ActivityOptionsCompat#makeSceneTransitionAnimation(Activity, Pair[])} factory
+ * method.
*/
- ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation(
+ ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
this,
// Now we provide a list of Pair items which contain the view we can transitioning
// from, and the name of the view it is transitioning to, in the launched activity
- new Pair<View, String>(
- view.findViewById(R.id.imageview_item),
+ new Pair<View, String>(view.findViewById(R.id.imageview_item),
DetailActivity.VIEW_NAME_HEADER_IMAGE),
- new Pair<View, String>(
- view.findViewById(R.id.textview_name),
- DetailActivity.VIEW_NAME_HEADER_TITLE)
- );
+ new Pair<View, String>(view.findViewById(R.id.textview_name),
+ DetailActivity.VIEW_NAME_HEADER_TITLE));
// Now we can start the Activity, providing the activity options as a bundle
- startActivity(intent, activityOptions.toBundle());
+ ActivityCompat.startActivity(this, intent, activityOptions.toBundle());
// END_INCLUDE(start_activity)
}
@@ -123,22 +116,13 @@ public class MainActivity extends Activity implements AdapterView.OnItemClickLis
final Item item = getItem(position);
// Load the thumbnail image
- NetworkImageView image = (NetworkImageView) view.findViewById(R.id.imageview_item);
- image.setImageUrl(item.getThumbnailUrl(), mImageLoader);
+ ImageView image = (ImageView) view.findViewById(R.id.imageview_item);
+ Picasso.with(image.getContext()).load(item.getThumbnailUrl()).into(image);
// Set the TextView's contents
TextView name = (TextView) view.findViewById(R.id.textview_name);
name.setText(item.getName());
- // BEGIN_INCLUDE(grid_set_view_name)
- /**
- * As we're in an adapter we need to set each view's name dynamically, using the
- * item's ID so that the names are unique.
- */
- image.setTransitionName("grid:image:" + item.getId());
- name.setTransitionName("grid:name:" + item.getId());
- // END_INCLUDE(grid_set_view_name)
-
return view;
}
}