Internal thumbnail, better than lutim generated
This commit is contained in:
parent
15564d1b49
commit
3fec21c32d
3 changed files with 37 additions and 20 deletions
|
@ -214,13 +214,7 @@ public class NetworkManager {
|
|||
String hashOutput = msg.getString("short");
|
||||
String realHashOutput = msg.getString("real_short");
|
||||
String token = msg.getString("token");
|
||||
String thumb = msg.getString("thumb");
|
||||
//get thumbnail and transform it to useful data
|
||||
if(thumb != null && thumb.contains(","))
|
||||
thumb = thumb.substring(thumb.indexOf(","));
|
||||
byte[] thumbData = Base64.decode(thumb, Base64.DEFAULT);
|
||||
System.out.println("Data is not null? " + thumbData.length);
|
||||
imgOutput = new Img(0, siteUrl, hashOutput, realHashOutput, Calendar.getInstance(), nbDays, thumbData,token);
|
||||
imgOutput = new Img(0, siteUrl, hashOutput, realHashOutput, Calendar.getInstance(), nbDays, null,token);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.content.ContentResolver;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
import android.os.Bundle;
|
||||
|
@ -64,6 +65,7 @@ public class UploadActivity extends AppCompatActivity {
|
|||
private List<String> urls;
|
||||
private List<Integer> deletedDays;
|
||||
private ProgressDialog progressDialog;
|
||||
private Bitmap bt;
|
||||
|
||||
//static value to handle storage durations options
|
||||
private static final int NEVER = 0;
|
||||
|
@ -72,6 +74,8 @@ public class UploadActivity extends AppCompatActivity {
|
|||
private static final int THIRTY = 30;
|
||||
private static final int YEAR = 365;
|
||||
|
||||
private static final int THUMB_MAX_SIDE = 800;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -119,6 +123,10 @@ public class UploadActivity extends AppCompatActivity {
|
|||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
bt.compress(Bitmap.CompressFormat.JPEG,70,outputStream);
|
||||
image.setThumbData(outputStream.toByteArray());
|
||||
|
||||
//add uploaded img to history
|
||||
Long id = Database.getInstance(getApplicationContext()).addImage(image);
|
||||
//dismiss progressDialog
|
||||
|
@ -234,9 +242,9 @@ public class UploadActivity extends AppCompatActivity {
|
|||
if(imageUri != null) {
|
||||
ContentResolver contentResolver = getContentResolver();
|
||||
//display it in the imageView
|
||||
Bitmap bt;
|
||||
try {
|
||||
bt = MediaStore.Images.Media.getBitmap(contentResolver, imageUri);
|
||||
bt = generateThumb(bt);
|
||||
ImageView view = (ImageView) findViewById(R.id.thumbnail_main);
|
||||
view.setImageBitmap(bt);
|
||||
} catch (IOException e) {
|
||||
|
@ -332,6 +340,23 @@ public class UploadActivity extends AppCompatActivity {
|
|||
|
||||
}
|
||||
|
||||
private Bitmap generateThumb(Bitmap original){
|
||||
|
||||
int ratio = 1;
|
||||
if(original.getWidth()>THUMB_MAX_SIDE || original.getHeight() > THUMB_MAX_SIDE){
|
||||
if(original.getWidth()>original.getHeight())
|
||||
ratio = original.getWidth()/THUMB_MAX_SIDE;
|
||||
else
|
||||
ratio = original.getHeight()/THUMB_MAX_SIDE;
|
||||
}
|
||||
|
||||
int newWidth = original.getWidth()/ratio;
|
||||
int newHeight = original.getHeight()/ratio;
|
||||
|
||||
Bitmap thumb = Bitmap.createScaledBitmap(original,newWidth,newHeight,false);
|
||||
return thumb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode,Intent returnIntent) {
|
||||
if(resultCode == RESULT_OK){
|
||||
|
|
|
@ -30,10 +30,12 @@ public class Img {
|
|||
private String url;
|
||||
private Calendar date;
|
||||
private int storageDuration;
|
||||
private byte[] thumb;
|
||||
private Bitmap image;
|
||||
private String shortHash;
|
||||
private String realShortHash;
|
||||
private String token;
|
||||
private int val = 0;
|
||||
|
||||
public Img(long id, String url, String shortHash, String realShortHash, Calendar date, int storageDuration, byte[] thumbData, String token) {
|
||||
this.url = url;
|
||||
|
@ -43,11 +45,10 @@ public class Img {
|
|||
this.date = date;
|
||||
this.storageDuration = storageDuration;
|
||||
this.token = token;
|
||||
if(thumbData != null) {
|
||||
image = BitmapFactory.decodeByteArray(thumbData, 0, thumbData.length);
|
||||
thumb = thumbData;
|
||||
if(thumb != null) {
|
||||
image = BitmapFactory.decodeByteArray(thumb, 0, thumb.length);
|
||||
}
|
||||
else
|
||||
image = null;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
|
@ -87,14 +88,11 @@ public class Img {
|
|||
|
||||
public byte[] getThumbData()
|
||||
{
|
||||
if(image != null) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||
return stream.toByteArray();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return thumb;
|
||||
}
|
||||
|
||||
public void setThumbData(byte[] thumbData){
|
||||
thumb = thumbData;
|
||||
}
|
||||
|
||||
public String getToken(){
|
||||
|
|
Loading…
Reference in a new issue