Commit ddf2bab3 authored by Teng-Hui Zhu's avatar Teng-Hui Zhu
Browse files

Add the vector drawable support lib demo code

b/22564270

Change-Id: Id4f721cfd6e9450d8346410997ecfc1f2c3926c1
parent d0b49194
......@@ -3,3 +3,6 @@
*.pyc
*.pyc-2.4
Thumbs.db
*.iml
.idea/
gen/
# Copyright (C) 2015 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_MODULE_TAGS := tests
LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := SupportAnimatedVectorDrawable
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v11-animatedvectordrawable android-support-v4
LOCAL_AAPT_FLAGS += --auto-add-overlay \
--extra-packages android.support.graphics.drawable \
--no-version-vectors
include $(BUILD_PACKAGE)
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.support.vectordrawable" >
<uses-sdk android:minSdkVersion="11" />
<application android:icon="@drawable/app_sample_code" android:label="AnimatedVectorDrawableCompatTest" >
<activity android:name="com.example.android.support.vectordrawable.app.AnimatedButtonBackground" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</application>
</manifest>
\ No newline at end of file
<!-- Copyright (C) 2015 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.
-->
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
android:duration="3350"
android:propertyName="alpha"
android:valueFrom="1"
android:valueTo="0.2" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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.
-->
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3300"
android:propertyName="rotation"
android:valueFrom="0"
android:valueTo="450" />
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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.
-->
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
android:duration="1300"
android:interpolator="@android:anim/linear_interpolator"
android:propertyName="trimPathStart"
android:repeatCount="-1"
android:valueFrom="0"
android:valueTo="0.75"
android:valueType="floatType" />
<objectAnimator
android:duration="1300"
android:interpolator="@android:anim/linear_interpolator"
android:propertyName="trimPathEnd"
android:repeatCount="-1"
android:valueFrom="0.25"
android:valueTo="1.0"
android:valueType="floatType" />
<objectAnimator
android:duration="1300"
android:interpolator="@android:anim/linear_interpolator"
android:propertyName="trimPathOffset"
android:repeatCount="-1"
android:valueFrom="0"
android:valueTo="0.25"
android:valueType="floatType" />
</set>
\ No newline at end of file
<!--
Copyright (C) 2015 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.
-->
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector_drawable_grouping_1" >
<target
android:name="sun"
android:animation="@anim/animation_grouping_1_01" />
<target
android:name="earth"
android:animation="@anim/animation_grouping_1_01" />
</animated-vector>
\ No newline at end of file
<!--
Copyright (C) 2015 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.
-->
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector_drawable_progress_bar" >
<target
android:name="pie1"
android:animation="@anim/trim_path_animation_progress_bar" />
<target
android:name="root_bar"
android:animation="@anim/alpha_animation_progress_bar" />
</animated-vector>
\ No newline at end of file
samples/SupportVectorDrawable/animated/res/drawable/app_sample_code.png

3.52 KB

<!--
Copyright (C) 2015 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="256"
android:viewportWidth="256" >
<group
android:name="shape_layer_1"
android:translateX="128"
android:translateY="128" >
<group android:name="sun" >
<path
android:name="ellipse_path_1"
android:fillColor="#ffff8000"
android:pathData="m -25 0 a 25,25 0 1,0 50,0 a 25,25 0 1,0 -50,0" />
<group
android:name="earth"
android:translateX="75" >
<path
android:name="ellipse_path_1_1"
android:fillColor="#ff5656ea"
android:pathData="m -10 0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0" />
<group
android:name="moon"
android:translateX="25" >
<path
android:name="ellipse_path_1_2"
android:fillColor="#ffadadad"
android:pathData="m -5 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0" />
</group>
</group>
</group>
</group>
</vector>
\ No newline at end of file
<!--
Copyright (C) 2015 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="64"
android:viewportWidth="64"
android:name="root_bar" >
<group
android:name="root"
android:pivotX="0.0"
android:pivotY="0.0"
android:rotation="0"
android:translateX="32.0"
android:translateY="32.0" >
<group
android:name="rotationGroup"
android:pivotX="0.0"
android:pivotY="0.0"
android:rotation="0" >
<path
android:name="pie1"
android:fillColor="#00000000"
android:pathData="M0, 0 m 0, -9.5 a 9.5,9.5 0 1,1 0,19 a 9.5,9.5 0 1,1 0,-19"
android:strokeColor="#FF00FFFF"
android:strokeLineCap="round"
android:strokeLineJoin="miter"
android:strokeWidth="2"
android:trimPathEnd="0.1"
android:trimPathOffset="0"
android:trimPathStart="0" />
</group>
</group>
</vector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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="twoLinePathData">"M 0,0 v 100 M 0,0 h 100"</string>
<string name="triangle"> "M300,70 l 0,-70 70,70 0,0 -70,70z"</string>
<string name="rectangle">"M300,70 l 0,-70 70,0 0,140 -70,0 z"</string>
<string name="rectangle2">"M300,70 l 0,-70 70,0 0,70z M300,70 l 70,0 0,70 -70,0z"</string>
<string name="equal2"> "M300,35 l 0,-35 70,0 0,35z M300,105 l 70,0 0,35 -70,0z"</string>
<string name="round_box">"m2.10001,-6c-1.9551,0 -0.5,0.02499 -2.10001,0.02499c-1.575,0 0.0031,-0.02499 -1.95,-0.02499c-2.543,0 -4,2.2816 -4,4.85001c0,3.52929 0.25,6.25 5.95,6.25c5.7,0 6,-2.72071 6,-6.25c0,-2.56841 -1.35699,-4.85001 -3.89999,-4.85001"</string>
<string name="heart"> "m4.5,-7c-1.95509,0 -3.83009,1.26759 -4.5,3c-0.66991,-1.73241 -2.54691,-3 -4.5,-3c-2.543,0 -4.5,1.93159 -4.5,4.5c0,3.5293 3.793,6.2578 9,11.5c5.207,-5.2422 9,-7.9707 9,-11.5c0,-2.56841 -1.957,-4.5 -4.5,-4.5"</string>
<string name="rectangle200">"M 0,0 l 200,0 l 0, 200 l -200, 0 z"</string>
</resources>
\ No newline at end of file
. $ANDROID_BUILD_TOP/build/envsetup.sh && \
mmm -j20 . && \
adb install -r $OUT/data/app/SupportAnimatedVectorDrawable/SupportAnimatedVectorDrawable.apk && \
adb shell am start -n com.example.android.support.vectordrawable/com.example.android.support.vectordrawable.app.AnimatedButtonBackground
/*
* Copyright (C) 2015 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.support.vectordrawable.app;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.graphics.drawable.AnimatedVectorDrawableCompat;
import android.support.test.vectordrawable.R;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import java.text.DecimalFormat;
public class AnimatedButtonBackground extends Activity implements View.OnClickListener{
private static final String LOG_TAG = "TestActivity";
private static final String LOGCAT = "VectorDrawable1";
protected int[] icon = {
R.drawable.animation_vector_drawable_grouping_1,
R.drawable.animation_vector_progress_bar,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
ObjectAnimator oa = new ObjectAnimator();
super.onCreate(savedInstanceState);
ScrollView scrollView = new ScrollView(this);
LinearLayout container = new LinearLayout(this);
scrollView.addView(container);
container.setOrientation(LinearLayout.VERTICAL);
Resources res = this.getResources();
container.setBackgroundColor(0xFF888888);
AnimatedVectorDrawableCompat []d = new AnimatedVectorDrawableCompat[icon.length];
long time = android.os.SystemClock.currentThreadTimeMillis();
for (int i = 0; i < icon.length; i++) {
d[i] = AnimatedVectorDrawableCompat.create(this, icon[i]);
}
time = android.os.SystemClock.currentThreadTimeMillis()-time;
TextView t = new TextView(this);
DecimalFormat df = new DecimalFormat("#.##");
t.setText("avgL=" + df.format(time / (icon.length)) + " ms");
container.addView(t);
addDrawableButtons(container, d);
// Now test constant state and mutate a bit.
if (d[0].getConstantState() != null) {
AnimatedVectorDrawableCompat[] copies = new AnimatedVectorDrawableCompat[3];
copies[0] = (AnimatedVectorDrawableCompat) d[0].getConstantState().newDrawable();
copies[1] = (AnimatedVectorDrawableCompat) d[0].getConstantState().newDrawable();
copies[2] = (AnimatedVectorDrawableCompat) d[0].getConstantState().newDrawable();
copies[0].setAlpha(128);
// Expect to see the copies[0, 1] are showing alpha 128, and [2] are showing 255.
copies[2].mutate();
copies[2].setAlpha(255);
addDrawableButtons(container, copies);
}
setContentView(scrollView);
}
private void addDrawableButtons(LinearLayout container, AnimatedVectorDrawableCompat[] d) {
for (int i = 0; i < d.length; i++) {
Button button = new Button(this);
button.setWidth(200);
button.setHeight(200);
button.setBackgroundDrawable(d[i]);
container.addView(button);
button.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
AnimatedVectorDrawableCompat d = (AnimatedVectorDrawableCompat) v.getBackground();
d.start();
}
}
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := samples tests
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := SupportVectorDrawable
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v7-vectordrawable android-support-v4
LOCAL_SDK_VERSION := current
LOCAL_AAPT_FLAGS += --auto-add-overlay \
--extra-packages android.support.graphics.drawable \
--no-version-vectors
include $(BUILD_PACKAGE)
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.support.vectordrawable" >
<uses-sdk android:minSdkVersion="7"/>
<application android:icon="@drawable/app_sample_code" android:label="VectorDrawableCompatTest" >
<activity android:name=".app.SimpleButtonBackground" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</application>
</manifest>
samples/SupportVectorDrawable/static/res/drawable/app_sample_code.png

3.52 KB

<!--
Copyright (C) 2015 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="48dp"
android:width="48dp"
android:viewportHeight="480"
android:viewportWidth="480" >
<group>
<path
android:name="box1"
android:pathData="m20,200l100,90l180-180l-35-35l-145,145l-60-60l-40,40z"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</group>
</vector>
<!-- Copyright (C) 2015 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp" android:viewportWidth="320"
android:viewportHeight="320">
<group
android:rotation="180"
android:pivotX="70"
android:pivotY="120">
<path
android:name="house"
android:pathData="M 130,225 L 130,115 L 130,115 L 70,15 L 10,115 L 10,115 L 10,225 z"
android:fillColor="#ff440000"
android:strokeColor="#FF00FF00"
android:strokeWidth="10"
android:trimPathStart=".1"
android:trimPathEnd=".9"/>
</group>
</vector>
<!--
Copyright (C) 2015 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:viewportHeight="12.25"
android:viewportWidth="7.30625"
android:width="64dp" >
<group
android:pivotX="3.65"
android:pivotY="6.125"
android:rotation="-30" >
<clip-path
android:name="clip1"
android:pathData="
M 0, 6.125
l 7.3, 0
l 0, 12.25
l-7.3, 0
z" />
<group
android:pivotX="3.65"
android:pivotY="6.125"
android:rotation="30" >
<path
android:name="one"
android:fillColor="#ff88ff"
android:pathData="M 1.215625,9.5l 1.9375,0.0 0.0-6.671875-2.109375,0.421875 0.0-1.078125
l 2.09375-0.421875 1.1874998,0.0 0.0,7.75 1.9375,0.0 0.0,1.0
l-5.046875,0.0 0.0-1.0Z" />
</group>
</group>
<group
android:pivotX="3.65"
android:pivotY="6.125"
android:rotation="-30" >
<clip-path
android:name="clip2"
android:pathData="
M 0, 0
l 7.3, 0
l 0, 6.125
l-7.3, 0
z" />
<group
android:pivotX="3.65"
android:pivotY="6.125"
android:rotation="30" >
<path
android:name="two"
android:fillColor="#ff88ff"
android:pathData="M 2.534375,9.6875l 4.140625,0.0 0.0,1.0-5.5625,0.0 0.0-1.0q 0.671875-0.6875 1.828125-1.859375
q 1.1718752-1.1875 1.4687502-1.53125 0.578125-0.625 0.796875-1.0625
q 0.234375-0.453125 0.234375-0.875 0.0-0.703125-0.5-1.140625
q-0.484375-0.4375-1.2656252-0.4375-0.5625,0.0-1.1875,0.1875
q-0.609375,0.1875-1.3125,0.59375l 0.0-1.203125q 0.71875-0.28125 1.328125-0.421875
q 0.625-0.15625 1.140625-0.15625 1.3593752,0.0 2.1718752,0.6875
q 0.8125,0.671875 0.8125,1.8125 0.0,0.53125-0.203125,1.015625
q-0.203125,0.484375-0.734375,1.140625-0.15625,0.171875-0.9375,0.984375
q-0.78125024,0.8125-2.2187502,2.265625Z" />
</group>
</group>
</vector>
\ 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