blob: 378948033ac42c95473a48016d3e2f765935a76d [file] [log] [blame]
Wenyi Wangcc3016e2015-12-30 16:54:05 -08001/*
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 Mai69c182a2016-12-05 13:07:03 -080017package com.android.contacts.preference;
Wenyi Wangcc3016e2015-12-30 16:54:05 -080018
Tingting Wang87dabf12016-03-08 12:27:28 -080019import android.content.ActivityNotFoundException;
Wenyi Wangcc3016e2015-12-30 16:54:05 -080020import android.content.Context;
21import android.content.Intent;
22import android.content.pm.PackageInfo;
23import android.content.pm.PackageManager;
Tingting Wang87dabf12016-03-08 12:27:28 -080024import android.net.Uri;
Wenyi Wangcc3016e2015-12-30 16:54:05 -080025import android.os.Bundle;
26import android.preference.Preference;
27import android.preference.PreferenceFragment;
Tingting Wang87dabf12016-03-08 12:27:28 -080028import android.widget.Toast;
Wenyi Wangcc3016e2015-12-30 16:54:05 -080029
Arthur Wang3f6a2442016-12-05 14:51:59 -080030import com.android.contacts.R;
Gary Mai0a49afa2016-12-05 15:53:58 -080031import com.android.contacts.activities.LicenseActivity;
Wenyi Wangcc3016e2015-12-30 16:54:05 -080032
33/**
34 * This fragment shows the preferences for "about".
35 */
36public class AboutPreferenceFragment extends PreferenceFragment {
37
James Laskeyff9a19d2016-11-15 13:36:34 -080038 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 Wang87dabf12016-03-08 12:27:28 -080040
Wenyi Wanga0313442016-05-16 11:55:19 -070041 public static AboutPreferenceFragment newInstance() {
42 return new AboutPreferenceFragment();
43 }
44
Wenyi Wangcc3016e2015-12-30 16:54:05 -080045 @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 Wang87dabf12016-03-08 12:27:28 -080066
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 Wangcc3016e2015-12-30 16:54:05 -080090 }
91
92 @Override
93 public Context getContext() {
94 return getActivity();
95 }
Tingting Wang87dabf12016-03-08 12:27:28 -080096
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 Wangcc3016e2015-12-30 16:54:05 -0800103}
104