Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Krishna Vemulavada
/
vera_2.1_app
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ceab0740
authored
Sep 22, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
UOFLMA-89: Fix - App is force closed when we clicked on date button.
parent
b4bf90c9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
25 deletions
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueVariableScreen.java
app/src/main/java/com/vsoft/uoflservicenow/utils/Util.java
app/src/main/res/values/strings.xml
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueVariableScreen.java
View file @
ceab0740
...
@@ -20,6 +20,7 @@ import android.view.MenuItem;
...
@@ -20,6 +20,7 @@ import android.view.MenuItem;
import
android.view.MotionEvent
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.View
;
import
android.webkit.WebView
;
import
android.webkit.WebView
;
import
android.widget.Button
;
import
android.widget.DatePicker
;
import
android.widget.DatePicker
;
import
android.widget.EditText
;
import
android.widget.EditText
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
...
@@ -350,9 +351,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
...
@@ -350,9 +351,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
String
jsonColumnValue
=
value
;
String
jsonColumnValue
=
value
;
/*Convert date and time long value to string for server communication*/
/*Convert date and time long value to string for server communication*/
if
(
viewType
==
ViewType
.
DATE
)
{
if
(
viewType
==
ViewType
.
DATE
)
{
jsonColumnValue
=
Util
.
getDateFromLong
(
Long
.
parseLo
ng
(
value
));
jsonColumnValue
=
Util
.
getDateFromLong
(
Util
.
getDateFromStri
ng
(
value
));
}
else
if
(
viewType
==
ViewType
.
DATE_AND_TIME
)
{
}
else
if
(
viewType
==
ViewType
.
DATE_AND_TIME
)
{
jsonColumnValue
=
Util
.
getDateTime
FromLong
(
Long
.
parseLo
ng
(
value
));
jsonColumnValue
=
Util
.
getDateTime
(
Util
.
getDateTimeFromStri
ng
(
value
));
}
}
if
(
viewType
!=
ViewType
.
SELECT_BOX
)
{
if
(
viewType
!=
ViewType
.
SELECT_BOX
)
{
...
@@ -423,14 +424,20 @@ public class CatalogueVariableScreen extends AppCompatActivity {
...
@@ -423,14 +424,20 @@ public class CatalogueVariableScreen extends AppCompatActivity {
DatePickerDialog
.
OnDateSetListener
dateListener
=
new
DatePickerDialog
.
OnDateSetListener
()
{
DatePickerDialog
.
OnDateSetListener
dateListener
=
new
DatePickerDialog
.
OnDateSetListener
()
{
@Override
@Override
public
void
onDateSet
(
DatePicker
view
,
int
year
,
int
monthOfYear
,
int
dayOfMonth
)
{
public
void
onDateSet
(
DatePicker
view
,
int
year
,
int
monthOfYear
,
int
dayOfMonth
)
{
((
TextView
)
v
).
setText
(
String
.
format
(
getString
(
R
.
string
.
date_string
),
(
dayOfMonth
<
10
?
"0"
+
dayOfMonth
:
dayOfMonth
),
getMonth
(
monthOfYear
),
year
));
((
Button
)
v
).
setText
(
String
.
format
(
getString
(
R
.
string
.
date_string
),
(
dayOfMonth
<
10
?
"0"
+
dayOfMonth
:
dayOfMonth
),
getMonth
(
monthOfYear
),
year
));
}
}
};
};
TimePickerDialog
.
OnTimeSetListener
timeListener
=
new
TimePickerDialog
.
OnTimeSetListener
()
{
TimePickerDialog
.
OnTimeSetListener
timeListener
=
new
TimePickerDialog
.
OnTimeSetListener
()
{
@Override
@Override
public
void
onTimeSet
(
TimePicker
view
,
int
hourOfDay
,
int
minute
)
{
public
void
onTimeSet
(
TimePicker
view
,
int
hourOfDay
,
int
minute
)
{
((
TextView
)
v
).
append
(
String
.
format
(
getString
(
R
.
string
.
date_and_time_string
),
(
hourOfDay
<
10
?
"0"
+
hourOfDay
:
hourOfDay
),
(
minute
<
10
?
"0"
+
minute
:
minute
)));
Button
button
=
(
Button
)
v
;
String
existText
=
button
.
getText
().
toString
();
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
existText
);
builder
.
append
(
" "
);
builder
.
append
(
String
.
format
(
getString
(
R
.
string
.
date_and_time_string
),
(
hourOfDay
<
10
?
"0"
+
hourOfDay
:
hourOfDay
),
(
minute
<
10
?
"0"
+
minute
:
minute
)));
button
.
setText
(
builder
.
toString
());
}
}
};
};
...
...
app/src/main/java/com/vsoft/uoflservicenow/utils/Util.java
View file @
ceab0740
...
@@ -31,7 +31,6 @@ import java.text.ParseException;
...
@@ -31,7 +31,6 @@ import java.text.ParseException;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.Locale
;
/**
/**
* Created by Kunj on 12/8/16.
* Created by Kunj on 12/8/16.
...
@@ -100,7 +99,7 @@ public class Util {
...
@@ -100,7 +99,7 @@ public class Util {
return
dateTextButton
;
return
dateTextButton
;
case
DATE_AND_TIME:
case
DATE_AND_TIME:
Button
dateTimeButton
=
new
Button
(
context
);
Button
dateTimeButton
=
new
Button
(
context
);
dateTimeButton
.
setText
(
getDefaultDate
()
+
" "
+
getDefaultTime
()
);
dateTimeButton
.
setText
(
getDefaultDate
Time
()
/* + " " + getDefaultTime()*/
);
dateTimeButton
.
setGravity
(
Gravity
.
CENTER_VERTICAL
);
dateTimeButton
.
setGravity
(
Gravity
.
CENTER_VERTICAL
);
return
dateTimeButton
;
return
dateTimeButton
;
case
REFERENCE:
case
REFERENCE:
...
@@ -208,10 +207,10 @@ public class Util {
...
@@ -208,10 +207,10 @@ public class Util {
return
wideSingleLineEditText
.
getText
().
toString
();
return
wideSingleLineEditText
.
getText
().
toString
();
case
DATE:
case
DATE:
Button
dateTextButton
=
(
Button
)
view
;
Button
dateTextButton
=
(
Button
)
view
;
return
""
+
getDateFromString
(
dateTextButton
.
getText
().
toString
()
);
return
dateTextButton
.
getText
().
toString
(
);
case
DATE_AND_TIME:
case
DATE_AND_TIME:
Button
dateTimeButton
=
(
Button
)
view
;
Button
dateTimeButton
=
(
Button
)
view
;
return
""
+
getDateTimeFromString
(
dateTimeButton
.
getText
().
toString
()
);
return
dateTimeButton
.
getText
().
toString
(
);
case
REFERENCE:
case
REFERENCE:
TagObject
tagObject
=
(
TagObject
)
view
.
getTag
();
TagObject
tagObject
=
(
TagObject
)
view
.
getTag
();
Reference
reference
=
(
Reference
)
tagObject
.
getTagObject
();
Reference
reference
=
(
Reference
)
tagObject
.
getTagObject
();
...
@@ -244,19 +243,18 @@ public class Util {
...
@@ -244,19 +243,18 @@ public class Util {
public
static
String
getDefaultDate
()
{
public
static
String
getDefaultDate
()
{
Calendar
c
=
Calendar
.
getInstance
();
Calendar
c
=
Calendar
.
getInstance
();
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"dd MMM, yyyy"
,
Locale
.
US
);
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"dd MMM, yyyy"
);
return
df
.
format
(
c
.
getTime
());
return
df
.
format
(
c
.
getTime
());
}
}
public
static
String
getDefaultTime
()
{
public
static
String
getDefault
Date
Time
()
{
Calendar
c
=
Calendar
.
getInstance
();
Calendar
c
=
Calendar
.
getInstance
();
int
hour
=
c
.
get
(
Calendar
.
HOUR_OF_DAY
);
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"dd MMM, yyyy HH:mm"
);
int
min
=
c
.
get
(
Calendar
.
MINUTE
);
return
df
.
format
(
c
.
getTime
());
return
(
hour
<
10
?
(
"0"
+
hour
)
:
hour
)
+
":"
+
(
min
<
10
?
(
"0"
+
min
)
:
min
);
}
}
public
static
long
getDateFromString
(
String
strDate
)
{
public
static
long
getDateFromString
(
String
strDate
)
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"dd MMM, yyyy"
,
Locale
.
US
);
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"dd MMM, yyyy"
);
Date
date
=
null
;
Date
date
=
null
;
try
{
try
{
date
=
df
.
parse
(
strDate
);
date
=
df
.
parse
(
strDate
);
...
@@ -266,14 +264,8 @@ public class Util {
...
@@ -266,14 +264,8 @@ public class Util {
return
date
.
getTime
();
return
date
.
getTime
();
}
}
public
static
String
getDateFromLong
(
long
timeStamp
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
US
);
return
dateFormat
.
format
(
timeStamp
);
}
public
static
long
getDateTimeFromString
(
String
strDate
)
{
public
static
long
getDateTimeFromString
(
String
strDate
)
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"dd MMM, yyyy HH:mm"
,
Locale
.
US
);
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"dd MMM, yyyy HH:mm"
);
Date
date
=
null
;
Date
date
=
null
;
try
{
try
{
date
=
df
.
parse
(
strDate
);
date
=
df
.
parse
(
strDate
);
...
@@ -283,14 +275,24 @@ public class Util {
...
@@ -283,14 +275,24 @@ public class Util {
return
date
.
getTime
();
return
date
.
getTime
();
}
}
public
static
String
getDateFromLong
(
long
timeStamp
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
dateFormat
.
format
(
timeStamp
);
}
public
static
String
getDateTime
(
long
timeStamp
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
return
dateFormat
.
format
(
timeStamp
);
}
public
static
String
getDateTimeFromLong
(
long
timeStamp
)
{
public
static
String
getDateTimeFromLong
(
long
timeStamp
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"dd MMM, yyyy HH:mm"
,
Locale
.
US
);
(
"dd MMM, yyyy HH:mm"
);
return
dateFormat
.
format
(
timeStamp
);
return
dateFormat
.
format
(
timeStamp
);
}
}
public
static
long
getDateTimeForMyIncidentFromString
(
String
strDate
)
{
public
static
long
getDateTimeForMyIncidentFromString
(
String
strDate
)
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
US
);
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
date
=
null
;
Date
date
=
null
;
try
{
try
{
date
=
df
.
parse
(
strDate
);
date
=
df
.
parse
(
strDate
);
...
@@ -301,7 +303,7 @@ public class Util {
...
@@ -301,7 +303,7 @@ public class Util {
}
}
public
static
long
getDateTimeForMyRequestFromString
(
String
strDate
)
{
public
static
long
getDateTimeForMyRequestFromString
(
String
strDate
)
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
US
);
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
date
=
null
;
Date
date
=
null
;
try
{
try
{
date
=
df
.
parse
(
strDate
);
date
=
df
.
parse
(
strDate
);
...
...
app/src/main/res/values/strings.xml
View file @
ceab0740
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
<string
name=
"rejected"
>
Rejected
</string>
<string
name=
"rejected"
>
Rejected
</string>
<string
name=
"date_string"
>
%1$s %2$s, %3$s
</string>
<string
name=
"date_string"
>
%1$s %2$s, %3$s
</string>
<string
name=
"date_and_time_string"
>
%1$s:%2$s
</string>
<string
name=
"date_and_time_string"
>
%1$s:%2$s
</string>
<!--Failed to fetch-->
<!--Failed to fetch-->
<string
name=
"failed_to_fetch_catalogue_category_string"
>
Failed to fetch Catalogue Category.
</string>
<string
name=
"failed_to_fetch_catalogue_category_string"
>
Failed to fetch Catalogue Category.
</string>
...
...
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