diff options
author | PaulK <contact@paulk.fr> | 2011-06-07 23:20:46 +0200 |
---|---|---|
committer | PaulK <contact@paulk.fr> | 2011-06-07 23:20:46 +0200 |
commit | 4b8b2ec5d2e9a8c01561b034bad47862653a5bce (patch) | |
tree | d2f2a8ea3dcbae32f4e9fbd91e737f6ff471824b | |
download | packages_apps_replicantwallpapers-4b8b2ec5d2e9a8c01561b034bad47862653a5bce.zip packages_apps_replicantwallpapers-4b8b2ec5d2e9a8c01561b034bad47862653a5bce.tar.gz packages_apps_replicantwallpapers-4b8b2ec5d2e9a8c01561b034bad47862653a5bce.tar.bz2 |
Initial commit
43 files changed, 598 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..8b3f40d --- /dev/null +++ b/Android.mk @@ -0,0 +1,26 @@ +# +# Copyright (C) 2008 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_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_MODULE_TAGS := optional + +LOCAL_PACKAGE_NAME := ReplicantWallpapers + +include $(BUILD_PACKAGE) diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100755 index 0000000..6c0fcac --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="us.replicant.ReplicantWallpapers"> + + <uses-permission android:name="android.permission.SET_WALLPAPER" /> + + <application android:label="@string/app_name" android:icon="@drawable/replicant_logo"> + <activity + android:name="WallpaperChooser" + android:label="@string/app_label" + android:icon="@drawable/replicant_logo" + android:screenOrientation="nosensor" + android:finishOnCloseSystemDialogs="true"> + <intent-filter> + <action android:name="android.intent.action.SET_WALLPAPER" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </activity> + + </application> + +</manifest> diff --git a/res/drawable-hdpi/fire_breathing.jpg b/res/drawable-hdpi/fire_breathing.jpg Binary files differnew file mode 100644 index 0000000..4271138 --- /dev/null +++ b/res/drawable-hdpi/fire_breathing.jpg diff --git a/res/drawable-hdpi/fire_breathing_small.jpg b/res/drawable-hdpi/fire_breathing_small.jpg Binary files differnew file mode 100644 index 0000000..93ecae4 --- /dev/null +++ b/res/drawable-hdpi/fire_breathing_small.jpg diff --git a/res/drawable-hdpi/glass_beach.jpg b/res/drawable-hdpi/glass_beach.jpg Binary files differnew file mode 100644 index 0000000..384e844 --- /dev/null +++ b/res/drawable-hdpi/glass_beach.jpg diff --git a/res/drawable-hdpi/glass_beach_small.jpg b/res/drawable-hdpi/glass_beach_small.jpg Binary files differnew file mode 100644 index 0000000..24dd7ce --- /dev/null +++ b/res/drawable-hdpi/glass_beach_small.jpg diff --git a/res/drawable-hdpi/landscape.jpg b/res/drawable-hdpi/landscape.jpg Binary files differnew file mode 100644 index 0000000..a059f92 --- /dev/null +++ b/res/drawable-hdpi/landscape.jpg diff --git a/res/drawable-hdpi/landscape_small.jpg b/res/drawable-hdpi/landscape_small.jpg Binary files differnew file mode 100644 index 0000000..e3d8924 --- /dev/null +++ b/res/drawable-hdpi/landscape_small.jpg diff --git a/res/drawable-hdpi/replicant_logo.png b/res/drawable-hdpi/replicant_logo.png Binary files differnew file mode 100644 index 0000000..1601b8c --- /dev/null +++ b/res/drawable-hdpi/replicant_logo.png diff --git a/res/drawable-hdpi/sunrise.jpg b/res/drawable-hdpi/sunrise.jpg Binary files differnew file mode 100644 index 0000000..3f996c7 --- /dev/null +++ b/res/drawable-hdpi/sunrise.jpg diff --git a/res/drawable-hdpi/sunrise_small.jpg b/res/drawable-hdpi/sunrise_small.jpg Binary files differnew file mode 100644 index 0000000..4eeee80 --- /dev/null +++ b/res/drawable-hdpi/sunrise_small.jpg diff --git a/res/drawable-hdpi/train.jpg b/res/drawable-hdpi/train.jpg Binary files differnew file mode 100644 index 0000000..4105a7d --- /dev/null +++ b/res/drawable-hdpi/train.jpg diff --git a/res/drawable-hdpi/train_small.jpg b/res/drawable-hdpi/train_small.jpg Binary files differnew file mode 100644 index 0000000..a1bf40e --- /dev/null +++ b/res/drawable-hdpi/train_small.jpg diff --git a/res/drawable-mdpi/fire_breathing.jpg b/res/drawable-mdpi/fire_breathing.jpg Binary files differnew file mode 100644 index 0000000..26d3e93 --- /dev/null +++ b/res/drawable-mdpi/fire_breathing.jpg diff --git a/res/drawable-mdpi/fire_breathing_small.jpg b/res/drawable-mdpi/fire_breathing_small.jpg Binary files differnew file mode 100644 index 0000000..a7da6a0 --- /dev/null +++ b/res/drawable-mdpi/fire_breathing_small.jpg diff --git a/res/drawable-mdpi/glass_beach.jpg b/res/drawable-mdpi/glass_beach.jpg Binary files differnew file mode 100644 index 0000000..a297b03 --- /dev/null +++ b/res/drawable-mdpi/glass_beach.jpg diff --git a/res/drawable-mdpi/glass_beach_small.jpg b/res/drawable-mdpi/glass_beach_small.jpg Binary files differnew file mode 100644 index 0000000..9adf4e2 --- /dev/null +++ b/res/drawable-mdpi/glass_beach_small.jpg diff --git a/res/drawable-mdpi/landscape.jpg b/res/drawable-mdpi/landscape.jpg Binary files differnew file mode 100644 index 0000000..b5fc540 --- /dev/null +++ b/res/drawable-mdpi/landscape.jpg diff --git a/res/drawable-mdpi/landscape_small.jpg b/res/drawable-mdpi/landscape_small.jpg Binary files differnew file mode 100644 index 0000000..5accb26 --- /dev/null +++ b/res/drawable-mdpi/landscape_small.jpg diff --git a/res/drawable-mdpi/replicant_logo.png b/res/drawable-mdpi/replicant_logo.png Binary files differnew file mode 100644 index 0000000..1f19521 --- /dev/null +++ b/res/drawable-mdpi/replicant_logo.png diff --git a/res/drawable-mdpi/sunrise.jpg b/res/drawable-mdpi/sunrise.jpg Binary files differnew file mode 100644 index 0000000..ba477be --- /dev/null +++ b/res/drawable-mdpi/sunrise.jpg diff --git a/res/drawable-mdpi/sunrise_small.jpg b/res/drawable-mdpi/sunrise_small.jpg Binary files differnew file mode 100644 index 0000000..81f6c70 --- /dev/null +++ b/res/drawable-mdpi/sunrise_small.jpg diff --git a/res/drawable-mdpi/train.jpg b/res/drawable-mdpi/train.jpg Binary files differnew file mode 100644 index 0000000..a3b899d --- /dev/null +++ b/res/drawable-mdpi/train.jpg diff --git a/res/drawable-mdpi/train_small.jpg b/res/drawable-mdpi/train_small.jpg Binary files differnew file mode 100644 index 0000000..5fc2bd0 --- /dev/null +++ b/res/drawable-mdpi/train_small.jpg diff --git a/res/layout/wallpaper_chooser.xml b/res/layout/wallpaper_chooser.xml new file mode 100755 index 0000000..8644aed --- /dev/null +++ b/res/layout/wallpaper_chooser.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2008, The Replicant 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. +*/ +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + <ImageView android:id="@+id/wallpaper" + android:layout_width="fill_parent" + android:layout_height="0dip" + android:layout_weight="1.0" + android:scaleType="fitCenter" /> + + <Gallery android:id="@+id/gallery" + android:layout_width="fill_parent" + android:layout_height="wrap_content" /> + + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="horizontal" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" > + + <Button android:id="@+id/set" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/set_wallpaper" /> + + <Button android:id="@+id/about" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/about" + android:layout_alignLeft="@id/set" + android:onClick="onAbout" /> + + + + </LinearLayout> +</LinearLayout> + diff --git a/res/layout/wallpaper_item.xml b/res/layout/wallpaper_item.xml new file mode 100755 index 0000000..dc5220d --- /dev/null +++ b/res/layout/wallpaper_item.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2008 The Replicant 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. +--> + +<ImageView xmlns:android="http://schemas.android.com/apk/res/android" + android:background="?android:attr/galleryItemBackground" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:scaleType="fitXY" + android:focusable="true" /> diff --git a/res/values-ca/strings.xml b/res/values-ca/strings.xml new file mode 100644 index 0000000..d1e3161 --- /dev/null +++ b/res/values-ca/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">Fons de pantalla del Replicant</string> + <string name="app_label">Fons de pantalla del Replicant</string> + <string name="set_wallpaper">Estableix el fons de pantalla</string> +</resources> diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml new file mode 100644 index 0000000..ef63588 --- /dev/null +++ b/res/values-de/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Replicant Hintergrundbilder</string> +<string name="app_label">Replicant Hintergrundbilder</string> +<string name="set_wallpaper">Einstellen</string> +</resources> diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml new file mode 100644 index 0000000..c6070da --- /dev/null +++ b/res/values-es/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Replicant Fondos</string> +<string name="app_label">Replicant Fondos</string> +<string name="set_wallpaper">Escoger Fondo Pantalla</string> +</resources> diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml new file mode 100644 index 0000000..036ba65 --- /dev/null +++ b/res/values-fr/strings.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Fonds d\'écran Replicant</string> +<string name="app_label">Fonds d\'écran Replicant</string> +<string name="set_wallpaper">Appliquer</string> +<string name="about">À propos</string> +<string name="author">Auteur : </string> +<string name="license">Licence : </string> +</resources> diff --git a/res/values-hdpi/wallpapers.xml b/res/values-hdpi/wallpapers.xml new file mode 100644 index 0000000..01c32f6 --- /dev/null +++ b/res/values-hdpi/wallpapers.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + * Copyright (C) 2009 Google Inc. + * + * 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-array name="wallpapers" translatable="false"> + <item>landscape</item> + <item>sunrise</item> + <item>train</item> + <item>glass_beach</item> + <item>fire_breathing</item> + </string-array> + <string-array name="authors" translatable="false"> + <item>Chmee2/Valtameri (Wikimedia Commons users)</item> + <item>Dori (Wikimedia Commons user)</item> + <item>Kabelleger (Wikimedia Commons user) / David Gubler</item> + <item>Jef Poskanzer</item> + <item>Luc Viatour</item> + </string-array> + <string-array name="licenses" translatable="false"> + <item>Creative Commons Attribution 3.0 Unported</item> + <item>Creative Commons Attribution-Share Alike 3.0 Unported</item> + <item>Public domain</item> + <item>Creative Commons Attribution 2.0 Generic</item> + <item>Creative Commons Attribution-Share Alike 3.0 Unported</item> + </string-array> +</resources> diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml new file mode 100644 index 0000000..1b60d2f --- /dev/null +++ b/res/values-it/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Sfondi Replicant</string> +<string name="app_label">Sfondi Replicant</string> +<string name="set_wallpaper">Imposta sfondo</string> +</resources> diff --git a/res/values-ja/strings.xml b/res/values-ja/strings.xml new file mode 100644 index 0000000..e3329f5 --- /dev/null +++ b/res/values-ja/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Replicant壁紙</string> +<string name="app_label">Replicant壁紙</string> +<string name="set_wallpaper">壁紙に設定</string> +</resources> diff --git a/res/values-ko/strings.xml b/res/values-ko/strings.xml new file mode 100644 index 0000000..2186432 --- /dev/null +++ b/res/values-ko/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Replicant 배경화면</string> +<string name="app_label">Replicant 배경화면</string> +<string name="set_wallpaper">배경화면 설정</string> +</resources> diff --git a/res/values-mdpi/wallpapers.xml b/res/values-mdpi/wallpapers.xml new file mode 100644 index 0000000..01c32f6 --- /dev/null +++ b/res/values-mdpi/wallpapers.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + * Copyright (C) 2009 Google Inc. + * + * 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-array name="wallpapers" translatable="false"> + <item>landscape</item> + <item>sunrise</item> + <item>train</item> + <item>glass_beach</item> + <item>fire_breathing</item> + </string-array> + <string-array name="authors" translatable="false"> + <item>Chmee2/Valtameri (Wikimedia Commons users)</item> + <item>Dori (Wikimedia Commons user)</item> + <item>Kabelleger (Wikimedia Commons user) / David Gubler</item> + <item>Jef Poskanzer</item> + <item>Luc Viatour</item> + </string-array> + <string-array name="licenses" translatable="false"> + <item>Creative Commons Attribution 3.0 Unported</item> + <item>Creative Commons Attribution-Share Alike 3.0 Unported</item> + <item>Public domain</item> + <item>Creative Commons Attribution 2.0 Generic</item> + <item>Creative Commons Attribution-Share Alike 3.0 Unported</item> + </string-array> +</resources> diff --git a/res/values-nb/strings.xml b/res/values-nb/strings.xml new file mode 100644 index 0000000..7ea2f63 --- /dev/null +++ b/res/values-nb/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Replicant Bakgrunnsbilder</string> +<string name="app_label">Replicant Bakgrunnsbilder</string> +<string name="set_wallpaper">Velg bakgrunnsbilde</string> +</resources> diff --git a/res/values-pl/strings.xml b/res/values-pl/strings.xml new file mode 100644 index 0000000..6e34d44 --- /dev/null +++ b/res/values-pl/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Tapety Replicanta</string> +<string name="app_label">Tapety Replicanta</string> +<string name="set_wallpaper">Ustaw tapetę</string> +</resources> diff --git a/res/values-pt-rPT/strings.xml b/res/values-pt-rPT/strings.xml new file mode 100755 index 0000000..d0067e8 --- /dev/null +++ b/res/values-pt-rPT/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Replicant Wallpapers</string> +<string name="app_label">Replicant Wallpapers</string> +<string name="set_wallpaper">Definir Wallpaper</string> +</resources> diff --git a/res/values-pt/strings.xml b/res/values-pt/strings.xml new file mode 100755 index 0000000..eb03f8e --- /dev/null +++ b/res/values-pt/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">Papeis de Parede Replicant</string> + <string name="app_label">Papeis de Parede Replicant</string> + <string name="set_wallpaper">Definir Papel de Parede</string> +</resources> diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml new file mode 100644 index 0000000..01cddcc --- /dev/null +++ b/res/values-zh-rTW/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Replicant 桌布</string> +<string name="app_label">Replicant 桌布</string> +<string name="set_wallpaper">設定桌布</string> +</resources> diff --git a/res/values/extra_wallpapers.xml b/res/values/extra_wallpapers.xml new file mode 100755 index 0000000..b3be991 --- /dev/null +++ b/res/values/extra_wallpapers.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + * Copyright (C) 2009 Google Inc. + * + * 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-array name="extra_wallpapers"> + </string-array> + <string-array name="extra_authors"> + </string-array> + <string-array name="extra_licenses"> + </string-array> +</resources> diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..bef2349 --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="app_name">Replicant Wallpapers</string> +<string name="app_label">Replicant Wallpapers</string> +<string name="set_wallpaper">Set wallpaper</string> +<string name="about">About</string> +<string name="author">Author: </string> +<string name="license">License: </string> +</resources> diff --git a/src/us/replicant/ReplicantWallpapers/WallpaperChooser.java b/src/us/replicant/ReplicantWallpapers/WallpaperChooser.java new file mode 100644 index 0000000..137c59c --- /dev/null +++ b/src/us/replicant/ReplicantWallpapers/WallpaperChooser.java @@ -0,0 +1,281 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Modified by Paul Kocialkowski to add about button. + * + * 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 us.replicant.ReplicantWallpapers; + +import android.app.Activity; +import android.content.res.Resources; +import android.graphics.BitmapFactory; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.AsyncTask; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.View.OnClickListener; +import android.widget.AdapterView; +import android.widget.BaseAdapter; +import android.widget.Gallery; +import android.widget.ImageView; +import android.app.AlertDialog; +import android.content.Context; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.lang.String; + +public class WallpaperChooser extends Activity implements AdapterView.OnItemSelectedListener, + OnClickListener { + private static final String TAG = "ReplicantWallpapers"; + + private Gallery mGallery; + private ImageView mImageView; + private boolean mIsWallpaperSet; + + private Bitmap mBitmap; + + private ArrayList<Integer> mThumbs; + private ArrayList<Integer> mImages; + private String[] mAuthors = null; + private String[] mLicenses = null; + + private WallpaperLoader mLoader; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + requestWindowFeature(Window.FEATURE_NO_TITLE); + + findWallpapers(); + + setContentView(R.layout.wallpaper_chooser); + + mGallery = (Gallery) findViewById(R.id.gallery); + mGallery.setAdapter(new ImageAdapter(this)); + mGallery.setOnItemSelectedListener(this); + mGallery.setCallbackDuringFling(false); + + findViewById(R.id.set).setOnClickListener(this); + + mImageView = (ImageView) findViewById(R.id.wallpaper); + } + + private void findWallpapers() { + final Resources resources = getResources(); + final String packageName = getApplication().getPackageName(); + + int mImagesSize=resources.getStringArray(R.array.wallpapers).length; + int mAuthorsSize=resources.getStringArray(R.array.authors).length; + int mLicensesSize=resources.getStringArray(R.array.licenses).length; + + mThumbs = new ArrayList<Integer>(mImagesSize); + mImages = new ArrayList<Integer>(mImagesSize); + mAuthors = new String[mAuthorsSize]; + mLicenses = new String[mLicensesSize]; + + addWallpapers(resources, packageName, R.array.wallpapers, R.array.authors, R.array.licenses); + addWallpapers(resources, packageName, R.array.extra_wallpapers, R.array.extra_authors, R.array.extra_licenses); + } + + private void addWallpapers(Resources resources, String packageName, int list_w, int list_a, int list_l) { + final String[] extras_w = resources.getStringArray(list_w); + final String[] extras_a = resources.getStringArray(list_a); + final String[] extras_l = resources.getStringArray(list_l); + int i=0, j=0; + + for (String extra : extras_w) { + int res = resources.getIdentifier(extra, "drawable", packageName); + if (res != 0) { + final int thumbRes = resources.getIdentifier(extra + "_small", + "drawable", packageName); + + if (thumbRes != 0) { + mThumbs.add(thumbRes); + mImages.add(res); + mAuthors[j]=extras_a[i]; + mLicenses[j]=extras_l[i]; + j++; + // Log.d(TAG, "addWallpapers: [" + packageName + "]: " + extra + " (" + res + ")"); + } + } + i++; + } + } + + @Override + protected void onResume() { + super.onResume(); + mIsWallpaperSet = false; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) { + mLoader.cancel(true); + mLoader = null; + } + } + + public void onItemSelected(AdapterView parent, View v, int position, long id) { + if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) { + mLoader.cancel(); + } + mLoader = (WallpaperLoader) new WallpaperLoader().execute(position); + } + + /* + * When using touch if you tap an image it triggers both the onItemClick and + * the onTouchEvent causing the wallpaper to be set twice. Ensure we only + * set the wallpaper once. + */ + private void selectWallpaper(int position) { + if (mIsWallpaperSet) { + return; + } + + mIsWallpaperSet = true; + try { + InputStream stream = getResources().openRawResource(mImages.get(position)); + setWallpaper(stream); + setResult(RESULT_OK); + finish(); + } catch (IOException e) { + Log.e("Paperless System", "Failed to set wallpaper: " + e); + } + } + + public void onNothingSelected(AdapterView parent) { + } + + private class ImageAdapter extends BaseAdapter { + private LayoutInflater mLayoutInflater; + + ImageAdapter(WallpaperChooser context) { + mLayoutInflater = context.getLayoutInflater(); + } + + public int getCount() { + return mThumbs.size(); + } + + public Object getItem(int position) { + return position; + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + ImageView image; + + if (convertView == null) { + image = (ImageView) mLayoutInflater.inflate(R.layout.wallpaper_item, parent, false); + } else { + image = (ImageView) convertView; + } + + int thumbRes = mThumbs.get(position); + image.setImageResource(thumbRes); + Drawable thumbDrawable = image.getDrawable(); + if (thumbDrawable != null) { + thumbDrawable.setDither(true); + } else { + Log.e(TAG, "Error decoding thumbnail resId=" + thumbRes + " for wallpaper #" + + position); + } + return image; + } + } + + public void onClick(View v) { + selectWallpaper(mGallery.getSelectedItemPosition()); + } + + class WallpaperLoader extends AsyncTask<Integer, Void, Bitmap> { + BitmapFactory.Options mOptions; + + WallpaperLoader() { + mOptions = new BitmapFactory.Options(); + mOptions.inDither = false; + mOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; + } + + protected Bitmap doInBackground(Integer... params) { + if (isCancelled()) return null; + try { + return BitmapFactory.decodeResource(getResources(), + mImages.get(params[0]), mOptions); + } catch (OutOfMemoryError e) { + return null; + } + } + + @Override + protected void onPostExecute(Bitmap b) { + if (b == null) return; + + if (!isCancelled() && !mOptions.mCancel) { + // Help the GC + if (mBitmap != null) { + mBitmap.recycle(); + } + + final ImageView view = mImageView; + view.setImageBitmap(b); + + mBitmap = b; + + final Drawable drawable = view.getDrawable(); + drawable.setFilterBitmap(true); + drawable.setDither(true); + + view.postInvalidate(); + + mLoader = null; + } else { + b.recycle(); + } + } + + void cancel() { + mOptions.requestCancelDecode(); + super.cancel(true); + } + + } + + public void onAbout(View view) { + int position = mGallery.getSelectedItemPosition(); + AlertDialog.Builder about_dialog_builder=new AlertDialog.Builder(this); + + String about_dialog_message = getString(R.string.author) + ' ' + mAuthors[position] + '\n' + + getString(R.string.license) + ' ' + mLicenses[position]; + + about_dialog_builder.setMessage(about_dialog_message); + about_dialog_builder.setPositiveButton(android.R.string.ok, null); + about_dialog_builder.show(); + + } +} |