use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.
the class ObservationEditor method onCreate.
/**
* LIFECYCLE CALLBACKS
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
String action = intent != null ? intent.getAction() : null;
String type = intent != null ? intent.getType() : null;
if ((savedInstanceState == null) && (intent != null) && (intent.getData() != null)) {
int uriMatch = ObservationProvider.URI_MATCHER.match(intent.getData());
if ((uriMatch == Observation.OBSERVATIONS_URI_CODE) || (uriMatch == ObservationPhoto.OBSERVATION_PHOTOS_URI_CODE)) {
// Show the confirmation screen
mIsConfirmation = true;
} else {
mIsConfirmation = false;
}
} else if ((intent != null) && (action != null) && (Intent.ACTION_SEND.equals(action))) {
// Single share photo with iNaturalist
mIsConfirmation = true;
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
mSharePhotos = new ArrayList<>();
mSharePhotos.add(imageUri);
} else if ((intent != null) && (action != null) && (Intent.ACTION_SEND_MULTIPLE.equals(action))) {
// Multiple share photo with iNaturalist
mSharePhotos = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
} else if (savedInstanceState != null) {
// Show the observation editor screen
mIsConfirmation = savedInstanceState.getBoolean("mIsConfirmation", false);
}
mCameraPhotos = new ArrayList<String>();
setContentView(R.layout.observation_confirmation);
if (mIsConfirmation) {
setTitle(R.string.details);
} else {
setTitle(R.string.edit_observation);
}
if (mApp == null) {
mApp = (INaturalistApp) getApplicationContext();
}
if (mHelper == null) {
mHelper = new ActivityHelper(this);
}
if (mSharePhotos != null) {
// Share photos(s) with iNaturalist
mUri = getContentResolver().insert(Observation.CONTENT_URI, null);
if (mUri == null) {
Log.e(TAG, "Failed to insert new observation into " + Observation.CONTENT_URI);
finish();
return;
}
setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
getIntent().setAction(Intent.ACTION_INSERT);
mPhotosAdded = new ArrayList<String>();
mPhotosRemoved = new ArrayList<ObservationPhoto>();
} else if (savedInstanceState == null) {
// Do some setup based on the action being performed.
Uri uri = intent.getData();
if (uri == null) {
Log.e(TAG, "Null URI from intent.getData");
finish();
return;
}
switch(ObservationProvider.URI_MATCHER.match(uri)) {
case Observation.OBSERVATION_ID_URI_CODE:
getIntent().setAction(Intent.ACTION_EDIT);
mUri = uri;
break;
case Observation.OBSERVATIONS_URI_CODE:
mUri = getContentResolver().insert(uri, null);
if (mUri == null) {
Log.e(TAG, "Failed to insert new observation into " + uri);
finish();
return;
}
setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
getIntent().setAction(Intent.ACTION_INSERT);
break;
case ObservationPhoto.OBSERVATION_PHOTOS_URI_CODE:
mFileUri = (Uri) intent.getExtras().get("photoUri");
if (mFileUri == null) {
Toast.makeText(getApplicationContext(), getString(R.string.photo_not_specified), Toast.LENGTH_SHORT).show();
finish();
return;
}
mFileUri = getPath(this, mFileUri);
mUri = getContentResolver().insert(Observation.CONTENT_URI, null);
if (mUri == null) {
Log.e(TAG, "Failed to insert new observation into " + uri);
finish();
return;
}
mCursor = managedQuery(mUri, Observation.PROJECTION, null, null, null);
mObservation = new Observation(mCursor);
updateImageOrientation(mFileUri);
createObservationPhotoForPhoto(mFileUri);
setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
getIntent().setAction(Intent.ACTION_INSERT);
mFileUri = null;
break;
default:
Log.e(TAG, "Unknown action, exiting");
finish();
return;
}
mPhotosAdded = new ArrayList<String>();
mPhotosRemoved = new ArrayList<ObservationPhoto>();
} else {
String fileUri = savedInstanceState.getString("mFileUri");
if (fileUri != null) {
mFileUri = Uri.parse(fileUri);
}
String obsUri = savedInstanceState.getString("mUri");
if (obsUri != null) {
mUri = Uri.parse(obsUri);
} else {
mUri = intent.getData();
}
mObservation = (Observation) savedInstanceState.getSerializable("mObservation");
mProjects = (ArrayList<BetterJSONObject>) savedInstanceState.getSerializable("mProjects");
mProjectIds = savedInstanceState.getIntegerArrayList("mProjectIds");
mProjectFieldValues = (HashMap<Integer, ProjectFieldValue>) savedInstanceState.getSerializable("mProjectFieldValues");
mProjectFieldsUpdated = savedInstanceState.getBoolean("mProjectFieldsUpdated");
mPictureTaken = savedInstanceState.getBoolean("mPictureTaken", false);
mPreviousTaxonSearch = savedInstanceState.getString("mPreviousTaxonSearch");
mTaxonPicUrl = savedInstanceState.getString("mTaxonPicUrl");
mIsCaptive = savedInstanceState.getBoolean("mIsCaptive", false);
mFirstPositionPhotoId = savedInstanceState.getString("mFirstPositionPhotoId");
mGettingLocation = savedInstanceState.getBoolean("mGettingLocation");
mLocationManuallySet = savedInstanceState.getBoolean("mLocationManuallySet");
mReturnToObservationList = savedInstanceState.getBoolean("mReturnToObservationList");
mPhotosChanged = savedInstanceState.getBoolean("mPhotosChanged");
mPhotosAdded = savedInstanceState.getStringArrayList("mPhotosAdded");
mPhotosRemoved = (ArrayList<ObservationPhoto>) savedInstanceState.getSerializable("mPhotosRemoved");
mCameraPhotos = savedInstanceState.getStringArrayList("mCameraPhotos");
mChoseNewPhoto = savedInstanceState.getBoolean("mChoseNewPhoto");
}
findViewById(R.id.locationVisibility).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
mHelper.selection(getString(R.string.location_visibility), getResources().getStringArray(R.array.geoprivacy_items), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mGeoprivacy.setSelection(which);
updateObservationVisibilityDescription();
int index = mGeoprivacy.getSelectedItemPosition();
String value;
switch(index) {
case 2:
value = AnalyticsClient.EVENT_VALUE_GEOPRIVACY_PRIVATE;
break;
case 1:
value = AnalyticsClient.EVENT_VALUE_GEOPRIVACY_OBSCURED;
break;
case 0:
default:
value = AnalyticsClient.EVENT_VALUE_GEOPRIVACY_OPEN;
}
try {
JSONObject eventParams = new JSONObject();
eventParams.put(AnalyticsClient.EVENT_PARAM_NEW_VALUE, value);
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_OBS_GEOPRIVACY_CHANGED, eventParams);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
});
findViewById(R.id.is_captive_checkbox).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
mIsCaptive = !mIsCaptive;
if (mIsCaptive) {
findViewById(R.id.is_captive_on_icon).setVisibility(View.VISIBLE);
findViewById(R.id.is_captive_off_icon).setVisibility(View.GONE);
} else {
findViewById(R.id.is_captive_on_icon).setVisibility(View.GONE);
findViewById(R.id.is_captive_off_icon).setVisibility(View.VISIBLE);
}
try {
JSONObject eventParams = new JSONObject();
eventParams.put(AnalyticsClient.EVENT_PARAM_NEW_VALUE, mIsCaptive ? AnalyticsClient.EVENT_PARAM_VALUE_YES : AnalyticsClient.EVENT_PARAM_VALUE_NO);
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_OBS_CAPTIVE_CHANGED, eventParams);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
mGeoprivacy = (Spinner) findViewById(R.id.geoprivacy);
mSpeciesGuessTextView = (EditText) findViewById(R.id.speciesGuess);
mSpeciesGuessSub = (TextView) findViewById(R.id.speciesGuessSub);
mClearSpeciesGuess = (ImageView) findViewById(R.id.clear_species_guess);
mSpeciesGuessIcon = (ImageView) findViewById(R.id.species_guess_icon);
mDescriptionTextView = (TextView) findViewById(R.id.description);
mClearSpeciesGuess.setVisibility(View.VISIBLE);
mClearSpeciesGuess.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearSpeciesGuess();
}
});
mDescriptionTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String newDescription = charSequence.toString().trim();
String originalDescription = mObservation.description != null ? mObservation.description.trim() : "";
if (!newDescription.equals(originalDescription)) {
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_OBS_NOTES_CHANGED);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
mSaveButton = (TextView) findViewById(R.id.save_observation);
mObservedOnButton = (TextView) findViewById(R.id.observed_on);
mObservedOnStringTextView = (TextView) findViewById(R.id.observed_on_string);
mTimeObservedAtButton = (TextView) findViewById(R.id.time_observed_at);
mGallery = (TwoWayView) findViewById(R.id.gallery);
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());
mGallery.setItemMargin((int) px);
mLatitudeView = (TextView) findViewById(R.id.latitude);
mLongitudeView = (TextView) findViewById(R.id.longitude);
mAccuracyView = (TextView) findViewById(R.id.accuracy);
mLocationProgressView = (ProgressBar) findViewById(R.id.locationProgress);
mLocationRefreshButton = (View) findViewById(R.id.locationRefreshButton);
mTopActionBar = getSupportActionBar();
mDeleteButton = (ImageButton) findViewById(R.id.delete_observation);
mViewOnInat = (ImageButton) findViewById(R.id.view_on_inat);
mProjectSelector = (TextView) findViewById(R.id.select_projects);
mProjectCount = (TextView) findViewById(R.id.project_count);
mProjectFieldsTable = (TableLayout) findViewById(R.id.project_fields);
mLocationIcon = (ImageView) findViewById(R.id.location_icon);
mLocationGuess = (TextView) findViewById(R.id.location_guess);
mFindingCurrentLocation = (TextView) findViewById(R.id.finding_current_location);
mCloseSpeciesNameOnboarding = findViewById(R.id.onboarding_species_name_close);
mSpeciesNameOnboarding = (ViewGroup) findViewById(R.id.onboarding_species_name);
mSpeciesNameOnboarding = (ViewGroup) findViewById(R.id.onboarding_species_name);
final SharedPreferences prefs = getSharedPreferences("iNaturalistPreferences", MODE_PRIVATE);
mCloseSpeciesNameOnboarding.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
mSpeciesNameOnboarding.setVisibility(View.GONE);
prefs.edit().putBoolean("onboarded_species_guess", true).commit();
}
});
// Decide if to show onboarding message
boolean hasOnboardedSpeciesGuess = prefs.getBoolean("onboarded_species_guess", false);
mSpeciesNameOnboarding.setVisibility(hasOnboardedSpeciesGuess ? View.GONE : View.VISIBLE);
mProjectSelector.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ObservationEditor.this, ProjectSelectorActivity.class);
intent.putExtra(INaturalistService.OBSERVATION_ID, (mObservation.id == null ? mObservation._id : mObservation.id));
intent.putExtra(ProjectSelectorActivity.IS_CONFIRMATION, true);
intent.putExtra(ProjectSelectorActivity.PROJECT_FIELDS, mProjectFieldValues);
intent.putIntegerArrayListExtra(INaturalistService.PROJECT_ID, mProjectIds);
startActivityForResult(intent, PROJECT_SELECTOR_REQUEST_CODE);
}
});
findViewById(R.id.coordinates).setVisibility(View.GONE);
if (mTaxonPicUrl != null) {
UrlImageViewHelper.setUrlDrawable(mSpeciesGuessIcon, mTaxonPicUrl, R.drawable.ic_species_guess_black_24dp, new UrlImageViewCallback() {
@Override
public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
mSpeciesGuessIcon.setAlpha(1.0f);
}
}
@Override
public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
return loadedBitmap;
}
});
}
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View view) {
mTaxonSearchStarted = true;
if ((mGallery.getAdapter().getCount() == 0) || (!mApp.getSuggestSpecies())) {
// No photos / suggest species setting is off - show the regular species search (by name)
Intent intent = new Intent(ObservationEditor.this, TaxonSearchActivity.class);
intent.putExtra(TaxonSearchActivity.SPECIES_GUESS, mSpeciesGuessTextView.getText().toString());
intent.putExtra(TaxonSearchActivity.SHOW_UNKNOWN, true);
intent.putExtra(TaxonSearchActivity.OBSERVATION_ID, mObservation.id);
intent.putExtra(TaxonSearchActivity.OBSERVATION_ID_INTERNAL, mObservation._id);
intent.putExtra(TaxonSearchActivity.OBSERVATION_JSON, mObservation.toJSONObject().toString());
startActivityForResult(intent, TAXON_SEARCH_REQUEST_CODE);
} else {
// At least one photo - show taxon suggestions screen
Intent intent = new Intent(ObservationEditor.this, TaxonSuggestionsActivity.class);
int pos = mImageCursor.getPosition();
mImageCursor.moveToFirst();
intent.putExtra(TaxonSuggestionsActivity.OBS_PHOTO_FILENAME, mImageCursor.getString(mImageCursor.getColumnIndex(ObservationPhoto.PHOTO_FILENAME)));
intent.putExtra(TaxonSuggestionsActivity.OBS_PHOTO_URL, mImageCursor.getString(mImageCursor.getColumnIndex(ObservationPhoto.PHOTO_URL)));
mImageCursor.move(pos);
intent.putExtra(TaxonSuggestionsActivity.LONGITUDE, mObservation.longitude);
intent.putExtra(TaxonSuggestionsActivity.LATITUDE, mObservation.latitude);
intent.putExtra(TaxonSuggestionsActivity.OBSERVED_ON, mObservation.observed_on);
intent.putExtra(TaxonSuggestionsActivity.OBSERVATION_ID, mObservation.id);
intent.putExtra(TaxonSuggestionsActivity.OBSERVATION_ID_INTERNAL, mObservation._id);
intent.putExtra(TaxonSuggestionsActivity.OBSERVATION, mObservation.toJSONObject().toString());
startActivityForResult(intent, TAXON_SEARCH_REQUEST_CODE);
}
}
};
findViewById(R.id.species_guess_container).setOnClickListener(listener);
mSpeciesGuessTextView.setOnClickListener(listener);
mTopActionBar.setHomeButtonEnabled(true);
mTopActionBar.setDisplayHomeAsUpEnabled(true);
View takePhoto;
mTopActionBar.setLogo(R.drawable.ic_arrow_back);
mTopActionBar.setTitle(getString(R.string.details));
takePhoto = findViewById(R.id.take_photo);
takePhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openImageIntent(ObservationEditor.this);
}
});
mSpeciesGuess = intent.getStringExtra(SPECIES_GUESS);
initObservation();
if ((intent != null) && (!mPictureTaken)) {
if (intent.getBooleanExtra(TAKE_PHOTO, false)) {
// Immediately take a photo
takePhoto();
} else if (intent.getBooleanExtra(CHOOSE_PHOTO, false)) {
// Immediately choose an existing photo
mChoseNewPhoto = true;
choosePhoto();
}
}
initUi();
if (intent != null) {
String taxonJson = (String) mApp.getServiceResult(TAXON);
if (taxonJson != null) {
BetterJSONObject taxon = new BetterJSONObject(taxonJson);
JSONObject idPhoto = taxon.getJSONObject("default_photo");
int rankLevel = taxon.getInt("rank_level") != null ? taxon.getInt("rank_level") : 0;
setTaxon(getTaxonName(taxon.getJSONObject()), TaxonUtils.getTaxonScientificName(taxon.getJSONObject()), rankLevel, false, taxon.getInt("id"), idPhoto != null ? idPhoto.optString("square_url") : null, taxon.getString("iconic_taxon_name"));
mApp.setServiceResult(TAXON, null);
} else if (mObservation.taxon_id != null) {
// Taxon info not loaded - download it now
mTaxonReceiver = new TaxonReceiver();
IntentFilter filter = new IntentFilter(INaturalistService.ACTION_GET_TAXON_NEW_RESULT);
Log.i(TAG, "Registering ACTION_GET_TAXON_NEW_RESULT");
BaseFragmentActivity.safeRegisterReceiver(mTaxonReceiver, filter, this);
Intent serviceIntent = new Intent(INaturalistService.ACTION_GET_TAXON_NEW, null, this, INaturalistService.class);
serviceIntent.putExtra(INaturalistService.TAXON_ID, mObservation.taxon_id);
startService(serviceIntent);
}
}
mObservedOnButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
mTimeObservedAtButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID);
}
});
mLocationRefreshButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(ObservationEditor.this);
// Set the adapter
String[] items = { getResources().getString(R.string.get_current_location), getResources().getString(R.string.edit_location) };
builder.setAdapter(new ArrayAdapter<String>(ObservationEditor.this, android.R.layout.simple_list_item_1, items), null);
final AlertDialog alertDialog = builder.create();
ListView listView = alertDialog.getListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
alertDialog.dismiss();
if (position == 0) {
// Get current place
mLocationManuallySet = true;
getLocation();
} else {
// Edit place
Intent intent = new Intent(ObservationEditor.this, LocationChooserActivity.class);
Double lat, lon;
lat = mObservation.private_latitude == null ? mObservation.latitude : mObservation.private_latitude;
lon = mObservation.private_longitude == null ? mObservation.longitude : mObservation.private_longitude;
intent.putExtra(LocationChooserActivity.LONGITUDE, lon);
intent.putExtra(LocationChooserActivity.LATITUDE, lat);
intent.putExtra(LocationChooserActivity.ACCURACY, (mObservation.positional_accuracy != null ? mObservation.positional_accuracy.doubleValue() : 0));
intent.putExtra(LocationChooserActivity.ICONIC_TAXON_NAME, mObservation.iconic_taxon_name);
startActivityForResult(intent, LOCATION_CHOOSER_REQUEST_CODE);
}
}
});
alertDialog.show();
}
});
if (getCurrentFocus() != null) {
// Hide keyboard
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
if (mProjectIds == null) {
if ((intent != null) && (intent.hasExtra(OBSERVATION_PROJECT))) {
Integer projectId = intent.getIntExtra(OBSERVATION_PROJECT, 0);
mProjectIds = new ArrayList<Integer>();
mProjectIds.add(projectId);
} else {
// Get IDs of project-observations
int obsId = (mObservation.id == null ? mObservation._id : mObservation.id);
Cursor c = getContentResolver().query(ProjectObservation.CONTENT_URI, ProjectObservation.PROJECTION, "(observation_id = " + obsId + ") AND ((is_deleted = 0) OR (is_deleted is NULL))", null, ProjectObservation.DEFAULT_SORT_ORDER);
c.moveToFirst();
mProjectIds = new ArrayList<Integer>();
while (c.isAfterLast() == false) {
ProjectObservation projectObservation = new ProjectObservation(c);
mProjectIds.add(projectObservation.project_id);
c.moveToNext();
}
c.close();
}
}
refreshProjectFields();
mProjectReceiver = new ProjectReceiver();
IntentFilter filter = new IntentFilter(INaturalistService.ACTION_JOINED_PROJECTS_RESULT);
BaseFragmentActivity.safeRegisterReceiver(mProjectReceiver, filter, this);
if (intent != null) {
mReturnToObservationList = intent.getBooleanExtra(RETURN_TO_OBSERVATION_LIST, false);
}
updateObservationVisibilityDescription();
((SwipeableLinearLayout) findViewById(R.id.swipeable_layout)).setOnSwipeListener(new SwipeableLinearLayout.SwipeListener() {
@Override
public void onSwipeRight() {
editNextObservation(-1);
}
@Override
public void onSwipeLeft() {
editNextObservation(1);
}
});
if (mSharePhotos != null) {
stopGetLocation();
// Share photos(s) with iNaturalist (override any place with the one from the shared images)
importPhotos(mSharePhotos, true);
}
}
use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.
the class ObservationEditor method setTaxon.
private void setTaxon(String idName, String scientificName, int rankLevel, boolean isCustomTaxon, int taxonId, String idPicUrl, String iconicTaxonName) {
String speciesGuess = String.format("%s", idName);
mObservation.preferred_common_name = isCustomTaxon ? null : idName;
mSpeciesGuess = speciesGuess;
mObservation.species_guess = speciesGuess;
mObservation.taxon_id = isCustomTaxon ? null : taxonId;
mTaxonTextChanged = true;
mSpeciesGuessTextView.setText(mSpeciesGuess);
mSpeciesGuessSub.setText(scientificName);
mSpeciesGuessSub.setVisibility(View.VISIBLE);
mClearSpeciesGuess.setVisibility(View.VISIBLE);
mScientificName = scientificName;
mTaxonRankLevel = rankLevel;
mSpeciesGuessSub.setTypeface(null, mTaxonRankLevel <= 20 ? Typeface.ITALIC : Typeface.NORMAL);
mTaxonTextChanged = false;
mPreviousTaxonSearch = mSpeciesGuess;
mTaxonPicUrl = isCustomTaxon ? null : idPicUrl;
mIsTaxonUnknown = false;
mIsCustomTaxon = isCustomTaxon;
mObservation.iconic_taxon_name = isCustomTaxon ? null : iconicTaxonName;
((EditText) mSpeciesGuessTextView).clearFocus();
mDescriptionTextView.clearFocus();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
if (!mIsCustomTaxon) {
UrlImageViewHelper.setUrlDrawable(mSpeciesGuessIcon, mTaxonPicUrl, R.drawable.ic_species_guess_black_24dp, new UrlImageViewCallback() {
@Override
public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
mSpeciesGuessIcon.setAlpha(1.0f);
}
if (loadedBitmap != null)
imageView.setImageBitmap(ImageUtils.getRoundedCornerBitmap(loadedBitmap));
}
@Override
public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
return loadedBitmap;
}
});
} else {
mSpeciesGuessIcon.setImageResource(R.drawable.iconic_taxon_unknown);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
mSpeciesGuessIcon.setAlpha(1.0f);
}
}
}
use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.
the class ProfileEditor method refreshUserDetails.
private void refreshUserDetails() {
String iconUrl = mUserIconUrl;
mUserNameText.setText(mUserName);
mUserFullNameText.setText(mUserFullName);
mUserBioText.setText(mUserBio);
mUserEmailText.setText(mUserEmail);
if ((iconUrl != null) && (iconUrl.length() > 0)) {
if (!mUserIconUrl.startsWith("http")) {
mUserPic.setImageURI(Uri.parse(mUserIconUrl));
} else {
UrlImageViewHelper.setUrlDrawable(mUserPic, iconUrl + "?edit=1", 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) {
Bitmap centerCrop = ImageUtils.centerCropBitmap(loadedBitmap);
return centerCrop;
}
});
}
} else {
mUserPic.setImageResource(R.drawable.ic_person_white_24dp);
}
}
use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.
the class MissionDetails method refreshViewState.
private void refreshViewState() {
BetterJSONObject taxon = new BetterJSONObject(mMission.getJSONObject("taxon"));
BetterJSONObject defaultPhoto = new BetterJSONObject(taxon.getJSONObject("default_photo"));
UrlImageViewHelper.setUrlDrawable(mMissionBackground, defaultPhoto.getString("medium_url"), 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 loadedBitmap;
}
});
mTaxonName.setText(taxon.getString("preferred_common_name"));
mCollapsingToolbar.setTitle(taxon.getString("preferred_common_name"));
mCollapsingToolbar.setExpandedTitleColor(getResources().getColor(android.R.color.transparent));
mCollapsingToolbar.setCollapsedTitleTextColor(Color.parseColor("#000000"));
mCollapsingToolbar.setBackgroundColor(Color.parseColor("#FFFFFF"));
mTaxonScientificName.setText(TaxonUtils.getTaxonScientificName(taxon.getJSONObject()));
if (mObservations == null) {
mLoadingMap.setVisibility(View.VISIBLE);
mMapContainer.setVisibility(View.GONE);
mMissionLocationContainer.setVisibility(View.GONE);
mLoadingNearbyObservations.setVisibility(View.VISIBLE);
mNearbyObservationsViewPager.setVisibility(View.GONE);
} else {
mLoadingMap.setVisibility(View.GONE);
mMapContainer.setVisibility(View.VISIBLE);
mMissionLocationContainer.setVisibility(View.VISIBLE);
mLoadingNearbyObservations.setVisibility(View.GONE);
mNearbyObservationsViewPager.setVisibility(View.VISIBLE);
mNearbyObservationsPageAdapter = new ObservationsPagerAdapter(this, mObservations);
mNearbyObservationsViewPager.setAdapter(mNearbyObservationsPageAdapter);
int coordsCount = 0;
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
if (mMissionMap != null) {
mMissionMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
// Show the map screen
Intent intent = new Intent(MissionDetails.this, MissionDetailsMapActivity.class);
JSONArray arr = new JSONArray(mObservations);
intent.putExtra(MissionDetailsMapActivity.OBSERVATIONS, arr.toString());
startActivity(intent);
}
});
mMissionMap.clear();
for (int i = 0; i < mObservations.size(); i++) {
BetterJSONObject observation = new BetterJSONObject(mObservations.get(i));
String placeGuess = observation.getString("place_guess");
Double latitude = observation.getDouble("latitude");
Double longitude = observation.getDouble("longitude");
if (i == 0) {
// First observation - determines initial map place, place guess text and the first big marker
if ((placeGuess != null) && (placeGuess.length() > 0)) {
mMissionLocation.setText(placeGuess);
} else if (latitude != null) {
// No place guess
mMissionLocation.setText(String.format(getString(R.string.location_coords_no_acc), String.format("%.3f...", latitude), String.format("%.3f...", longitude)));
} else {
// No place at all
((ViewGroup) mMissionLocation.getParent()).setVisibility(View.GONE);
}
if (latitude != null) {
LatLng latLng = new LatLng(latitude, longitude);
// Add the marker (it's the main one, so it's bigger in size)
BitmapDrawable bd = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
bd = (BitmapDrawable) getDrawable(R.drawable.mm_34_dodger_blue);
} else {
bd = (BitmapDrawable) getResources().getDrawable(R.drawable.mm_34_dodger_blue);
}
Bitmap bitmap = bd.getBitmap();
Bitmap doubleBitmap = Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth() * 1.3), (int) (bitmap.getHeight() * 1.3), false);
MarkerOptions opts = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(doubleBitmap));
Marker m = mMissionMap.addMarker(opts);
builder.include(latLng);
coordsCount++;
}
} else if (latitude != null) {
// Add observation marker
LatLng latLng = new LatLng(latitude, longitude);
MarkerOptions opts = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.mm_34_dodger_blue));
Marker m = mMissionMap.addMarker(opts);
builder.include(latLng);
coordsCount++;
}
}
}
if (mMissionMap != null) {
final int finalCoordsCount = coordsCount;
mMissionMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition arg0) {
if (finalCoordsCount > 0) {
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 100);
mMissionMap.moveCamera(cu);
}
// Remove listener to prevent position reset on camera move.
mMissionMap.setOnCameraChangeListener(null);
}
});
}
}
mNearbyMissionsPageAdapter = new MissionsPagerAdapter(this, mNearByMissions, mLocationExpansion, true);
mNearbyMissionsViewPager.setAdapter(mNearbyMissionsPageAdapter);
if (mAboutText == null) {
mLoadingAbout.setVisibility(View.VISIBLE);
mAboutTaxonText.setVisibility(View.GONE);
mViewOnWikipedia.setVisibility(View.GONE);
} else {
mLoadingAbout.setVisibility(View.GONE);
mAboutTaxonText.setVisibility(View.VISIBLE);
mViewOnWikipedia.setVisibility(View.VISIBLE);
mAboutTaxonText.setText(Html.fromHtml(mAboutText));
}
}
use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.
the class ProjectDetails method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHelper = new ActivityHelper(this);
final Intent intent = getIntent();
setContentView(R.layout.project_details);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
mAppBarLayout = (AppBarLayout) findViewById(R.id.project_top_bar);
mAppBarLayout.addOnOffsetChangedListener(this);
if (mApp == null) {
mApp = (INaturalistApp) getApplicationContext();
}
if (savedInstanceState == null) {
mProject = new BetterJSONObject(intent.getStringExtra("project"));
mViewType = VIEW_TYPE_OBSERVATIONS;
} else {
mProject = new BetterJSONObject(savedInstanceState.getString("project"));
mViewType = savedInstanceState.getString("mViewType");
mObservations = loadListFromBundle(savedInstanceState, "mObservations");
mSpecies = loadListFromBundle(savedInstanceState, "mSpecies");
mObservers = loadListFromBundle(savedInstanceState, "mObservers");
mIdentifiers = loadListFromBundle(savedInstanceState, "mIdentifiers");
mTotalIdentifiers = savedInstanceState.getInt("mTotalIdentifiers");
mTotalObervers = savedInstanceState.getInt("mTotalObervers");
mTotalObservations = savedInstanceState.getInt("mTotalObservations");
mTotalSpecies = savedInstanceState.getInt("mTotalSpecies");
mJoinedOrLeftProject = savedInstanceState.getBoolean("mJoinedOrLeftProject");
}
// Tab Initialization
initializeTabs();
mJoinLeaveProject = (Button) findViewById(R.id.join_leave_project);
mAboutProject = (Button) findViewById(R.id.about_project);
mProjectNews = (Button) findViewById(R.id.project_news);
if (mProject == null) {
finish();
return;
}
mProjectNews.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ProjectDetails.this, ProjectNews.class);
intent.putExtra("project", mProject);
startActivity(intent);
}
});
mAboutProject.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ProjectDetails.this, ProjectDetailsAbout.class);
intent.putExtra(ProjectDetailsAbout.KEY_PROJECT, mProject);
startActivity(intent);
}
});
mProjectPicContainer = (ViewGroup) findViewById(R.id.project_pic_container);
final ImageView projectPic = (ImageView) findViewById(R.id.project_pic);
String iconUrl = mProject.getString("icon_url");
if ((iconUrl != null) && (iconUrl.length() > 0)) {
projectPic.setVisibility(View.VISIBLE);
findViewById(R.id.project_pic_none).setVisibility(View.GONE);
UrlImageViewHelper.setUrlDrawable(projectPic, iconUrl);
UrlImageViewHelper.setUrlDrawable((ImageView) findViewById(R.id.project_bg), iconUrl + "?bg=1", new UrlImageViewCallback() {
@Override
public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
if (loadedBitmap != null) {
imageView.setImageBitmap(ImageUtils.blur(ProjectDetails.this, ImageUtils.centerCropBitmap(loadedBitmap.copy(loadedBitmap.getConfig(), true))));
}
}
@Override
public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
return loadedBitmap;
}
});
} else {
projectPic.setVisibility(View.GONE);
findViewById(R.id.project_pic_none).setVisibility(View.VISIBLE);
}
collapsingToolbar.setTitle(mProject.getString("title"));
Boolean isJoined = mProject.getBoolean("joined");
if ((isJoined != null) && (isJoined == true)) {
mJoinLeaveProject.setText(R.string.leave);
} else {
mJoinLeaveProject.setText(R.string.join);
}
mJoinLeaveProject.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mJoinedOrLeftProject = true;
Boolean isJoined = mProject.getBoolean("joined");
if ((isJoined != null) && (isJoined == true)) {
mHelper.confirm(getString(R.string.leave_project), getString(R.string.leave_project_confirmation), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int buttonId) {
// Leave the project
mJoinLeaveProject.setText(R.string.join);
mProject.put("joined", false);
Intent serviceIntent = new Intent(INaturalistService.ACTION_LEAVE_PROJECT, null, ProjectDetails.this, INaturalistService.class);
serviceIntent.putExtra(INaturalistService.PROJECT_ID, mProject.getInt("id"));
startService(serviceIntent);
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
}, R.string.yes, R.string.no);
} else {
String terms = mProject.getString("terms");
if ((terms != null) && (terms.length() > 0)) {
mHelper.confirm(getString(R.string.do_you_agree_to_the_following), mProject.getString("terms"), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
joinProject();
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}, R.string.yes, R.string.no);
} else {
joinProject();
}
}
}
});
}
Aggregations