Wallpaper tutorial - Part 2


SDK Version: 
M3

This article was requested by some of our community members. It is based on the Android Gallery, ImageView Example tutorial by Sasikumar (Part 1 is here). I extended his example with a new function. If you long click on the big image, an alert dialog show up and ask “Do you want to use this image as a wallpaper?". If you click yes, the actually image will be your new wallpaper.

I only changed the Activity class:

  1. package org.androidpeople.gallery;
  2.  
  3. import java.io.IOException;
  4.  
  5. import android.app.Activity;
  6. import android.app.AlertDialog;
  7. import android.content.Context;
  8. import android.content.DialogInterface;
  9. import android.content.res.TypedArray;
  10. import android.graphics.Bitmap;
  11. import android.graphics.BitmapFactory;
  12. import android.os.Bundle;
  13. import android.util.Log;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.widget.AdapterView;
  17. import android.widget.BaseAdapter;
  18. import android.widget.Gallery;
  19. import android.widget.ImageView;
  20. import android.widget.AdapterView.OnItemClickListener;
  21.  
  22. public class GalleryExample extends Activity {
  23.  
  24.         private Gallery gallery;
  25.         private ImageView imgView;
  26.         int position;
  27.         private Integer[] Imgid = { R.drawable.a_1, R.drawable.a_2, R.drawable.a_3,
  28.                         R.drawable.a_4, R.drawable.a_5, R.drawable.a_6, R.drawable.a_7 };
  29.  
  30.         @Override
  31.         public void onCreate(Bundle savedInstanceState) {
  32.                 super.onCreate(savedInstanceState);
  33.                 setContentView(R.layout.main);
  34.                 position = 0;
  35.                 imgView = (ImageView) findViewById(R.id.ImageView01);
  36.                 imgView.setImageResource(Imgid[0]);
  37.  
  38.                 gallery = (Gallery) findViewById(R.id.examplegallery);
  39.                 gallery.setAdapter(new AddImgAdp(this));
  40.  
  41.                 gallery.setOnItemClickListener(new OnItemClickListener() {
  42.                         public void onItemClick(AdapterView parent, View v, int position,
  43.                                         long id) {
  44.                                 imgView.setImageResource(Imgid[position]);
  45.                                 GalleryExample.this.position = position;
  46.                         }
  47.                 });
  48.  
  49.  
  50.                 imgView.setOnLongClickListener(new View.OnLongClickListener() {
  51.                         public boolean onLongClick(View v) {
  52.  
  53.                                 AlertDialog alertDialog = new AlertDialog.Builder(
  54.                                                 GalleryExample.this).create();
  55.                                 alertDialog.setTitle("Confirmation");
  56.                                 alertDialog
  57.                                                 .setMessage("Do you want to set this image as wallaper?");
  58.                                 alertDialog.setButton("Yes",
  59.                                                 new DialogInterface.OnClickListener() {
  60.                                                         public void onClick(DialogInterface dialog,
  61.                                                                         int which) {
  62.  
  63.                                                                 Bitmap bitmap = BitmapFactory.decodeResource(
  64.                                                                                 getResources(), Imgid[position]);
  65.                                                                 try {
  66.                                                                         GalleryExample.this.setWallpaper(bitmap);
  67.                                                                 } catch (IOException e) {
  68.                                                                         // TODO Auto-generated catch block
  69.                                                                         e.printStackTrace();
  70.                                                                 }
  71.                                                                 Log.d("Gallery Example", "Image setted.");
  72.  
  73.                                                         }
  74.                                                 });
  75.  
  76.                                 alertDialog.show();
  77.                                 return true;
  78.                         }
  79.                 });
  80.  
  81.         }
  82.  
  83.         public class AddImgAdp extends BaseAdapter {
  84.                 int GalItemBg;
  85.                 private Context cont;
  86.  
  87.                 public AddImgAdp(Context c) {
  88.                         cont = c;
  89.                         TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
  90.                         GalItemBg = typArray.getResourceId(
  91.                                         R.styleable.GalleryTheme_android_galleryItemBackground, 0);
  92.                         typArray.recycle();
  93.                 }
  94.  
  95.                 public int getCount() {
  96.                         return Imgid.length;
  97.                 }
  98.  
  99.                 public Object getItem(int position) {
  100.                         return position;
  101.                 }
  102.  
  103.                 public long getItemId(int position) {
  104.                         return position;
  105.                 }
  106.  
  107.                 public View getView(int position, View convertView, ViewGroup parent) {
  108.                         ImageView imgView = new ImageView(cont);
  109.  
  110.                         imgView.setImageResource(Imgid[position]);
  111.                         imgView.setLayoutParams(new Gallery.LayoutParams(80, 70));
  112.                         imgView.setScaleType(ImageView.ScaleType.FIT_XY);
  113.                         imgView.setBackgroundResource(GalItemBg);
  114.  
  115.                         return imgView;
  116.                 }
  117.         }
  118.  
  119. }

I declared the position variable at the begin of the main class. So this variable is global now.

  1.  GalleryExample.this.position = position;
  2.  

Put this line to gallery.setonlicklistener part. After this step you can use this number to get the resource from Imgid[] array.

The following lines going to listen your long click on imageview. An alertdialog will show up after long click. You can read more about alertdialogs at this site.

  1.                 imgView.setOnLongClickListener(new View.OnLongClickListener() {
  2.                         public boolean onLongClick(View v) {
  3.  
  4.                                 AlertDialog alertDialog = new AlertDialog.Builder(
  5.                                                 GalleryExample.this).create();
  6.                                 alertDialog.setTitle("Confirmation");
  7.                                 alertDialog
  8.                                                 .setMessage("Do you want to set this image as wallaper?");
  9.                                 alertDialog.setButton("Yes",
  10.                                                 new DialogInterface.OnClickListener() {
  11.                                                         public void onClick(DialogInterface dialog,
  12.                                                                         int which) {
  13.  
  14.                                                                 Bitmap bitmap = BitmapFactory.decodeResource(
  15.                                                                                 getResources(), Imgid[position]);
  16.                                                                 try {
  17.                                                                         GalleryExample.this.setWallpaper(bitmap);
  18.                                                                 } catch (IOException e) {
  19.                                                                         // TODO Auto-generated catch block
  20.                                                                         e.printStackTrace();
  21.                                                                 }
  22.                                                                 Log.d("Gallery Example", "Image setted.");
  23.  
  24.                                                         }
  25.                                                 });
  26.  
  27.                                 alertDialog.show();
  28.                                 return true;
  29.                         }
  30.                 });

That’s it. Feel free to download the complete changed source code from here.

Comments

العاب توم وجيري

العاب بنات

العاب طبخ

العاب سيارات

العاب تلبيس

العاب دراجات

العاب قص الشعر

العاب حرب

العاب سبونج بوب

العاب اطفال

العاب اكشن

العاب بلياردو

العاب باربي

العاب ماريو

العاب كرة القدم

العاب سونيك

العاب بن تن

العاب توم وجيري

العاب فلة

العاب كراش

العاب بنات

العاب باربي

العاب بنات

العاب لولو كاتي

العاب تلبيس

العاب تلوين

العاب ديكور

العاب قص الشعر

العاب طبخ

العاب دوار

العاب براتز

العاب هانا مونتانا

العاب ديزني

اخريطة ي

اخريطة ي

اخريطة ي

العاب اطفال

العاب سيارات اطفال

العاب بنات اطفال

العاب دراجات اطفال

العاب سبونج بوب اطفال

العاب باربي اطفال

العاب تلبيس اطفال

االعاب قص الشعر اطفال

العاب طبخ اطفال

العاب دورا اطفال

العاب ماريو اطفال

العاب سكوبي دو اطفال

العاب

العاب بنات

العاب طبخ

العاب سيارات

العاب تلبيس

العاب دراجات

العاب قص الشعر

العاب حرب

العاب سبونج بوب

العاب اطفال

العاب اكشن

العاب بلياردو

العاب باربي

العاب ماريو

العاب داني الشبح

العاب سونيك

العاب دورا

العاب تلوين

العاب ديكور

العاب بن تن

العاب كرة القدم

العاب مكياج

العاب رياضية

العاب ذكاء

العاب سكوبي دو

دليل رمث

فضائح الفنانين
فضائح ممثلات عاريات
جرائم
اغتصاب
فضائح المشاهير
تحميل الاغاني العراقية
اغاني عراقية
ابراج الحظ,برجك اليوم
صور الفنانات,صور الممثلين
نكت عراقية
التعارف والاصدقاء
مسلسلات
صور ممثلات
صور فنانين
ابراج اليوم
الدليل العراقي
اغاني عراقية
دليل المواقع العراقية
جات عراقي
دردشة عراقية
دردشة
اغاني عراقية mp3
اغاني mp3
عراق اب
اغاني عراقية
البوم تامر حسني اللي جاي احلى 2011
حسام الرسام
نصرت البدر
جات عراقنا
دردشة عراقية صوتية
عراقنا
دردشة عراقنا
احمد السلطان
احمد المصلاوي
احمد شاكر
حمزة القيسي
حيدر الحسناوي
ضياء الميالي
زيد الحبيب
رنا وليد
شذى حسون
رنا وليد
علي صابر
غزلان
غزوان الفهد
علي بدر
عماد الريحاني
غيث محمد
قائد حلمي
قيس هشام
فرقة ميلودك
لبنى كمر
محمد السالم
محمد عبد الجبار
مؤيد الاصيل
محمد الشاعري
محمد الفارس
ماجد المهندس
معن العربي
مهند عدنان
هيبت البدر
هيثم يوسف
وليد الشامي
حسين غزال
اغاني تركية
منتديات عراقية
مناقصات
منتدى المرأة العراقية
صور واخبار الفنانات والفنانين
دليل المواقع العراقية
منتدى العراق
منتدى بنات العراق
شات العراق
العاب كومبيوتر
وظائف شاغرة
شعر شعبي عراقي
هكر واختراق
جات كردي
دردشة بغداد
جات بغداد
دردشة الانبار
دردشة البصرة
دردشة الموصل
دردشة الحلة بابل
دردشة ديالى بعقوبة
دردشة ميسان العمارة
دردشة الناصرية
دردشة اربيل هولير
دردشة دهوك
دردشة تكريت صلاح الدين
دردشة السماوة
دردشة النجف
دردشة كربلاء
دردشة كركوك
دردشة ذي قار
دردشة العاشق
دردشة عراقية
دردشة شط العرب
دردشة دجلةدردشة
شات عراقي
جات عراقي
موقع العاشق
ابراج
نكت عراقية
منتديات عراقية
مناقصات
منتدى المرأة العراقية
صور واخبار الفنانات والفنانين
دليل المواقع العراقية
منتدى العراق
منتدى بنات العراق
شات العراق
العاب كومبيوتر
وظائف شاغرة
شعر شعبي عراقي
هكر واختراق
دردشة كويتية
دردشة الصبايا الكويتية
شات كويتي
جات كردي
دردشة بغداد
جات بغداد
دردشة الانبار
دردشة البصرة
دردشة الموصل
دردشة الحلة بابل
دردشة ديالى بعقوبة
دردشة ميسان العمارة
دردشة الناصرية
دردشة اربيل هولير
دردشة دهوك
دردشة تكريت صلاح الدين
دردشة السماوة
دردشة النجف
دردشة كربلاء
دردشة كركوك
الدردشات العراقية
دردشة ذي قار

This really a great android tutorial.

Many thanks

شات صوتي

دردشة صوتية

دردشة

دردشه

شات سعودي

شات خليجي
سكر بنات

جات

شات صوتي سعودي خليجي

chat voice

ahj

خليجي الصوتي

سعودي الصوتي

دردشة صوتي

شات صوتي
دردشة صوتية
شات كتابي

شات كتابي خليجي

شات عسل الصوتي

دردشة كتابية

chat
سعودي كول
سعودي كول 6666

كول

سعودي

سعودي كول انحراف

سعودي كول بنات

سعودي كول 1994

سعودي كول 94

شات سعودي كول

سعودي انحراف

سعودي انحراف2010

سعودي انحراف الصوتي

شات سعودي انحراف

دردشة سعودي انحراف

سعودي انحراف الصوتية

شبكة سعودي انحراف

سعودي انحراف الاصلي

سعودي انحراف كول

سعودي انحراف 2010

انحراف سعودي

saudideviation

دردشة صوتية سعوديه
دردشة صوتية سعودية

دردشة كتابية
دردشة كتابية خليجية
شات
دردشة
خاص للبنات

عرب ذوق

عرب ذوق الصوتي

عرب ذوق الصوتية

دردشة عرب ذوق

شات عرب ذوق

شبكة عرب ذوق

شات صوتي بنات

شات بنات الصوتي

دردشة بنات الصوتي

Girls Chat

شبكة عفناك

صوتية عفناك

شات عفناك

دردشة عفناك

عفناك الصوتي

دردشة عفناك

الخيال
الخيال كام
شبكة الخيال
الخيال الصوتي
الخيال الصوتية
دردشة الخيال
الخيال الصوتية
دردشة صوتية الخيال

شات سعودي خليجي

منتدى نونو

منتدى

منتديات

موقع

شبكة

نونو

Chat Nono

ahj w,jd

]v]am w,jdm

دليل مواقع ويب

دليل مواقع

دليل

مواقع

بنت كول
بنت كول الصوتي
شات بنت كول

دردشة بنت كول
شات بنت كول الصوتية

بنت كول الصوتيه
سعودي كول
صوتية سعودي كول
شات سعودي كول
دردشة سعودي كول
سعودي كول الصوتي
سعودي كول 6666
سعودي كول6666
سكر بنات
شات صوتي زين
شات صوتي ملوك
شات صوتي سعودي
شاتات صوتيه
مكتبة ماسنجر
شات صوتي حبي
شات صوتي كويت
YouTube - Broadcast Yourself.‏ , اليوتيوب نونو
صيف كام
شات صوتي كول
شات انحراف
وه بس
خريطة الموقع نونو
الرياض كول الصوتي
كامات 6666
شات المها
كامات6666
شات كامات 6666
كامات 666
كامات 66
سعودي انحراف
شاتكامات6666
سعودي احوه
شات سعودي احوه
سعودي احوه الصوتي
سعودي احوه كول
دردشة سعودي احوه
احوه سعودي
بنات احوه
دبي الصوتي
سعودي في اي بي الصوتي
شبكة الرياض الصوتي
روعة الليل
لايف كام
الخليج كام
شات كان زمان الصوتي
شات صوتي قصيمي
شات قلبي
ارجوان
شات صوتي قطري
بدور الخليج

منتدى روح

شبكة روح

روح ديزاين

تحميل ماسنجر بلس

توبيكات حزينه

توبيكات

ماسنجر

ماسنجر بلس

تحميل ماسنجر

توبيكات رومنسيه

