Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MOBAPP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
THONG Sylvain
MOBAPP
Commits
06aca573
Commit
06aca573
authored
3 months ago
by
s22thong
Browse files
Options
Downloads
Patches
Plain Diff
fix(UX): AlertDialog for Call permission in DisplayUser Fragment
parent
11e915e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/fr/imt_atlantique/myfirstapplication/DisplayUserFragment.java
+52
-1
52 additions, 1 deletion
...mt_atlantique/myfirstapplication/DisplayUserFragment.java
with
52 additions
and
1 deletion
app/src/main/java/fr/imt_atlantique/myfirstapplication/DisplayUserFragment.java
+
52
−
1
View file @
06aca573
package
fr.imt_atlantique.myfirstapplication
;
package
fr.imt_atlantique.myfirstapplication
;
import
android.Manifest
;
import
android.app.AlertDialog
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
androidx.core.app.ActivityCompat
;
import
androidx.core.content.ContextCompat
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.Fragment
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
...
@@ -9,6 +16,9 @@ import android.view.View;
...
@@ -9,6 +16,9 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.android.material.snackbar.Snackbar
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -21,7 +31,6 @@ public class DisplayUserFragment extends Fragment {
...
@@ -21,7 +31,6 @@ public class DisplayUserFragment extends Fragment {
private
static
final
String
ARG_BIRTH_DATE
=
"paramBirthDate"
;
private
static
final
String
ARG_BIRTH_DATE
=
"paramBirthDate"
;
private
static
final
String
ARG_PHONE_NUMBERS_LIST
=
"paramPhoneNumbersList"
;
private
static
final
String
ARG_PHONE_NUMBERS_LIST
=
"paramPhoneNumbersList"
;
// TODO: Rename and change types of parameters
private
String
mFirstName
;
private
String
mFirstName
;
private
String
mLastName
;
private
String
mLastName
;
private
String
mBirthCity
;
private
String
mBirthCity
;
...
@@ -29,6 +38,8 @@ public class DisplayUserFragment extends Fragment {
...
@@ -29,6 +38,8 @@ public class DisplayUserFragment extends Fragment {
private
String
mBirthDate
;
private
String
mBirthDate
;
private
ArrayList
<
String
>
mPhoneNumbersList
;
private
ArrayList
<
String
>
mPhoneNumbersList
;
private
View
rootView
;
public
DisplayUserFragment
()
{
public
DisplayUserFragment
()
{
// Required empty public constructor
// Required empty public constructor
}
}
...
@@ -87,6 +98,46 @@ public class DisplayUserFragment extends Fragment {
...
@@ -87,6 +98,46 @@ public class DisplayUserFragment extends Fragment {
phonesLinearLayout
.
addView
(
phoneView
);
phonesLinearLayout
.
addView
(
phoneView
);
}
}
rootView
=
view
;
return
view
;
return
view
;
}
}
public
void
callPhoneNumber
(
View
v
)
{
ViewGroup
phoneRow
=
(
ViewGroup
)
v
.
getParent
();
TextView
phoneTextView
=
phoneRow
.
findViewById
(
R
.
id
.
secondPhoneNumberTextView
);
String
phoneNumber
=
phoneTextView
.
getText
().
toString
();
if
(
phoneNumber
.
trim
().
isEmpty
())
{
Snackbar
.
make
(
rootView
.
findViewById
(
R
.
id
.
mainContent
),
getString
(
R
.
string
.
invalid_phone_number
),
Snackbar
.
LENGTH_LONG
).
show
();
return
;
}
// We check for the application "Call permission"
if
(
ContextCompat
.
checkSelfPermission
(
requireContext
(),
Manifest
.
permission
.
CALL_PHONE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
grantPermissionAlertDialog
();
return
;
}
// Just in case, we try/catch possible security exceptions
try
{
Intent
callIntent
=
new
Intent
(
Intent
.
ACTION_CALL
);
callIntent
.
setData
(
Uri
.
parse
(
"tel:"
+
phoneNumber
));
startActivity
(
callIntent
);
}
catch
(
SecurityException
e
)
{
Snackbar
.
make
(
v
,
getString
(
R
.
string
.
call_attempt_error
)
+
e
,
Snackbar
.
LENGTH_SHORT
).
show
();
}
}
private
void
grantPermissionAlertDialog
()
{
new
AlertDialog
.
Builder
(
requireContext
())
.
setTitle
(
getString
(
R
.
string
.
call_permission_title
))
.
setMessage
(
getString
(
R
.
string
.
call_permission_message
))
.
setNegativeButton
(
getString
(
R
.
string
.
cancel
),
(
dialog
,
which
)
->
Toast
.
makeText
(
requireContext
(),
getString
(
R
.
string
.
permission_denied
),
Toast
.
LENGTH_SHORT
)
.
show
())
.
setPositiveButton
(
"Ok"
,
(
dialog
,
which
)
->
ActivityCompat
.
requestPermissions
(
requireActivity
(),
new
String
[]{
Manifest
.
permission
.
CALL_PHONE
},
3
))
.
create
()
.
show
();
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment