Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 17 | package com.android.contacts.preference; |
Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 18 | |
Tingting Wang | 87dabf1 | 2016-03-08 12:27:28 -0800 | [diff] [blame] | 19 | import android.content.ActivityNotFoundException; |
Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.pm.PackageInfo; |
| 23 | import android.content.pm.PackageManager; |
Tingting Wang | 87dabf1 | 2016-03-08 12:27:28 -0800 | [diff] [blame] | 24 | import android.net.Uri; |
Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
| 26 | import android.preference.Preference; |
| 27 | import android.preference.PreferenceFragment; |
Tingting Wang | 87dabf1 | 2016-03-08 12:27:28 -0800 | [diff] [blame] | 28 | import android.widget.Toast; |
Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 29 | |
Arthur Wang | 3f6a244 | 2016-12-05 14:51:59 -0800 | [diff] [blame] | 30 | import com.android.contacts.R; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 31 | import com.android.contacts.activities.LicenseActivity; |
Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * This fragment shows the preferences for "about". |
| 35 | */ |
| 36 | public class AboutPreferenceFragment extends PreferenceFragment { |
| 37 | |
James Laskey | ff9a19d | 2016-11-15 13:36:34 -0800 | [diff] [blame] | 38 | public static final String PRIVACY_POLICY_URL = "http://www.google.com/policies/privacy"; |
| 39 | public static final String TERMS_OF_SERVICE_URL = "http://www.google.com/policies/terms"; |
Tingting Wang | 87dabf1 | 2016-03-08 12:27:28 -0800 | [diff] [blame] | 40 | |
Wenyi Wang | a031344 | 2016-05-16 11:55:19 -0700 | [diff] [blame] | 41 | public static AboutPreferenceFragment newInstance() { |
| 42 | return new AboutPreferenceFragment(); |
| 43 | } |
| 44 | |
Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 45 | @Override |
| 46 | public void onCreate(Bundle savedInstanceState) { |
| 47 | super.onCreate(savedInstanceState); |
| 48 | |
| 49 | // Load the preferences from an XML resource |
| 50 | addPreferencesFromResource(R.xml.preference_about); |
| 51 | |
| 52 | // Set build version of Contacts App. |
| 53 | final PackageManager manager = getActivity().getPackageManager(); |
| 54 | try { |
| 55 | final PackageInfo info = manager.getPackageInfo(getActivity().getPackageName(), 0); |
| 56 | final Preference versionPreference = findPreference( |
| 57 | getString(R.string.pref_build_version_key)); |
| 58 | versionPreference.setSummary(info.versionName); |
| 59 | } catch (PackageManager.NameNotFoundException e) { |
| 60 | // Nothing |
| 61 | } |
| 62 | |
| 63 | final Preference licensePreference = findPreference( |
| 64 | getString(R.string.pref_open_source_licenses_key)); |
| 65 | licensePreference.setIntent(new Intent(getActivity(), LicenseActivity.class)); |
Tingting Wang | 87dabf1 | 2016-03-08 12:27:28 -0800 | [diff] [blame] | 66 | |
| 67 | final Preference privacyPolicyPreference = findPreference("pref_privacy_policy"); |
| 68 | final Preference termsOfServicePreference = findPreference("pref_terms_of_service"); |
| 69 | |
| 70 | final Preference.OnPreferenceClickListener listener = |
| 71 | new Preference.OnPreferenceClickListener() { |
| 72 | @Override |
| 73 | public boolean onPreferenceClick(Preference preference) { |
| 74 | try { |
| 75 | if (preference == privacyPolicyPreference) { |
| 76 | startActivityForUrl(PRIVACY_POLICY_URL); |
| 77 | } else if (preference == termsOfServicePreference) { |
| 78 | startActivityForUrl(TERMS_OF_SERVICE_URL); |
| 79 | } |
| 80 | } catch (ActivityNotFoundException ex) { |
| 81 | Toast.makeText(getContext(), getString(R.string.url_open_error_toast), |
| 82 | Toast.LENGTH_SHORT).show(); |
| 83 | } |
| 84 | return true; |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | privacyPolicyPreference.setOnPreferenceClickListener(listener); |
| 89 | termsOfServicePreference.setOnPreferenceClickListener(listener); |
Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public Context getContext() { |
| 94 | return getActivity(); |
| 95 | } |
Tingting Wang | 87dabf1 | 2016-03-08 12:27:28 -0800 | [diff] [blame] | 96 | |
| 97 | private void startActivityForUrl(String urlString) { |
| 98 | final Intent intent = new Intent(); |
| 99 | intent.setAction(Intent.ACTION_VIEW); |
| 100 | intent.setData(Uri.parse(urlString)); |
| 101 | startActivity(intent); |
| 102 | } |
Wenyi Wang | cc3016e | 2015-12-30 16:54:05 -0800 | [diff] [blame] | 103 | } |
| 104 | |