Skip to content

Commit

Permalink
Merge pull request #7 from Hatzen/master
Browse files Browse the repository at this point in the history
Fix support library issue with android sdk 19 relates to issue #6
  • Loading branch information
hsmnzaydn authored Jul 8, 2021
2 parents 7d57c1d + efa9bf4 commit ceafe65
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
Expand Down Expand Up @@ -126,14 +127,31 @@ public void setConfig(ImageViewZoomConfig config){
public void onClick(View view) {
if (getDrawable() != null) {
if(imageSaveProperties != null){
new Dialog().show(((FragmentActivity) getContext()).getSupportFragmentManager(), getBitmap(),this.imageViewZoomConfig,imageSaveProperties);
new Dialog().show(getActivity().getSupportFragmentManager(), getBitmap(),this.imageViewZoomConfig,imageSaveProperties);
}else{
new Dialog().show(((FragmentActivity) getContext()).getSupportFragmentManager(), getBitmap(),this.imageViewZoomConfig);
new Dialog().show(getActivity().getSupportFragmentManager(), getBitmap(),this.imageViewZoomConfig);
}
}
}


/**
* Return the activity which might be needed as context object but is not given by View#getContext
* as with support library <23.0.0 it might just be a wrapper.
*
* Solution from https://stackoverflow.com/a/38814443/8524651
*
* @return the correct activity context
*/
private FragmentActivity getActivity() {
Context context = getContext();
while (context instanceof ContextWrapper) {
if (context instanceof FragmentActivity) {
return (FragmentActivity) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
return null;
}


@Override
Expand Down

0 comments on commit ceafe65

Please sign in to comment.