diff options
author | Andy Doan <andy.doan@linaro.org> | 2011-12-05 18:03:14 -0600 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2011-12-05 18:03:14 -0600 |
commit | d30f15f2120c92d1f4bc6ea5115c1dabff817220 (patch) | |
tree | b59f66cf47b2a9ad9a1e17c8253b1e36bb862db1 | |
download | LinaroWallpaper-d30f15f2120c92d1f4bc6ea5115c1dabff817220.tar.gz |
initial commit
-rw-r--r-- | .classpath | 8 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .project | 33 | ||||
-rw-r--r-- | AndroidManifest.xml | 24 | ||||
-rw-r--r-- | proguard.cfg | 40 | ||||
-rw-r--r-- | project.properties | 11 | ||||
-rw-r--r-- | res/drawable/box.xml | 11 | ||||
-rw-r--r-- | res/drawable/icon.png | bin | 0 -> 2176 bytes | |||
-rw-r--r-- | res/drawable/logo.png | bin | 0 -> 1678 bytes | |||
-rw-r--r-- | res/values/strings.xml | 5 | ||||
-rw-r--r-- | res/xml/logo1.xml | 7 | ||||
-rw-r--r-- | src/org/linaro/wallpaper/LogoWallpaper.java | 209 | ||||
-rw-r--r-- | src/org/linaro/wallpaper/MovingDrawable.java | 56 |
13 files changed, 406 insertions, 0 deletions
diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..a4763d1 --- /dev/null +++ b/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="gen"/> + <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> + <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> + <classpathentry kind="output" path="bin/classes"/> +</classpath> diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e614fbb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin +gen diff --git a/.project b/.project new file mode 100644 index 0000000..92d5f05 --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>LinaroWallpaper</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.android.ide.eclipse.adt.ApkBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>com.android.ide.eclipse.adt.AndroidNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..f3a2f73 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="org.linaro.wallpaper" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk android:minSdkVersion="10" /> + <uses-feature android:name="android.software.live_wallpaper" /> + + <application + android:icon="@drawable/icon" + android:label="@string/app_name" > + + <service + android:label="@string/wallpaper_logo1" + android:name=".LogoWallpaper" + android:permission="android.permission.BIND_WALLPAPER"> + <intent-filter> + <action android:name="android.service.wallpaper.WallpaperService" /> + </intent-filter> + <meta-data android:name="android.service.wallpaper" android:resource="@xml/logo1" /> + </service> + </application> +</manifest>
\ No newline at end of file diff --git a/proguard.cfg b/proguard.cfg new file mode 100644 index 0000000..b1cdf17 --- /dev/null +++ b/proguard.cfg @@ -0,0 +1,40 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native <methods>; +} + +-keepclasseswithmembers class * { + public <init>(android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public <init>(android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..f049142 --- /dev/null +++ b/project.properties @@ -0,0 +1,11 @@ +# 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 use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-10 diff --git a/res/drawable/box.xml b/res/drawable/box.xml new file mode 100644 index 0000000..dc53453 --- /dev/null +++ b/res/drawable/box.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + + <corners android:radius="2dip" /> + + <size android:width="14dip" android:height="14dip"/> + + <solid android:color="#a1cd41" /> +</shape> + diff --git a/res/drawable/icon.png b/res/drawable/icon.png Binary files differnew file mode 100644 index 0000000..53c689d --- /dev/null +++ b/res/drawable/icon.png diff --git a/res/drawable/logo.png b/res/drawable/logo.png Binary files differnew file mode 100644 index 0000000..de9e2a1 --- /dev/null +++ b/res/drawable/logo.png diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..3f9aa8b --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">Linaro Live Wallpaper</string> + <string name="wallpaper_logo1">Linaro Animated Logo</string> +</resources>
\ No newline at end of file diff --git a/res/xml/logo1.xml b/res/xml/logo1.xml new file mode 100644 index 0000000..49eee72 --- /dev/null +++ b/res/xml/logo1.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- The attributes in this XML file provide configuration information --> + +<wallpaper xmlns:android="http://schemas.android.com/apk/res/android" + android:thumbnail="@drawable/icon" +/> diff --git a/src/org/linaro/wallpaper/LogoWallpaper.java b/src/org/linaro/wallpaper/LogoWallpaper.java new file mode 100644 index 0000000..05e7a87 --- /dev/null +++ b/src/org/linaro/wallpaper/LogoWallpaper.java @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2009 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 org.linaro.wallpaper; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Point; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.service.wallpaper.WallpaperService; +import android.view.SurfaceHolder; + +public class LogoWallpaper extends WallpaperService { + + private final Handler mHandler = new Handler(); + + /** + * The number of pixels between the left edge of logo.png and where the + * first edge of the boxes should start at + */ + private final static int BOX_XOFFSET = 48; + /** + * The number of pixels between the bottom of logo.png and where the top + * of each box should be located at + */ + private final static int BOX_YOFFSET = 36; + + /** + * The number of animation frames used to draw each box + */ + private final int NUM_FRAMES = 20; + + @Override + public Engine onCreateEngine() { + return new WallpaperEngine(); + } + + class WallpaperEngine extends Engine { + + private final Runnable mDrawHandler = new Runnable() { + @Override + public void run() { + drawFrame(); + } + }; + private boolean mVisible; + + private final int mBGColor; + private final Bitmap mLogo; + private MovingDrawable mBox[]; + + private float mLogoX = 0; + private float mLogoY = 0; + + //let's each box render mNumFrameDelays before starting to render the + //next box + private int mNumFrameDelays = 0; + + + WallpaperEngine() { + mBGColor = Color.rgb(5, 5, 5); + mLogo = BitmapFactory.decodeResource(getResources(), R.drawable.logo); + } + + @Override + public void onCreate(SurfaceHolder surfaceHolder) { + super.onCreate(surfaceHolder); + } + + @Override + public void onDestroy() { + super.onDestroy(); + mHandler.removeCallbacks(mDrawHandler); + } + + @Override + public void onVisibilityChanged(boolean visible) { + mVisible = visible; + if (visible) { + drawFrame(); + } else { + mHandler.removeCallbacks(mDrawHandler); + } + } + + @Override + public void onSurfaceChanged(SurfaceHolder holder, int format, + int width, int height) { + super.onSurfaceChanged(holder, format, width, height); + + float density = getResources().getDisplayMetrics().density; + + mLogoX = (width/2.0f) - (mLogo.getWidth()/2.0f); + mLogoY = (height/2.0f) - (mLogo.getHeight()/2.0f); + + mBox = new MovingDrawable[5]; + + int boxX = Math.round(mLogoX + (BOX_XOFFSET*density)); + int boxY = Math.round(mLogoY + (BOX_YOFFSET*density)); + Drawable d = getResources().getDrawable(R.drawable.box); + int w = d.getIntrinsicWidth() + Math.round(3*density); + + //box 1 from the top,left + Point start = new Point(0, 0); + Point end = new Point(boxX + (0*w), boxY); + mBox[0] = new MovingDrawable(d, start, end, NUM_FRAMES); + + //box 2 from the bottom,left + start = new Point(0, height); + end = new Point(boxX + (1*w), boxY); + mBox[1] = new MovingDrawable(d, start, end, NUM_FRAMES); + + //box 3 from the top + start = new Point(boxX + (2*w), 0); + end = new Point(boxX + (2*w), boxY); + mBox[2] = new MovingDrawable(d, start, end, NUM_FRAMES); + + //box 4 from the bottom,right + start = new Point(width, height); + end = new Point(boxX + (3*w), boxY); + mBox[3] = new MovingDrawable(d, start, end, NUM_FRAMES); + + //box 5 from the top,left + start = new Point(width, 0); + end = new Point(boxX + (4*w), boxY); + mBox[4] = new MovingDrawable(d, start, end, NUM_FRAMES); + + mNumFrameDelays = NUM_FRAMES / mBox.length; + + drawFrame(); + } + + @Override + public void onSurfaceDestroyed(SurfaceHolder holder) { + super.onSurfaceDestroyed(holder); + mVisible = false; + mHandler.removeCallbacks(mDrawHandler); + } + + @Override + public void onOffsetsChanged(float xOffset, float yOffset, float xStep, + float yStep, int xPixels, int yPixels) { + drawFrame(); + } + + /** + * Draw one frame of the animation. This method gets called repeatedly + * by posting a delayed Runnable. + */ + void drawFrame() { + final SurfaceHolder holder = getSurfaceHolder(); + + Canvas c = null; + try { + c = holder.lockCanvas(); + if (c != null) + drawFrame(c); + } finally { + if (c != null) + holder.unlockCanvasAndPost(c); + } + + // Reschedule the next redraw + mHandler.removeCallbacks(mDrawHandler); + if (mVisible) { + //restart the animation if needed + if( mBox[mBox.length-1].done() ) { + for(MovingDrawable m: mBox) + m.restart(); + //wait longer for redrawing to show the completed image + mHandler.postDelayed(mDrawHandler, 1000); + } + else { + mHandler.postDelayed(mDrawHandler, 1000/100); + } + } + } + + void drawFrame(Canvas c) { + c.save(); + + c.drawColor(mBGColor); + c.drawBitmap(mLogo, mLogoX, mLogoY, null); + + for(int i = 0; i < mBox.length; i++) { + if( i == 0 || mBox[i-1].curFrame() > mNumFrameDelays ) + mBox[i].draw(c); + } + + c.restore(); + } + } +} diff --git a/src/org/linaro/wallpaper/MovingDrawable.java b/src/org/linaro/wallpaper/MovingDrawable.java new file mode 100644 index 0000000..072db8b --- /dev/null +++ b/src/org/linaro/wallpaper/MovingDrawable.java @@ -0,0 +1,56 @@ +package org.linaro.wallpaper; + +import android.graphics.Canvas; +import android.graphics.Point; +import android.graphics.drawable.Drawable; + +public class MovingDrawable { + + private final Drawable mDrawable; + private final Point mPositions[]; + + private int mCurPosition = -1; + + /** + * A wrapper class for a drawable object that can be moved from a staring + * point to an ending point + * + * @param numFrames - the number of animation iterations wanted to go from + * start to finish + */ + public MovingDrawable(Drawable d, Point start, Point end, int numFrames) { + mDrawable = d; + mPositions = new Point[numFrames]; + + int xinc = (end.x - start.x) / (numFrames-1); + int yinc = (end.y - start.y) / (numFrames-1); + for(int i = 0; i < numFrames; i++) + mPositions[i] = new Point(start.x+(i*xinc), start.y+(i*yinc)); + + //just to be sure we don't screw up on rounding on the destination + mPositions[mPositions.length-1] = end; + } + + private static void move(Drawable d, Point p) { + d.setBounds(p.x, p.y, d.getIntrinsicWidth()+p.x, d.getIntrinsicHeight()+p.y); + } + + public void draw(Canvas c) { + if( mCurPosition < mPositions.length -1) + mCurPosition++; + move(mDrawable, mPositions[mCurPosition]); + mDrawable.draw(c); + } + + public boolean done() { + return mCurPosition == mPositions.length-1; + } + + public void restart() { + mCurPosition = -1; + } + + public int curFrame() { + return mCurPosition; + } +} |