Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
org.benoitharrault.ameixanonfree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
org.benoitharrault.ameixanonfree
Commits
35ba1cea
Commit
35ba1cea
authored
May 30, 2016
by
Xphnx
Browse files
Options
Downloads
Patches
Plain Diff
Delete IceImageUtils.java
parent
2fb2f801
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/ovh/ice/icecons/IceImageUtils.java
+0
-146
0 additions, 146 deletions
app/src/main/java/ovh/ice/icecons/IceImageUtils.java
with
0 additions
and
146 deletions
app/src/main/java/ovh/ice/icecons/IceImageUtils.java
deleted
100644 → 0
+
0
−
146
View file @
2fb2f801
package
ovh.ice.icecons
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.os.AsyncTask
;
import
android.view.View
;
import
android.widget.ImageView
;
import
java.lang.ref.WeakReference
;
public
class
IceImageUtils
{
public
static
void
bitmapLoadAsync
(
ImageView
imageView
,
Resources
res
,
int
resId
,
int
width
,
int
height
)
{
BitmapWorkerTask
task
=
new
BitmapWorkerTask
(
imageView
);
task
.
res
=
res
;
task
.
resId
=
resId
;
task
.
width
=
width
;
task
.
height
=
height
;
task
.
execute
(
resId
);
}
public
static
Bitmap
bitmapLoad
(
Resources
res
,
int
resId
,
int
width
,
int
height
)
{
// calc scale, load appropriately sampled bitmap from given resource
BitmapFactory
.
Options
resOptions
=
new
BitmapFactory
.
Options
();
resOptions
.
inJustDecodeBounds
=
true
;
BitmapFactory
.
decodeResource
(
res
,
resId
,
resOptions
);
int
resHeight
=
resOptions
.
outHeight
;
int
resWidth
=
resOptions
.
outWidth
;
float
xScale
=
(
float
)
width
/
(
float
)
resWidth
;
float
yScale
=
(
float
)
height
/
(
float
)
resHeight
;
float
scale
=
Math
.
max
(
xScale
,
yScale
);
if
(
scale
>
1
)
if
(
width
==
0
)
width
=
Math
.
round
(
resWidth
/
scale
);
else
if
(
height
==
0
)
height
=
Math
.
round
(
resHeight
/
scale
);
resOptions
.
inSampleSize
=
sampleSize
(
scale
);
resWidth
/=
resOptions
.
inSampleSize
;
resHeight
/=
resOptions
.
inSampleSize
;
resOptions
.
inJustDecodeBounds
=
false
;
Bitmap
rawBitmap
=
BitmapFactory
.
decodeResource
(
res
,
resId
,
resOptions
);
// compare aspect ratio and crop
rawBitmap
=
bitmapCrop
(
rawBitmap
,
width
,
height
,
resWidth
,
resHeight
);
// scale to desired size
return
Bitmap
.
createScaledBitmap
(
rawBitmap
,
width
,
height
,
true
);
}
// calc sample size for scaled resource loading
private
static
int
sampleSize
(
float
scale
)
{
int
size
=
1
;
while
(
scale
<
0.5f
)
{
size
*=
2
;
scale
*=
2
;
}
return
size
;
}
// crop bitmap to chosen aspect ratio
private
static
Bitmap
bitmapCrop
(
Bitmap
rawBitmap
,
int
width
,
int
height
,
int
resWidth
,
int
resHeight
)
{
int
cropX
,
cropY
,
cropWidth
,
cropHeight
;
float
xScale
=
(
float
)
width
/
(
float
)
resWidth
;
float
yScale
=
(
float
)
height
/
(
float
)
resHeight
;
float
scale
=
Math
.
max
(
xScale
,
yScale
);
if
(
xScale
>=
yScale
)
{
cropWidth
=
Math
.
round
(
resWidth
);
cropX
=
0
;
cropHeight
=
Math
.
round
(
height
/
scale
);
cropY
=
(
resHeight
-
cropHeight
)
/
2
;
}
else
{
cropWidth
=
Math
.
round
(
width
/
scale
);
cropX
=
(
resWidth
-
cropWidth
)
/
2
;
cropHeight
=
Math
.
round
(
resHeight
);
cropY
=
0
;
}
return
Bitmap
.
createBitmap
(
rawBitmap
,
cropX
,
cropY
,
cropWidth
,
cropHeight
);
}
}
class
BitmapWorkerTask
extends
AsyncTask
<
Integer
,
Void
,
Bitmap
>
{
private
final
WeakReference
<
ImageView
>
imageViewReference
;
Resources
res
;
int
resId
,
width
,
height
;
public
BitmapWorkerTask
(
ImageView
imageView
)
{
imageViewReference
=
new
WeakReference
<
ImageView
>(
imageView
);
}
// Decode image in background
@Override
protected
Bitmap
doInBackground
(
Integer
...
parameters
)
{
return
IceImageUtils
.
bitmapLoad
(
res
,
resId
,
width
,
height
);
}
// Check if image view still exists and set bitmap
@Override
protected
void
onPostExecute
(
Bitmap
bitmap
)
{
if
(
imageViewReference
!=
null
&&
bitmap
!=
null
)
{
final
ImageView
imageView
=
imageViewReference
.
get
();
if
(
imageView
!=
null
)
{
imageView
.
setImageBitmap
(
bitmap
);
imageView
.
setAlpha
(
0
f
);
imageView
.
setVisibility
(
View
.
VISIBLE
);
imageView
.
animate
()
.
alpha
(
1
f
)
.
setDuration
(
res
.
getInteger
(
android
.
R
.
integer
.
config_mediumAnimTime
)
)
.
setListener
(
null
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment