diff options
Diffstat (limited to 'framesequence/samples/FrameSequenceSamples')
15 files changed, 432 insertions, 0 deletions
diff --git a/framesequence/samples/FrameSequenceSamples/Android.mk b/framesequence/samples/FrameSequenceSamples/Android.mk new file mode 100644 index 0000000..fff4a15 --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/Android.mk @@ -0,0 +1,40 @@ +# 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. + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_PACKAGE_NAME := FrameSequenceSample + +# java dependency +LOCAL_STATIC_JAVA_LIBRARIES += android-common-framesequence + +# native dependency +ifneq (,$(TARGET_BUILD_APPS)) + LOCAL_JNI_SHARED_LIBRARIES := libframesequence +else + LOCAL_REQUIRED_MODULES := libframesequence +endif + +# proguard for framesequence library code +LOCAL_PROGUARD_FLAG_FILES := proguard.flags + +LOCAL_SDK_VERSION := 19 + +LOCAL_SRC_FILES := $(call all-java-files-under, src) +LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, res) +LOCAL_AAPT_FLAGS := --auto-add-overlay +LOCAL_AAPT_FLAGS += --extra-packages com.android.framesequence.samples + +include $(BUILD_PACKAGE) diff --git a/framesequence/samples/FrameSequenceSamples/AndroidManifest.xml b/framesequence/samples/FrameSequenceSamples/AndroidManifest.xml new file mode 100644 index 0000000..d614631 --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/AndroidManifest.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.framesequence.samples" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk + android:minSdkVersion="15" + android:targetSdkVersion="18" /> + + <application + android:allowBackup="true" + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" > + <activity + android:name=".SamplesList" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity android:name=".FrameSequenceTest" /> + </application> + +</manifest> diff --git a/framesequence/samples/FrameSequenceSamples/build.xml b/framesequence/samples/FrameSequenceSamples/build.xml new file mode 100644 index 0000000..5e55b4e --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/build.xml @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="RastermillSamples" default="help"> + + <!-- The local.properties file is created and updated by the 'android' tool. + It contains the path to the SDK. It should *NOT* be checked into + Version Control Systems. --> + <property file="local.properties" /> + + <!-- The ant.properties file can be created by you. It is only edited by the + 'android' tool to add properties to it. + This is the place to change some Ant specific build properties. + Here are some properties you may want to change/update: + + source.dir + The name of the source directory. Default is 'src'. + out.dir + The name of the output directory. Default is 'bin'. + + For other overridable properties, look at the beginning of the rules + files in the SDK, at tools/ant/build.xml + + Properties related to the SDK location or the project target should + be updated using the 'android' tool with the 'update' action. + + This file is an integral part of the build system for your + application and should be checked into Version Control Systems. + + --> + <property file="ant.properties" /> + + <!-- if sdk.dir was not set from one of the property file, then + get it from the ANDROID_HOME env var. + This must be done before we load project.properties since + the proguard config can use sdk.dir --> + <property environment="env" /> + <condition property="sdk.dir" value="${env.ANDROID_HOME}"> + <isset property="env.ANDROID_HOME" /> + </condition> + + <!-- The project.properties file is created and updated by the 'android' + tool, as well as ADT. + + This contains project specific properties such as project target, and library + dependencies. Lower level build properties are stored in ant.properties + (or in .classpath for Eclipse projects). + + This file is an integral part of the build system for your + application and should be checked into Version Control Systems. --> + <loadproperties srcFile="project.properties" /> + + <!-- quick check on sdk.dir --> + <fail + message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." + unless="sdk.dir" + /> + + <target name="-pre-build"> + <ant dir="../../" target="release" inheritAll="false" /> + <copy todir="libs"> + <fileset dir="../../exported_libs" /> + </copy> + </target> + + <!-- + Import per project custom build rules if present at the root of the project. + This is the place to put custom intermediary targets such as: + -pre-build + -pre-compile + -post-compile (This is typically used for code obfuscation. + Compiled code location: ${out.classes.absolute.dir} + If this is not done in place, override ${out.dex.input.absolute.dir}) + -post-package + -post-build + -pre-clean + --> + <import file="custom_rules.xml" optional="true" /> + + <!-- Import the actual build file. + + To customize existing targets, there are two options: + - Customize only one target: + - copy/paste the target into this file, *before* the + <import> task. + - customize it to your needs. + - Customize the whole content of build.xml + - copy/paste the content of the rules files (minus the top node) + into this file, replacing the <import> task. + - customize to your needs. + + *********************** + ****** IMPORTANT ****** + *********************** + In all cases you must update the value of version-tag below to read 'custom' instead of an integer, + in order to avoid having your file be overridden by tools such as "android update project" + --> + <!-- version-tag: 1 --> + <import file="${sdk.dir}/tools/ant/build.xml" /> + +</project> diff --git a/framesequence/samples/FrameSequenceSamples/proguard.flags b/framesequence/samples/FrameSequenceSamples/proguard.flags new file mode 100644 index 0000000..4acde2d --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/proguard.flags @@ -0,0 +1,3 @@ +-keep class android.support.rastermill.** { + *; +} diff --git a/framesequence/samples/FrameSequenceSamples/project.properties b/framesequence/samples/FrameSequenceSamples/project.properties new file mode 100644 index 0000000..ce39f2d --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-18 diff --git a/framesequence/samples/FrameSequenceSamples/res/drawable-hdpi/ic_launcher.png b/framesequence/samples/FrameSequenceSamples/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..96a442e --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/res/drawable-hdpi/ic_launcher.png diff --git a/framesequence/samples/FrameSequenceSamples/res/drawable-mdpi/ic_launcher.png b/framesequence/samples/FrameSequenceSamples/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..359047d --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/res/drawable-mdpi/ic_launcher.png diff --git a/framesequence/samples/FrameSequenceSamples/res/drawable-xhdpi/ic_launcher.png b/framesequence/samples/FrameSequenceSamples/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..71c6d76 --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/res/drawable-xhdpi/ic_launcher.png diff --git a/framesequence/samples/FrameSequenceSamples/res/layout/basic_test_activity.xml b/framesequence/samples/FrameSequenceSamples/res/layout/basic_test_activity.xml new file mode 100644 index 0000000..0b9a2df --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/res/layout/basic_test_activity.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <ImageView + android:id="@+id/imageview" + android:layout_width="match_parent" + android:layout_height="300dp" /> + <LinearLayout + android:orientation="horizontal" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + <Button + android:id="@+id/start" + android:text="@string/start" + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + <Button + android:id="@+id/stop" + android:text="@string/stop" + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + <Button + android:id="@+id/vis" + android:text="@string/vis" + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + <Button + android:id="@+id/invis" + android:text="@string/invis" + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + </LinearLayout> + +</LinearLayout>
\ No newline at end of file diff --git a/framesequence/samples/FrameSequenceSamples/res/raw/animated_gif.gif b/framesequence/samples/FrameSequenceSamples/res/raw/animated_gif.gif Binary files differnew file mode 100644 index 0000000..51baf15 --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/res/raw/animated_gif.gif diff --git a/framesequence/samples/FrameSequenceSamples/res/raw/animated_webp.webp b/framesequence/samples/FrameSequenceSamples/res/raw/animated_webp.webp Binary files differnew file mode 100644 index 0000000..25c6a4d --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/res/raw/animated_webp.webp diff --git a/framesequence/samples/FrameSequenceSamples/res/values/strings.xml b/framesequence/samples/FrameSequenceSamples/res/values/strings.xml new file mode 100644 index 0000000..dc0962e --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/res/values/strings.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <!-- NOTE: all strings should be marked as translatable=false, + since this sample app is for testing, and won't be shipped --> + + <string name="app_name" translatable="false">FrameSequence Samples</string> + <string name="action_settings" translatable="false">Settings</string> + + <string name="start" translatable="false">start</string> + <string name="stop" translatable="false">stop</string> + <string name="vis" translatable="false">vis</string> + <string name="invis" translatable="false">invis</string> + +</resources> diff --git a/framesequence/samples/FrameSequenceSamples/res/values/styles.xml b/framesequence/samples/FrameSequenceSamples/res/values/styles.xml new file mode 100644 index 0000000..737bdc3 --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/res/values/styles.xml @@ -0,0 +1,7 @@ +<resources> + + <!-- Application theme. --> + <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> + </style> + +</resources> diff --git a/framesequence/samples/FrameSequenceSamples/src/com/android/framesequence/samples/FrameSequenceTest.java b/framesequence/samples/FrameSequenceSamples/src/com/android/framesequence/samples/FrameSequenceTest.java new file mode 100644 index 0000000..5587dc6 --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/src/com/android/framesequence/samples/FrameSequenceTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 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. + */ +package com.android.framesequence.samples; + +import android.app.Activity; +import android.graphics.Bitmap; +import android.os.Bundle; +import android.support.rastermill.FrameSequence; +import android.support.rastermill.FrameSequenceDrawable; +import android.view.View; +import android.widget.ImageView; +import android.widget.Toast; + +import java.io.InputStream; +import java.util.HashSet; + +public class FrameSequenceTest extends Activity { + FrameSequenceDrawable mDrawable; + int mResourceId; + + // This provider is entirely unnecessary, just here to validate the acquire/release process + private class CheckingProvider implements FrameSequenceDrawable.BitmapProvider { + HashSet<Bitmap> mBitmaps = new HashSet<Bitmap>(); + @Override + public Bitmap acquireBitmap(int minWidth, int minHeight) { + Bitmap bitmap = + Bitmap.createBitmap(minWidth + 1, minHeight + 4, Bitmap.Config.ARGB_8888); + mBitmaps.add(bitmap); + return bitmap; + } + + @Override + public void releaseBitmap(Bitmap bitmap) { + if (!mBitmaps.contains(bitmap)) throw new IllegalStateException(); + mBitmaps.remove(bitmap); + bitmap.recycle(); + } + + public boolean isEmpty() { + return mBitmaps.isEmpty(); + } + } + + final CheckingProvider mProvider = new CheckingProvider(); + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mResourceId = getIntent().getIntExtra("resourceId", R.raw.animated_gif); + + setContentView(R.layout.basic_test_activity); + findViewById(R.id.start).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mDrawable.start(); + } + }); + findViewById(R.id.stop).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mDrawable.stop(); + } + }); + findViewById(R.id.vis).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mDrawable.setVisible(true, true); + } + }); + findViewById(R.id.invis).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mDrawable.setVisible(false, true); + } + }); + } + + @Override + protected void onResume() { + super.onResume(); + + ImageView imageView = (ImageView) findViewById(R.id.imageview); + InputStream is = getResources().openRawResource(mResourceId); + + FrameSequence fs = FrameSequence.decodeStream(is); + mDrawable = new FrameSequenceDrawable(fs, mProvider); + mDrawable.setOnFinishedListener(new FrameSequenceDrawable.OnFinishedListener() { + @Override + public void onFinished(FrameSequenceDrawable drawable) { + Toast.makeText(getApplicationContext(), + "The animation has finished", Toast.LENGTH_SHORT).show(); + } + }); + imageView.setImageDrawable(mDrawable); + } + + @Override + protected void onPause() { + super.onPause(); + ImageView imageView = (ImageView) findViewById(R.id.imageview); + + mDrawable.destroy(); + if (!mProvider.isEmpty()) throw new IllegalStateException("All bitmaps not recycled"); + + mDrawable = null; + imageView.setImageDrawable(null); + + } +} diff --git a/framesequence/samples/FrameSequenceSamples/src/com/android/framesequence/samples/SamplesList.java b/framesequence/samples/FrameSequenceSamples/src/com/android/framesequence/samples/SamplesList.java new file mode 100644 index 0000000..c67b83c --- /dev/null +++ b/framesequence/samples/FrameSequenceSamples/src/com/android/framesequence/samples/SamplesList.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 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. + */ + +package com.android.framesequence.samples; + +import android.app.ListActivity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.ListView; +import android.widget.SimpleAdapter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class SamplesList extends ListActivity { + + static final String KEY_NAME = "name"; + static final String KEY_CLASS = "clazz"; + static final String KEY_RESOURCE = "res"; + + static Map<String,?> makeSample(String name, Class<?> activity, int resourceId) { + Map<String,Object> ret = new HashMap<String,Object>(); + ret.put(KEY_NAME, name); + ret.put(KEY_CLASS, activity); + ret.put(KEY_RESOURCE, resourceId); + return ret; + } + + @SuppressWarnings("serial") + static final ArrayList<Map<String,?>> SAMPLES = new ArrayList<Map<String,?>>() {{ + add(makeSample("GIF animation", FrameSequenceTest.class, R.raw.animated_gif)); + add(makeSample("WEBP animation", FrameSequenceTest.class, R.raw.animated_webp)); + }}; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setListAdapter(new SimpleAdapter(this, SAMPLES, + android.R.layout.simple_list_item_1, new String[] { KEY_NAME }, + new int[] { android.R.id.text1 })); + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + Class<?> clazz = (Class<?>) SAMPLES.get(position).get(KEY_CLASS); + int resourceId = ((Integer) SAMPLES.get(position).get(KEY_RESOURCE)).intValue(); + + Intent intent = new Intent(this, clazz); + intent.putExtra("resourceId", resourceId); + startActivity(intent); + } + +} |