Commit 806a45c1 authored by iman Fauzi's avatar iman Fauzi

Merge branch 'dev' into cart

parents 35045735 408c233d
...@@ -179,6 +179,7 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -179,6 +179,7 @@ public class FormProductActivity extends AppCompatActivity {
productModels.getPriceProduct() != 0 || productModels.getPriceProduct() != 0 ||
productModels.getStockProduct() != 0 productModels.getStockProduct() != 0
){ ){
progressDialog.setCancelable(false);
progressDialog.show(); progressDialog.show();
ProductService productService = client.Client(ProductService.class); ProductService productService = client.Client(ProductService.class);
Log.i("data_post", "saveProduct: "+utils.convertGson(productModels)); Log.i("data_post", "saveProduct: "+utils.convertGson(productModels));
...@@ -208,7 +209,8 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -208,7 +209,8 @@ public class FormProductActivity extends AppCompatActivity {
@Override @Override
public void onFailure(Call<DataResponse<ProductModels>> call, Throwable t) { public void onFailure(Call<DataResponse<ProductModels>> call, Throwable t) {
t.printStackTrace(); progressDialog.dismiss();
Log.e("Error input", "onFailure: ",t );
} }
}); });
} }
...@@ -267,7 +269,7 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -267,7 +269,7 @@ public class FormProductActivity extends AppCompatActivity {
binding.ivProduct.setImageBitmap(utils.decodeImageBase64(utils.convertImageBase64File(getRealPathFromURI(selectedImage)))); binding.ivProduct.setImageBitmap(utils.decodeImageBase64(utils.convertImageBase64File(getRealPathFromURI(selectedImage))));
productModels.setImageProduct(getRealPathFromURI(selectedImage)); productModels.setImageProduct(utils.convertImageBase64File(getRealPathFromURI(selectedImage)));
// utils.convertImageBase64File(getRealPathFromURI(selectedImage)) // utils.convertImageBase64File(getRealPathFromURI(selectedImage))
} }
} }
......
...@@ -3,6 +3,7 @@ package com.yono.messeripos.models; ...@@ -3,6 +3,7 @@ package com.yono.messeripos.models;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.databinding.BindingAdapter; import androidx.databinding.BindingAdapter;
...@@ -15,6 +16,8 @@ import com.yono.messeripos.api.ApiHelper; ...@@ -15,6 +16,8 @@ import com.yono.messeripos.api.ApiHelper;
import com.yono.messeripos.utils.Utils; import com.yono.messeripos.utils.Utils;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class ProductModels<T> implements Parcelable { public class ProductModels<T> implements Parcelable {
...@@ -131,6 +134,7 @@ public class ProductModels<T> implements Parcelable { ...@@ -131,6 +134,7 @@ public class ProductModels<T> implements Parcelable {
@BindingAdapter("path") @BindingAdapter("path")
public static void setPathImage(ImageView view, String path) { public static void setPathImage(ImageView view, String path) {
Utils utils = new Utils(); Utils utils = new Utils();
if (TextUtils.isEmpty(path)) view.setImageResource(R.drawable.ic_meser_create); if (TextUtils.isEmpty(path)) view.setImageResource(R.drawable.ic_meser_create);
else { else {
view.setImageBitmap(utils.decodeImageBase64(path)); view.setImageBitmap(utils.decodeImageBase64(path));
......
...@@ -6,6 +6,7 @@ import android.graphics.Bitmap; ...@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Build; import android.os.Build;
import android.util.Base64; import android.util.Base64;
import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
...@@ -86,10 +87,18 @@ public class Utils { ...@@ -86,10 +87,18 @@ public class Utils {
public String convertImageBase64File(String pathname){ public String convertImageBase64File(String pathname){
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeFile(pathname);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inSampleSize = 3;
// options.inSampleSize = calculateInSampleSize(options, 20,20);
Bitmap bitmap = BitmapFactory.decodeFile(pathname,options);
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
byte[] b = baos.toByteArray(); byte[] b = baos.toByteArray();
String encodeImage = Base64.encodeToString(b, Base64.DEFAULT); String encodeImage = Base64.encodeToString(b, Base64.DEFAULT);
Log.i("Count_encode", "convertImageBase64Resource: "+bitmap.getByteCount());
return encodeImage; return encodeImage;
} }
...@@ -102,23 +111,55 @@ public class Utils { ...@@ -102,23 +111,55 @@ public class Utils {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] b = baos.toByteArray(); byte[] b = baos.toByteArray();
Bitmap bitmap = BitmapFactory.decodeResource(resource, id); BitmapFactory.Options options = new BitmapFactory.Options();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); options.inJustDecodeBounds = false;
String encodeImage = Base64.encodeToString(b, Base64.DEFAULT); options.inSampleSize = 3;
options.inSampleSize = calculateInSampleSize(options, 500,500);
Bitmap bitmap = BitmapFactory.decodeResource(resource, id, options);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
String encodeImage = Base64.encodeToString(b, Base64.DEFAULT);
Log.i("Count_encode", "convertImageBase64Resource: "+bitmap.getByteCount());
return encodeImage; return encodeImage;
} }
public Bitmap decodeImageBase64(String source){ public Bitmap decodeImageBase64(String source){
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] imageBytes = baos.toByteArray(); byte[] imageBytes = baos.toByteArray();
imageBytes = Base64.decode(source, Base64.DEFAULT); imageBytes = Base64.decode(source, Base64.DEFAULT);
Bitmap decodeImages = BitmapFactory.decodeByteArray(imageBytes,0,imageBytes.length); Bitmap decodeImages = BitmapFactory.decodeByteArray(imageBytes,0,imageBytes.length);
// Bitmap bf = BitmapFactory.decodeFile(source, options);
Log.i("Size bitmap", "decodeImageBase64: "+decodeImages.getByteCount());
return decodeImages; return decodeImages;
} }
public long grandTotalCart(){ public long grandTotalCart(){
return grandTotal; return grandTotal;
} }
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) >= reqHeight
&& (halfWidth / inSampleSize) >= reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment