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
8aea3233
Commit
8aea3233
authored
Aug 05, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AccountInfoEditorFragment: birth date selected via DatePicker dialog.
parent
2f746c26
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
11 deletions
+82
-11
AccountInfoEditorFragment.java
...java/com/xabber/android/ui/AccountInfoEditorFragment.java
+64
-5
account_info_editor_fragment.xml
app/src/main/res/layout/account_info_editor_fragment.xml
+17
-6
contact_viewer.xml
app/src/main/res/values/contact_viewer.xml
+1
-0
No files found.
app/src/main/java/com/xabber/android/ui/AccountInfoEditorFragment.java
View file @
8aea3233
package
com
.
xabber
.
android
.
ui
;
package
com
.
xabber
.
android
.
ui
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.app.DatePickerDialog
;
import
android.app.Fragment
;
import
android.app.Fragment
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.net.Uri
;
...
@@ -11,6 +12,7 @@ import android.view.LayoutInflater;
...
@@ -11,6 +12,7 @@ import android.view.LayoutInflater;
import
android.view.MenuItem
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.DatePicker
;
import
android.widget.EditText
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
...
@@ -38,8 +40,16 @@ import java.io.File;
...
@@ -38,8 +40,16 @@ import java.io.File;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.MalformedURLException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.Locale
;
import
java.util.TimeZone
;
public
class
AccountInfoEditorFragment
extends
Fragment
implements
OnVCardSaveListener
,
OnVCardListener
{
public
class
AccountInfoEditorFragment
extends
Fragment
implements
OnVCardSaveListener
,
OnVCardListener
,
DatePickerDialog
.
OnDateSetListener
{
public
static
final
String
ARGUMENT_ACCOUNT
=
"com.xabber.android.ui.AccountInfoEditorFragment.ARGUMENT_ACCOUNT"
;
public
static
final
String
ARGUMENT_ACCOUNT
=
"com.xabber.android.ui.AccountInfoEditorFragment.ARGUMENT_ACCOUNT"
;
public
static
final
String
ARGUMENT_VCARD
=
"com.xabber.android.ui.AccountInfoEditorFragment.ARGUMENT_USER"
;
public
static
final
String
ARGUMENT_VCARD
=
"com.xabber.android.ui.AccountInfoEditorFragment.ARGUMENT_USER"
;
...
@@ -48,6 +58,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -48,6 +58,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
public
static
final
String
TEMP_FILE_NAME
=
"cropped"
;
public
static
final
String
TEMP_FILE_NAME
=
"cropped"
;
public
static
final
int
KB_SIZE_IN_BYTES
=
1024
;
public
static
final
int
KB_SIZE_IN_BYTES
=
1024
;
public
static
final
int
TAKE_PHOTO_REQUEST_CODE
=
3
;
public
static
final
int
TAKE_PHOTO_REQUEST_CODE
=
3
;
public
static
final
String
DATE_FORMAT
=
"yyyy-mm-dd"
;
public
static
final
String
DATE_FORMAT_INT_TO_STRING
=
"%d-%02d-%02d"
;
private
VCard
vCard
;
private
VCard
vCard
;
private
EditText
prefixName
;
private
EditText
prefixName
;
...
@@ -61,7 +73,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -61,7 +73,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
private
Uri
newAvatarImageUri
;
private
Uri
newAvatarImageUri
;
private
EditText
organization
;
private
EditText
organization
;
private
EditText
organizationUnit
;
private
EditText
organizationUnit
;
private
EditText
birthDate
;
private
TextView
birthDate
;
private
EditText
title
;
private
EditText
title
;
private
EditText
role
;
private
EditText
role
;
private
EditText
url
;
private
EditText
url
;
...
@@ -79,7 +91,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -79,7 +91,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
private
Lister
lister
;
private
Lister
lister
;
private
View
changeAvatarButton
;
private
View
changeAvatarButton
;
private
Uri
photoFileUri
;
private
Uri
photoFileUri
;
private
DatePickerDialog
datePicker
;
interface
Lister
{
interface
Lister
{
void
onVCardSavingStarted
();
void
onVCardSavingStarted
();
...
@@ -150,7 +162,15 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -150,7 +162,15 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
}
}
);
);
birthDate
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_birth_date
);
birthDate
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
vcard_birth_date
);
View
changeBirthDateButton
=
view
.
findViewById
(
R
.
id
.
vcard_change_birth_date
);
changeBirthDateButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
datePicker
.
show
();
}
});
title
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_title
);
title
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_title
);
role
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_role
);
role
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
vcard_role
);
...
@@ -208,6 +228,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -208,6 +228,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
birthDate
.
setText
(
vCard
.
getField
(
VCardProperty
.
BDAY
.
name
()));
birthDate
.
setText
(
vCard
.
getField
(
VCardProperty
.
BDAY
.
name
()));
updateDatePickerDialog
();
title
.
setText
(
vCard
.
getField
(
VCardProperty
.
TITLE
.
name
()));
title
.
setText
(
vCard
.
getField
(
VCardProperty
.
TITLE
.
name
()));
role
.
setText
(
vCard
.
getField
(
VCardProperty
.
ROLE
.
name
()));
role
.
setText
(
vCard
.
getField
(
VCardProperty
.
ROLE
.
name
()));
organization
.
setText
(
vCard
.
getOrganization
());
organization
.
setText
(
vCard
.
getOrganization
());
...
@@ -235,6 +257,38 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -235,6 +257,38 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
emailWork
.
setText
(
vCard
.
getEmailWork
());
emailWork
.
setText
(
vCard
.
getEmailWork
());
}
}
public
void
updateDatePickerDialog
()
{
Calendar
calendar
=
null
;
String
vCardBirthDate
=
vCard
.
getField
(
VCardProperty
.
BDAY
.
name
());
if
(
vCardBirthDate
!=
null
)
{
DateFormat
dateFormat
=
new
SimpleDateFormat
(
DATE_FORMAT
,
Locale
.
US
);
Date
result
=
null
;
try
{
result
=
dateFormat
.
parse
(
vCardBirthDate
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
if
(
result
!=
null
)
{
calendar
=
new
GregorianCalendar
();
calendar
.
setTime
(
result
);
}
}
if
(
calendar
==
null
)
{
calendar
=
Calendar
.
getInstance
(
TimeZone
.
getDefault
());
}
datePicker
=
new
DatePickerDialog
(
getActivity
(),
AccountInfoEditorFragment
.
this
,
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
));
datePicker
.
setCancelable
(
false
);
}
private
void
changeAvatar
()
{
private
void
changeAvatar
()
{
PopupMenu
menu
=
new
PopupMenu
(
getActivity
(),
changeAvatarButton
);
PopupMenu
menu
=
new
PopupMenu
(
getActivity
(),
changeAvatarButton
);
menu
.
inflate
(
R
.
menu
.
change_avatar
);
menu
.
inflate
(
R
.
menu
.
change_avatar
);
...
@@ -331,7 +385,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -331,7 +385,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
}
}
}
}
String
getValueFromEditText
(
EditText
editText
)
{
String
getValueFromEditText
(
TextView
editText
)
{
String
trimText
=
editText
.
getText
().
toString
().
trim
();
String
trimText
=
editText
.
getText
().
toString
().
trim
();
if
(
trimText
.
isEmpty
())
{
if
(
trimText
.
isEmpty
())
{
return
null
;
return
null
;
...
@@ -477,4 +531,9 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
...
@@ -477,4 +531,9 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
getActivity
().
finish
();
getActivity
().
finish
();
}
}
}
}
@Override
public
void
onDateSet
(
DatePicker
view
,
int
year
,
int
monthOfYear
,
int
dayOfMonth
)
{
birthDate
.
setText
(
String
.
format
(
DATE_FORMAT_INT_TO_STRING
,
year
,
monthOfYear
+
1
,
dayOfMonth
));
}
}
}
app/src/main/res/layout/account_info_editor_fragment.xml
View file @
8aea3233
...
@@ -154,13 +154,13 @@
...
@@ -154,13 +154,13 @@
<Button
<Button
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"
C
hange"
android:text=
"
@string/c
hange"
android:id=
"@+id/vcard_change_avatar"
android:id=
"@+id/vcard_change_avatar"
android:layout_marginLeft=
"
16
dp"
android:layout_marginLeft=
"
44
dp"
android:layout_gravity=
"top"
/>
android:layout_gravity=
"top"
/>
<TextView
<TextView
android:layout_marginLeft=
"
24
dp"
android:layout_marginLeft=
"
56
dp"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/vcard_avatar_size_text_view"
android:id=
"@+id/vcard_avatar_size_text_view"
...
@@ -193,21 +193,32 @@
...
@@ -193,21 +193,32 @@
<LinearLayout
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"
vertic
al"
android:orientation=
"
horizont
al"
android:layout_marginRight=
"16dp"
android:layout_marginRight=
"16dp"
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
android:layout_marginBottom=
"8dp"
android:layout_marginBottom=
"8dp"
>
>
<
EditText
<
TextView
android:layout_width=
"
match_parent
"
android:layout_width=
"
100dp
"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:hint=
"@string/vcard_birth_date"
android:hint=
"@string/vcard_birth_date"
android:layout_gravity=
"center_vertical"
android:layout_gravity=
"center_vertical"
android:id=
"@+id/vcard_birth_date"
android:id=
"@+id/vcard_birth_date"
android:singleLine=
"true"
android:singleLine=
"true"
android:textAppearance=
"?android:attr/textAppearanceMedium"
android:inputType=
"date"
android:inputType=
"date"
android:paddingLeft=
"4dp"
android:paddingTop=
"16dp"
/>
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/change"
android:id=
"@+id/vcard_change_birth_date"
android:layout_marginLeft=
"16dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
...
...
app/src/main/res/values/contact_viewer.xml
View file @
8aea3233
...
@@ -57,4 +57,5 @@
...
@@ -57,4 +57,5 @@
<string
name=
"choose_from_gallery"
>
Choose from gallery
</string>
<string
name=
"choose_from_gallery"
>
Choose from gallery
</string>
<string
name=
"take_photo"
>
Take photo
</string>
<string
name=
"take_photo"
>
Take photo
</string>
<string
name=
"remove_avatar"
>
Remove avatar
</string>
<string
name=
"remove_avatar"
>
Remove avatar
</string>
<string
name=
"change"
>
Change
</string>
</resources>
</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