diff options
author | Yorke Lee <yorkelee@google.com> | 2015-10-27 17:43:38 +0000 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2015-10-27 22:04:21 +0000 |
commit | 9ce5286ab3644733339ff739bf15f8ce36e41524 (patch) | |
tree | 17ef53f0aa4188fff3215cc124314293813311e1 | |
parent | 996cb6f52901ab9e67354978f7f04e677600ee9f (diff) |
Remove onboarding flow
Straight revert of all onboarding flow related CLs -
the onboarding flow is not needed for now as the Dialer
will always at least be the system dialer.
Bug: 25020847
Change-Id: Ic1c5020b9b423de50801485f764209b21d5d7f33
26 files changed, 0 insertions, 980 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3e75b3597..6e1a51d2a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -242,12 +242,6 @@ <activity android:name="com.android.contacts.common.vcard.ExportVCardActivity" android:theme="@style/BackgroundOnlyTheme"/> - <activity - android:name="com.android.dialer.onboard.OnboardingActivity" - android:theme="@style/OnboardingFlowTheme" - android:screenOrientation="nosensor" - android:exported="false" /> - <service android:name="com.android.contacts.common.vcard.VCardService" android:exported="false"/> diff --git a/res/drawable-hdpi/ill_onboard_default.png b/res/drawable-hdpi/ill_onboard_default.png Binary files differdeleted file mode 100644 index d16c1f429..000000000 --- a/res/drawable-hdpi/ill_onboard_default.png +++ /dev/null diff --git a/res/drawable-hdpi/ill_onboard_permissions.png b/res/drawable-hdpi/ill_onboard_permissions.png Binary files differdeleted file mode 100644 index 90ef14c80..000000000 --- a/res/drawable-hdpi/ill_onboard_permissions.png +++ /dev/null diff --git a/res/drawable-mdpi/ill_onboard_default.png b/res/drawable-mdpi/ill_onboard_default.png Binary files differdeleted file mode 100644 index 41de46742..000000000 --- a/res/drawable-mdpi/ill_onboard_default.png +++ /dev/null diff --git a/res/drawable-mdpi/ill_onboard_permissions.png b/res/drawable-mdpi/ill_onboard_permissions.png Binary files differdeleted file mode 100644 index 3ec39db9d..000000000 --- a/res/drawable-mdpi/ill_onboard_permissions.png +++ /dev/null diff --git a/res/drawable-xhdpi/ill_onboard_default.png b/res/drawable-xhdpi/ill_onboard_default.png Binary files differdeleted file mode 100644 index 1cf47df28..000000000 --- a/res/drawable-xhdpi/ill_onboard_default.png +++ /dev/null diff --git a/res/drawable-xhdpi/ill_onboard_permissions.png b/res/drawable-xhdpi/ill_onboard_permissions.png Binary files differdeleted file mode 100644 index ab52a5823..000000000 --- a/res/drawable-xhdpi/ill_onboard_permissions.png +++ /dev/null diff --git a/res/drawable-xxhdpi/ill_onboard_default.png b/res/drawable-xxhdpi/ill_onboard_default.png Binary files differdeleted file mode 100644 index f243d44c0..000000000 --- a/res/drawable-xxhdpi/ill_onboard_default.png +++ /dev/null diff --git a/res/drawable-xxhdpi/ill_onboard_permissions.png b/res/drawable-xxhdpi/ill_onboard_permissions.png Binary files differdeleted file mode 100644 index 4725bfd29..000000000 --- a/res/drawable-xxhdpi/ill_onboard_permissions.png +++ /dev/null diff --git a/res/drawable-xxxhdpi/ill_onboard_default.png b/res/drawable-xxxhdpi/ill_onboard_default.png Binary files differdeleted file mode 100644 index 53f858d0b..000000000 --- a/res/drawable-xxxhdpi/ill_onboard_default.png +++ /dev/null diff --git a/res/drawable-xxxhdpi/ill_onboard_permissions.png b/res/drawable-xxxhdpi/ill_onboard_permissions.png Binary files differdeleted file mode 100644 index f406a9531..000000000 --- a/res/drawable-xxxhdpi/ill_onboard_permissions.png +++ /dev/null diff --git a/res/layout/onboarding_activity.xml b/res/layout/onboarding_activity.xml deleted file mode 100644 index a893ce4e7..000000000 --- a/res/layout/onboarding_activity.xml +++ /dev/null @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2015 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. ---> - -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:id="@+id/onboarding_fragment_container"> -</FrameLayout> diff --git a/res/layout/onboarding_screen_fragment.xml b/res/layout/onboarding_screen_fragment.xml deleted file mode 100644 index f60225d90..000000000 --- a/res/layout/onboarding_screen_fragment.xml +++ /dev/null @@ -1,71 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2015 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. ---> - -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:paddingBottom="20dp" > - - <ImageView - android:layout_width="match_parent" - android:layout_height="match_parent" - android:id="@+id/onboarding_screen_background_image" - android:scaleType="centerCrop" - android:importantForAccessibility="no" /> - - <TextView - android:id="@+id/onboarding_screen_title" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_above="@+id/onboarding_screen_content" - android:textAppearance="?android:attr/textAppearanceLarge" - android:textColor="@color/onboarding_primary_text_color" - android:layout_marginStart="@dimen/onboard_screen_side_padding" - android:layout_marginEnd="@dimen/onboard_screen_side_padding" /> - - <TextView - android:id="@id/onboarding_screen_content" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_above="@+id/onboard_next_button" - android:layout_marginTop="20dp" - android:textColor="@color/onboarding_primary_text_color" - android:layout_marginStart="@dimen/onboard_screen_side_padding" - android:layout_marginEnd="@dimen/onboard_screen_side_padding" /> - - <Button - android:id="@+id/onboard_skip_button" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignTop="@id/onboard_next_button" - android:layout_toStartOf="@id/onboard_next_button" - android:text="@string/onboarding_skip_button" - android:textColor="@color/onboarding_primary_text_color" - style="?android:attr/borderlessButtonStyle" /> - - <Button - android:id="@id/onboard_next_button" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentEnd="true" - android:layout_alignParentBottom="true" - android:layout_marginBottom="5dp" - android:layout_marginEnd="@dimen/onboard_screen_side_padding" - android:text="@string/onboarding_next_button" - android:textColor="@color/onboarding_primary_text_color" - style="@android:style/Widget.Material.Button" /> - -</RelativeLayout> diff --git a/res/values/colors.xml b/res/values/colors.xml index da68061e9..76bc0938b 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -134,12 +134,6 @@ <color name="blocked_number_header_color">@color/dialer_theme_color</color> <color name="blocked_number_disabled_emergency_header_color">#616161</color> - <!-- Colors for onboarding flow --> - <color name="onboarding_primary_text_color">#ffffff</color> - <color name="onboarding_default_dialer_screen_background_color">#e06055</color> - <color name="onboarding_permissions_screen_background_color">#689f38</color> - <color name="onboarding_next_button_color">#ffffff</color> - <!-- Grey 700 --> <color name="call_detail_footer_text_color">#616161</color> <color name="call_detail_footer_icon_tint">@color/call_detail_footer_text_color</color> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 8ea7d1c0d..18f33d5f2 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -167,6 +167,4 @@ <dimen name="blocked_number_settings_description_text_size">16sp</dimen> <dimen name="call_type_icon_size">12dp</dimen> - - <dimen name="onboard_screen_side_padding">20dp</dimen> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index dd325bc4c..b5703c6bf 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -937,22 +937,4 @@ <!-- Shown as a message that notifies the user that the Phone app cannot write to system settings, which is why the system settings app is being launched directly instead. [CHAR LIMIT=NONE]--> <string name="toast_cannot_write_system_settings">Phone app does not have permission to write to system settings.</string> - - <!-- Title of the onboarding screen that asks the user to make Phone the default Phone app [CHAR LIMIT=NONE]--> - <string name="request_default_dialer_screen_title">A better way of calling is calling</string> - - <!-- Content of the onboarding screen that asks the user to make Phone the default Phone app [CHAR LIMIT=NONE]--> - <string name="request_default_dialer_screen_content">Make Phone your default phone app to be able to do things like see who\'s calling you, even when they\'re not in your contacts.</string> - - <!-- Title of the onboarding screen that asks the user to grant us the Contacts and Phone permissions [CHAR LIMIT=NONE]--> - <string name="request_permissions_screen_title">Get talking to your friends and family</string> - - <!-- Content of the onboarding screen that asks the user to grant us the Contacts and Phone permissions [CHAR LIMIT=NONE]--> - <string name="request_permissions_screen_content">Phone will need to access your phone and contacts to make calls to people in your contacts.</string> - - <!-- The label of the button used to skip a screen in the onboarding flow [CHAR LIMIT=30]--> - <string name="onboarding_skip_button">Skip</string> - - <!-- The label of the button used to go to the next screen in the onboarding flow [CHAR LIMIT=30]--> - <string name="onboarding_next_button">Next</string> </resources> diff --git a/res/values/styles.xml b/res/values/styles.xml index 108f299d3..d3d160da4 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -115,15 +115,6 @@ <item name="actionOverflowButtonStyle">@style/DialtactsActionBarOverflowWhite</item> </style> - <style name="OnboardingFlowTheme" parent="DialtactsThemeWithoutActionBarOverlay"> - <item name="android:windowActionBar">false</item> - <item name="windowActionBar">false</item> - <item name="android:windowNoTitle">true</item> - <item name="windowNoTitle">true</item> - <item name="android:colorButtonNormal">@color/onboarding_next_button_color</item> - <item name="colorButtonNormal">@color/onboarding_next_button_color</item> - </style> - <!-- Hide the actionbar title during the activity preview --> <style name="DialtactsActivityTheme" parent="DialtactsTheme"> <!-- Styles that require AppCompat compatibility, remember to update both sets --> diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 2aff61c4c..2121e988d 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -57,7 +57,6 @@ import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlocke import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.filterednumber.FilterNumberDialogFragment; import com.android.dialer.filterednumber.FilteredNumbersUtil; -import com.android.dialer.onboard.OnboardingActivity; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.IntentUtil.CallIntentBuilder; import com.android.dialer.util.PhoneNumberUtil; @@ -217,11 +216,6 @@ public class CallDetailActivity extends AppCompatActivity protected void onCreate(Bundle icicle) { super.onCreate(icicle); - if (OnboardingActivity.shouldStartOnboardingActivity(this)) { - OnboardingActivity.startOnboardingActivity(this); - finish(); - } - mContext = this; mResources = getResources(); mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index 140437e40..9105e6f5a 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -82,7 +82,6 @@ import com.android.dialer.list.RegularSearchFragment; import com.android.dialer.list.SearchFragment; import com.android.dialer.list.SmartDialSearchFragment; import com.android.dialer.list.SpeedDialFragment; -import com.android.dialer.onboard.OnboardingActivity; import com.android.dialer.settings.DialerSettingsActivity; import com.android.dialer.util.IntentUtil; import com.android.dialer.util.TelecomUtil; @@ -380,11 +379,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O Trace.beginSection(TAG + " onCreate"); super.onCreate(savedInstanceState); - if (OnboardingActivity.shouldStartOnboardingActivity(this)) { - OnboardingActivity.startOnboardingActivity(this); - finish(); - } - mFirstLaunch = true; final Resources resources = getResources(); diff --git a/src/com/android/dialer/onboard/OnboardingActivity.java b/src/com/android/dialer/onboard/OnboardingActivity.java deleted file mode 100644 index 9be0fd0a7..000000000 --- a/src/com/android/dialer/onboard/OnboardingActivity.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (C) 2015 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.dialer.onboard; - -import static android.Manifest.permission.CALL_PHONE; -import static android.Manifest.permission.READ_CONTACTS; - -import android.Manifest; -import android.app.Activity; -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.telecom.TelecomManager; - -import com.android.contacts.common.util.PermissionsUtil; -import com.android.dialer.TransactionSafeActivity; -import com.android.dialer.onboard.OnboardingController.OnboardingScreen; -import com.android.dialer.onboard.OnboardingController.OnboardingUi; -import com.android.dialer.util.TelecomUtil; -import com.android.dialer.R; - -/** - * Activity hosting the onboarding UX flow that appears when you launch Dialer and you don't have - * the necessary permissions to run the app. - */ -public class OnboardingActivity extends TransactionSafeActivity implements OnboardingUi, - PermissionsChecker, OnboardingFragment.HostInterface { - public static final String KEY_ALREADY_REQUESTED_DEFAULT_DIALER = - "key_already_requested_default_dialer"; - public static final String KEY_CALLING_ACTIVITY_INTENT = - "key_calling_activity_intent"; - - public static final int SCREEN_DEFAULT_DIALER = 0; - public static final int SCREEN_PERMISSIONS = 1; - public static final int SCREEN_COUNT = 2; - - private OnboardingController mOnboardingController; - - private DefaultDialerOnboardingScreen mDefaultDialerOnboardingScreen; - private PermissionsOnboardingScreen mPermissionsOnboardingScreen; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.onboarding_activity); - mOnboardingController = new OnboardingController(this); - mDefaultDialerOnboardingScreen = new DefaultDialerOnboardingScreen(this); - mPermissionsOnboardingScreen = new PermissionsOnboardingScreen(this); - mOnboardingController.addScreen(mDefaultDialerOnboardingScreen); - mOnboardingController.addScreen(mPermissionsOnboardingScreen); - - mOnboardingController.showNextScreen(); - } - - @Override - public void showScreen(int screenId) { - if (!isSafeToCommitTransactions()) { - return; - } - final Fragment fragment; - switch (screenId) { - case SCREEN_DEFAULT_DIALER: - fragment = mDefaultDialerOnboardingScreen.getFragment(); - break; - case SCREEN_PERMISSIONS: - fragment = mPermissionsOnboardingScreen.getFragment(); - break; - default: - return; - } - - final FragmentTransaction ft = getFragmentManager().beginTransaction(); - ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); - ft.replace(R.id.onboarding_fragment_container, fragment); - ft.commit(); - } - - @Override - public void completeOnboardingFlow() { - final Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); - editor.putBoolean(KEY_ALREADY_REQUESTED_DEFAULT_DIALER, true).apply(); - - // Once we have completed the onboarding flow, relaunch the activity that called us, so - // that we return the user to the intended activity. - if (getIntent() != null && getIntent().getExtras() != null) { - final Intent previousActivityIntent = - getIntent().getExtras().getParcelable(KEY_CALLING_ACTIVITY_INTENT); - if (previousActivityIntent != null) { - startActivity(previousActivityIntent); - } - } - finish(); - } - - @Override - public boolean hasPhonePermissions() { - return PermissionsUtil.hasPhonePermissions(this); - } - - @Override - public boolean hasContactsPermissions() { - return PermissionsUtil.hasContactsPermissions(this); - } - - @Override - public boolean isDefaultOrSystemDialer() { - return TelecomUtil.hasModifyPhoneStatePermission(this); - } - - @Override - public boolean hasAlreadyRequestedDefaultDialer() { - return getAlreadyRequestedDefaultDialerFromPreferences(this); - } - - private static boolean getAlreadyRequestedDefaultDialerFromPreferences(Context context) { - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - return preferences.getBoolean(KEY_ALREADY_REQUESTED_DEFAULT_DIALER, false); - } - - /** - * Checks the current permissions/application state to determine if the - * {@link OnboardingActivity} should be displayed. The onboarding flow should be launched if - * the current application is NOT the system dialer AND any of these criteria are true. - * - * 1) The phone application is not currently the default dialer AND we have not - * previously displayed a prompt to ask the user to set our app as the default dialer. - * 2) The phone application does not have the Phone permission. - * 3) The phone application does not have the Contacts permission. - * - * The exception if the current application is the system dialer applies because: - * - * 1) The system dialer must always provide immediate access to the dialpad to allow - * emergency calls to be made. - * 2) In order for the system dialer to require the onboarding flow, the user must have - * intentionally removed certain permissions/selected a different dialer. This assumes the - * that the user understands the implications of the actions previously taken. For example, - * removing the Phone permission from the system dialer displays a dialog that warns the - * user that this might break certain core phone functionality. Furthermore, various elements in - * the Dialer will prompt the user to grant permissions as needed. - * - * @param context A valid context object. - * @return {@code true} if the onboarding flow should be launched to request for the - * necessary permissions or prompt the user to make us the default dialer, {@code false} - * otherwise. - */ - public static boolean shouldStartOnboardingActivity(Context context) { - // Since there is no official TelecomManager API to check for the system dialer, - // check to see if we have the system-only MODIFY_PHONE_STATE permission. - if (PermissionsUtil.hasPermission(context, Manifest.permission.MODIFY_PHONE_STATE)) { - return false; - } - - return (!getAlreadyRequestedDefaultDialerFromPreferences(context) - && !TelecomUtil.isDefaultDialer(context)) - || !PermissionsUtil.hasPhonePermissions(context) - || !PermissionsUtil.hasContactsPermissions(context); - } - - public static void startOnboardingActivity(Activity callingActivity) { - final Intent intent = new Intent(callingActivity, OnboardingActivity.class); - intent.putExtra(KEY_CALLING_ACTIVITY_INTENT, callingActivity.getIntent()); - callingActivity.startActivity(intent); - } - - /** - * Triggers the screen-specific logic that should occur when the next button is clicked. - */ - @Override - public void onNextClicked(int screenId) { - switch (screenId) { - case SCREEN_DEFAULT_DIALER: - mDefaultDialerOnboardingScreen.onNextClicked(this); - break; - case SCREEN_PERMISSIONS: - mPermissionsOnboardingScreen.onNextClicked(this); - break; - default: - return; - } - } - - @Override - public void onSkipClicked(int screenId) { - mOnboardingController.onScreenResult(screenId, false); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == SCREEN_DEFAULT_DIALER - && resultCode == RESULT_OK) { - mOnboardingController.onScreenResult(SCREEN_DEFAULT_DIALER, true); - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, - int[] grantResults) { - boolean allPermissionsGranted = true; - if (requestCode == SCREEN_PERMISSIONS) { - if (permissions.length == 0 && grantResults.length == 0) { - // Cancellation of permissions dialog - allPermissionsGranted = false; - } else { - for (int result : grantResults) { - if (result == PackageManager.PERMISSION_DENIED) { - allPermissionsGranted = false; - } - } - } - - if (allPermissionsGranted) { - mOnboardingController.onScreenResult(SCREEN_PERMISSIONS, true); - } - } - } - - public static class DefaultDialerOnboardingScreen extends OnboardingScreen { - private PermissionsChecker mPermissionsChecker; - - public DefaultDialerOnboardingScreen(PermissionsChecker permissionsChecker) { - mPermissionsChecker = permissionsChecker; - } - - @Override - public boolean shouldShowScreen() { - return !mPermissionsChecker.hasAlreadyRequestedDefaultDialer() - && !mPermissionsChecker.isDefaultOrSystemDialer(); - } - - @Override - public boolean canSkipScreen() { - return true; - } - - public Fragment getFragment() { - return new OnboardingFragment( - SCREEN_DEFAULT_DIALER, - canSkipScreen(), - R.color.onboarding_default_dialer_screen_background_color, - R.drawable.ill_onboard_default, - R.string.request_default_dialer_screen_title, - R.string.request_default_dialer_screen_content - ); - } - - @Override - public void onNextClicked(Activity activity) { - final Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER); - intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, - activity.getPackageName()); - activity.startActivityForResult(intent, SCREEN_DEFAULT_DIALER); - } - } - - public static class PermissionsOnboardingScreen extends OnboardingScreen { - private PermissionsChecker mPermissionsChecker; - - public PermissionsOnboardingScreen(PermissionsChecker permissionsChecker) { - mPermissionsChecker = permissionsChecker; - } - - @Override - public boolean shouldShowScreen() { - return !(mPermissionsChecker.hasPhonePermissions() - && mPermissionsChecker.hasContactsPermissions()); - } - - @Override - public boolean canSkipScreen() { - return false; - } - - public Fragment getFragment() { - return new OnboardingFragment( - SCREEN_PERMISSIONS, - canSkipScreen(), - R.color.onboarding_permissions_screen_background_color, - R.drawable.ill_onboard_permissions, - R.string.request_permissions_screen_title, - R.string.request_permissions_screen_content - ); - } - - @Override - public void onNextClicked(Activity activity) { - activity.requestPermissions(new String[] {CALL_PHONE, READ_CONTACTS}, - SCREEN_PERMISSIONS); - } - } -} diff --git a/src/com/android/dialer/onboard/OnboardingController.java b/src/com/android/dialer/onboard/OnboardingController.java deleted file mode 100644 index f799479ed..000000000 --- a/src/com/android/dialer/onboard/OnboardingController.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2015 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.dialer.onboard; - -import android.app.Activity; - -import java.util.ArrayList; - -/** - * Class that manages the display of various fragments that show the user prompts asking for - * certain privileged positions. - */ -public class OnboardingController { - public static abstract class OnboardingScreen { - public abstract boolean shouldShowScreen(); - public abstract boolean canSkipScreen(); - public abstract void onNextClicked(Activity activity); - } - - public interface OnboardingUi { - public void showScreen(int screenId); - /** - * Called when all the necessary permissions have been granted and the main activity - * can launch. - */ - public void completeOnboardingFlow(); - } - - private int mCurrentScreen = -1; - private OnboardingUi mOnboardingUi; - private ArrayList<OnboardingScreen> mScreens = new ArrayList<> (); - - public OnboardingController(OnboardingUi onBoardingUi) { - mOnboardingUi = onBoardingUi; - } - - public void addScreen(OnboardingScreen screen) { - mScreens.add(screen); - } - - public void showNextScreen() { - mCurrentScreen++; - - if (mCurrentScreen >= mScreens.size()) { - // Reached the end of onboarding flow - mOnboardingUi.completeOnboardingFlow(); - return; - } - - if (mScreens.get(mCurrentScreen).shouldShowScreen()) { - mOnboardingUi.showScreen(mCurrentScreen); - } else { - showNextScreen(); - } - } - - public void onScreenResult(int screenId, boolean success) { - if (screenId >= mScreens.size()) { - return; - } - - // Show the next screen in the onboarding flow only under the following situations: - // 1) Success was indicated, and the - // 2) The user tried to skip the screen, and the screen can be skipped - if (success && !mScreens.get(mCurrentScreen).shouldShowScreen()) { - showNextScreen(); - } else if (mScreens.get(mCurrentScreen).canSkipScreen()) { - showNextScreen(); - } - } -} diff --git a/src/com/android/dialer/onboard/OnboardingFragment.java b/src/com/android/dialer/onboard/OnboardingFragment.java deleted file mode 100644 index 2836a958c..000000000 --- a/src/com/android/dialer/onboard/OnboardingFragment.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2015 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.dialer.onboard; - -import android.app.Fragment; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; - -import com.android.dialer.R; - -public class OnboardingFragment extends Fragment implements OnClickListener { - public static final String ARG_SCREEN_ID = "arg_screen_id"; - public static final String ARG_CAN_SKIP_SCREEN = "arg_can_skip_screen"; - public static final String ARG_BACKGROUND_COLOR_RESOURCE = "arg_background_color_resource"; - public static final String ARG_BACKGROUND_IMAGE_RESOURCE="arg_background_image_resource"; - public static final String ARG_TEXT_TITLE_RESOURCE = "arg_text_title_resource"; - public static final String ARG_TEXT_CONTENT_RESOURCE = "arg_text_content_resource"; - - private int mScreenId; - - public interface HostInterface { - public void onNextClicked(int screenId); - public void onSkipClicked(int screenId); - } - - public OnboardingFragment() {} - - public OnboardingFragment(int screenId, boolean canSkipScreen, int backgroundColorResourceId, - int backgroundImageResourceId, int textTitleResourceId, int textContentResourceId) { - final Bundle args = new Bundle(); - args.putInt(ARG_SCREEN_ID, screenId); - args.putBoolean(ARG_CAN_SKIP_SCREEN, canSkipScreen); - args.putInt(ARG_BACKGROUND_COLOR_RESOURCE, backgroundColorResourceId); - args.putInt(ARG_BACKGROUND_IMAGE_RESOURCE, backgroundImageResourceId); - args.putInt(ARG_TEXT_TITLE_RESOURCE, textTitleResourceId); - args.putInt(ARG_TEXT_CONTENT_RESOURCE, textContentResourceId); - setArguments(args); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mScreenId = getArguments().getInt(ARG_SCREEN_ID); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.onboarding_screen_fragment, container, false); - final int backgroundColor = getResources().getColor( - getArguments().getInt(ARG_BACKGROUND_COLOR_RESOURCE), null); - view.setBackgroundColor(backgroundColor); - ((ImageView) view.findViewById(R.id.onboarding_screen_background_image)).setImageResource( - getArguments().getInt(ARG_BACKGROUND_IMAGE_RESOURCE)); - ((TextView) view.findViewById(R.id.onboarding_screen_content)). - setText(getArguments().getInt(ARG_TEXT_CONTENT_RESOURCE)); - ((TextView) view.findViewById(R.id.onboarding_screen_title)). - setText(getArguments().getInt(ARG_TEXT_TITLE_RESOURCE)); - ((Button) view.findViewById(R.id.onboard_next_button)).setTextColor(backgroundColor); - - if (!getArguments().getBoolean(ARG_CAN_SKIP_SCREEN)) { - view.findViewById(R.id.onboard_skip_button).setVisibility(View.INVISIBLE); - } - - view.findViewById(R.id.onboard_skip_button).setOnClickListener(this); - view.findViewById(R.id.onboard_next_button).setOnClickListener(this); - - return view; - } - - int getScreenId() { - return mScreenId; - } - - @Override - public void onClick(View v) { - if (v.getId() == R.id.onboard_skip_button) { - ((HostInterface) getActivity()).onSkipClicked(getScreenId()); - } else if (v.getId() == R.id.onboard_next_button) { - ((HostInterface) getActivity()).onNextClicked(getScreenId()); - } - } -} diff --git a/src/com/android/dialer/onboard/PermissionsChecker.java b/src/com/android/dialer/onboard/PermissionsChecker.java deleted file mode 100644 index c6b0bbf30..000000000 --- a/src/com/android/dialer/onboard/PermissionsChecker.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2015 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.dialer.onboard; - -/** - * Defines a mockable interface used to verify whether certain permissions/privileged operations - * are possible. - */ -public interface PermissionsChecker { - public boolean hasPhonePermissions(); - public boolean hasContactsPermissions(); - public boolean isDefaultOrSystemDialer(); - public boolean hasAlreadyRequestedDefaultDialer(); -} diff --git a/tests/src/com/android/dialer/onboard/DefaultDialerOnboardScreenTest.java b/tests/src/com/android/dialer/onboard/DefaultDialerOnboardScreenTest.java deleted file mode 100644 index 5e6544f4a..000000000 --- a/tests/src/com/android/dialer/onboard/DefaultDialerOnboardScreenTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2015 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.dialer.onboard; - -import static org.mockito.Mockito.when; - -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import com.android.dialer.onboard.OnboardingActivity.DefaultDialerOnboardingScreen; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -@SmallTest -public class DefaultDialerOnboardScreenTest extends AndroidTestCase { - private DefaultDialerOnboardingScreen mScreen; - @Mock private PermissionsChecker mPermissionsChecker; - - @Override - protected void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); - mScreen = new DefaultDialerOnboardingScreen(mPermissionsChecker); - } - - public void testNeverRequestedForDefaultDialer_shouldShowScreen() { - when(mPermissionsChecker.hasAlreadyRequestedDefaultDialer()).thenReturn(false); - assertTrue(mScreen.shouldShowScreen()); - } - - public void testAlreadyAskedForDefaultDialer_shouldNotShowScreen() { - when(mPermissionsChecker.hasAlreadyRequestedDefaultDialer()).thenReturn(true); - assertFalse(mScreen.shouldShowScreen()); - } - - public void testAlreadySetAsDefaultDialer_shouldNotShowScreen() { - when(mPermissionsChecker.hasAlreadyRequestedDefaultDialer()).thenReturn(false); - when(mPermissionsChecker.isDefaultOrSystemDialer()).thenReturn(true); - assertFalse(mScreen.shouldShowScreen()); - } - - public void testCanSkipScreen() { - assertTrue(mScreen.canSkipScreen()); - } -} diff --git a/tests/src/com/android/dialer/onboard/OnboardingControllerTest.java b/tests/src/com/android/dialer/onboard/OnboardingControllerTest.java deleted file mode 100644 index d6348553f..000000000 --- a/tests/src/com/android/dialer/onboard/OnboardingControllerTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2015 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.dialer.onboard; - -import android.app.Activity; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; - -@SmallTest -public class OnboardingControllerTest extends AndroidTestCase { - private MockOnboardUi mOnboardUi; - private OnboardingController mController; - - public class MockOnboardUi implements OnboardingController.OnboardingUi { - public int currentScreen = -1; - public boolean completedOnboardingFlow = false; - - @Override - public void showScreen(int screenId) { - currentScreen = screenId; - } - - @Override - public void completeOnboardingFlow() { - completedOnboardingFlow = true; - } - } - - public class MockScreen extends OnboardingController.OnboardingScreen { - boolean shouldShowScreen; - boolean canSkipScreen; - - public MockScreen(boolean shouldShowScreen, boolean canSkipScreen) { - this.shouldShowScreen = shouldShowScreen; - this.canSkipScreen = canSkipScreen; - } - - @Override - public boolean shouldShowScreen() { - return shouldShowScreen; - } - - @Override - public boolean canSkipScreen() { - return canSkipScreen; - } - - @Override - public void onNextClicked(Activity activity) { - } - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - mOnboardUi = new MockOnboardUi(); - mController = new OnboardingController(mOnboardUi); - } - - @Suppress - public void testNoScreensToDisplay_OnboardingFlowImmediatelyCompleted() { - mController.showNextScreen(); - assertEquals(-1, mOnboardUi.currentScreen); - assertTrue(mOnboardUi.completedOnboardingFlow); - } - - @Suppress - public void testSkipAllScreens_OnboardingFlowImmediatelyCompleted() { - mController.addScreen(new MockScreen(false /* shouldShowScreen */, - true /* canSkipScreen */)); - mController.addScreen(new MockScreen(false /* shouldShowScreen */, - true /* canSkipScreen */)); - mController.addScreen(new MockScreen(false /* shouldShowScreen */, - true /* canSkipScreen */)); - mController.showNextScreen(); - assertEquals(-1, mOnboardUi.currentScreen); - assertTrue(mOnboardUi.completedOnboardingFlow); - } - - @Suppress - public void testFirstScreenNotNeeded_ShowsSecondScreen() { - mController.addScreen(new MockScreen(false /* shouldShowScreen */, - false /* canSkipScreen */)); - mController.addScreen(new MockScreen(true /* shouldShowScreen */, - false /* canSkipScreen */)); - mController.showNextScreen(); - assertEquals(1, mOnboardUi.currentScreen); - } - - @Suppress - public void testScreenRequired() { - final MockScreen mockScreen = - new MockScreen(true /* shouldShowScreen */, false /* canSkipScreen */); - mController.addScreen(mockScreen); - - mController.showNextScreen(); - assertEquals(0, mOnboardUi.currentScreen); - assertFalse(mOnboardUi.completedOnboardingFlow); - - // User tried to skip an unskippable screen - mController.onScreenResult(0, false); - assertEquals(0, mOnboardUi.currentScreen); - assertFalse(mOnboardUi.completedOnboardingFlow); - - // User said yes, but the underlying requirements have not been fulfilled yet, so don't - // show the next screen. Should be very rare in practice. - mController.onScreenResult(0, true); - assertEquals(0, mOnboardUi.currentScreen); - assertFalse(mOnboardUi.completedOnboardingFlow); - - // Requirement has been fulfiled. - mockScreen.shouldShowScreen = false; - mController.onScreenResult(0, true); - assertTrue(mOnboardUi.completedOnboardingFlow); - } - - /** - * Verifies the use case where completing the first screen will provide the necessary conditions - * to skip the second screen as well. - * - * For example, setting the default dialer in the first screen will automatically grant - * permissions such that the second permissions screen is no longer needed. - */ - @Suppress - public void testFirstScreenCompleted_SkipsSecondScreen() { - final MockScreen mockScreen1 = - new MockScreen(true /* shouldShowScreen */, true /* canSkipScreen */); - final MockScreen mockScreen2 = - new MockScreen(true /* shouldShowScreen */, false /* canSkipScreen */); - mController.addScreen(mockScreen1); - mController.addScreen(mockScreen2); - - mController.showNextScreen(); - assertEquals(0, mOnboardUi.currentScreen); - assertFalse(mOnboardUi.completedOnboardingFlow); - - // Screen 1 succeeded, screen 2 is no longer necessary - mockScreen2.shouldShowScreen = false; - mController.onScreenResult(0, true); - assertEquals(0, mOnboardUi.currentScreen); - assertTrue(mOnboardUi.completedOnboardingFlow); - } - - /** - * Verifies the use case where skipping the first screen will proceed to show the second screen - * since the necessary conditions to skip the second screen have not been met. - */ - @Suppress - public void testFirstScreenSkipped_ShowsSecondScreen() { - final MockScreen mockScreen1 = - new MockScreen(true /* shouldShowScreen */, true /* canSkipScreen */); - final MockScreen mockScreen2 = - new MockScreen(true /* shouldShowScreen */, false /* canSkipScreen */); - mController.addScreen(mockScreen1); - mController.addScreen(mockScreen2); - - mController.showNextScreen(); - assertEquals(0, mOnboardUi.currentScreen); - assertFalse(mOnboardUi.completedOnboardingFlow); - - // Screen 1 skipped - mController.onScreenResult(0, false); - assertEquals(1, mOnboardUi.currentScreen); - assertFalse(mOnboardUi.completedOnboardingFlow); - - // Repeatedly trying to skip screen 2 will not work since it is marked as unskippable. - mController.onScreenResult(1, false); - assertEquals(1, mOnboardUi.currentScreen); - assertFalse(mOnboardUi.completedOnboardingFlow); - } -} diff --git a/tests/src/com/android/dialer/onboard/PermissionsOnboardScreenTest.java b/tests/src/com/android/dialer/onboard/PermissionsOnboardScreenTest.java deleted file mode 100644 index 4c5ea33b8..000000000 --- a/tests/src/com/android/dialer/onboard/PermissionsOnboardScreenTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2015 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.dialer.onboard; - -import static org.mockito.Mockito.when; - -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import com.android.dialer.onboard.OnboardingActivity.PermissionsOnboardingScreen; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -@SmallTest -public class PermissionsOnboardScreenTest extends AndroidTestCase { - private PermissionsOnboardingScreen mScreen; - @Mock private PermissionsChecker mPermissionsChecker; - - @Override - protected void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); - mScreen = new PermissionsOnboardingScreen(mPermissionsChecker); - } - - public void testMissingContactsAndPhonePermissions_shouldShowScreen() { - when(mPermissionsChecker.hasContactsPermissions()).thenReturn(false); - when(mPermissionsChecker.hasPhonePermissions()).thenReturn(false); - assertTrue(mScreen.shouldShowScreen()); - } - - public void testMissingContactsPermission_shouldShowScreen() { - when(mPermissionsChecker.hasContactsPermissions()).thenReturn(false); - when(mPermissionsChecker.hasPhonePermissions()).thenReturn(true); - assertTrue(mScreen.shouldShowScreen()); - } - - public void testMissingPhonePermission_shouldShowScreen() { - when(mPermissionsChecker.hasContactsPermissions()).thenReturn(true); - when(mPermissionsChecker.hasPhonePermissions()).thenReturn(false); - assertTrue(mScreen.shouldShowScreen()); - } - - public void testHasAllPermissions_shouldNotShowScreen() { - when(mPermissionsChecker.hasContactsPermissions()).thenReturn(true); - when(mPermissionsChecker.hasPhonePermissions()).thenReturn(true); - assertFalse(mScreen.shouldShowScreen()); - } - - public void testCanSkipScreen() { - assertFalse(mScreen.canSkipScreen()); - } -} |