diff options
author | Sam Judd <judds@google.com> | 2014-10-19 14:14:15 -0700 |
---|---|---|
committer | Sam Judd <judds@google.com> | 2014-10-19 14:21:44 -0700 |
commit | 159f8c3a53939196c0e7a5f4a1667aa1fdfcd205 (patch) | |
tree | 521fc44c01be7374be9d2257d49ed9e781c196b7 | |
parent | 1579932986cc7438b103c811adeb0a14feab0ada (diff) | |
download | glide-159f8c3a53939196c0e7a5f4a1667aa1fdfcd205.tar.gz |
Add fullscreen activity to GIF sample.
7 files changed, 87 insertions, 11 deletions
diff --git a/samples/giphy/src/main/AndroidManifest.xml b/samples/giphy/src/main/AndroidManifest.xml index ea0809f5..c5dbccb8 100644 --- a/samples/giphy/src/main/AndroidManifest.xml +++ b/samples/giphy/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ <application android:allowBackup="true" android:icon="@drawable/ic_launcher" + android:largeHeap="true" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity @@ -17,6 +18,7 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + <activity android:name=".FullscreenActivity" /> </application> </manifest> diff --git a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/Api.java b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/Api.java index 26d71ffd..0973129f 100644 --- a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/Api.java +++ b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/Api.java @@ -19,7 +19,7 @@ import java.util.HashSet; * A java wrapper for Giphy's http api based on https://github.com/Giphy/GiphyAPI. */ public final class Api { - private static Api api = null; + private static volatile Api api = null; private static final String BETA_KEY = "dc6zaTOxFJmzC"; private static final String BASE_URL = "http://api.giphy.com"; private static final String SEARCH_PATH = "/v1/gifs/search"; diff --git a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/FullscreenActivity.java b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/FullscreenActivity.java new file mode 100644 index 00000000..6a30ccc4 --- /dev/null +++ b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/FullscreenActivity.java @@ -0,0 +1,59 @@ +package com.bumptech.glide.samples.giphy; + +import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.ImageView; +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.drawable.GlideDrawable; +import com.bumptech.glide.load.resource.transcode.BitmapToGlideDrawableTranscoder; +import com.google.gson.Gson; + +/** + * An {@link android.app.Activity} for displaying full size original GIFs. + */ +public class FullscreenActivity extends Activity { + private static final String EXTRA_RESULT_JSON = "result_json"; + + public static Intent getIntent(Context context, Api.GifResult result) { + Intent intent = new Intent(context, FullscreenActivity.class); + intent.putExtra(EXTRA_RESULT_JSON, new Gson().toJson(result)); + return intent; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.fullscreen_activity); + + String resultJson = getIntent().getStringExtra(EXTRA_RESULT_JSON); + final Api.GifResult result = new Gson().fromJson(resultJson, Api.GifResult.class); + + ImageView gifView = (ImageView) findViewById(R.id.fullscreen_gif); + + gifView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("giphy_url", result.images.original.url); + clipboard.setPrimaryClip(clip); + } + }); + + Glide.with(this) + .load(result.images.original.url) + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + .thumbnail(Glide.with(this) + .load(result) + .asBitmap() + .transcode(new BitmapToGlideDrawableTranscoder(this), GlideDrawable.class) + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + ) + .into(gifView); + } +} diff --git a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyModelLoader.java b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyModelLoader.java index c501b2cd..c3168af4 100644 --- a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyModelLoader.java +++ b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyModelLoader.java @@ -2,7 +2,6 @@ package com.bumptech.glide.samples.giphy; import android.content.Context; import android.text.TextUtils; - import com.bumptech.glide.load.model.GenericLoaderFactory; import com.bumptech.glide.load.model.ModelLoader; import com.bumptech.glide.load.model.ModelLoaderFactory; @@ -55,6 +54,5 @@ public class GiphyModelLoader extends BaseGlideUrlLoader<Api.GifResult> { private static int getDifference(Api.GifImage gifImage, int width, int height) { return Math.abs(width - gifImage.width) + Math.abs(height - gifImage.height); - } } diff --git a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java index e8b25e71..44acd82d 100644 --- a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java +++ b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java @@ -1,6 +1,7 @@ package com.bumptech.glide.samples.giphy; import android.app.Activity; +import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; @@ -12,6 +13,7 @@ import com.bumptech.glide.DrawableRequestBuilder; import com.bumptech.glide.GenericRequestBuilder; import com.bumptech.glide.Glide; import com.bumptech.glide.ListPreloader; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import java.io.InputStream; import java.util.ArrayList; @@ -24,7 +26,7 @@ public class MainActivity extends Activity implements Api.Monitor { private static final String TAG = "GiphyActivity"; private GifAdapter adapter; - private DrawableRequestBuilder<Api.GifResult> fullRequest; + private DrawableRequestBuilder<Api.GifResult> gifItemRequest; @Override protected void onCreate(Bundle savedInstanceState) { @@ -32,7 +34,6 @@ public class MainActivity extends Activity implements Api.Monitor { setContentView(R.layout.activity_main); Glide.get(this).register(Api.GifResult.class, InputStream.class, new GiphyModelLoader.Factory()); - Api.get().getTrending(); ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view); Glide.with(this) @@ -43,11 +44,12 @@ public class MainActivity extends Activity implements Api.Monitor { ListView gifList = (ListView) findViewById(R.id.gif_list); GiphyPreloader preloader = new GiphyPreloader(2); - fullRequest = Glide.with(this) + gifItemRequest = Glide.with(this) .from(Api.GifResult.class) + .diskCacheStrategy(DiskCacheStrategy.ALL) .fitCenter(); - adapter = new GifAdapter(this, preloader, fullRequest); + adapter = new GifAdapter(this, preloader, gifItemRequest); gifList.setAdapter(adapter); gifList.setOnScrollListener(preloader); } @@ -56,6 +58,9 @@ public class MainActivity extends Activity implements Api.Monitor { protected void onStart() { super.onStart(); Api.get().addMonitor(this); + if (adapter.getCount() == 0) { + Api.get().getTrending(); + } } @Override @@ -93,7 +98,7 @@ public class MainActivity extends Activity implements Api.Monitor { @Override protected GenericRequestBuilder getRequestBuilder(Api.GifResult item) { - return fullRequest.load(item); + return gifItemRequest.load(item); } } @@ -143,11 +148,18 @@ public class MainActivity extends Activity implements Api.Monitor { convertView = activity.getLayoutInflater().inflate(R.layout.gif_list_item, parent, false); } - Api.GifResult result = results[position]; + final Api.GifResult result = results[position]; if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "load result: " + result); } final ImageView gifView = (ImageView) convertView.findViewById(R.id.gif_view); + gifView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent fullscreenIntent = FullscreenActivity.getIntent(activity, result); + activity.startActivity(fullscreenIntent); + } + }); requestBuilder .load(result) diff --git a/samples/giphy/src/main/res/layout/fullscreen_activity.xml b/samples/giphy/src/main/res/layout/fullscreen_activity.xml new file mode 100644 index 00000000..09967b3e --- /dev/null +++ b/samples/giphy/src/main/res/layout/fullscreen_activity.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<ImageView + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/fullscreen_gif" + android:layout_width="match_parent" + android:layout_height="match_parent"/> diff --git a/samples/giphy/src/main/res/layout/gif_list_item.xml b/samples/giphy/src/main/res/layout/gif_list_item.xml index 2f403224..6f79bb1c 100644 --- a/samples/giphy/src/main/res/layout/gif_list_item.xml +++ b/samples/giphy/src/main/res/layout/gif_list_item.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> - <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gif_view" android:layout_width="match_parent" - android:layout_height="100dp" + android:layout_height="125dp" android:contentDescription="@string/image_description" /> |