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
ebc3d2d4
Commit
ebc3d2d4
authored
Aug 04, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AccountInfoEditor: avatar can be taken from camera. avatar can be removed.
parent
2023e181
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
113 additions
and
17 deletions
+113
-17
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-0
AvatarManager.java
...m/xabber/android/data/extension/avatar/AvatarManager.java
+10
-4
AccountInfoEditorFragment.java
...java/com/xabber/android/ui/AccountInfoEditorFragment.java
+85
-13
change_avatar.xml
app/src/main/res/menu/change_avatar.xml
+14
-0
contact_viewer.xml
app/src/main/res/values/contact_viewer.xml
+3
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
ebc3d2d4
...
...
@@ -32,6 +32,7 @@
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<application
android:name=
".data.Application"
...
...
app/src/main/java/com/xabber/android/data/extension/avatar/AvatarManager.java
View file @
ebc3d2d4
...
...
@@ -22,6 +22,7 @@ import android.graphics.drawable.BitmapDrawable;
import
android.graphics.drawable.ColorDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.graphics.drawable.LayerDrawable
;
import
android.support.annotation.NonNull
;
import
com.xabber.android.R
;
import
com.xabber.android.data.Application
;
...
...
@@ -286,13 +287,18 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
if
(
value
!=
null
)
{
return
new
BitmapDrawable
(
application
.
getResources
(),
value
);
}
else
{
Drawable
[]
layers
=
new
Drawable
[
2
];
layers
[
0
]
=
new
ColorDrawable
(
accountColors
[
AccountManager
.
getInstance
().
getColorLevel
(
account
)]);
layers
[
1
]
=
application
.
getResources
().
getDrawable
(
R
.
drawable
.
ic_avatar_1
);
return
new
LayerDrawable
(
layers
);
return
getDefaultAccountAvatar
(
account
);
}
}
@NonNull
public
Drawable
getDefaultAccountAvatar
(
String
account
)
{
Drawable
[]
layers
=
new
Drawable
[
2
];
layers
[
0
]
=
new
ColorDrawable
(
accountColors
[
AccountManager
.
getInstance
().
getColorLevel
(
account
)]);
layers
[
1
]
=
application
.
getResources
().
getDrawable
(
R
.
drawable
.
ic_avatar_1
);
return
new
LayerDrawable
(
layers
);
}
/**
* Gets avatar for regular user.
*
...
...
app/src/main/java/com/xabber/android/ui/AccountInfoEditorFragment.java
View file @
ebc3d2d4
...
...
@@ -5,13 +5,16 @@ import android.app.Fragment;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.provider.MediaStore
;
import
android.support.annotation.Nullable
;
import
android.view.LayoutInflater
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.PopupMenu
;
import
android.widget.TextView
;
import
android.widget.Toast
;
...
...
@@ -44,6 +47,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
public
static
final
int
MAX_AVATAR_SIZE_PIXELS
=
192
;
public
static
final
String
TEMP_FILE_NAME
=
"cropped"
;
public
static
final
int
KB_SIZE_IN_BYTES
=
1024
;
public
static
final
int
TAKE_PHOTO_REQUEST_CODE
=
3
;
private
VCard
vCard
;
private
EditText
prefixName
;
...
...
@@ -54,7 +58,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
private
EditText
nickName
;
private
String
account
;
private
ImageView
avatar
;
private
Uri
cropped
ImageUri
;
private
Uri
newAvatar
ImageUri
;
private
EditText
organization
;
private
EditText
organizationUnit
;
private
EditText
birthDate
;
...
...
@@ -73,6 +77,9 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
private
TextView
avatarSize
;
private
Lister
lister
;
private
View
changeAvatarButton
;
private
Uri
photoFileUri
;
interface
Lister
{
void
onVCardSavingStarted
();
...
...
@@ -134,12 +141,13 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
nickName
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_nickname
);
avatar
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
vcard_avatar
);
view
.
findViewById
(
R
.
id
.
vcard_change_avatar
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
changeAvatar
();
}
}
changeAvatarButton
=
view
.
findViewById
(
R
.
id
.
vcard_change_avatar
);
changeAvatarButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
changeAvatar
();
}
}
);
birthDate
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_birth_date
);
...
...
@@ -228,13 +236,75 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
}
private
void
changeAvatar
()
{
PopupMenu
menu
=
new
PopupMenu
(
getActivity
(),
changeAvatarButton
);
menu
.
inflate
(
R
.
menu
.
change_avatar
);
menu
.
setOnMenuItemClickListener
(
new
PopupMenu
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
switch
(
item
.
getItemId
())
{
case
R
.
id
.
action_choose_from_gallery
:
chooseFromGallery
();
return
true
;
case
R
.
id
.
action_take_photo
:
takePhoto
();
return
true
;
case
R
.
id
.
action_remove_avatar
:
removeAvatar
();
return
true
;
default
:
return
false
;
}
}
});
menu
.
show
();
}
private
void
chooseFromGallery
()
{
Crop
.
pickImage
(
getActivity
());
}
private
void
takePhoto
()
{
Intent
takePictureIntent
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
if
(
takePictureIntent
.
resolveActivity
(
getActivity
().
getPackageManager
())
!=
null
)
{
File
imageFile
=
null
;
try
{
imageFile
=
createImageFile
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(
imageFile
!=
null
)
{
photoFileUri
=
Uri
.
fromFile
(
imageFile
);
takePictureIntent
.
putExtra
(
MediaStore
.
EXTRA_OUTPUT
,
photoFileUri
);
startActivityForResult
(
takePictureIntent
,
TAKE_PHOTO_REQUEST_CODE
);
}
}
}
private
File
createImageFile
()
throws
IOException
{
// Create an image file name
return
File
.
createTempFile
(
TEMP_FILE_NAME
,
/* prefix */
".jpg"
,
/* suffix */
getActivity
().
getExternalFilesDir
(
null
)
/* directory */
);
}
private
void
removeAvatar
()
{
newAvatarImageUri
=
null
;
avatar
.
setImageDrawable
(
AvatarManager
.
getInstance
().
getDefaultAccountAvatar
(
account
));
}
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
result
)
{
if
(
requestCode
==
Crop
.
REQUEST_PICK
&&
resultCode
==
Activity
.
RESULT_OK
)
{
beginCrop
(
result
.
getData
());
}
else
if
(
requestCode
==
TAKE_PHOTO_REQUEST_CODE
&&
resultCode
==
Activity
.
RESULT_OK
)
{
beginCrop
(
photoFileUri
);
}
else
if
(
requestCode
==
Crop
.
REQUEST_CROP
)
{
handleCrop
(
resultCode
,
result
);
}
...
...
@@ -242,17 +312,17 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
}
private
void
beginCrop
(
Uri
source
)
{
cropped
ImageUri
=
Uri
.
fromFile
(
new
File
(
getActivity
().
getCacheDir
(),
TEMP_FILE_NAME
));
Crop
.
of
(
source
,
cropped
ImageUri
).
withMaxSize
(
MAX_AVATAR_SIZE_PIXELS
,
MAX_AVATAR_SIZE_PIXELS
).
start
(
getActivity
());
newAvatar
ImageUri
=
Uri
.
fromFile
(
new
File
(
getActivity
().
getCacheDir
(),
TEMP_FILE_NAME
));
Crop
.
of
(
source
,
newAvatar
ImageUri
).
withMaxSize
(
MAX_AVATAR_SIZE_PIXELS
,
MAX_AVATAR_SIZE_PIXELS
).
start
(
getActivity
());
}
private
void
handleCrop
(
int
resultCode
,
Intent
result
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
// null prompts image view to reload file.
avatar
.
setImageURI
(
null
);
avatar
.
setImageURI
(
cropped
ImageUri
);
avatar
.
setImageURI
(
newAvatar
ImageUri
);
File
file
=
new
File
(
cropped
ImageUri
.
getPath
());
File
file
=
new
File
(
newAvatar
ImageUri
.
getPath
());
avatarSize
.
setText
(
file
.
length
()
/
KB_SIZE_IN_BYTES
+
"KB"
);
avatarSize
.
setVisibility
(
View
.
VISIBLE
);
}
else
if
(
resultCode
==
Crop
.
RESULT_ERROR
)
{
...
...
@@ -289,12 +359,14 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
vCard
.
setField
(
VCardProperty
.
FN
.
name
(),
formattedNameText
);
}
if
(
cropped
ImageUri
!=
null
)
{
if
(
newAvatar
ImageUri
!=
null
)
{
try
{
vCard
.
setAvatar
(
new
URL
(
cropped
ImageUri
.
toString
()));
vCard
.
setAvatar
(
new
URL
(
newAvatar
ImageUri
.
toString
()));
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
}
else
{
vCard
.
removeAvatar
();
}
vCard
.
setField
(
VCardProperty
.
BDAY
.
name
(),
getValueFromEditText
(
birthDate
));
...
...
app/src/main/res/menu/change_avatar.xml
0 → 100644
View file @
ebc3d2d4
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item
android:id=
"@+id/action_choose_from_gallery"
android:title=
"@string/choose_from_gallery"
/>
<item
android:id=
"@+id/action_take_photo"
android:title=
"@string/take_photo"
/>
<item
android:id=
"@+id/action_remove_avatar"
android:title=
"@string/remove_avatar"
/>
</menu>
\ No newline at end of file
app/src/main/res/values/contact_viewer.xml
View file @
ebc3d2d4
...
...
@@ -54,4 +54,7 @@
<string
name=
"account_user_info_save_fail"
>
Could not save account user info
</string>
<string
name=
"account_user_info_save_started"
>
Saving account user info…
</string>
<string
name=
"saving"
>
Saving…
</string>
<string
name=
"choose_from_gallery"
>
Choose from gallery
</string>
<string
name=
"take_photo"
>
Take photo
</string>
<string
name=
"remove_avatar"
>
Remove avatar
</string>
</resources>
\ No newline at end of file
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