Skip to content

Commit

Permalink
volatile pictogram in order to avoid the pictograms out output memory
Browse files Browse the repository at this point in the history
  • Loading branch information
gonojuarez committed Jul 8, 2022
1 parent ebcec0e commit b06465c
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 24 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
apply plugin: 'maven-publish'

android {
compileSdkVersion 31
compileSdkVersion 32
buildToolsVersion '30.0.3'

defaultConfig {
applicationId "com.stonefacesoft.pictogramas"
minSdkVersion 21
targetSdkVersion 31
targetSdkVersion 32
versionCode 1
versionName "1.1"

Expand All @@ -25,8 +25,8 @@ android {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':app:pictogramslibrary')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
4 changes: 2 additions & 2 deletions app/pictogramslibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ plugins {
}

android {
compileSdkVersion 31
compileSdkVersion 32
buildToolsVersion '30.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 31
targetSdkVersion 32

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
public class GlideAttatcher implements GlideModelTypes {
private Glide glide;
private Context mContext;
private int height = 150;
private int width = 150;
private volatile int height = 300;
private volatile int width = 300;
private int radius = 20;
private int scaleType=0;
private boolean useDiskCacheStrategy;
private boolean useCornerRadious;
private boolean useDecodeFormat;



public GlideAttatcher(final @NonNull Context mContext) {
this.mContext = mContext;
getGlide();
Expand Down Expand Up @@ -114,62 +115,62 @@ public GlideAttatcher UseCornerRadius(boolean useCornerRadious) {
@Override
public Object loadDrawable(@Nullable Bitmap bitmap, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(bitmap)))))).fallback(R.drawable.ic_baseline_cloud_download_24).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(bitmap))))))).fallback(R.drawable.ic_baseline_cloud_download_24).into(imageView).waitForLayout();
return this;
}

@NonNull
@Override
public Object loadDrawable(@Nullable Drawable drawable, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(drawable)))))).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(drawable))))))).into(imageView).waitForLayout();
return this;
}

@NonNull
@Override
public Object loadDrawable(@Nullable String string, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(string)))))).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(string))))))).into(imageView).waitForLayout();
return this;
}

@NonNull
@Override
public Object loadDrawable(@Nullable Uri uri, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(uri).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(uri).error(R.drawable.ic_baseline_cloud_download_24))))))).into(imageView).waitForLayout();
return this;
}

@NonNull
@Override
public Object loadDrawable(@Nullable File file, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(file)))))).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(file))))))).into(imageView).waitForLayout();
return this;
}

@NonNull
@Override
public Object loadDrawable(@Nullable Integer resourceId, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(resourceId)))))).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(resourceId))))))).into(imageView).waitForLayout();
return this;
}

@Override
public Object loadDrawable(@Nullable URL url, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(url).signature(new ObjectKey(url)).error(R.drawable.ic_baseline_cloud_download_24)))))).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(url).signature(new ObjectKey(url)).error(R.drawable.ic_baseline_cloud_download_24))))))).into(imageView).waitForLayout();
return this;
}

@NonNull
@Override
public Object loadDrawable(@Nullable byte[] model, ImageView imageView){
if(isValidContext(mContext)) {
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(model)))))).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(model))))))).into(imageView).waitForLayout();

}
return this;
Expand All @@ -179,11 +180,17 @@ public Object loadDrawable(@Nullable byte[] model, ImageView imageView){
@Override
public Object loadDrawable(@Nullable Object model, ImageView imageView) {
if(isValidContext(mContext))
glideScaleItem(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(model)))))).into(imageView).waitForLayout();
glideScaleItem(resizeGraphic(overrideMethod(cornerRadious(useDecodeFormat(useDiskCacheStrategic(getGlide().getRequestManagerRetriever().get(mContext).load(model))))))).into(imageView).waitForLayout();
return this;
}


public RequestBuilder<Drawable> resizeGraphic(RequestBuilder<Drawable> drawableRequestBuilder){
return drawableRequestBuilder.override(height,width);
}



