json - Android:image animation using separate layout -



json - Android:image animation using separate layout -

i building app wallpaper. trying image server. able image server when trying animate , alter image of imageview , work work in in lastly 13 images not on images. how can set animation images? here code:

mainactivity.java

package com.example.featuredwallpaper; import com.koushikdutta.urlimageviewhelper.urlimageviewhelper; import android.view.animation.animationutils; public class mainactivity extends activity { public static final string tag_success = "status_code"; public static final string tag_array = "info"; jsonarray images = null; linearlayout resultdisplaylayout; jsonparser jparser = new jsonparser(); string projectname = "heart"; public static string url = "http://frontlinkinfotech.com/lwp/c_wall/get_images"; private progressdialog pdialog; squareimageviewhalf image1,image2, image4, image5, image7, image8, image12, image13; squareimageview image3, image6, image9, image10, image11; arraylist<squareimageviewhalf> image1animation = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.activity_main); resultdisplaylayout = (linearlayout) findviewbyid(r.id.resultdisplaylayout); new loadimages().execute(); handlechangeimage(r.id.imageview1); } @suppresswarnings("static-access") private animation selectanimation(int index) { switch (index) { case 0: homecoming new animationutils().loadanimation(this, r.anim.fade); case 1: homecoming new animationutils().loadanimation(this, r.anim.slide_left); case 2: homecoming new animationutils().loadanimation(this, r.anim.wave_scale); case 3: homecoming new animationutils().loadanimation(this, r.anim.hold); case 4: homecoming new animationutils().loadanimation(this, r.anim.zoom_enter); } homecoming null; } void handlechangeimage(final int id) { handler hand = new handler(); hand.postdelayed(new runnable() { @override public void run() { random rand = new random(); int index = rand.nextint(cc.images_popular.length); // handlechangeimage(); switch (id) { case r.id.imageview1: urlimageviewhelper.seturldrawable(image1, cc.images_popular[index], r.drawable.ima); image1.startanimation(selectanimation((int) (math .random() * 5))); handlechangeimage(r.id.imageview2); break; case r.id.imageview2: urlimageviewhelper.seturldrawable(image2, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image2.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview3); break; case r.id.imageview3: urlimageviewhelper.seturldrawable(image3, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image3.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview4); break; case r.id.imageview4: urlimageviewhelper.seturldrawable(image4, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image4.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview5); break; case r.id.imageview5: urlimageviewhelper.seturldrawable(image5, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image5.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview6); break; case r.id.imageview6: urlimageviewhelper.seturldrawable(image6, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image6.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview7); break; case r.id.imageview7: urlimageviewhelper.seturldrawable(image7, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image7.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview8); break; case r.id.imageview8: urlimageviewhelper.seturldrawable(image8, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image8.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview9); break; case r.id.imageview9: urlimageviewhelper.seturldrawable(image9, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image9.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview10); break; case r.id.imageview10: urlimageviewhelper.seturldrawable(image10, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image10.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview11); break; case r.id.imageview11: urlimageviewhelper.seturldrawable(image11, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image11.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview12); break; case r.id.imageview12: urlimageviewhelper.seturldrawable(image12, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image12.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview13); break; case r.id.imageview13: urlimageviewhelper.seturldrawable(image13, cc.images_popular[rand .nextint(cc.images_popular.length)], r.drawable.ima); image13.startanimation(selectanimation((int) (math.random() * 5))); handlechangeimage(r.id.imageview1); break; } } }, 4000); } class loadimages extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(mainactivity.this); pdialog.setmessage("please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } @override protected string doinbackground(string... args) { log.d("back", "in background"); list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("cat_name", projectname)); string uuu = "http://frontlinkinfotech.com/lwp/c_wall/get_all_images"; jsonobject json = jparser.makehttprequest(uuu, "post", params); log.d("back", "get image"); seek { int success = json.getint(tag_success); arraylist<string> list1 = new arraylist<string>(); if (success == 200) { log.d("back", "success"); images = json.getjsonarray(tag_array); (int = 0; < images.length(); i++) { string jkr = images.getstring(i); string front end = jkr.replace("jkrdevelopers", "frontlinkinfotech"); list1.add(front); } cc.images_popular = list1.toarray(new string[list1.size()]); // collections.shuffle(list1); log.d("array", cc.images_popular.tostring()); log.d("array", list1.tostring()); // cc.images_new = list1.toarray(new string[list1.size()]); } } grab (exception e) { // todo: handle exception e.printstacktrace(); } homecoming null; } @override protected void onpostexecute(string result) { super.onpostexecute(result); if (pdialog.isshowing()) { pdialog.dismiss(); log.d("back", "in post"); resultdisplaylayout.removeallviews(); log.d("size", cc.images_popular.length + ""); log.d("size", cc.images_popular.length / 13 + ""); (int = 0; < cc.images_popular.length / 13; i++) { // display_toast_message(collect_rs_rd_value.get(i)); layoutinflater inflater = (layoutinflater) getsystemservice(getapplicationcontext().layout_inflater_service); view view = inflater.inflate(r.layout.image_listview, null); (int j = 0; j < 13; j++) { image1 = (squareimageviewhalf) view .findviewbyid(r.id.imageview1); urlimageviewhelper.seturldrawable(image1, cc.images_popular[i], r.drawable.ima); image2 = (squareimageviewhalf) view .findviewbyid(r.id.imageview2); urlimageviewhelper.seturldrawable(image2, cc.images_popular[i + 1], r.drawable.ima); image3 = (squareimageview) view .findviewbyid(r.id.imageview3); urlimageviewhelper.seturldrawable(image3, cc.images_popular[i + 2], r.drawable.ima); image4 = (squareimageviewhalf) view .findviewbyid(r.id.imageview4); urlimageviewhelper.seturldrawable(image4, cc.images_popular[i + 3], r.drawable.ima); image5 = (squareimageviewhalf) view .findviewbyid(r.id.imageview5); urlimageviewhelper.seturldrawable(image5, cc.images_popular[i + 4], r.drawable.ima); image6 = (squareimageview) view .findviewbyid(r.id.imageview6); urlimageviewhelper.seturldrawable(image6, cc.images_popular[i + 5], r.drawable.ima); image7 = (squareimageviewhalf) view .findviewbyid(r.id.imageview7); urlimageviewhelper.seturldrawable(image7, cc.images_popular[i + 6], r.drawable.ima); image8 = (squareimageviewhalf) view .findviewbyid(r.id.imageview8); urlimageviewhelper.seturldrawable(image8, cc.images_popular[i + 7], r.drawable.ima); image9 = (squareimageview) view .findviewbyid(r.id.imageview9); urlimageviewhelper.seturldrawable(image9, cc.images_popular[i + 8], r.drawable.ima); image10 = (squareimageview) view .findviewbyid(r.id.imageview10); urlimageviewhelper.seturldrawable(image10, cc.images_popular[i + 9], r.drawable.ima); image11 = (squareimageview) view .findviewbyid(r.id.imageview11); urlimageviewhelper.seturldrawable(image11, cc.images_popular[i + 10], r.drawable.ima); image12 = (squareimageviewhalf) view .findviewbyid(r.id.imageview12); urlimageviewhelper.seturldrawable(image12, cc.images_popular[i + 11], r.drawable.ima); image13 = (squareimageviewhalf) view .findviewbyid(r.id.imageview13); urlimageviewhelper.seturldrawable(image13, cc.images_popular[i + 12], r.drawable.ima); } resultdisplaylayout.addview(view); } toast.maketext(getapplicationcontext(), "post", toast.length_short).show(); } } } }

activity_main.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.featuredwallpaper.mainactivity" > <scrollview android:id="@+id/scrollview1" android:layout_width="match_parent" android:layout_height="wrap_content" > <linearlayout android:id="@+id/resultdisplaylayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </linearlayout> </scrollview> </relativelayout>

image_listview.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:ignore="nestedweights,disablebaselinealignment" > <!-- start first layout --> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:baselinealigned="false" android:orientation="horizontal" > <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.50" android:orientation="vertical" > <com.example.featuredwallpaper.squareimageviewhalf android:id="@+id/imageview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaletype="fitxy" android:background="@drawable/border" android:padding="5dp" android:src="@drawable/ic_launcher" /> <com.example.featuredwallpaper.squareimageviewhalf android:id="@+id/imageview2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/border" android:padding="5dp" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.50" android:orientation="vertical" > <com.example.featuredwallpaper.squareimageview android:id="@+id/imageview3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/border" android:padding="5dp" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.50" android:orientation="vertical" > <com.example.featuredwallpaper.squareimageviewhalf android:id="@+id/imageview4" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="0.50" android:background="@drawable/border" android:padding="5dp" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> <com.example.featuredwallpaper.squareimageviewhalf android:id="@+id/imageview5" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="0.50" android:padding="5dp" android:background="@drawable/border" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> </linearlayout> </linearlayout> <linearlayout android:layout_width="fill_parent" android:layout_height="5dp" android:background="@android:color/black" ></linearlayout> <!-- end sec layout --> <!-- start 3rd layout --> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.50" android:orientation="vertical" > <com.example.featuredwallpaper.squareimageview android:id="@+id/imageview6" android:layout_width="fill_parent" android:padding="5dp" android:background="@drawable/border" android:layout_height="fill_parent" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.50" android:orientation="vertical" > <com.example.featuredwallpaper.squareimageviewhalf android:id="@+id/imageview7" android:layout_width="fill_parent" android:layout_height="0dp" android:background="@drawable/border" android:layout_weight="0.50" android:padding="5dp" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> <com.example.featuredwallpaper.squareimageviewhalf android:id="@+id/imageview8" android:layout_width="fill_parent" android:layout_height="0dp" android:background="@drawable/border" android:layout_weight="0.50" android:padding="5dp" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.50" android:orientation="vertical" > <com.example.featuredwallpaper.squareimageview android:id="@+id/imageview9" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/border" android:scaletype="fitxy" android:padding="5dp" android:src="@drawable/ic_launcher" /> </linearlayout> </linearlayout> <linearlayout android:layout_width="fill_parent" android:layout_height="5dp" android:background="@android:color/black" ></linearlayout> <!-- end 3rd layout --> <!-- start 4th layout --> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <linearlayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.50" > <com.example.featuredwallpaper.squareimageview android:id="@+id/imageview10" android:layout_width="fill_parent" android:padding="5dp" android:layout_height="fill_parent" android:scaletype="fitxy" android:background="@drawable/border" android:src="@drawable/ic_launcher" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.50" > <com.example.featuredwallpaper.squareimageview android:id="@+id/imageview11" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" android:scaletype="fitxy" android:background="@drawable/border" android:src="@drawable/ic_launcher" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.50" android:orientation="vertical" > <com.example.featuredwallpaper.squareimageviewhalf android:id="@+id/imageview12" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="0.50" android:padding="5dp" android:scaletype="fitxy" android:background="@drawable/border" android:src="@drawable/ic_launcher" /> <com.example.featuredwallpaper.squareimageviewhalf android:id="@+id/imageview13" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="0.50" android:scaletype="fitxy" android:background="@drawable/border" android:padding="5dp" android:src="@drawable/ic_launcher" /> </linearlayout> </linearlayout> <linearlayout android:layout_width="fill_parent" android:layout_height="5dp" android:background="@android:color/black" ></linearlayout> <!-- end 4th layout --> </linearlayout>

jsonparser.java

package com.example.featuredwallpaper; import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.io.unsupportedencodingexception; import java.util.list; import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httpget; import org.apache.http.client.methods.httppost; import org.apache.http.client.utils.urlencodedutils; import org.apache.http.impl.client.defaulthttpclient; import org.json.jsonexception; import org.json.jsonobject; import android.util.log; public class jsonparser { static inputstream = null; static jsonobject jobj = null; static string json = ""; // constructor public jsonparser() { } // function json url // making http post or mehtod public jsonobject makehttprequest(string url, string method, list<namevaluepair> params) { // making http request seek { // check request method if(method == "post"){ // request method post // defaulthttpclient defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url); httppost.setentity(new urlencodedformentity(params)); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); = httpentity.getcontent(); }else if(method == "get"){ // request method defaulthttpclient httpclient = new defaulthttpclient(); string paramstring = urlencodedutils.format(params, "utf-8"); url += "?" + paramstring; httpget httpget = new httpget(url); httpresponse httpresponse = httpclient.execute(httpget); httpentity httpentity = httpresponse.getentity(); = httpentity.getcontent(); } } grab (unsupportedencodingexception e) { e.printstacktrace(); } grab (clientprotocolexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } seek { bufferedreader reader = new bufferedreader(new inputstreamreader( is, "iso-8859-1"), 8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } is.close(); json = sb.tostring(); } grab (exception e) { log.e("buffer error", "error converting result " + e.tostring()); } // seek parse string json object seek { jobj = new jsonobject(json); } grab (jsonexception e) { log.e("json parser", "error parsing info " + e.tostring()); } // homecoming json string homecoming jobj; } }

cc.java

package com.example.featuredwallpaper; public class cc { public static string[] images_popular; public static string[] images_new; public static int pos=0; public static string imagename; public static int totalclick; public static class { public static final string images = "com.nostra13.example.universalimageloader.images"; public static final string image_position = "com.nostra13.example.universalimageloader.image_position"; } }

squareimageview.java

package com.example.featuredwallpaper; import android.content.context; import android.util.attributeset; import android.widget.imageview; public class squareimageview extends imageview { public squareimageview(context context) { super(context); } public squareimageview(context context, attributeset attrs) { super(context, attrs); } public squareimageview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); } @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { super.onmeasure(widthmeasurespec, heightmeasurespec); setmeasureddimension(getmeasuredwidth(), getmeasuredwidth()); //snap width } }

squareimageviewhalf.java

package com.example.featuredwallpaper; import android.content.context; import android.util.attributeset; import android.widget.imageview; public class squareimageviewhalf extends imageview { public squareimageviewhalf(context context) { super(context); } public squareimageviewhalf(context context, attributeset attrs) { super(context, attrs); } public squareimageviewhalf(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); } @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { super.onmeasure(widthmeasurespec, heightmeasurespec); setmeasureddimension(getmeasuredwidth(), getmeasuredwidth()/2); } }

loading images view in android big problem. because of limited cache size. think tutorial may help you.

android json android-layout android-animation

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -