import java.io.BufferedinputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.inputStream; import java.net.MalformedURLException; import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import org.apache.http.httpentity; import org.apache.http.httpResponse; import org.apache.http.clIEnt.httpClIEnt; import org.apache.http.clIEnt.methods.httpGet; import org.apache.http.entity.Bufferedhttpentity; import org.apache.http.impl.clIEnt.DefaulthttpClIEnt; import androID.app.Activity; import androID.content.Context; import androID.content.Intent; import androID.graphics.Bitmap; import androID.graphics.BitmapFactory; import androID.graphics.drawable.Drawable; import androID.net.Uri; import androID.util.Log; import androID.vIEw.LayoutInflater; import androID.vIEw.VIEw; import androID.vIEw.VIEw.OnClickListener; import androID.vIEw.VIEwGroup; import androID.vIEw.VIEwGroup.LayoutParams; import androID.vIEw.VIEwParent; import androID.webkit.WebVIEw; import androID.Widget.BaseAdapter; import androID.Widget.ImageVIEw; import androID.Widget.ImageVIEw.ScaleType; import androID.Widget.linearLayout; import androID.Widget.TextVIEw; import androID.Widget.VIEwAnimator; public class NewsScreenAdapter extends BaseAdapter { LayoutInflater inflater; public GifDecoderVIEw webvIEw1; public static vIEwholder holder; VIEw vIEw = null; public static Context context; public ImageLoader IL; public String imgurl; public static String addurl; public NewsScreenActivity activity; String image; public static String str; public static Date parsed; public static String ac, cat_ID; int storyLenght; public NewsScreenAdapter(NewsScreenActivity a) { // Todo auto-generated constructor stub context = a.getApplicationContext(); this.activity = a; inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); IL = new ImageLoader(activity.getApplicationContext()); } @OverrIDe public int getCount() { // Todo auto-generated method stub // return NewsScreenActivity.arrayList_header.size(); return NewsScreenActivity.TotalDataArray.size(); } @OverrIDe public Object getItem(int position) { // Todo auto-generated method stub return position; } @OverrIDe public int getItemVIEwType(int position) { // Todo auto-generated method stub return position; } @OverrIDe public int getVIEwTypeCount() { // Todo auto-generated method stub return NewsScreenActivity.TotalDataArray.size(); } @OverrIDe public long getItemID(int position) { // Todo auto-generated method stub return position; } @OverrIDe public VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup parent) { // Todo auto-generated method stub VIEw vi = convertVIEw; holder = new vIEwholder(); vi = inflater.inflate(R.layout.newsscren_row, null); holder.news_header_Title = (TextVIEw) vi.findVIEwByID(R.ID.header_Title); holder.ll_data = (linearLayout) vi.findVIEwByID(R.ID.data); vi.setTag(holder); holder.news_header_Title.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub cat_ID = NewsScreenActivity.arrayList_header.get(position); ac = ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray.get(position)).catID; activity.startActivity(new Intent(activity,categoryActivity.class).putExtra("ID", ac)); } }); holder.ll_data.removeAllVIEws(); try { storyLenght = ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray.get(position)).storyArr.size(); } catch (Exception e) { // Todo: handle exception } Log.d("Adapter ", " story Lenght " + storyLenght); for (int i = 0; i < storyLenght; i++) { vIEw = LayoutInflater.from(activity).inflate(R.layout.sub_row, null); holder.short_text = (TextVIEw) vIEw.findVIEwByID(R.ID.short_text); holder.image = (ImageVIEw) vIEw.findVIEwByID(R.ID.image); holder.des = (TextVIEw) vIEw.findVIEwByID(R.ID.des); holder.date_time = (TextVIEw) vIEw.findVIEwByID(R.ID.date_time); holder.llAdd = (linearLayout) vIEw.findVIEwByID(R.ID.sub_llAdd); holder.imgAdd = (ImageVIEw) vIEw.findVIEwByID(R.ID.imgAdd); try{ holder.image.setTag(NewsScreenActivity.arrayList_image.get(i)); IL.displayImage( ((NewsScreenActivity.ImagesData) ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).imageArr.get(0)).smallurl, activity, holder.image); notifyDataSetChanged(); } catch (Exception e) { // Todo: handle exception } try { holder.short_text.setText(((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray.get(position)).storyArr.get(i)).Title); holder.des.setText(((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray.get(position)).storyArr.get(i)).description); String st = ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).date; parsed = new Date(Long.parseLong(st.substring(6, st.length() - 2))); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy hh:mmaa"); System.out.println(sdf.format(parsed)); String concat = sdf.format(parsed); String data = concat; String half1 = data.substring(0, 11); Log.e("1st date", "" + half1); SimpleDateFormat display_date = new SimpleDateFormat("dd.MM.yyyy"); Date d_date = new Date(); String dis_date = display_date.format(parsed); String half2 = data.substring(11, 19); Log.e("2st time", "" + half2); SimpleDateFormat currentdate = new SimpleDateFormat("MMM dd,yyyy"); Date currunt = new Date(); String day = currentdate.format(currunt); if (half1.equalsIgnoreCase(day) == true) { holder.date_time.setText(half2); Log.v("if condition", "" + half2); } else { half1 = dis_date; holder.date_time.setText(half1); Log.v("else condition", "" + half1); } Log.e("currunt time", "" + day); holder.news_header_Title.setText(((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).catdisplay); if (!((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).advertising .equalsIgnoreCase("null")) { holder.short_text.setVisibility(vIEw.GONE); holder.date_time.setVisibility(vIEw.GONE); holder.des.setVisibility(vIEw.GONE); imgurl = ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).adData.imageurl; // Todo auto-generated method stub addurl = ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).adData.targeturl; //-----------------GIF Image vIEw ------------ //holder.imgAdd.setimageBitmap(IL.getBitmap(imgurl)); holder.imgAdd.setimageBitmap(loadImageFromUrl(imgurl)); /* inputStream is = null; try { is = (inputStream) new URL(imgurl).getContent(); webvIEw1 = new GifDecoderVIEw(context, is); activity.setContentVIEw(webvIEw1); } catch (Exception e) { return null; }*/ try { inputStream is = (inputStream) new URL(imgurl).getContent(); GifDecoderVIEw webvIEw1 = new GifDecoderVIEw(activity, is); // GifMovIEVIEw webvIEw1 = new GifMovIEVIEw(activity, is); // holder.llAdd.addVIEw(webvIEw1, holder.imgAdd.getLayoutParams()); } catch (Exception e) { // Todo: handle exception } holder.imgAdd.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { activity.startActivity(new Intent(activity, AdvertismentActivity.class)); } }); Log.i("---", "---------" + imgurl); holder.llAdd.setVisibility(VIEw.VISIBLE); } holder.ll_data.addVIEw(vIEw); Log.i("Set Tag", position+"OK"+i); vIEw.setTag(position+"OK"+i); vIEw.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { String tag = (String) v.getTag(); String[] arr = tag.split("OK"); int p = Integer.parseInt(arr[0]); int i = Integer.parseInt(arr[1]); Log.i("Pos and I", p + " " + i ); str = ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(p)).storyArr.get(i)).storyID; Log.i("Pos and I and STR", p + " " + i + " " + str); Intent intent = new Intent(context,ShowFullDescriprion.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("ID", str); intent.putExtra("cat", p); intent.putExtra("pos",i); context.startActivity(intent); } }); } catch (Exception e) { // Todo: handle exception } } return vi; } public static String getDate(long milliSeconds, String dateFormat) { // Create a DateFormatter object for displaying date in specifIEd // format. DateFormat formatter = new SimpleDateFormat(dateFormat); // Create a calendar object that will convert the date and time value in // milliseconds to date. Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milliSeconds); return formatter.format(calendar.getTime()); } public static class vIEwholder { TextVIEw news_header_Title, short_text, des, date_time; linearLayout ll_data, llAdd; public ImageVIEw image, imgAdd; } public static Bitmap loadImageFromUrl(String url) { URL m; inputStream i = null; BufferedinputStream bis = null; ByteArrayOutputStream out =null; try { m = new URL(url); i = (inputStream) m.getContent(); bis = new BufferedinputStream(i,1024 * 8); out = new ByteArrayOutputStream(); int len=0; byte[] buffer = new byte[1024]; while((len = bis.read(buffer)) != -1){ out.write(buffer, 0, len); } out.close(); bis.close(); } catch (MalformedURLException e1) { e1.printstacktrace(); } catch (IOException e) { e.printstacktrace(); } byte[] data = out.toByteArray(); Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); //Drawable d = Drawable.createFromStream(i, "src"); return bitmap; } }
解决方法:
import java.io.BufferedinputStream;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.inputStream;import java.net.MalformedURLException;import java.net.URL;import java.net.URLConnection;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import org.apache.http.httpResponse;import org.apache.http.clIEnt.httpClIEnt;import org.apache.http.clIEnt.methods.httpPost;import org.apache.http.impl.clIEnt.DefaulthttpClIEnt;import org.apache.http.params.httpconnectionParams;import org.apache.http.util.EntityUtils;import org.Json.JsONArray;import org.Json.JsONObject;import androID.app.Activity;import androID.app.AlertDialog;import androID.app.ProgressDialog;import androID.content.broadcastReceiver;import androID.content.Context;import androID.content.DialogInterface;import androID.content.Intent;import androID.content.IntentFilter;import androID.graphics.Bitmap;import androID.graphics.BitmapFactory;import androID.graphics.color;import androID.net.ConnectivityManager;import androID.net.NetworkInfo;import androID.os.AsyncTask;import androID.os.Bundle;import androID.os.StrictMode;import androID.text.HTML;import androID.util.Log;import androID.vIEw.GestureDetector;import androID.vIEw.GestureDetector.SimpleOnGestureListener;import androID.vIEw.MotionEvent;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.vIEw.Window;import androID.vIEw.animation.Animation;import androID.vIEw.animation.TranslateAnimation;import androID.Widget.button;import androID.Widget.ImageVIEw;import androID.Widget.linearLayout;import androID.Widget.TextVIEw;import androID.Widget.Toast;public class ShowFullDescriprion extends Activity implements OnClickListener { ImageVIEw show_image, adv_image, refresh,show_home; TextVIEw Title_text, des_text, date_time_txt; button back_btn; linearLayout ll, llAdv; public static String url, full_des, advertising, adurl = "",img, targeturl; ProgressDialog progressDialog; TextVIEw mdisplay; AsyncTask<VoID, VoID, VoID> mRegisterTask; String TAG = "ShowFullDescriprion"; public static ArrayList<String> catID = new ArrayList<String>(); public static ArrayList<String> catdisp = new ArrayList<String>(); public static ArrayList<String> next_arrayList = new ArrayList<String>(); public static ArrayList<String> privIoUs_arrayList = new ArrayList<String>(); //public static ArrayList<String> arrayList_advertising = new ArrayList<String>(); SimpleGestureFilter simpleGestureFilter; linearLayout llCat; TextVIEw tvCatdisp; private static final int SWIPE_MIN_disTANCE = 200; private static final int SWIPE_MAX_OFF_PATH = 250; private static final int SWIPE_THRESHolD_VELociTY = 200; int swpCnt = 0; int SWIPE_MAX_VALUE = 1; int PIC_WIDTH = 0; private GestureDetector gestureDetector; VIEw.OntouchListener gestureListener; @SuppressWarnings("unused") private Animation animleftin = null, animleftout = null, animrightin = null, animrightout = null; public static String IDS, TitleS, dateS, descS, next, privIoUs, adv; public static String bigimageS=null; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { // Todo auto-generated method stub super.onCreate(savedInstanceState); requestwindowFeature(Window.FEATURE_NO_Title); setContentVIEw(R.layout.showfull_description); back_btn = (button) findVIEwByID(R.ID.button1); llCat = (linearLayout) findVIEwByID(R.ID.llcategory);// llCat.setonClickListener(this); adv_image = (ImageVIEw) findVIEwByID(R.ID.imgAdd); refresh = (ImageVIEw) findVIEwByID(R.ID.refresh_btn); show_home=(ImageVIEw)findVIEwByID(R.ID.showfull_des_home); llAdv = (linearLayout) findVIEwByID(R.ID.llAdd); // simpleGestureFilter = new SimpleGestureFilter(this, this); // int SWIPE_MAX_VALUE_new = ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray.get(getIntent().getExtras().getInt("cat"))).storyArr.size(); //swpCnt = ((categoryActivity.MainData) categoryActivity.TotalDataArray.get(getIntent().getExtras().getInt("cat"))).storyArr.indexOf(getIntent().getExtras().getString("ID")); //((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(p)).storyArr.get(i)).storyID; //String temp = ((categoryActivity.StoryData) ((categoryActivity.MainData) categoryActivity.TotalDataArray .get(getIntent().getExtras().getInt("cat"))).storyArr.get(getIntent().getExtras().getString("pos"))).storyID; // Log.i("Show full Description .....", "********************** cat "+getIntent().getExtras().getInt("cat")+" **** ID *** "+getIntent().getExtras().getString("ID")); //Log.i("Show full Description .....", "********************** SWIPE_MAX_VALUE_new "+ SWIPE_MAX_VALUE_new+" *** swpCnt **** "+temp +"**** Array *** "+((categoryActivity.MainData) categoryActivity.TotalDataArray.get(getIntent().getExtras().getInt("cat"))).storyArr.get(5)); try { // SWIPE_MAX_VALUE = ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray.get(getIntent().getExtras().getInt("cat"))).storyArr.size(); SWIPE_MAX_VALUE = ((categoryActivity.MainData) categoryActivity.TotalDataArray.get(getIntent().getExtras().getInt("cat"))).storyArr.size(); swpCnt = getIntent().getExtras().getInt("pos"); } catch (Exception e) { // Todo: handle exception } url = "http://maritimeglobalnews.com/Json/story/"+ getIntent().getExtras().getString("ID"); new StoryDataAsyn().execute(); Title_text = (TextVIEw) findVIEwByID(R.ID.show_full_des_Title_txt); show_image = (ImageVIEw) findVIEwByID(R.ID.show_full_des_image); des_text = (TextVIEw) findVIEwByID(R.ID.show_full_des_txt); date_time_txt = (TextVIEw) findVIEwByID(R.ID.show_full_des_datetime_txt); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); show_home.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub startActivity(new Intent(getBaseContext(), NewsScreenActivity.class)); finish(); } }); /* Log.i(TAG, "================InsIDe OnCreate Method=============================="); checkNotNull(SERVER_URL, "SERVER_URL"); checkNotNull(SENDER_ID, "SENDER_ID"); // Make sure the device has the proper dependencIEs. GCMRegistrar.checkDevice(getBaseContext()); // Make sure the manifest was properly set - comment out this line // while develoPing the app, then uncomment it when it's ready. GCMRegistrar.checkManifest(getBaseContext()); registerReceiver(mHandleMessageReceiver, new IntentFilter( disPLAY_MESSAGE_ACTION)); final String regID = GCMRegistrar.getRegistrationID(this); if (regID.equals("")) { Log.i(TAG, "================InsIDe if in regID=null =============================="); // automatically registers application on startup. GCMRegistrar.register(this, SENDER_ID); } else { Log.i(TAG, "================InsIDe else in regID=null =============================="); // Device is already registered on GCM, needs to check if it is // registered on our server as well. if (GCMRegistrar.isRegisteredOnServer(this)) { // Skips registration. Log.i(TAG, "================InsIDe else in regID=null Already register on Server ============================="); mdisplay.append(getString(R.string.already_registered) + "\n"); } else { Log.i(TAG, "================InsIDe else in regID=null trying to register on Server ============================="); // Try to register again, but not in the UI thread. // It's also necessary to cancel the thread onDestroy(), // hence the use of AsyncTask instead of a raw thread. final Context context = this; mRegisterTask = new AsyncTask<VoID, VoID, VoID>() { @OverrIDe protected VoID doInBackground(VoID... params) { Log.i(TAG, "================InsIDe doInBackground Method=============================="); boolean registered = ServerUtilitIEs.register(context, regID); // At this point all attempts to register with the app // server Failed, so we need to unregister the device // from GCM - the app will try to register again when // it is restarted. Note that GCM will send an // unregistered callback upon completion, but // GCMIntentService.onUnregistered() will ignore it. if (!registered) { GCMRegistrar.unregister(context); } return null; } @OverrIDe protected voID onPostExecute(VoID result) { Log.i(TAG, "================InsIDe onPostExecute Method=============================="); mRegisterTask = null; } }; mRegisterTask.execute(null, null, null); } } */ back_btn.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub ShowFullDescriprion.this.finish(); } }); refresh.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub new StoryDataAsyn().execute(); } }); gestureDetector = new GestureDetector(new MyGestureDetector()); gestureListener = new VIEw.OntouchListener() { public boolean ontouch(VIEw v, MotionEvent event) { return gestureDetector.ontouchEvent(event); } }; prepareAnimations(); } @OverrIDe public boolean ontouchEvent(MotionEvent event) { // Todo auto-generated method stub return super.ontouchEvent(event); } /*boolean net; //onCreate net = voID isOnline() { } if (net == true) { //perform internet related tasks in the app } //function public boolean isOnline1() { ConnectivityManager cm = (ConnectivityManager) this .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo(); return activeNetworkInfo != null; // return cm.getActiveNetworkInfo().isConnected(); }*/ public class StoryDataAsyn extends AsyncTask<VoID, VoID, VoID> { // NewsScreenActivity obj = new NewsScreenActivity(); @OverrIDe protected voID onPreExecute() { // Todo auto-generated method stub super.onPreExecute(); // if (isNetworkConnected() == true) // { progressDialog = new ProgressDialog(ShowFullDescriprion.this); progressDialog.setMessage("Loding ..."); progressDialog.setCancelable(false); progressDialog.show();/* } else { AlertDialog connection = new AlertDialog.Builder( ShowFullDescriprion.this) .setTitle("No Network Found") .setMessage( "Internet Connection Reqired To Use this Application") .setPositivebutton("Ok", new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog, int whichbutton) { } }).create(); connection.show(); }*/ } @OverrIDe protected VoID doInBackground(VoID... params) { // Todo auto-generated method stub catID.clear(); catdisp.clear(); getData(url); return null; } @OverrIDe protected voID onPostExecute(VoID result) { // Todo auto-generated method stub super.onPostExecute(result); if (isNetworkConnected() == true) { progressDialog.dismiss(); Title_text.setText(TitleS); /*if(bigimageS!= null && !bigimageS.equals("")) { show_image.setimageBitmap(decodeImage(bigimageS)); Log.v("if", ""+bigimageS); }else { show_image.setimageBitmap(decodeImage(null)); Log.v("else", ""+bigimageS); } */ if(isBlank(bigimageS)==true) { show_image.setVisibility(VIEw.GONE); show_image.setimageBitmap(decodeImage(null)); } else if(isBlank(bigimageS)==false) { show_image.setimageBitmap(decodeImage(bigimageS)); } // show_image.setimageBitmap(loadImageFromUrl(bigimageS)); //show_image.setimageBitmap(decodeImage(bigimageS)); des_text.setText(HTML.fromHTML(descS)); Date parsed = new Date(Long.parseLong(dateS.substring(6, dateS.length() - 2))); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy hh:mmaa"); System.out.println(sdf.format(parsed)); date_time_txt.setText(sdf.format(parsed)); llCat.removeAllVIEws(); for (int i = 0; i < catID.size(); i++) { tvCatdisp = new TextVIEw(ShowFullDescriprion.this); tvCatdisp.setText(""); tvCatdisp.setText(catdisp.get(i)); tvCatdisp.setBackgroundResource(R.drawable.Box); tvCatdisp.setTextcolor(color.BLACK); tvCatdisp.setTextSize(18); tvCatdisp.setTag(i); Log.e("tvCatdisp............", ""+catdisp.get(i)); tvCatdisp.setonClickListener(ShowFullDescriprion.this); tvCatdisp.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub int pos = Integer.parseInt(v.getTag().toString()); startActivity(new Intent(ShowFullDescriprion.this, categoryActivity.class).putExtra("ID",catID.get(pos))); } }); llCat.addVIEw(tvCatdisp); } llAdv.removeAllVIEws(); if ((!adurl.equalsIgnoreCase("")) && adurl != null) { llAdv.setVisibility(VIEw.VISIBLE); ImageLoader il = new ImageLoader(ShowFullDescriprion.this); // adv_image.setimageBitmap(il.getBitmap(adurl)); // adv_image.setimageBitmap(loadImageFromUrl(adurl)); try { inputStream is = (inputStream) new URL(adurl).getContent(); GifDecoderVIEw webvIEw1 = new GifDecoderVIEw(ShowFullDescriprion.this, is); // activity.setContentVIEw(webvIEw1); llAdv.addVIEw(webvIEw1,adv_image.getLayoutParams()); // holder.imgAdd.setimageBitmap(IL.getBitmap(imgurl)); } catch (Exception e) { } llAdv.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub // Intent showAdvIntent =new Intent(ShowFullDescriprion.this,AdvertismentActivity.class); // showAdvIntent.putExtra("ID",targeturl); startActivity(new Intent(getBaseContext(),AdvertismentActivity.class)); Log.e("show add url...", ""+targeturl); } }); } }else { llAdv.setVisibility(VIEw.GONE); AlertDialog connection = new AlertDialog.Builder( ShowFullDescriprion.this) .setTitle("No Network Found") .setMessage( "Internet Connection Reqired To Use this Application") .setPositivebutton("Ok", new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog, int whichbutton) { // new StoryDataAsyn().execute(); progressDialog.dismiss(); } }).create(); connection.show(); } } } public boolean isNetworkConnected() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni == null) { return false; } else return true; } public voID getData(String url) { httpClIEnt clIEnt = new DefaulthttpClIEnt(); httpconnectionParams.setConnectionTimeout(clIEnt.getParams(), 10000); // Timeout try { httpPost request = new httpPost(url); DefaulthttpClIEnt httpClIEnt = new DefaulthttpClIEnt(); httpResponse res = httpClIEnt.execute(request); Log.i("Request", request.toString()); String JsonResponseData = EntityUtils.toString(res.getEntity()); Log.i("JsON", JsonResponseData); JsONObject mainjsonObj = new JsONObject(JsonResponseData); TitleS = mainjsonObj.getString("Title"); dateS = mainjsonObj.getString("Date"); descS = mainjsonObj.getString("ContentHTML"); next = mainjsonObj.getString("NextStoryEID"); next_arrayList.add(next); Log.e("next ID", "" + next_arrayList); Log.e("nextstring ID", "" + next); privIoUs = mainjsonObj.getString("PrevStoryEID"); privIoUs_arrayList.add(privIoUs); Log.e("privIoUs ID", "" + privIoUs_arrayList); Log.e("privIoUs string ID", "" + privIoUs); try { JsONArray tmpAd = mainjsonObj.optJsONArray("advertising"); adurl = tmpAd.getJsONObject(0).getString("ImageUrl"); targeturl = tmpAd.getJsONObject(0).getString("TargetUrl"); Log.v("target url is", "" + targeturl); } catch (Exception e) { // Todo: handle exception } try { JsONArray tmpimg = mainjsonObj.optJsONArray("images"); bigimageS = tmpimg.getJsONObject(0).getString("iPhoneBigImageURL"); Log.v("bigimageS is", "" + bigimageS); } catch (Exception e) { // Todo: handle exception } JsONArray categJsonArr = mainjsonObj.getJsONArray("categorIEs"); for (int i = 0; i < categJsonArr.length(); i++) { catID.add(categJsonArr.getJsONObject(i) .getString("categoryEID")); catdisp.add(categJsonArr.getJsONObject(i).getString("categorydisplay")); } } catch (Exception e) { e.printstacktrace(); } } public static Bitmap loadImageFromUrl(String url) { URL m; inputStream i = null; BufferedinputStream bis = null; ByteArrayOutputStream out =null; try { m = new URL(url); i = (inputStream) m.getContent(); bis = new BufferedinputStream(i,1024 * 8); out = new ByteArrayOutputStream(); int len=0; byte[] buffer = new byte[1024]; while((len = bis.read(buffer)) != -1){ out.write(buffer, 0, len); } out.close(); bis.close(); } catch (MalformedURLException e1) { e1.printstacktrace(); } catch (IOException e) { e.printstacktrace(); } byte[] data = out.toByteArray(); Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); //Drawable d = Drawable.createFromStream(i, "src"); return bitmap; } public static Bitmap decodeImage(String arrayList_image) { URL aURL; try { aURL = new URL(arrayList_image); URLConnection conn = aURL.openConnection(); conn.connect(); inputStream is = conn.getinputStream(); BufferedinputStream bis = new BufferedinputStream(is); Bitmap bm = BitmapFactory.decodeStream(bis); bis.close(); is.close(); return bm; } catch (MalformedURLException e) { e.printstacktrace(); } catch (IOException e) { e.printstacktrace(); } return null; } @OverrIDe public boolean dispatchtouchEvent(MotionEvent me) { this.gestureDetector.ontouchEvent(me); return super.dispatchtouchEvent(me); } class MyGestureDetector extends SimpleOnGestureListener { @OverrIDe public boolean onDown(MotionEvent e) { // Todo auto-generated method stub return super.onDown(e); } @OverrIDe public boolean onFling(MotionEvent e1, MotionEvent e2, float veLocityX, float veLocityY) { Log.e("InsIDe onfling", "Call"); if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_disTANCE && Math.abs(veLocityX) > SWIPE_THRESHolD_VELociTY) { url = "http://maritimeglobalnews.com/Json/story/"+next; new StoryDataAsyn().execute(); Log.d("url next mate", ""+url); Log.d("right to left privIoUs.....", ""+next_arrayList); try { Log.i("","swip count " + swpCnt+" ***** "+((categoryActivity.MainData) categoryActivity.TotalDataArray.get(getIntent().getExtras().getInt("cat"))).storyArr.size()); } catch (Exception e) { // Todo: handle exception } if (swpCnt >= 0 && swpCnt < SWIPE_MAX_VALUE - 1) { swpCnt++; /* url = "http://maritimeglobalnews.com/Json/story/"+next; new StoryDataAsyn().execute(); Log.d("url next mate", ""+url); Log.d("right to left privIoUs.....", ""+next_arrayList); */ } } else if (e2.getX() - e1.getX() > SWIPE_MIN_disTANCE && Math.abs(veLocityX) > SWIPE_THRESHolD_VELociTY ){ url = "http://maritimeglobalnews.com/Json/story/"+privIoUs; Log.v("prevIoUsID first if", ""+privIoUs); Log.i("right to left privIoUs first if.....", ""+privIoUs_arrayList); new StoryDataAsyn().execute(); if (swpCnt > 0 && swpCnt <= SWIPE_MAX_VALUE - 1) { swpCnt--; /*url = "http://maritimeglobalnews.com/Json/story/"+privIoUs; Log.v("url",""+url); Log.v("prevIoUsID 2 if", ""+privIoUs); new StoryDataAsyn().execute(); */ } try { Log.i("","swip count " + swpCnt+" ***** "+((categoryActivity.MainData) categoryActivity.TotalDataArray.get(getIntent().getExtras().getInt("cat"))).storyArr.size()); } catch (Exception e) { // Todo: handle exception } /*if (swpCnt > 0 && swpCnt <= SWIPE_MAX_VALUE - 1) { swpCnt--; url = "http://maritimeglobalnews.com/Json/story/"+privIoUs; Log.v("prevIoUsID 3 if", ""+privIoUs); Log.i("right to left privIoUs. 3 if", ""+privIoUs_arrayList); new StoryDataAsyn().execute(); } */ } return false; } } private voID prepareAnimations() { animleftin = new TranslateAnimation(Animation.relative_TO_PARENT, +1.0f, Animation.relative_TO_PARENT, 0.0f, Animation.relative_TO_PARENT, 0.0f, Animation.relative_TO_PARENT, 0.0f); animleftout = new TranslateAnimation(Animation.relative_TO_PARENT, 0.0f, Animation.relative_TO_PARENT, -1.0f, Animation.relative_TO_PARENT, 0.0f, Animation.relative_TO_PARENT, 0.0f); animrightin = new TranslateAnimation(Animation.relative_TO_PARENT, -1.0f, Animation.relative_TO_PARENT, 0.0f, Animation.relative_TO_PARENT, 0.0f, Animation.relative_TO_PARENT, 0.0f); animrightout = new TranslateAnimation(Animation.relative_TO_PARENT, 0.0f, Animation.relative_TO_PARENT, +1.0f, Animation.relative_TO_PARENT, 0.0f, Animation.relative_TO_PARENT, 0.0f); } /*@OverrIDe protected voID onDestroy() { Log.i(TAG, "================InsIDe OnDestroy Method=============================="); if (mRegisterTask != null) { mRegisterTask.cancel(true); } unregisterReceiver(mHandleMessageReceiver); GCMRegistrar.onDestroy(this); super.onDestroy(); } private voID checkNotNull(Object reference, String @R_301_6889@) { Log.i(TAG, "================InsIDe checkNotNull Method=============================="); if (reference == null) { throw new NullPointerException(getString(R.string.error_config, @R_301_6889@)); } } private final broadcastReceiver mHandleMessageReceiver = new broadcastReceiver() { @OverrIDe public voID onReceive(Context context, Intent intent) { Log.i(TAG, "================InsIDe OnReceive in broadcastReceiver Method=============================="); String newMessage = intent.getExtras().getString(EXTRA_MESSAGE); mdisplay.append(newMessage + "\n"); } };*/ @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub if (v == tvCatdisp) { // Todo auto-generated method stub startActivity(new Intent(ShowFullDescriprion.this, categoryActivity.class).putExtra("ID", catID.get((Integer)v.getTag()))); } } public static boolean isBlank(String string) { if (bigimageS == null || bigimageS.length() == 0) return true; int l = bigimageS.length(); for (int i = 0; i < l; i++) { if (!Character.isWhitespace(bigimageS.codePointAt(i))) return false; } return true; }}
总结 以上是内存溢出为你收集整理的android-自定义listview滚动口吃全部内容,希望文章能够帮你解决android-自定义listview滚动口吃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)