منتديات روح
دردشة
شات سعودي
خليجي
شات صوتي
سعودي انحراف 2010 , صوتية سعودي انحراف , شبكة سعودي انحراف , موقع سعودي انحراف , سعودي انحراف لايف , مواقع انحرافية , دردشة شات سعودي انحراف الصوتي , سعودي لايف 2010 , سعودي انحراف 2011 , بنات لايف , منحرفات لايف جاتسعودي انحراف 6666- سعودي انحراف 2010 - سعودي انحراف2010 - سعودي انحراف 2007 - سعودي فور انحراف - سعودي انحراف - Saudi an7raf سعودي انحراف , deviation Saudi 2010‏ دردشة, شات, سعودي, انحراف 2010, كامات, ,شات انحرافي saudi, an7raf, deviation.‏ سعودي انحراف , انحراف , An7raf 6666‏سعودي انحراف , شات سعودي انحراف , شات انحرافي , انحراف 2010سعودي انحراف , سعودي انحراف 2010 , chat saudi an7raf , saudi ...‏

That was pretty much the scene laid out in an April 14 front-page dispatch stock marketby New York Times financial columnist Gretchen stock market todayMorgenson, noting just how far we’ve come sincemortgage calculator the 1,000-plus federal prosecutions in the aftermath of the 1980s S&L debaclemortgage calculator.



صور بنات


بنات
,

اجمل نساء
,

ممنوع من العرض
,
 العاب
,

دليل
,

برامج
,

افلام
,

الثقافه الجنسية
  ,

استار اكاديمى
,

الماسنجر
  ,

السيارات
  ,

فضائح
  ,

اغانى
,

منتدى
,

برامج الشبكات
  ,

عطعوط
  ,

يلا كورة


صور
  ,

سكربتات
  ,

المصارعه
,

تيوب
,

كليبات
,

العاب طبخ
,

فوتو شوب
,

اختراق
,

هيفاء
,

سكس
,

بروكسى
,

ليلى علوي
,

89
 

دنيا سمير غانم
,

مى عز الدين


اغانى افراح
,

الفيس بوك
,

سلمى حايك
,

صور اطفال
,

الهام شاهين
 

صور sex

توبيكات حزينه -
توبيكات انجليزيه 
توبيكات اسلاميه
- توبيكات رياضية -
توبيكات العيد 
-
توبيكات منوعة 

توبيكات مضحكه 

توبيكات رومانسية -
توبيكات اغاني -
توبيكات اسماء


أفلام رومانسية
|

أفلام كوميدية
|

أفلام اكشن
|

أفلام دراما
|

مسرحيات
|

افلام اجنبى وهندى
|

ممنوعه من العرض
|

افلام قديمه

      العاب بنات
- العاب اكشن -
العاب تلبيس -
العاب فلاش  -

لعبة البلياردو
-  

  -

لعبة السيارات
-

العاب ماريو
-

سودوكو
- سبونج
بوب
-

make-up ميك اب باربي
-

لعبة البلياردو


العاب g9g
  -يوتيوب
YouTube - يتوب
- مقاطع فيديو -
يوتوب


رقص


2010


ضحك


مصر


ستار


wwe


و


اكاديمي


في


برنامج


قناة


محمد


الكاميرا


شعر


جديد


كاميرا


اهداف


Funny


كرتون


السعودية


من


كوميدي


الخفية


arabic


الكويت


مصارعة


wwf


تامر


مضحك


أحمد


خفية


الشعر


الجزء


عربي


جمال


الجديد


مسرحية


ECW


egypt


dance


كليب


السعودي


زكريا


فيديو


حسين


comedy


الزمالك


حسني


عمرو


سعودي


music


محمود


مسلسل


العناية


divas


arab


2009


WWFE


الاهلي


عرب


توم


الحمل


قمر


بالشعر


جيري


طرق


مقلب


البرايم


كارتون


علاج


عناية


ECW Divas


ECW Superstars


تفحيط


Superstars


14


ECW Video


World Wrestling Entertainment


ECW Videos


World Wrestling Federation


WWE ECW


الشاعر


ابو


أفضل


Melody


WWE ECW Divas


WWE ECW Superstars


Coldplay


المصري


خبير


بنات


بومبا


ela>

تساقط


video


صبغة


مباراة


نقار


جدا


تيمون

thank you very much for this lesson .
العاب العاب طخ قصص منتديات

A transparency mask can be added to each layer, it’s called Layer mask. A layer mask has the same 70-441 | 70-442 size and same pixel number as the layer to which it is attached. Every pixel of the mask can then be coupled with a pixel at the same location in the layer. The mask is a set of 70-443 | 70-444 pixels in gray-tone on a value scale from 0 to 255. The pixels with a value 0 are black and give a full transparency to the coupled pixel in the layer. The pixels with a 70-445 | 70-446 value 255 are white and give a full opacity to the coupled pixel in the layer.
----------------------------------
70-447 70-451 | 70-452 | 70-454

Pretty good post, this is one of the best aritcles that I have ever seen! This is a great site and I have to congratulate you on the content. I appreciate it!Pretty good post, this is one of the best aritcles that I have ever seen! This is a great site and I have to congratulate you on the content. I appreciate it!Pretty good post, this is one of the best aritcles that I have ever seen! This is a great site and I have to congratulate you on the content. I appreciate it!
------------------------------------------------------------------------------------------
testking 650-568 || testking 156-215.70 || testking 1Y0-A17 || testking E20-001 || testking 640-721 || testking HP0-S28 || testking 642-262
------------------------------------------------------------------------------------------

Your blog is a great one. What really impresses me is 70-290 dumps that you are correctly 650-568 dumps mentioned that there are thousands of tools that are available to create a 1Y0-A17 dumps website or launch one but what matters is that you choose the right one, the one that gives 642-165 dumps you all that is actually needed.

Tommy Jamess
special Education Lecturer
640-553 dumps | 1Y0-A05 dumps
Oxford College
642-456 dumps | RH202 dumps
USA

it is sometimes hard to Pandora in a world of adults Pandora Bracelets

I loved the tutorial, its much harder to find the most basic of walk through than I thought.
mkv to iphone

This post is great.i like the testking 640-553 idea of present.the way you adopt is nice always try to do testking 642-974 nice work.keep it up.your ideas definitely worthy. I believe in love,loyalty and respect and testking 642-446 I hope one day to reap the benefits.i am waiting something new from your side and will come back here to see more updates in future testking 70-291 as well.my best wishes for you always so keep it up.Good luck

Wallpaper is a kind of material used to cover and decorate the interior walls of homes, microsoft certification offices, and other buildings; it is one aspect of interior decoration. It is usually sold in rolls and are put onto a wall using wallpaper paste. Wallpapers can come either plain (so that it can be painted), or with patterned cisco ccna graphics.

Wallpaper printing techniques include surface printing, gravure printing, silk screen-printing, and rotary sas certification printing. Mathematically speaking, there are seventeen basic patterns, described as wallpaper groups, that can be used to tile an infinite plane. All manufactured wallpaper patterns are based on these groups. A single mcsa certification pattern can be issued in several different colorways.

Many people have a fear of taking changes. What if they don’t turn out? You don’t have to be afraid! I think, these simple tips will help people take their opportunities. Thx mate! windows vps vm

Many people have a fear of taking changes. What if they don't turn out? You don't have to be afraid! I think, these simple tips will help people take their opportunities. Thx mate! Samsung Telephone Systems

I took a completely different route than you to obtain the same end result (using a decode to dump as wallpaper). Your code is far less buggier than mine!! :-)

One thing I would like to do with this gallery example is when you click a thumbnail from the ticker at the top, to make that image the background to the entire window. In other words, stretch the image and center it just like "real wallpaper". One of my coworkers made the suggestion, and it's a good one. I just haven't figured out a way to do it.

I thought I would mention it, in case you ever wanted to do a "Part 3" to this tutorial.

Thanks for sharing!
-Ray Dios Haque

Cute Android wallpaper! Great that you've shared this step by step procedure. Looking forward to learn more tutorials from this site.Adam Gardner