/**
* scale option method
* 0 default value
Expand Down Expand Up @@ -263,4 +270,5 @@ public void destroy(){




}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public GameGroupView(@NonNull Context context, @Nullable AttributeSet attrs) {
try {
Custom_Texto = a.getString(R.styleable.Custom_Picto_Texto);
Custom_Color = a.getColor(R.styleable.Custom_Picto_Color, getResources().getColor(R.color.Black));
height = a.getInt(R.styleable.Custom_Picto_iconHeight,300);
width = a.getInt(R.styleable.Custom_Picto_iconWidth,300);
// Custom_Imagen = a.getInteger(R.styleable.Custom_Picto_Imagen, 0);
} finally {
a.recycle();
Expand All @@ -53,6 +55,8 @@ public GameGroupView(@NonNull Context context, @Nullable AttributeSet attrs, in
try {
Custom_Texto = a.getString(R.styleable.Custom_Picto_Texto);
Custom_Color = a.getColor(R.styleable.Custom_Picto_Color, getResources().getColor(R.color.Black));
height = a.getInt(R.styleable.Custom_Picto_iconHeight,300);
width = a.getInt(R.styleable.Custom_Picto_iconWidth,300);
// Custom_Imagen = a.getInteger(R.styleable.Custom_Picto_Imagen, 0);
} finally {
a.recycle();
Expand Down Expand Up @@ -81,7 +85,7 @@ protected void setData() {
setCustom_Texto(pictogramsLibraryGameGroup.getObjectName());
if (pictogramsLibraryGameGroup.getEditedPictogram().isEmpty()) {
Drawable drawable = findResource();
glideAttatcher.setHeight(icon.getHeight()).setWidth(icon.getWidth()).useDiskCacheStrategy().loadDrawable(drawable, this.icon);
glideAttatcher.setHeight(height).setWidth(width).useDiskCacheStrategy().loadDrawable(drawable, this.icon);
} else {
selectIcon();
}
Expand Down Expand Up @@ -131,4 +135,16 @@ public void selectIcon() {
else
glideAttatcher.useDiskCacheStrategy().loadDrawable(Uri.parse(pictogramsLibraryGameGroup.getUrl()), this.icon);
}

@Override
public void setData(int height, int with) {
id = pictogramsLibraryGameGroup.getId();
setCustom_Texto(pictogramsLibraryGameGroup.getObjectName());
if (pictogramsLibraryGameGroup.getEditedPictogram().isEmpty()) {
Drawable drawable = findResource();
glideAttatcher.setHeight(height).setWidth(with).useDiskCacheStrategy().loadDrawable(drawable, this.icon);
} else {
selectIcon();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public GroupView(@NonNull Context context, @Nullable AttributeSet attrs) {
try {
Custom_Texto = a.getString(R.styleable.Custom_Picto_Texto);
Custom_Color = a.getColor(R.styleable.Custom_Picto_Color, getResources().getColor(R.color.Black));
height = a.getInt(R.styleable.Custom_Picto_iconHeight,300);
width = a.getInt(R.styleable.Custom_Picto_iconWidth,300);
// Custom_Imagen = a.getInteger(R.styleable.Custom_Picto_Imagen, 0);
} finally {
a.recycle();
Expand All @@ -53,6 +55,8 @@ public GroupView(@NonNull Context context, @Nullable AttributeSet attrs, int def
try {
Custom_Texto = a.getString(R.styleable.Custom_Picto_Texto);
Custom_Color = a.getColor(R.styleable.Custom_Picto_Color, getResources().getColor(R.color.Black));
height = a.getInt(R.styleable.Custom_Picto_iconHeight,300);
width = a.getInt(R.styleable.Custom_Picto_iconWidth,300);
// Custom_Imagen = a.getInteger(R.styleable.Custom_Picto_Imagen, 0);
} finally {
a.recycle();
Expand Down Expand Up @@ -94,7 +98,7 @@ protected void setData() {
this.setCustom_Texto(pictogramsLibraryGroup.getObjectName());
if (pictogramsLibraryGroup.getEditedPictogram().isEmpty()) {
Drawable drawable = findResource();
glideAttatcher.setHeight(icon.getHeight()).setWidth(icon.getWidth()).useDiskCacheStrategy().setRadius(25).UseCornerRadius(true).loadDrawable(drawable, this.icon);
glideAttatcher.setHeight(height).setWidth(width).useDiskCacheStrategy().setRadius(25).UseCornerRadius(true).loadDrawable(drawable, this.icon);
} else {
selectIcon();
}
Expand Down Expand Up @@ -145,4 +149,15 @@ public void selectIcon() {
else
glideAttatcher.useDiskCacheStrategy().UseCornerRadius(true).setRadius(25).loadDrawable(Uri.parse(pictogramsLibraryGroup.getUrl()), this.icon);
}

@Override
public void setData(int height, int with) {
id = pictogramsLibraryGroup.getId();
this.setCustom_Texto(pictogramsLibraryGroup.getObjectName());
if (pictogramsLibraryGroup.getEditedPictogram().isEmpty()) {
Drawable drawable = findResource();
glideAttatcher.setHeight(height).setWidth(with).useDiskCacheStrategy().setRadius(25).UseCornerRadius(true).loadDrawable(drawable, this.icon);
} else {
selectIcon();
} }
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public PictoView(@NonNull Context context, @Nullable AttributeSet attrs) {
try {
Custom_Texto = a.getString(R.styleable.Custom_Picto_Texto);
Custom_Color = a.getColor(R.styleable.Custom_Picto_Color, getResources().getColor(R.color.Black));
// Custom_Imagen = a.getInteger(R.styleable.Custom_Picto_Imagen, 0);
height = a.getInt(R.styleable.Custom_Picto_iconHeight,300);
width = a.getInt(R.styleable.Custom_Picto_iconWidth,300);
// Custom_Imagen = a.getInteger(R.styleable.Custom_Picto_Imagen, 0);
} finally {
a.recycle();
}
Expand All @@ -54,6 +56,8 @@ public PictoView(@NonNull Context context, @Nullable AttributeSet attrs, int def
try {
Custom_Texto = a.getString(R.styleable.Custom_Picto_Texto);
Custom_Color = a.getColor(R.styleable.Custom_Picto_Color, getResources().getColor(R.color.Black));
height = a.getInt(R.styleable.Custom_Picto_iconHeight,300);
width = a.getInt(R.styleable.Custom_Picto_iconWidth,300);
// Custom_Imagen = a.getInteger(R.styleable.Custom_Picto_Imagen, 0);
} finally {
a.recycle();
Expand Down Expand Up @@ -158,7 +162,7 @@ protected void setData(){
cargarColor(pictogramsLibraryPictogram.getType());
if(pictogramsLibraryPictogram.getEditedPictogram().isEmpty()){
Drawable drawable = findResource();
glideAttatcher.setWidth(icon.getWidth()).setHeight(icon.getHeight()).useDiskCacheStrategy().loadDrawable(drawable,this.icon);
glideAttatcher.setWidth(width).setHeight(height).useDiskCacheStrategy().loadDrawable(drawable,this.icon);
}else{
selectIcon();
}
Expand Down Expand Up @@ -219,6 +223,20 @@ private void cargarColor(int color) {
}
}

@Override
public void setData(int height, int with) {
id= pictogramsLibraryPictogram.getId();
this.setCustom_Texto(pictogramsLibraryPictogram.getObjectName());
this.icon.setScaleType(ImageView.ScaleType.FIT_CENTER);
cargarColor(pictogramsLibraryPictogram.getType());
if(pictogramsLibraryPictogram.getEditedPictogram().isEmpty()){
Drawable drawable = findResource();
glideAttatcher.setWidth(height).setHeight(with).useDiskCacheStrategy().loadDrawable(drawable,this.icon);
}else{
selectIcon();
}
}

public Pictogram getPictogram() {
return pictogramsLibraryPictogram;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class TarjetView extends ConstraintLayout {
protected Drawable Custom_Imagen;
protected GlideAttatcher glideAttatcher;
protected Context mContext;
protected int height;
protected int width;

public TarjetView(@NonNull Context context) {
super(context);
Expand Down Expand Up @@ -88,6 +90,10 @@ protected void setData(){

}

public void setData(int height,int with){

}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Expand All @@ -100,4 +106,12 @@ protected void onFinishInflate() {
glideAttatcher.destroy();
}
}

public void setHeight(int height) {
this.height = height;
}

public void setWidth(int width) {
this.width = width;
}
}
3 changes: 3 additions & 0 deletions app/pictogramslibrary/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
<attr name="Texto" format="string" />
<attr name="Imagen" format="integer"/>
<attr name="Color" format="integer"/>
<attr name="iconHeight" format="integer"/>
<attr name="iconWidth" format="integer"/>
</declare-styleable>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<com.stonefacesoft.pictogramslibrary.view.GroupView
android:id="@+id/pictogram0"
android:layout_width="0dp"

android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/pictogram1"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/pictoview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.stonefacesoft.pictogramslibrary.PictogramsLibraryPictogram
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.stonefacesoft.pictogramslibrary.view.PictoView
android:layout_height="match_parent" android:layout_width="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
<attr name="Texto" format="string" />
<attr name="Imagen" format="integer"/>
<attr name="Color" format="integer"/>
<attr name="iconHeight" format="integer"/>
<attr name="iconWidth" format="integer"/>
</declare-styleable>

</resources>

0 comments on commit b06465c

Please sign in to comment.