-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable crosswiki notifications and minor UI fixes in displaying notif…
…ications
- Loading branch information
maskara
committed
May 20, 2018
1 parent
0cfcd4e
commit fea2288
Showing
11 changed files
with
204 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-keep public class * implements com.bumptech.glide.module.GlideModule | ||
-keep public class * extends com.bumptech.glide.module.AppGlideModule | ||
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** { | ||
**[] $VALUES; | ||
public *; | ||
} | ||
|
||
# for DexGuard only | ||
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/fr/free/nrw/commons/glide/SvgDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package fr.free.nrw.commons.glide; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.bumptech.glide.load.Options; | ||
import com.bumptech.glide.load.ResourceDecoder; | ||
import com.bumptech.glide.load.engine.Resource; | ||
import com.bumptech.glide.load.resource.SimpleResource; | ||
import com.caverock.androidsvg.SVG; | ||
import com.caverock.androidsvg.SVGParseException; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Decodes an SVG internal representation from an {@link InputStream}. | ||
*/ | ||
public class SvgDecoder implements ResourceDecoder<InputStream, SVG> { | ||
|
||
@Override | ||
public boolean handles(@NonNull InputStream source, @NonNull Options options) { | ||
// TODO: Can we tell? | ||
return true; | ||
} | ||
|
||
public Resource<SVG> decode(@NonNull InputStream source, int width, int height, | ||
@NonNull Options options) | ||
throws IOException { | ||
try { | ||
SVG svg = SVG.getFromInputStream(source); | ||
return new SimpleResource<>(svg); | ||
} catch (SVGParseException ex) { | ||
throw new IOException("Cannot load SVG from stream", ex); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/fr/free/nrw/commons/glide/SvgDrawableTranscoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package fr.free.nrw.commons.glide; | ||
|
||
import android.graphics.Picture; | ||
import android.graphics.drawable.PictureDrawable; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import com.bumptech.glide.load.Options; | ||
import com.bumptech.glide.load.engine.Resource; | ||
import com.bumptech.glide.load.resource.SimpleResource; | ||
import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; | ||
import com.caverock.androidsvg.SVG; | ||
|
||
/** | ||
* Convert the {@link SVG}'s internal representation to an Android-compatible one | ||
* ({@link Picture}). | ||
*/ | ||
public class SvgDrawableTranscoder implements ResourceTranscoder<SVG, PictureDrawable> { | ||
@Nullable | ||
@Override | ||
public Resource<PictureDrawable> transcode(@NonNull Resource<SVG> toTranscode, | ||
@NonNull Options options) { | ||
SVG svg = toTranscode.get(); | ||
Picture picture = svg.renderToPicture(); | ||
PictureDrawable drawable = new PictureDrawable(picture); | ||
return new SimpleResource<>(drawable); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/fr/free/nrw/commons/glide/SvgSoftwareLayerSetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fr.free.nrw.commons.glide; | ||
|
||
import android.graphics.drawable.PictureDrawable; | ||
import android.widget.ImageView; | ||
|
||
import com.bumptech.glide.load.DataSource; | ||
import com.bumptech.glide.load.engine.GlideException; | ||
import com.bumptech.glide.request.RequestListener; | ||
import com.bumptech.glide.request.target.ImageViewTarget; | ||
import com.bumptech.glide.request.target.Target; | ||
|
||
/** | ||
* Listener which updates the {@link ImageView} to be software rendered, because | ||
* {@link com.caverock.androidsvg.SVG SVG}/{@link android.graphics.Picture Picture} can't render on | ||
* a hardware backed {@link android.graphics.Canvas Canvas}. | ||
*/ | ||
public class SvgSoftwareLayerSetter implements RequestListener<PictureDrawable> { | ||
|
||
@Override | ||
public boolean onLoadFailed(GlideException e, Object model, Target<PictureDrawable> target, | ||
boolean isFirstResource) { | ||
ImageView view = ((ImageViewTarget<?>) target).getView(); | ||
view.setLayerType(ImageView.LAYER_TYPE_NONE, null); | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean onResourceReady(PictureDrawable resource, Object model, | ||
Target<PictureDrawable> target, DataSource dataSource, boolean isFirstResource) { | ||
ImageView view = ((ImageViewTarget<?>) target).getView(); | ||
view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/fr/free/nrw/commons/notification/SvgModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package fr.free.nrw.commons.notification; | ||
|
||
import android.content.Context; | ||
import android.graphics.drawable.PictureDrawable; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.bumptech.glide.Glide; | ||
import com.bumptech.glide.Registry; | ||
import com.bumptech.glide.annotation.GlideModule; | ||
import com.bumptech.glide.module.AppGlideModule; | ||
import com.caverock.androidsvg.SVG; | ||
|
||
import java.io.InputStream; | ||
|
||
import fr.free.nrw.commons.glide.SvgDecoder; | ||
import fr.free.nrw.commons.glide.SvgDrawableTranscoder; | ||
|
||
/** | ||
* Module for the SVG sample app. | ||
*/ | ||
@GlideModule | ||
public class SvgModule extends AppGlideModule { | ||
@Override | ||
public void registerComponents(@NonNull Context context, @NonNull Glide glide, | ||
@NonNull Registry registry) { | ||
registry.register(SVG.class, PictureDrawable.class, new SvgDrawableTranscoder()) | ||
.append(InputStream.class, SVG.class, new SvgDecoder()); | ||
} | ||
|
||
// Disable manifest parsing to avoid adding similar modules twice. | ||
@Override | ||
public boolean isManifestParsingEnabled() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters