Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
meser
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Muhammad Suryono
meser
Commits
806a45c1
Commit
806a45c1
authored
Aug 28, 2020
by
iman Fauzi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into cart
parents
35045735
408c233d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
7 deletions
+54
-7
FormProductActivity.java
...rc/main/java/com/yono/messeripos/FormProductActivity.java
+4
-2
ProductModels.java
...c/main/java/com/yono/messeripos/models/ProductModels.java
+4
-0
Utils.java
app/src/main/java/com/yono/messeripos/utils/Utils.java
+46
-5
No files found.
app/src/main/java/com/yono/messeripos/FormProductActivity.java
View file @
806a45c1
...
...
@@ -179,6 +179,7 @@ public class FormProductActivity extends AppCompatActivity {
productModels
.
getPriceProduct
()
!=
0
||
productModels
.
getStockProduct
()
!=
0
){
progressDialog
.
setCancelable
(
false
);
progressDialog
.
show
();
ProductService
productService
=
client
.
Client
(
ProductService
.
class
);
Log
.
i
(
"data_post"
,
"saveProduct: "
+
utils
.
convertGson
(
productModels
));
...
...
@@ -208,7 +209,8 @@ public class FormProductActivity extends AppCompatActivity {
@Override
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 {
binding
.
ivProduct
.
setImageBitmap
(
utils
.
decodeImageBase64
(
utils
.
convertImageBase64File
(
getRealPathFromURI
(
selectedImage
))));
productModels
.
setImageProduct
(
getRealPathFromURI
(
selectedImage
));
productModels
.
setImageProduct
(
utils
.
convertImageBase64File
(
getRealPathFromURI
(
selectedImage
)
));
// utils.convertImageBase64File(getRealPathFromURI(selectedImage))
}
}
...
...
app/src/main/java/com/yono/messeripos/models/ProductModels.java
View file @
806a45c1
...
...
@@ -3,6 +3,7 @@ package com.yono.messeripos.models;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.ImageView
;
import
androidx.databinding.BindingAdapter
;
...
...
@@ -15,6 +16,8 @@ import com.yono.messeripos.api.ApiHelper;
import
com.yono.messeripos.utils.Utils
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
public
class
ProductModels
<
T
>
implements
Parcelable
{
...
...
@@ -131,6 +134,7 @@ public class ProductModels<T> implements Parcelable {
@BindingAdapter
(
"path"
)
public
static
void
setPathImage
(
ImageView
view
,
String
path
)
{
Utils
utils
=
new
Utils
();
if
(
TextUtils
.
isEmpty
(
path
))
view
.
setImageResource
(
R
.
drawable
.
ic_meser_create
);
else
{
view
.
setImageBitmap
(
utils
.
decodeImageBase64
(
path
));
...
...
app/src/main/java/com/yono/messeripos/utils/Utils.java
View file @
806a45c1
...
...
@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import
android.graphics.BitmapFactory
;
import
android.os.Build
;
import
android.util.Base64
;
import
android.util.Log
;
import
android.widget.Toast
;
import
androidx.annotation.RequiresApi
;
...
...
@@ -86,10 +87,18 @@ public class Utils {
public
String
convertImageBase64File
(
String
pathname
){
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
();
String
encodeImage
=
Base64
.
encodeToString
(
b
,
Base64
.
DEFAULT
);
Log
.
i
(
"Count_encode"
,
"convertImageBase64Resource: "
+
bitmap
.
getByteCount
());
return
encodeImage
;
}
...
...
@@ -102,23 +111,55 @@ public class Utils {
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
byte
[]
b
=
baos
.
toByteArray
();
Bitmap
bitmap
=
BitmapFactory
.
decodeResource
(
resource
,
id
);
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
baos
);
String
encodeImage
=
Base64
.
encodeToString
(
b
,
Base64
.
DEFAULT
);
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
false
;
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
;
}
public
Bitmap
decodeImageBase64
(
String
source
){
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
byte
[]
imageBytes
=
baos
.
toByteArray
();
imageBytes
=
Base64
.
decode
(
source
,
Base64
.
DEFAULT
);
Bitmap
decodeImages
=
BitmapFactory
.
decodeByteArray
(
imageBytes
,
0
,
imageBytes
.
length
);
// Bitmap bf = BitmapFactory.decodeFile(source, options);
Log
.
i
(
"Size bitmap"
,
"decodeImageBase64: "
+
decodeImages
.
getByteCount
());
return
decodeImages
;
}
public
long
grandTotalCart
(){
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment