diff options
author | Zhizhi Liu <zhizhiliu@google.com> | 2018-05-11 17:07:37 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-05-11 17:07:37 +0000 |
commit | 9b0f141b515c1cafae7e34285da904991a6243d2 (patch) | |
tree | 57a5c7481d6cf6a457d728686e3b46045830775b | |
parent | f68373cadfdcb04464ee765de8a461967042dd11 (diff) | |
parent | 45cc75b5fc8c04183990752ad3c9c8117343b5a8 (diff) | |
download | TvSettings-9b0f141b515c1cafae7e34285da904991a6243d2.tar.gz |
Merge "Implement settings suggestion for device name." into pi-dev
9 files changed, 232 insertions, 2 deletions
diff --git a/Settings/AndroidManifest.xml b/Settings/AndroidManifest.xml index c1bc7724d..953d95e22 100644 --- a/Settings/AndroidManifest.xml +++ b/Settings/AndroidManifest.xml @@ -490,6 +490,22 @@ <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> + <activity android:name=".name.DeviceNameSuggestionActivity" + android:excludeFromRecents="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.android.settings.suggested.category.FIRST_IMPRESSION" /> + </intent-filter> + <!--Default title for suggested setting--> + <meta-data android:name="com.android.settings.title" + android:resource="@string/device_name_suggestion_title" /> + <!--Default summary for suggested setting--> + <meta-data android:name="com.android.settings.summary" + android:resource="@string/device_name_suggestion_summary" /> + <!--Default icon for our suggested setting--> + <meta-data android:name="com.android.settings.icon" + android:resource="@drawable/ic_device_name_suggestion" /> + </activity> <activity android:name=".name.setup.DeviceNameFlowStartActivity" android:configChanges="keyboardHidden|navigation" @@ -655,6 +671,14 @@ <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider> + <provider + android:name=".name.SuggestionContentProvider" + android:authorities="com.android.tv.settings.name" + android:exported="true" > + <intent-filter> + <action android:name="com.android.settings.action.SUGGESTION_STATE_PROVIDER" /> + </intent-filter> + </provider> </application> </manifest> diff --git a/Settings/res/drawable/ic_device_name_suggestion.xml b/Settings/res/drawable/ic_device_name_suggestion.xml new file mode 100644 index 000000000..f9f6429f4 --- /dev/null +++ b/Settings/res/drawable/ic_device_name_suggestion.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2018 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. +--> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + + <path + android:pathData="M 0 0 L 24 0 L 24 24 L 0 24 Z" /> + <path + android:fillColor="#FFFFFF" + android:pathData="M21,3H3C1.9,3,1,3.9,1,5v12c0,1.1,0.9,2,2,2h5v2h8v-2h5c1.1,0,1.99-0.9,1.99-2L23,5C23,3.9,22.1,3,21,3z M21,17H3V5h18V17z M4,14v2h2C6,14.89,5.11,14,4,14z M4,11v1.43c1.97,0,3.57,1.6,3.57,3.57H9C9,13.24,6.76,11,4,11z M4,8v1.45 c3.61,0,6.55,2.93,6.55,6.55H12C12,11.58,8.41,8,4,8z" /> +</vector>
\ No newline at end of file diff --git a/Settings/res/layout/suggestion_item.xml b/Settings/res/layout/suggestion_item.xml index 9d8c39bff..ec041a3cf 100644 --- a/Settings/res/layout/suggestion_item.xml +++ b/Settings/res/layout/suggestion_item.xml @@ -77,6 +77,7 @@ android:id="@+id/dismiss_button" android:layout_width="22dp" android:layout_height="22dp" + android:layout_marginStart="6dp" android:layout_gravity="center_vertical" android:alpha="0.4" android:clickable="true" diff --git a/Settings/res/values/strings.xml b/Settings/res/values/strings.xml index 1ee0e469d..2a36177c3 100644 --- a/Settings/res/values/strings.xml +++ b/Settings/res/values/strings.xml @@ -1514,6 +1514,10 @@ <string name="device_rename_title">Rename this <xliff:g id="devicemodel" example="Nexus Player">%1$s</xliff:g></string> <!-- Description on summary/status screen that tells you what the name of your device is [CHAR LIMIT=NONE] --> <string name="device_rename_description">This <xliff:g id="devicemodel" example="Nexus Player">%1$s</xliff:g> is currently named \"<xliff:g id="devicename" example="Living Room Player">%2$s</xliff:g>\"</string> + <!-- The title of the suggestion to notify the user to name the device [CHART LIMIT = 50] --> + <string name="device_name_suggestion_title">Set your device name</string> + <!-- The summary of the suggestion to notify the user to name the device [CHAR LIMIT = 100] --> + <string name="device_name_suggestion_summary">Use this name when casting photos, videos or more from your phone to your TV</string> <!-- The 'yes' or 'edit' equivalent in a yes/no choice circumstance [CHAR LIMIT=30] --> <string name="change_setting">Change</string> <!-- The 'no' or 'keep the same' equivalent in a yes/no choice circumstance [CHAR LIMIT=30]--> diff --git a/Settings/src/com/android/tv/settings/name/DeviceNameSetCustomFragment.java b/Settings/src/com/android/tv/settings/name/DeviceNameSetCustomFragment.java index 877c2add0..03d010370 100644 --- a/Settings/src/com/android/tv/settings/name/DeviceNameSetCustomFragment.java +++ b/Settings/src/com/android/tv/settings/name/DeviceNameSetCustomFragment.java @@ -106,7 +106,8 @@ public class DeviceNameSetCustomFragment extends GuidedStepFragment { if (getActivity() instanceof DeviceNameFlowStartActivity) { ((DeviceNameFlowStartActivity) getActivity()).setResultOk(true); } - + DeviceNameSuggestionStatus.getInstance( + getActivity().getApplicationContext()).setFinished(); getActivity().finish(); return super.onGuidedActionEditedAndProceed(action); } else { diff --git a/Settings/src/com/android/tv/settings/name/DeviceNameSetFragment.java b/Settings/src/com/android/tv/settings/name/DeviceNameSetFragment.java index c987db569..17da8487b 100644 --- a/Settings/src/com/android/tv/settings/name/DeviceNameSetFragment.java +++ b/Settings/src/com/android/tv/settings/name/DeviceNameSetFragment.java @@ -128,7 +128,8 @@ public class DeviceNameSetFragment extends GuidedStepFragment { if (getActivity() instanceof DeviceNameFlowStartActivity) { ((DeviceNameFlowStartActivity) getActivity()).setResultOk(true); } - + DeviceNameSuggestionStatus.getInstance( + getActivity().getApplicationContext()).setFinished(); getActivity().setResult(Activity.RESULT_OK); getActivity().finish(); } else if (id == mDeviceNames.size()) { diff --git a/Settings/src/com/android/tv/settings/name/DeviceNameSuggestionActivity.java b/Settings/src/com/android/tv/settings/name/DeviceNameSuggestionActivity.java new file mode 100644 index 000000000..56f6635aa --- /dev/null +++ b/Settings/src/com/android/tv/settings/name/DeviceNameSuggestionActivity.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 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.tv.settings.name; + +import android.annotation.Nullable; +import android.app.Activity; +import android.os.Bundle; +import android.support.v17.leanback.app.GuidedStepFragment; + +/** + * Entry activity for settings suggestions. + */ +public class DeviceNameSuggestionActivity extends Activity { + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState == null) { + GuidedStepFragment.addAsRoot(this, DeviceNameSetFragment.newInstance(), + android.R.id.content); + } + } +} diff --git a/Settings/src/com/android/tv/settings/name/DeviceNameSuggestionStatus.java b/Settings/src/com/android/tv/settings/name/DeviceNameSuggestionStatus.java new file mode 100644 index 000000000..c403a1115 --- /dev/null +++ b/Settings/src/com/android/tv/settings/name/DeviceNameSuggestionStatus.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018 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.tv.settings.name; + +import android.content.Context; +import android.content.SharedPreferences; + +/** + * The class to store the status of device name suggestion indicating whether it is finished. + */ +public class DeviceNameSuggestionStatus { + private static final String SUGGESTION_STATUS_STORAGE_FILE_NAME = "suggestionStatusStorage"; + private static final String IS_SUGGESTION_FINISHED = "IsSuggestionFinished"; + private SharedPreferences mSharedPreferences; + private static DeviceNameSuggestionStatus sInstance; + + /** + * Create the instance if it does not exist. + */ + public static DeviceNameSuggestionStatus getInstance(Context context) { + if (sInstance == null) { + sInstance = new DeviceNameSuggestionStatus(context); + } + return sInstance; + } + + private DeviceNameSuggestionStatus(Context context) { + mSharedPreferences = context.getSharedPreferences( + SUGGESTION_STATUS_STORAGE_FILE_NAME, Context.MODE_PRIVATE); + } + + /** + * Set the suggestion to be finished. + */ + public void setFinished() { + if (!isFinished()) { + mSharedPreferences.edit().putBoolean(IS_SUGGESTION_FINISHED, true).apply(); + } + } + + /** + * Return the status of the suggestion. + * @return True if finished. + */ + public boolean isFinished() { + return mSharedPreferences.getBoolean(IS_SUGGESTION_FINISHED, false); + } +} diff --git a/Settings/src/com/android/tv/settings/name/SuggestionContentProvider.java b/Settings/src/com/android/tv/settings/name/SuggestionContentProvider.java new file mode 100644 index 000000000..1efbf32e3 --- /dev/null +++ b/Settings/src/com/android/tv/settings/name/SuggestionContentProvider.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2018 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.tv.settings.name; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; + +/** + * The content provider to provide the information about the device name suggestion which would be + * used for settings suggestions. + */ +public class SuggestionContentProvider extends ContentProvider { + private static final String GET_SUGGESTION_STATE_METHOD = "getSuggestionState"; + private static final String EXTRA_IS_COMPLETE = "candidate_is_complete"; + + @Override + public boolean onCreate() { + return true; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + throw new UnsupportedOperationException("query operation not supported currently."); + } + + @Override + public String getType(Uri uri) { + throw new UnsupportedOperationException("getType operation not supported currently."); + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + throw new UnsupportedOperationException("insert operation not supported currently."); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + throw new UnsupportedOperationException("delete operation not supported currently."); + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + throw new UnsupportedOperationException("update operation not supported currently."); + } + + @Override + public Bundle call(String method, String arg, Bundle extras) { + Bundle bundle = new Bundle(); + if (method.equals(GET_SUGGESTION_STATE_METHOD)) { + boolean isComplete = DeviceNameSuggestionStatus.getInstance(getContext()).isFinished(); + bundle.putBoolean(EXTRA_IS_COMPLETE, isComplete); + } + return bundle; + } +} |