use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.
the class ProjectUserAdapter method getView.
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.project_user_item, parent, false);
JSONObject item = null;
int count;
try {
JSONObject jsonObject = mResultList.get(position);
if (jsonObject.has("observation_count")) {
count = jsonObject.getInt("observation_count");
} else {
count = jsonObject.getInt("count");
}
item = jsonObject.getJSONObject("user");
} catch (JSONException e) {
e.printStackTrace();
return view;
}
// Get the taxon display name according to device locale
try {
ImageView userPic = (ImageView) view.findViewById(R.id.user_pic);
TextView username = (TextView) view.findViewById(R.id.username);
TextView rank = (TextView) view.findViewById(R.id.rank);
TextView countText = (TextView) view.findViewById(R.id.count);
DecimalFormat formatter = new DecimalFormat("#,###,###");
rank.setText(formatter.format(position + 1));
username.setText(item.getString("login"));
countText.setText(formatter.format(count));
if (item.has("icon_url") && !item.isNull("icon_url")) {
UrlImageViewHelper.setUrlDrawable(userPic, item.getString("icon_url"), R.drawable.ic_account_circle_black_24dp, new UrlImageViewCallback() {
@Override
public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
}
@Override
public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
// Return a circular version of the profile picture
Bitmap centerCrop = ImageUtils.centerCropBitmap(loadedBitmap);
return ImageUtils.getCircleBitmap(centerCrop);
}
});
} else {
userPic.setImageResource(R.drawable.ic_account_circle_black_24dp);
}
view.setTag(item);
} catch (JSONException e) {
e.printStackTrace();
}
return view;
}
use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.
the class UserProfile method refreshUserDetails.
private void refreshUserDetails() {
mUserName.setText(mUser.getString("login"));
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
String fullName = mUser.getString("name");
if ((fullName == null) || (fullName.length() == 0)) {
// No full name - use username instead
collapsingToolbar.setTitle(mUser.getString("login"));
mUserName.setVisibility(View.INVISIBLE);
} else {
collapsingToolbar.setTitle(fullName);
mUserName.setVisibility(View.VISIBLE);
}
final String bio = mUser.getString("description");
mUserBio.setOnClickListener(null);
final View.OnClickListener onBio = new View.OnClickListener() {
@Override
public void onClick(View view) {
String bio = mUser.getString("description");
if ((bio == null) || (bio.length() == 0)) {
// No bio
return;
}
String title;
String fullName = mUser.getString("name");
if ((fullName == null) || (fullName.length() == 0)) {
title = mUser.getString("login");
} else {
title = fullName;
}
mHelper.alert(title, mUser.getString("description"));
}
};
if ((bio == null) || (bio.length() == 0)) {
mUserBio.setVisibility(View.GONE);
} else {
mUserBio.setVisibility(View.VISIBLE);
mUserBio.setText(Html.fromHtml(bio));
ViewTreeObserver vto = mUserBio.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < 16) {
mUserBio.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mUserBio.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
Layout l = mUserBio.getLayout();
if (l != null) {
int lines = l.getLineCount();
if (lines > 0) {
if (l.getEllipsisCount(lines - 1) > 0) {
// Bio is ellipsized - Trim the bio text to show the more link
String newBio = bio.substring(0, l.getLineStart(lines - 1) + l.getEllipsisStart(lines - 1) - 8) + "... " + getString(R.string.more_bio);
mUserBio.setText(Html.fromHtml(newBio));
// Show the full bio when the shortened bio is clicked
mUserBio.setOnClickListener(onBio);
}
}
}
}
});
}
final ImageView userPic = (ImageView) findViewById(R.id.user_pic);
String iconUrl = mUser.getString("medium_user_icon_url");
if (iconUrl == null)
iconUrl = mUser.getString("user_icon_url");
if (iconUrl == null)
iconUrl = mUser.getString("icon_url");
if ((iconUrl != null) && (iconUrl.length() > 0)) {
UrlImageViewHelper.setUrlDrawable(userPic, iconUrl, new UrlImageViewCallback() {
@Override
public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
findViewById(R.id.no_user_pic).setVisibility(View.GONE);
userPic.setVisibility(View.VISIBLE);
}
@Override
public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
Bitmap centerCrop = ImageUtils.centerCropBitmap(loadedBitmap);
return ImageUtils.getCircleBitmap(centerCrop);
}
});
UrlImageViewHelper.setUrlDrawable((ImageView) findViewById(R.id.user_bg), iconUrl + "?bg=1", new UrlImageViewCallback() {
@Override
public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
imageView.setImageBitmap(ImageUtils.blur(UserProfile.this, ImageUtils.centerCropBitmap(loadedBitmap.copy(loadedBitmap.getConfig(), true))));
}
@Override
public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
return loadedBitmap;
}
});
userPic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Only show the photo viewer if a large enough image exists
if ((mUser.getString("original_user_icon_url") != null) || (mUser.getString("medium_user_icon_url") != null) || (mUser.getString("icon_url") != null)) {
Intent intent = new Intent(UserProfile.this, ProfilePhotoViewer.class);
intent.putExtra(ProfilePhotoViewer.USER, mUser.getJSONObject().toString());
startActivity(intent);
}
}
});
} else {
userPic.setVisibility(View.GONE);
findViewById(R.id.no_user_pic).setVisibility(View.VISIBLE);
}
}
use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.
the class BaseFragmentActivity method refreshUserDetails.
public void refreshUserDetails() {
SharedPreferences prefs = getSharedPreferences("iNaturalistPreferences", MODE_PRIVATE);
String username = prefs.getString("username", null);
Integer obsCount = prefs.getInt("observation_count", -1);
String userIconUrl = prefs.getString("user_icon_url", null);
Long lastRefreshTime = prefs.getLong("last_user_details_refresh_time", 0);
if (username != null) {
((TextView) findViewById(R.id.side_menu_username)).setText(username);
findViewById(R.id.menu_login).setVisibility(View.INVISIBLE);
findViewById(R.id.side_menu_username).setVisibility(View.VISIBLE);
if (System.currentTimeMillis() - lastRefreshTime > 1000 * 60 * USER_REFRESH_TIME_MINS) {
// Get fresh user details from the server
Intent serviceIntent = new Intent(INaturalistService.ACTION_GET_USER_DETAILS, null, this, INaturalistService.class);
startService(serviceIntent);
}
} else {
findViewById(R.id.menu_login).setVisibility(View.VISIBLE);
findViewById(R.id.side_menu_username).setVisibility(View.INVISIBLE);
}
if (obsCount > -1) {
if (obsCount == 1) {
((TextView) findViewById(R.id.observation_count)).setText(String.format(getString(R.string.observation_count_single), obsCount));
} else {
DecimalFormat formatter = new DecimalFormat("#,###,###");
((TextView) findViewById(R.id.observation_count)).setText(String.format(getString(R.string.observation_count), formatter.format(obsCount)));
}
} else {
String conditions = "(_synced_at IS NULL";
if (username != null) {
conditions += " OR user_login = '" + username + "'";
}
// Don't show deleted observations
conditions += ") AND (is_deleted = 0 OR is_deleted is NULL)";
Cursor cursor = getContentResolver().query(Observation.CONTENT_URI, Observation.PROJECTION, conditions, null, Observation.DEFAULT_SORT_ORDER);
int count = cursor.getCount();
if (count == 1) {
((TextView) findViewById(R.id.observation_count)).setText(String.format(getString(R.string.observation_count_single), count));
} else {
((TextView) findViewById(R.id.observation_count)).setText(String.format(getString(R.string.observation_count), count));
}
cursor.close();
}
if (userIconUrl != null) {
UrlImageViewHelper.setUrlDrawable((ImageView) findViewById(R.id.side_menu_user_pic), userIconUrl, new UrlImageViewCallback() {
@Override
public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
((ImageView) findViewById(R.id.side_menu_no_user_pic)).setVisibility(View.GONE);
((ImageView) findViewById(R.id.side_menu_user_pic)).setVisibility(View.VISIBLE);
}
@Override
public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
// Return a circular version of the profile picture
Bitmap centerCrop = ImageUtils.centerCropBitmap(loadedBitmap);
return ImageUtils.getCircleBitmap(centerCrop);
}
});
} else {
((ImageView) findViewById(R.id.side_menu_no_user_pic)).setVisibility(View.VISIBLE);
((ImageView) findViewById(R.id.side_menu_user_pic)).setVisibility(View.GONE);
}
}
Aggregations