Skip to content

Commit

Permalink
Fix Jasonette#104: Crop background
Browse files Browse the repository at this point in the history
When you put a background image to your view, it streched to fit screen
dimension.
With this patch, image is cropped to keep the aspect ratio.
  • Loading branch information
realitix committed Jun 28, 2017
1 parent 5c832fa commit d893196
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/com/jasonette/seed/Core/JasonViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.ViewTarget;
import com.eclipsesource.v8.debug.mirror.Frame;
import com.jasonette.seed.Component.JasonComponentFactory;
import com.jasonette.seed.Component.JasonImageComponent;
Expand Down Expand Up @@ -1443,22 +1444,26 @@ public void run() {
JSONObject c = new JSONObject();
c.put("url", background);
if(background.matches("(file|http[s]?):\\/\\/.*")) {
ViewTarget target;
if (background.matches(".*\\.gif")) {
with(JasonViewActivity.this).load(JasonImageComponent.resolve_url(c, JasonViewActivity.this)).asGif().into(new SimpleTarget<GifDrawable>() {
target = new ViewTarget<LinearLayout, GifDrawable>(sectionLayout) {
@Override
public void onResourceReady(GifDrawable resource, GlideAnimation<? super GifDrawable> glideAnimation) {
sectionLayout.setBackground(resource);

}
});
};
} else {
with(JasonViewActivity.this).load(JasonImageComponent.resolve_url(c, JasonViewActivity.this)).into(new SimpleTarget<GlideDrawable>() {
target = new ViewTarget<LinearLayout, GlideDrawable>(sectionLayout) {
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
sectionLayout.setBackground(resource);
}
});
};
}
with(JasonViewActivity.this)
.load(JasonImageComponent.resolve_url(c, JasonViewActivity.this))
.centerCrop()
.into(target);
} else if(background == "camera") {
} else if(background.matches("data:image.*")){
String base64 = background.substring("data:image/jpeg;base64,".length());
Expand Down

0 comments on commit d893196

Please sign in to comment.