Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.tulpar.restapi.restapi;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.ClipData;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.os.AsyncTask;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.google.gson.Gson;
- import com.tulpar.restapi.restapi.models.Service;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.List;
- /**
- * Created by tegar on 14/06/16.
- */
- public class ServiceAdapter extends ArrayAdapter<String> {
- private final Activity context;
- private final String[] name;
- private final String[] icon;
- private List<Service> service;
- private int sizes;
- Bitmap bitmap;
- ImageView imagename;
- public ServiceAdapter(Activity context,int size , List<Service> services) {
- super(context, R.layout.content_main);
- this.context=context;
- this.name = new String[services.size()];
- this.icon = new String[services.size()];
- sizes = size;
- this.service = services;
- for (int i = 0; i < services.size(); i++) {
- name[i] = services.get(i).getName();
- icon[i] = services.get(i).getIcon();
- }
- Log.i("Tag", "Name data " + new Gson().toJson(services));
- Log.i("Tag", "Name data Name " + new Gson().toJson(name));
- }
- @Override
- public int getCount() {
- return service.size();
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- public View getView(int position,View view,ViewGroup parent) {
- LayoutInflater inflater=context.getLayoutInflater();
- View rowView=inflater.inflate(R.layout.content_main, null, true);
- Log.i("Tag", "Name data Size2 " + new Gson().toJson(position));
- sizes = position;
- name[position] = service.get(position).getName();
- icon[position] = service.get(position).getIcon();
- TextView name2 = (TextView) rowView.findViewById(R.id.name);
- imagename = (ImageView) rowView.findViewById(R.id.icon);
- new LoadImage().execute(new Gson().toJson(icon[position]).replaceAll("^\"|\"$", ""));
- String nama = new Gson().toJson(name[position]).replaceAll("^\"|\"$", "");
- name2.setText(nama);
- Log.i("Tag", "Name data5 " + new Gson().toJson(icon[position]).replaceAll("^\"|\"$", ""));
- Log.i("Tag", "Name data3 " + new Gson().toJson(name));
- return rowView;
- };
- private class LoadImage extends AsyncTask<String, String, Bitmap> {
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- protected Bitmap doInBackground(String... args) {
- try {
- bitmap = BitmapFactory.decodeStream((InputStream)new URL(args[0]).getContent());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return bitmap;
- }
- protected void onPostExecute(Bitmap image) {
- if(image != null){
- imagename.setImageBitmap(image);
- }else{
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment