Last active
August 29, 2015 13:56
-
-
Save basitis/9096847 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import android.app.Activity; | |
import android.app.AlertDialog; | |
import android.app.AlertDialog.Builder; | |
import android.app.DownloadManager; | |
import android.app.WallpaperManager; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.content.SharedPreferences.Editor; | |
import android.graphics.Bitmap; | |
import android.graphics.Bitmap.CompressFormat; | |
import android.graphics.BitmapFactory; | |
import android.graphics.drawable.BitmapDrawable; | |
import android.graphics.drawable.Drawable; | |
import android.net.Uri; | |
import android.os.Environment; | |
import android.preference.PreferenceManager; | |
import android.support.v4.view.PagerAdapter; | |
import android.support.v4.view.ViewPager; | |
import android.util.Log; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.view.View.OnLongClickListener; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.LinearLayout; | |
import com.salim.hot.hothdwallpaper.GlobalApplication; | |
import com.salim.hot.hothdwallpaper.R; | |
import com.squareup.picasso.Picasso; | |
import com.squareup.picasso.Picasso.Listener; | |
import com.squareup.picasso.Picasso.LoadedFrom; | |
import com.squareup.picasso.Target; | |
public class FullImageAdapter extends PagerAdapter { | |
private Activity _activity; | |
private String[] _imagePaths; | |
private LayoutInflater inflater; | |
SharedPreferences preferenceManager; | |
DownloadManager downloadManager; | |
final String strPref_Download_ID = "DOWNLOAD_ID"; | |
Picasso picasso; | |
// constructor | |
public FullImageAdapter(Activity activity, String[] uRLS) { | |
this._activity = activity; | |
this._imagePaths = uRLS; | |
preferenceManager = PreferenceManager | |
.getDefaultSharedPreferences(_activity); | |
_activity.getApplicationContext(); | |
downloadManager = (DownloadManager) _activity.getApplicationContext() | |
.getSystemService(Context.DOWNLOAD_SERVICE); | |
picasso = new com.squareup.picasso.Picasso.Builder(_activity) | |
.debugging(true).listener(new Listener() { | |
@Override | |
public void onImageLoadFailed(Picasso arg0, Uri arg1, | |
Exception arg2) { | |
Log.v("TAG", "Image failed to load : :" + arg1 + ":::" | |
+ arg2.getMessage()); | |
} | |
}).build(); | |
picasso.setDebugging(true); | |
} | |
@Override | |
public int getCount() { | |
return this._imagePaths.length; | |
} | |
@Override | |
public boolean isViewFromObject(View view, Object object) { | |
return view == ((LinearLayout) object); | |
} | |
@Override | |
public Object instantiateItem(ViewGroup container, int position) { | |
final ImageView imgDisplay; | |
inflater = (LayoutInflater) _activity | |
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, | |
container, false); | |
imgDisplay = (ImageView) viewLayout.findViewById(R.id.ivFull); | |
imgDisplay.setTag(position); | |
BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inPreferredConfig = Bitmap.Config.ARGB_8888; | |
picasso.load(_imagePaths[position]) | |
.resize(GlobalApplication.FULL_IMAGE_WIDTH, | |
GlobalApplication.FULL_IMAGE_HEIGHT).centerInside() | |
.into(new Target() { | |
@Override | |
public void onPrepareLoad(Drawable arg0) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onBitmapLoaded(Bitmap arg0, LoadedFrom arg1) { | |
// TODO Auto-generated method stub | |
imgDisplay.setImageBitmap(arg0); | |
} | |
@Override | |
public void onBitmapFailed(Drawable arg0) { | |
// TODO Auto-generated method stub | |
} | |
}); | |
Log.v("TAG", Picasso.with(_activity).getSnapshot().toString()); | |
((ViewPager) container).addView(viewLayout); | |
return viewLayout; | |
} | |
@Override | |
public void destroyItem(ViewGroup container, int position, Object object) { | |
((ViewPager) container).removeView((LinearLayout) object); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment