Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xabber-android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
xabber-android
Commits
79d1abb6
Commit
79d1abb6
authored
Feb 06, 2013
by
Alexander Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resize avatar for shortcut icon. Close #107.
parent
086ea51d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
165 additions
and
8 deletions
+165
-8
AvatarManager.java
...m/xabber/android/data/extension/avatar/AvatarManager.java
+25
-0
BaseShortcutHelper.java
...ber/android/data/extension/avatar/BaseShortcutHelper.java
+29
-0
GingerbreadShortcutHelper.java
...roid/data/extension/avatar/GingerbreadShortcutHelper.java
+56
-0
HoneycombShortcutHelper.java
...ndroid/data/extension/avatar/HoneycombShortcutHelper.java
+47
-0
ContactList.java
src/com/xabber/android/ui/ContactList.java
+8
-8
No files found.
src/com/xabber/android/data/extension/avatar/AvatarManager.java
View file @
79d1abb6
...
@@ -462,4 +462,29 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
...
@@ -462,4 +462,29 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
setHash
(
bareAddress
,
hash
);
setHash
(
bareAddress
,
hash
);
}
}
}
}
/**
* @param bitmap
* @return Scaled bitmap to be used for shortcut.
*/
public
Bitmap
createShortcutBitmap
(
Bitmap
bitmap
)
{
int
size
=
getLauncherLargeIconSize
();
int
max
=
Math
.
max
(
bitmap
.
getWidth
(),
bitmap
.
getHeight
());
if
(
max
==
size
)
return
bitmap
;
double
scale
=
((
double
)
size
)
/
max
;
int
width
=
(
int
)
(
bitmap
.
getWidth
()
*
scale
);
int
height
=
(
int
)
(
bitmap
.
getHeight
()
*
scale
);
return
Bitmap
.
createScaledBitmap
(
bitmap
,
width
,
height
,
true
);
}
private
int
getLauncherLargeIconSize
()
{
if
(
Application
.
SDK_INT
<
9
)
return
BaseShortcutHelper
.
getLauncherLargeIconSize
();
else
if
(
Application
.
SDK_INT
<
11
)
return
GingerbreadShortcutHelper
.
getLauncherLargeIconSize
();
else
return
HoneycombShortcutHelper
.
getLauncherLargeIconSize
();
}
}
}
src/com/xabber/android/data/extension/avatar/BaseShortcutHelper.java
0 → 100644
View file @
79d1abb6
package
com
.
xabber
.
android
.
data
.
extension
.
avatar
;
import
android.content.res.Resources
;
import
com.xabber.android.data.Application
;
/**
* Helper class to create shortcuts under Android < 2.3.
*
* @author alexander.ivanov
*
*/
public
class
BaseShortcutHelper
{
/**
* Get the preferred launcher icon size. This is used when custom drawables
* are created (e.g., for shortcuts).
*
* Based on {@link android.app.ActivityManager#getLauncherLargeIconSize()}
* for Android 3+.
*
* @return dimensions of square icons in terms of pixels
*/
static
int
getLauncherLargeIconSize
()
{
final
Resources
res
=
Application
.
getInstance
().
getResources
();
return
res
.
getDimensionPixelSize
(
android
.
R
.
dimen
.
app_icon_size
);
}
}
src/com/xabber/android/data/extension/avatar/GingerbreadShortcutHelper.java
0 → 100644
View file @
79d1abb6
package
com
.
xabber
.
android
.
data
.
extension
.
avatar
;
import
android.annotation.TargetApi
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.os.Build
;
import
android.util.DisplayMetrics
;
import
com.xabber.android.data.Application
;
/**
* Helper class to create shortcuts under Android >= 2.3.
*
* @author alexander.ivanov
*
*/
@TargetApi
(
Build
.
VERSION_CODES
.
GINGERBREAD
)
public
class
GingerbreadShortcutHelper
{
/**
* Get the preferred launcher icon size. This is used when custom drawables
* are created (e.g., for shortcuts).
*
* Based on {@link android.app.ActivityManager#getLauncherLargeIconSize()}
* for Android 3+.
*
* @return dimensions of square icons in terms of pixels
*/
static
int
getLauncherLargeIconSize
()
{
final
Resources
res
=
Application
.
getInstance
().
getResources
();
final
int
size
=
res
.
getDimensionPixelSize
(
android
.
R
.
dimen
.
app_icon_size
);
if
((
res
.
getConfiguration
().
screenLayout
&
Configuration
.
SCREENLAYOUT_SIZE_MASK
)
!=
Configuration
.
SCREENLAYOUT_SIZE_XLARGE
)
{
return
size
;
}
final
int
density
=
res
.
getDisplayMetrics
().
densityDpi
;
switch
(
density
)
{
case
DisplayMetrics
.
DENSITY_LOW
:
return
(
size
*
DisplayMetrics
.
DENSITY_MEDIUM
)
/
DisplayMetrics
.
DENSITY_LOW
;
case
DisplayMetrics
.
DENSITY_MEDIUM
:
return
(
size
*
DisplayMetrics
.
DENSITY_HIGH
)
/
DisplayMetrics
.
DENSITY_MEDIUM
;
case
DisplayMetrics
.
DENSITY_HIGH
:
return
(
size
*
DisplayMetrics
.
DENSITY_XHIGH
)
/
DisplayMetrics
.
DENSITY_HIGH
;
case
DisplayMetrics
.
DENSITY_XHIGH
:
return
(
size
*
DisplayMetrics
.
DENSITY_MEDIUM
*
2
)
/
DisplayMetrics
.
DENSITY_XHIGH
;
default
:
return
size
;
}
}
}
src/com/xabber/android/data/extension/avatar/HoneycombShortcutHelper.java
0 → 100644
View file @
79d1abb6
package
com
.
xabber
.
android
.
data
.
extension
.
avatar
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
android.content.Context
;
import
com.xabber.android.data.Application
;
/**
* Helper class to create shortcuts under Android >= 3.
*
* @author alexander.ivanov
*
*/
public
class
HoneycombShortcutHelper
{
/**
* Get the preferred launcher icon size. This is used when custom drawables
* are created (e.g., for shortcuts).
*
* @return dimensions of square icons in terms of pixels
*/
static
int
getLauncherLargeIconSize
()
{
android
.
app
.
ActivityManager
activityManager
=
(
android
.
app
.
ActivityManager
)
Application
.
getInstance
().
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
Method
method
;
try
{
method
=
activityManager
.
getClass
().
getMethod
(
"getLauncherLargeIconSize"
,
(
Class
[])
null
);
}
catch
(
SecurityException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
e
);
}
try
{
return
(
Integer
)
method
.
invoke
(
activityManager
,
(
Object
[])
null
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
IllegalAccessException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
src/com/xabber/android/ui/ContactList.java
View file @
79d1abb6
...
@@ -25,6 +25,7 @@ import android.content.DialogInterface.OnCancelListener;
...
@@ -25,6 +25,7 @@ import android.content.DialogInterface.OnCancelListener;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.res.ColorStateList
;
import
android.content.res.ColorStateList
;
import
android.content.res.TypedArray
;
import
android.content.res.TypedArray
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
android.graphics.drawable.Drawable
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Bundle
;
...
@@ -973,18 +974,17 @@ public class ContactList extends ManagedListActivity implements
...
@@ -973,18 +974,17 @@ public class ContactList extends ManagedListActivity implements
abstractContact
.
getUser
()));
abstractContact
.
getUser
()));
intent
.
putExtra
(
Intent
.
EXTRA_SHORTCUT_NAME
,
intent
.
putExtra
(
Intent
.
EXTRA_SHORTCUT_NAME
,
abstractContact
.
getName
());
abstractContact
.
getName
());
Bitmap
bitmap
;
if
(
MUCManager
.
getInstance
()
if
(
MUCManager
.
getInstance
()
.
hasRoom
(
abstractContact
.
getAccount
(),
.
hasRoom
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()))
abstractContact
.
getUser
()))
intent
.
putExtra
(
bitmap
=
AvatarManager
.
getInstance
().
getRoomBitmap
(
Intent
.
EXTRA_SHORTCUT_ICON
,
abstractContact
.
getUser
());
AvatarManager
.
getInstance
().
getRoomBitmap
(
abstractContact
.
getUser
()));
else
else
intent
.
putExtra
(
bitmap
=
AvatarManager
.
getInstance
().
getUserBitmap
(
Intent
.
EXTRA_SHORTCUT_ICON
,
abstractContact
.
getUser
());
AvatarManager
.
getInstance
().
getUserBitmap
(
intent
.
putExtra
(
Intent
.
EXTRA_SHORTCUT_ICON
,
AvatarManager
abstractContact
.
getUser
()
));
.
getInstance
().
createShortcutBitmap
(
bitmap
));
setResult
(
RESULT_OK
,
intent
);
setResult
(
RESULT_OK
,
intent
);
finish
();
finish
();
}
else
{
}
else
{
...
...
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