use of com.squareup.picasso.Picasso in project UltimateAndroid by cymcsg.
the class BaseSliderView method bindEventAndShow.
/**
* When you want to implement your own slider view, please call this method in the end in `getView()` method
* @param v the whole view
* @param targetImageView where to place image
*/
protected void bindEventAndShow(final View v, ImageView targetImageView) {
final BaseSliderView me = this;
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnSliderClickListener != null) {
mOnSliderClickListener.onSliderClick(me);
}
}
});
if (targetImageView == null)
return;
mLoadListener.onStart(me);
Picasso p = Picasso.with(mContext);
RequestCreator rq = null;
if (mUrl != null) {
rq = p.load(mUrl);
} else if (mFile != null) {
rq = p.load(mFile);
} else if (mRes != 0) {
rq = p.load(mRes);
} else {
return;
}
if (rq == null) {
return;
}
if (getEmpty() != 0) {
rq.placeholder(getEmpty());
}
if (getError() != 0) {
rq.error(getError());
}
switch(mScaleType) {
case Fit:
rq.fit();
break;
case CenterCrop:
rq.fit().centerCrop();
break;
case CenterInside:
rq.fit().centerInside();
break;
}
rq.into(targetImageView, new Callback() {
@Override
public void onSuccess() {
if (v.findViewById(R.id.loading_bar) != null) {
v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
}
}
@Override
public void onError() {
if (mLoadListener != null) {
mLoadListener.onEnd(false, me);
}
}
});
}
use of com.squareup.picasso.Picasso in project Tusky by Vavassor.
the class TuskyApplication method onCreate.
@Override
public void onCreate() {
super.onCreate();
// Initialize Picasso configuration
Picasso.Builder builder = new Picasso.Builder(this);
builder.downloader(new OkHttp3Downloader(this));
if (BuildConfig.DEBUG) {
builder.listener(new Picasso.Listener() {
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
exception.printStackTrace();
}
});
}
try {
Picasso.setSingletonInstance(builder.build());
} catch (IllegalStateException e) {
throw new RuntimeException(e);
}
if (BuildConfig.DEBUG) {
Picasso.with(this).setLoggingEnabled(true);
}
}
use of com.squareup.picasso.Picasso in project Manhua by ag2s20150909.
the class APP method onCreate.
@Override
public void onCreate() {
super.onCreate();
mContext = this;
fixdeThreadPool = Executors.newFixedThreadPool(1);
CrashHandler.getInstance().init(this).setOnCrashListener(new CrashHandler.OnCrashListener() {
@Override
public void onCrash(Context context, String errorMsg) {
Toast.makeText(context, errorMsg, Toast.LENGTH_LONG).show();
}
}).setCrashSave().setCrashSaveTargetFolder(this.getExternalFilesDir("crash").getPath());
File file = new File(mContext.getExternalCacheDir(), "okhttpcache");
if (!file.exists()) {
file.mkdirs();
}
okhttp3.Cache cache = new okhttp3.Cache(file, 1024 * 1024 * 500);
okhttp3.OkHttpClient client = new OkHttpClient.Builder().cache(cache).build();
OkHttp3Downloader okHttp3Downloader = new OkHttp3Downloader(client);
Picasso.Builder picassoBuilder = new Picasso.Builder(mContext);
picassoBuilder.downloader(okHttp3Downloader).build();
Picasso picasso = picassoBuilder.build();
Picasso.setSingletonInstance(picasso);
}
use of com.squareup.picasso.Picasso in project incubator-weex by apache.
the class ImageAdapter method setImage.
@Override
public void setImage(final String url, final ImageView view, WXImageQuality quality, final WXImageStrategy strategy) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (view == null || view.getLayoutParams() == null) {
return;
}
if (TextUtils.isEmpty(url)) {
view.setImageBitmap(null);
return;
}
String temp = url;
if (url.startsWith("//")) {
temp = "http:" + url;
}
if (view.getLayoutParams().width <= 0 || view.getLayoutParams().height <= 0) {
return;
}
if (!TextUtils.isEmpty(strategy.placeHolder)) {
Picasso.Builder builder = new Picasso.Builder(WXEnvironment.getApplication());
Picasso picasso = builder.build();
picasso.load(Uri.parse(strategy.placeHolder)).into(view);
view.setTag(strategy.placeHolder.hashCode(), picasso);
}
Picasso.with(WXEnvironment.getApplication()).load(temp).transform(new BlurTransformation(strategy.blurRadius)).into(view, new Callback() {
@Override
public void onSuccess() {
if (strategy.getImageListener() != null) {
strategy.getImageListener().onImageFinish(url, view, true, null);
}
if (!TextUtils.isEmpty(strategy.placeHolder)) {
((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view);
}
}
@Override
public void onError() {
if (strategy.getImageListener() != null) {
strategy.getImageListener().onImageFinish(url, view, false, null);
}
}
});
}
};
if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
runnable.run();
} else {
WXSDKManager.getInstance().postOnUiThread(runnable, 0);
}
}
use of com.squareup.picasso.Picasso in project iNaturalistAndroid by inaturalist.
the class INaturalistApp method onCreate.
@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
FacebookSdk.sdkInitialize(getApplicationContext());
AnalyticsClient.initAnalyticsClient(this);
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_APP_LAUNCH);
// Build a custom Picasso instance that uses more memory for image cache (50% of free memory
// instead of the default 15%)
Picasso picasso = new Picasso.Builder(getApplicationContext()).memoryCache(new LruCache((int) (Runtime.getRuntime().maxMemory() * 0.5))).build();
Picasso.setSingletonInstance(picasso);
// Picasso.with(getApplicationContext())
// .setIndicatorsEnabled(true);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
INaturalistApp.context = getApplicationContext();
deviceLocale = getResources().getConfiguration().locale;
applyLocaleSettings();
// Create the root offline guides directory, if needed
GuideXML.createOfflineGuidesDirectory(this);
SharedPreferences pref = getSharedPreferences("iNaturalistPreferences", MODE_PRIVATE);
String username = pref.getString("username", null);
if (username != null) {
setShownOnboarding(true);
}
int missionViewCount = getPrefs().getInt("mission_view_count", 0);
getPrefs().edit().putInt("mission_view_count", ++missionViewCount).commit();
}
Aggregations