package dengaev favim com import java util ArrayList import java util

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package dengaev.favim.com;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.widget.RelativeLayout.LayoutParams;
import com.etsy.android.grid.util.DynamicHeightTextView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
/***
* ADAPTER
*/
public class SampleAdapter extends ArrayAdapter<String> {
private static final String TAG = "SampleAdapter";
List<String> idddd = MainActivity.idImg;
List<String> ID = MainActivity.idImgID;
double k =0;
static class ViewHolder {
DynamicHeightTextView txtLineOne;
// Button btnGo;
ImageView imageView;
}
private final LayoutInflater mLayoutInflater;
private final Random mRandom;
private final ArrayList<Integer> mBackgroundColors;
Context context;
private static final SparseArray<Double> sPositionHeightRatios = new SparseArray<Double>();
public SampleAdapter(final Context context) {
super(context, 0);
mLayoutInflater = LayoutInflater.from(context);
mRandom = new Random();
mBackgroundColors = new ArrayList<Integer>();
// mBackgroundColors.add(R.color.orange);
// mBackgroundColors.add(R.color.green);
// mBackgroundColors.add(R.color.blue);
//mBackgroundColors.add(R.color.yellow);
//mBackgroundColors.add(R.color.grey);
this.context = context;
}
@SuppressWarnings("null")
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
final ViewHolder vh;
View view = convertView;
if (view == null) {
view = mLayoutInflater.inflate(R.layout.list_item_sample, parent, false);
vh = new ViewHolder();
// vh.txtLineOne = (DynamicHeightTextView) view.findViewById(R.id.txt_line1);
// vh.btnGo = (Button) view.findViewById(R.id.btn_go);
assert view != null;
vh.imageView = (ImageView) view.findViewById(R.id.imageView1);
view.setTag(vh);
}
else {
vh = (ViewHolder) view.getTag();
}
double positionHeight = getPositionRatio(position);
/* int backgroundIndex = position >= mBackgroundColors.size() ?
position % mBackgroundColors.size() : position;
view.setBackgroundResource(mBackgroundColors.get(backgroundIndex));
*/
// view.setBackgroundResource(mBackgroundColors.get(0));
Log.d(TAG, "getView position:" + position + " h:" + positionHeight);
// vh.txtLineOne.setHeightRatio(positionHeight);
// vh.txtLineOne.setText(getItem(position) + position);
vh.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
Toast.makeText(getContext(), "Button Clicked Position " +
position, Toast.LENGTH_SHORT).show();
open(position, context);
}
});
DisplayImageOptions
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
ImageLoader.getInstance()
.displayImage(getItem(position), vh.imageView, options, new SimpleImageLoadingListener() {
// .displayImage(imageUrls[position], vh.imageView, options, new SimpleImageLoadingListener() {
// .displayImage("https://pp.vk.me/c619420/v619420286/1a556/tCau56c4J3I.jpg", vh.imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
//vh.progressBar.setProgress(0);
//vh.progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
//vh.progressBar.setVisibility(View.GONE);
}
@SuppressLint("NewApi")
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
//vh.progressBar.setVisibility(View.GONE);
DisplayMetrics display = mLayoutInflater.getContext().getResources().getDisplayMetrics();
int imageWidth = display.widthPixels /2;
int imageWidth2 = display.widthPixels;
LayoutParams layoutParams = (RelativeLayout.LayoutParams) vh.imageView.getLayoutParams();
int x = imageWidth;
int yImg = loadedImage.getHeight();
int xImg = loadedImage.getWidth();
System.out.println("imageWidth = " + imageWidth);
k = (yImg*imageWidth/xImg);
System.out.println("k=== = " + k);
layoutParams.height = (int)k;
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
//vh.progressBar.setProgress(Math.round(100.0f * current / total));
}
});
return view;
}
private double getPositionRatio(final int position) {
double ratio = sPositionHeightRatios.get(position, 0.0);
// if not yet done generate and stash the columns height
// in our real world scenario this will be determined by
// some match based on the known height and width of the image
// and maybe a helpful way to get the column height!
if (ratio == 0) {
ratio = getRandomHeightRatio();
sPositionHeightRatios.append(position, ratio);
Log.d(TAG, "getPositionRatio:" + position + " ratio:" + ratio);
}
return ratio;
}
private double getRandomHeightRatio() {
return (mRandom.nextDouble() / 2.0) + 1.0; // height will be 1.0 - 1.5 the width
}
void open(int position, Context context)
{
Intent intent= new Intent(context, detali.class);
intent.putExtra("position", position);
intent.putExtra("id", "");
//idddd.get(position)
context.startActivity(intent);
}
}