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
0cdd5530
Commit
0cdd5530
authored
Aug 04, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AccountInfoEditorFragment: avatar selection improved. Image size is shown.
parent
97fa7b28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
41 deletions
+48
-41
AccountInfoEditorFragment.java
...java/com/xabber/android/ui/AccountInfoEditorFragment.java
+23
-36
account_info_editor_fragment.xml
app/src/main/res/layout/account_info_editor_fragment.xml
+25
-5
No files found.
app/src/main/java/com/xabber/android/ui/AccountInfoEditorFragment.java
View file @
0cdd5530
...
@@ -12,6 +12,7 @@ import android.view.ViewGroup;
...
@@ -12,6 +12,7 @@ import android.view.ViewGroup;
import
android.widget.EditText
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.soundcloud.android.crop.Crop
;
import
com.soundcloud.android.crop.Crop
;
...
@@ -30,10 +31,10 @@ import org.jivesoftware.smack.SmackException;
...
@@ -30,10 +31,10 @@ import org.jivesoftware.smack.SmackException;
import
org.jivesoftware.smackx.vcardtemp.packet.VCard
;
import
org.jivesoftware.smackx.vcardtemp.packet.VCard
;
import
org.xmlpull.v1.XmlPullParserException
;
import
org.xmlpull.v1.XmlPullParserException
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
public
class
AccountInfoEditorFragment
extends
Fragment
implements
OnVCardSaveListener
,
OnVCardListener
{
public
class
AccountInfoEditorFragment
extends
Fragment
implements
OnVCardSaveListener
,
OnVCardListener
{
...
@@ -50,7 +51,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -50,7 +51,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
private
EditText
nickName
;
private
EditText
nickName
;
private
String
account
;
private
String
account
;
private
ImageView
avatar
;
private
ImageView
avatar
;
private
Uri
i
mageUri
;
private
Uri
croppedI
mageUri
;
private
EditText
organization
;
private
EditText
organization
;
private
EditText
organizationUnit
;
private
EditText
organizationUnit
;
private
EditText
birthDate
;
private
EditText
birthDate
;
...
@@ -66,6 +67,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -66,6 +67,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
private
View
progressBar
;
private
View
progressBar
;
private
boolean
isSaveSuccess
;
private
boolean
isSaveSuccess
;
private
LinearLayout
fields
;
private
LinearLayout
fields
;
private
TextView
avatarSize
;
public
static
AccountInfoEditorFragment
newInstance
(
String
account
,
String
vCard
)
{
public
static
AccountInfoEditorFragment
newInstance
(
String
account
,
String
vCard
)
{
AccountInfoEditorFragment
fragment
=
new
AccountInfoEditorFragment
();
AccountInfoEditorFragment
fragment
=
new
AccountInfoEditorFragment
();
...
@@ -105,6 +107,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -105,6 +107,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
progressBar
=
view
.
findViewById
(
R
.
id
.
vcard_save_progress_bar
);
progressBar
=
view
.
findViewById
(
R
.
id
.
vcard_save_progress_bar
);
avatarSize
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
vcard_avatar_size_text_view
);
prefixName
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_prefix_name
);
prefixName
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_prefix_name
);
formattedName
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_formatted_name
);
formattedName
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_formatted_name
);
givenName
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_given_name
);
givenName
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_given_name
);
...
@@ -202,24 +206,11 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -202,24 +206,11 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
}
}
private
void
changeAvatar
()
{
private
void
changeAvatar
()
{
// Intent pickAvatar = new Intent(Intent.ACTION_PICK,
// android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// startActivityForResult(pickAvatar, 1);
Crop
.
pickImage
(
getActivity
());
Crop
.
pickImage
(
getActivity
());
}
}
@Override
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
result
)
{
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
result
)
{
LogManager
.
i
(
this
,
"onActivityResult"
);
// super.onActivityResult(requestCode, resultCode, data);
// if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
// imageUri = data.getData();
// avatar.setImageURI(imageUri);
// }
if
(
requestCode
==
Crop
.
REQUEST_PICK
&&
resultCode
==
Activity
.
RESULT_OK
)
{
if
(
requestCode
==
Crop
.
REQUEST_PICK
&&
resultCode
==
Activity
.
RESULT_OK
)
{
beginCrop
(
result
.
getData
());
beginCrop
(
result
.
getData
());
}
else
if
(
requestCode
==
Crop
.
REQUEST_CROP
)
{
}
else
if
(
requestCode
==
Crop
.
REQUEST_CROP
)
{
...
@@ -229,28 +220,26 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -229,28 +220,26 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
}
}
private
void
beginCrop
(
Uri
source
)
{
private
void
beginCrop
(
Uri
source
)
{
i
mageUri
=
Uri
.
fromFile
(
new
File
(
getActivity
().
getCacheDir
(),
"cropped"
));
croppedI
mageUri
=
Uri
.
fromFile
(
new
File
(
getActivity
().
getCacheDir
(),
"cropped"
));
Crop
.
of
(
source
,
imageUri
).
asSquare
(
).
start
(
getActivity
());
Crop
.
of
(
source
,
croppedImageUri
).
start
(
getActivity
());
}
}
private
void
handleCrop
(
int
resultCode
,
Intent
result
)
{
private
void
handleCrop
(
int
resultCode
,
Intent
result
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
avatar
.
setImageURI
(
Crop
.
getOutput
(
result
));
}
else
if
(
resultCode
==
Crop
.
RESULT_ERROR
)
{
Toast
.
makeText
(
getActivity
(),
Crop
.
getError
(
result
).
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
}
public
static
byte
[]
getBytes
(
InputStream
inputStream
)
throws
IOException
{
ByteArrayOutputStream
byteBuffer
=
new
ByteArrayOutputStream
();
int
bufferSize
=
1024
;
byte
[]
buffer
=
new
byte
[
bufferSize
];
int
len
;
avatar
.
setImageURI
(
null
);
while
((
len
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
avatar
.
setImageURI
(
croppedImageUri
);
byteBuffer
.
write
(
buffer
,
0
,
len
);
File
f
=
new
File
(
croppedImageUri
.
getPath
());
long
size
=
f
.
length
();
avatarSize
.
setVisibility
(
View
.
VISIBLE
);
avatarSize
.
setText
(
size
/
1024
+
"KB"
);
}
else
if
(
resultCode
==
Crop
.
RESULT_ERROR
)
{
avatarSize
.
setVisibility
(
View
.
INVISIBLE
);
Toast
.
makeText
(
getActivity
(),
Crop
.
getError
(
result
).
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
}
return
byteBuffer
.
toByteArray
();
}
}
String
getValueFromEditText
(
EditText
editText
)
{
String
getValueFromEditText
(
EditText
editText
)
{
...
@@ -281,14 +270,12 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -281,14 +270,12 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
vCard
.
setField
(
VCardProperty
.
FN
.
name
(),
formattedNameText
);
vCard
.
setField
(
VCardProperty
.
FN
.
name
(),
formattedNameText
);
}
}
if
(
i
mageUri
!=
null
)
{
if
(
croppedI
mageUri
!=
null
)
{
try
{
try
{
InputStream
inputStream
=
getActivity
().
getContentResolver
().
openInputStream
(
imageUri
);
vCard
.
setAvatar
(
new
URL
(
croppedImageUri
.
toString
()));
vCard
.
setAvatar
(
getBytes
(
inputStream
));
}
catch
(
MalformedURLException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
vCard
.
setField
(
VCardProperty
.
BDAY
.
name
(),
getValueFromEditText
(
birthDate
));
vCard
.
setField
(
VCardProperty
.
BDAY
.
name
(),
getValueFromEditText
(
birthDate
));
...
...
app/src/main/res/layout/account_info_editor_fragment.xml
View file @
0cdd5530
...
@@ -144,13 +144,33 @@
...
@@ -144,13 +144,33 @@
android:layout_height=
"@dimen/avatar_large_size"
android:layout_height=
"@dimen/avatar_large_size"
android:src=
"@drawable/ic_avatar_1"
/>
android:src=
"@drawable/ic_avatar_1"
/>
<
Button
<
LinearLayout
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Change"
android:orientation=
"vertical"
android:id=
"@+id/vcard_change_avatar"
android:layout_marginLeft=
"16dp"
>
android:layout_gravity=
"top"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Change"
android:id=
"@+id/vcard_change_avatar"
android:layout_marginLeft=
"16dp"
android:layout_gravity=
"top"
/>
<TextView
android:layout_marginLeft=
"24dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/vcard_avatar_size_text_view"
android:singleLine=
"true"
android:textAppearance=
"?android:attr/textAppearanceSmall"
android:text=
"173KB"
android:visibility=
"invisible"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
...
...
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