Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
29134206
Commit
29134206
authored
Jul 01, 2018
by
Sajal Narang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix image upload crash, load image in a background thread, fix #83
parent
c77e947b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
55 deletions
+14
-55
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/fragment/AddEventFragment.java
...n/ac/iitb/gymkhana/iitbapp/fragment/AddEventFragment.java
+6
-47
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/fragment/FeedFragment.java
...va/in/ac/iitb/gymkhana/iitbapp/fragment/FeedFragment.java
+8
-8
No files found.
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/fragment/AddEventFragment.java
View file @
29134206
...
...
@@ -14,9 +14,11 @@ import android.os.Bundle;
import
android.provider.MediaStore
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.widget.ImageViewCompat
;
import
android.util.Base64
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.PixelCopy
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.Button
;
...
...
@@ -30,6 +32,8 @@ import android.widget.TextView;
import
android.widget.TimePicker
;
import
android.widget.Toast
;
import
com.squareup.picasso.Picasso
;
import
java.io.ByteArrayOutputStream
;
import
java.sql.Timestamp
;
import
java.util.Arrays
;
...
...
@@ -293,53 +297,8 @@ public class AddEventFragment extends BaseFragment {
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
==
RESULT_LOAD_IMAGE
&&
resultCode
==
RESULT_OK
&&
null
!=
data
)
{
Uri
selectedImage
=
data
.
getData
();
String
[]
filePathColumn
=
{
MediaStore
.
Images
.
Media
.
DATA
};
Cursor
cursor
=
getActivity
().
getContentResolver
().
query
(
selectedImage
,
filePathColumn
,
null
,
null
,
null
);
cursor
.
moveToFirst
();
int
columnIndex
=
cursor
.
getColumnIndex
(
filePathColumn
[
0
]);
String
picturePath
=
cursor
.
getString
(
columnIndex
);
cursor
.
close
();
eventPictureImageView
.
setImageBitmap
(
getScaledBitmap
(
picturePath
,
imageButton
.
getWidth
(),
imageButton
.
getHeight
()));
eventPictureImageView
.
setScaleType
(
ImageView
.
ScaleType
.
CENTER_CROP
);
base64Image
=
convertImageToString
(
getScaledBitmap
(
picturePath
,
800
,
800
));
Log
.
d
(
TAG
,
"onActivityResult: "
+
base64Image
);
ImageViewCompat
.
setImageTintList
(
eventPictureImageView
,
null
);
Picasso
.
with
(
getContext
()).
load
(
selectedImage
).
into
(
eventPictureImageView
);
}
}
private
Bitmap
getScaledBitmap
(
String
picturePath
,
int
width
,
int
height
)
{
BitmapFactory
.
Options
sizeOptions
=
new
BitmapFactory
.
Options
();
sizeOptions
.
inJustDecodeBounds
=
true
;
BitmapFactory
.
decodeFile
(
picturePath
,
sizeOptions
);
int
inSampleSize
=
calculateInSampleSize
(
sizeOptions
,
width
,
height
);
sizeOptions
.
inJustDecodeBounds
=
false
;
sizeOptions
.
inSampleSize
=
inSampleSize
;
return
BitmapFactory
.
decodeFile
(
picturePath
,
sizeOptions
);
}
private
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
)
{
// Calculate ratios of height and width to requested height and
// width
final
int
heightRatio
=
Math
.
round
((
float
)
height
/
(
float
)
reqHeight
);
final
int
widthRatio
=
Math
.
round
((
float
)
width
/
(
float
)
reqWidth
);
// Choose the smallest ratio as inSampleSize value, this will
// guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize
=
heightRatio
<
widthRatio
?
heightRatio
:
widthRatio
;
}
return
inSampleSize
;
}
}
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/fragment/FeedFragment.java
View file @
29134206
...
...
@@ -58,6 +58,14 @@ public class FeedFragment extends BaseFragment {
fab
=
(
FloatingActionButton
)
view
.
findViewById
(
R
.
id
.
fab
);
feedSwipeRefreshLayout
=
view
.
findViewById
(
R
.
id
.
feed_swipe_refresh_layout
);
feedSwipeRefreshLayout
.
setOnRefreshListener
(
new
SwipeRefreshLayout
.
OnRefreshListener
()
{
@Override
public
void
onRefresh
()
{
updateFeed
();
}
});
fab
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
...
...
@@ -81,14 +89,6 @@ public class FeedFragment extends BaseFragment {
new
showEventsFromDB
().
execute
();
updateFeed
();
feedSwipeRefreshLayout
=
getActivity
().
findViewById
(
R
.
id
.
feed_swipe_refresh_layout
);
feedSwipeRefreshLayout
.
setOnRefreshListener
(
new
SwipeRefreshLayout
.
OnRefreshListener
()
{
@Override
public
void
onRefresh
()
{
updateFeed
();
}
});
}
private
void
updateFeed
()
{
...
...
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