summaryrefslogtreecommitdiffstats
path: root/src/com/android/managedprovisioning/UserConsentDialog.java
diff options
context:
space:
mode:
authorSander Alewijnse <salewijnse@google.com>2014-09-08 20:46:40 +0100
committerSander Alewijnse <salewijnse@google.com>2014-09-12 13:22:12 +0100
commit7a85694423d9c0246ddb477cb2fc0add9b7841e2 (patch)
treebaa8a2403368bfcaf803799a941ada8dec094e44 /src/com/android/managedprovisioning/UserConsentDialog.java
parenteed2f48f383ec7506fe4d38afa9f5e5d2658b0d7 (diff)
downloadandroid_packages_apps_ManagedProvisioning-7a85694423d9c0246ddb477cb2fc0add9b7841e2.tar.gz
android_packages_apps_ManagedProvisioning-7a85694423d9c0246ddb477cb2fc0add9b7841e2.tar.bz2
android_packages_apps_ManagedProvisioning-7a85694423d9c0246ddb477cb2fc0add9b7841e2.zip
Add hyperlink to learn more dialogs.
Create helper class to enable sharing of functionality between profile and device owner. Bug:15744182 Change-Id: Iedc9f4e832df0e79b32dc4aa8aa98326048ae7dc
Diffstat (limited to 'src/com/android/managedprovisioning/UserConsentDialog.java')
-rw-r--r--src/com/android/managedprovisioning/UserConsentDialog.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/com/android/managedprovisioning/UserConsentDialog.java b/src/com/android/managedprovisioning/UserConsentDialog.java
new file mode 100644
index 00000000..10e49dbd
--- /dev/null
+++ b/src/com/android/managedprovisioning/UserConsentDialog.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2014, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.managedprovisioning;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.TextView;
+import android.widget.Button;
+
+/**
+ * Dialog used to notify the user that the admin will have full control over the profile/device.
+ * Custom runnables can be passed that are run on consent or cancel.
+ */
+public class UserConsentDialog extends DialogFragment {
+ public static final int PROFILE_OWNER = 1;
+ public static final int DEVICE_OWNER = 2;
+
+ public static final String LEARN_MORE_URL_PROFILE_OWNER =
+ "https://support.google.com/android/work/answer/6090512";
+
+ private final Context mContext;
+ private final int mAdminMonitorsStringId;
+ private final Uri mLearnMoreUri;
+ private final Runnable mOnUserConsentRunnable;
+ private final Runnable mOnCancelRunnable;
+
+ public UserConsentDialog(final Context context, int ownerType,
+ final Runnable onUserConsentRunnable, final Runnable onCancelRunnable) {
+ super();
+ mContext = context;
+ if (ownerType == PROFILE_OWNER) {
+ mAdminMonitorsStringId = R.string.admin_has_ability_to_monitor_profile;
+ mLearnMoreUri = Uri.parse(LEARN_MORE_URL_PROFILE_OWNER);
+ } else if (ownerType == DEVICE_OWNER) {
+ mAdminMonitorsStringId = R.string.admin_has_ability_to_monitor_device;
+ mLearnMoreUri = null;
+ } else {
+ throw new IllegalArgumentException("Illegal value for argument ownerType.");
+ }
+ mOnUserConsentRunnable = onUserConsentRunnable;
+ mOnCancelRunnable = onCancelRunnable;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final Dialog dialog = new Dialog(mContext, R.style.ManagedProvisioningDialogTheme);
+ dialog.setContentView(R.layout.learn_more_dialog);
+
+ TextView text1 = (TextView) dialog.findViewById(R.id.learn_more_text1);
+ text1.setText(mAdminMonitorsStringId);
+
+ final TextView linkText = (TextView) dialog.findViewById(R.id.learn_more_link);
+ if (mLearnMoreUri != null) {
+ linkText.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent browserIntent = new Intent(Intent.ACTION_VIEW, mLearnMoreUri);
+ mContext.startActivity(browserIntent);
+ }
+ });
+ } else {
+ linkText.setVisibility(View.GONE);
+ }
+
+ Button positiveButton = (Button) dialog.findViewById(R.id.positive_button);
+ positiveButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ if (mOnUserConsentRunnable != null) {
+ mOnUserConsentRunnable.run();
+ }
+ }
+ });
+
+ Button negativeButton = (Button) dialog.findViewById(R.id.negative_button);
+ negativeButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ if (mOnCancelRunnable != null) {
+ mOnCancelRunnable.run();
+ }
+ }
+ });
+
+ return dialog;
+ }
+} \ No newline at end of file