Skip to content

Commit

Permalink
Update 1.0.2
Browse files Browse the repository at this point in the history
Added immutable bitmap support.
  • Loading branch information
GIGAMOLE committed Jul 26, 2015
1 parent 5c4d859 commit e9a5fdd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion TintLayout.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: "com.jfrog.bintray"

version = "1.0.1"
version = "1.0.2"

android {
compileSdkVersion 21
Expand All @@ -12,7 +12,7 @@ android {
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0.1"
versionName "1.0.2"
}
buildTypes {
release {
Expand Down
2 changes: 1 addition & 1 deletion library/library.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.github.gigamole.tintlayout" external.system.module.version="1.0.1" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.github.gigamole.tintlayout" external.system.module.version="1.0.2" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.gigamole.tintlayout.lib;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
Expand All @@ -29,11 +30,17 @@
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
* Created by GIGAMOLE on 21.06.2015.
*/
Expand Down Expand Up @@ -251,7 +258,7 @@ private void getTintBitmap() {
}

private void getBitmap() {
this.bitmap = Bitmap.createBitmap(drawableToBitmap(getBackground()));
this.bitmap = Bitmap.createBitmap(convertToMutable(drawableToBitmap(getBackground())));
this.canvas = new Canvas(this.bitmap);

this.isGet = true;
Expand Down Expand Up @@ -294,4 +301,40 @@ private Bitmap drawableToBitmap(final Drawable drawable) {

return bitmap;
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private Bitmap convertToMutable(final Bitmap imgIn) {
final int width = imgIn.getWidth(), height = imgIn.getHeight();
final Bitmap.Config type = imgIn.getConfig();

File outputFile = null;
final File outputDir = getContext().getCacheDir();
try {
outputFile = File.createTempFile(Long.toString(System.currentTimeMillis()), null, outputDir);
outputFile.deleteOnExit();

final RandomAccessFile randomAccessFile = new RandomAccessFile(outputFile, "rw");
final FileChannel channel = randomAccessFile.getChannel();
final MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE, 0, imgIn.getRowBytes() * height);

imgIn.copyPixelsToBuffer(map);
// imgIn.recycle();

final Bitmap result = Bitmap.createBitmap(width, height, type);

map.position(0);
result.copyPixelsFromBuffer(map);

channel.close();
randomAccessFile.close();

outputFile.delete();
return result;
} catch (final Exception e) {
} finally {
if (outputFile != null)
outputFile.delete();
}
return null;
}
}

0 comments on commit e9a5fdd

Please sign in to comment.