blob: 0d34f68070ec6b2611782e29ed8f65538f1404ab [file] [log] [blame]
Yorke Leeb3d841a2014-07-10 11:38:55 -07001/*
2 * Copyright (C) 2010 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;
Yorke Leeb3d841a2014-07-10 11:38:55 -070018
Wenyi Wang13874012016-05-27 15:23:53 -070019import android.app.Activity;
Wenyi Wanga0313442016-05-16 11:55:19 -070020import android.app.LoaderManager;
Marcus Hagerott819214d2016-09-29 14:58:27 -070021import android.content.BroadcastReceiver;
Wenyi Wanga0313442016-05-16 11:55:19 -070022import android.content.ContentUris;
Wenyi Wang9342fbb2015-11-17 19:36:35 -080023import android.content.Context;
Wenyi Wanga0313442016-05-16 11:55:19 -070024import android.content.CursorLoader;
25import android.content.Intent;
Marcus Hagerott819214d2016-09-29 14:58:27 -070026import android.content.IntentFilter;
Wenyi Wanga0313442016-05-16 11:55:19 -070027import android.content.Loader;
Walter Jang5665f362016-01-20 21:44:10 +000028import android.content.res.Resources;
Wenyi Wanga0313442016-05-16 11:55:19 -070029import android.database.Cursor;
30import android.net.Uri;
Yorke Leeb3d841a2014-07-10 11:38:55 -070031import android.os.Bundle;
Tingting Wangdebe2da2015-11-01 20:19:03 -080032import android.preference.Preference;
Brian Attwellc2e912c2014-10-27 12:29:44 -070033import android.preference.PreferenceFragment;
Wenyi Wangae5c3a02016-06-27 12:43:31 -070034import android.provider.BlockedNumberContract;
Wenyi Wanga0313442016-05-16 11:55:19 -070035import android.provider.ContactsContract.Contacts;
36import android.provider.ContactsContract.Profile;
Marcus Hagerott819214d2016-09-29 14:58:27 -070037import android.support.design.widget.Snackbar;
38import android.support.v4.content.LocalBroadcastManager;
Tingting Wangf5b12582016-06-30 18:27:22 -070039import android.telecom.TelecomManager;
40import android.telephony.TelephonyManager;
Marcus Hagerott819214d2016-09-29 14:58:27 -070041import android.view.LayoutInflater;
42import android.view.View;
43import android.view.ViewGroup;
44import android.widget.FrameLayout;
Yorke Leeb3d841a2014-07-10 11:38:55 -070045
Gary Mai0a49afa2016-12-05 15:53:58 -080046import com.android.contacts.ContactsUtils;
Marcus Hagerott819214d2016-09-29 14:58:27 -070047import com.android.contacts.R;
Marcus Hagerott95246bb2016-11-11 10:56:09 -080048import com.android.contacts.SimImportService;
Gary Mai69c182a2016-12-05 13:07:03 -080049import com.android.contacts.compat.TelecomManagerUtil;
50import com.android.contacts.compat.TelephonyManagerCompat;
51import com.android.contacts.interactions.ExportDialogFragment;
52import com.android.contacts.interactions.ImportDialogFragment;
53import com.android.contacts.list.ContactListFilter;
54import com.android.contacts.list.ContactListFilterController;
55import com.android.contacts.logging.ScreenEvent.ScreenType;
56import com.android.contacts.model.AccountTypeManager;
57import com.android.contacts.model.account.AccountWithDataSet;
58import com.android.contacts.util.AccountFilterUtil;
59import com.android.contacts.util.ImplicitIntentsUtil;
James Laskeyff9a19d2016-11-15 13:36:34 -080060import com.android.contactsbind.HelpUtils;
Tingting Wangc939ae32015-09-01 16:45:08 -070061
62import java.util.List;
Yorke Leeb3d841a2014-07-10 11:38:55 -070063
64/**
Wenyi Wangcc3016e2015-12-30 16:54:05 -080065 * This fragment shows the preferences for "display options"
Yorke Leeb3d841a2014-07-10 11:38:55 -070066 */
Wenyi Wang13874012016-05-27 15:23:53 -070067public class DisplayOptionsPreferenceFragment extends PreferenceFragment
68 implements Preference.OnPreferenceClickListener {
Yorke Leeb3d841a2014-07-10 11:38:55 -070069
Walter Jangf2cad222016-07-14 19:49:06 +000070 private static final int REQUEST_CODE_CUSTOM_CONTACTS_FILTER = 0;
71
Wenyi Wang13874012016-05-27 15:23:53 -070072 private static final String ARG_CONTACTS_AVAILABLE = "are_contacts_available";
Wenyi Wang13874012016-05-27 15:23:53 -070073 private static final String ARG_NEW_LOCAL_PROFILE = "new_local_profile";
Wenyi Wanga0313442016-05-16 11:55:19 -070074
75 private static final String KEY_ABOUT = "about";
76 private static final String KEY_ACCOUNTS = "accounts";
Tingting Wang940f0152016-06-30 13:15:49 -070077 private static final String KEY_DEFAULT_ACCOUNT = "defaultAccount";
Tingting Wangf5b12582016-06-30 18:27:22 -070078 private static final String KEY_BLOCKED_NUMBERS = "blockedNumbers";
Wenyi Wanga0313442016-05-16 11:55:19 -070079 private static final String KEY_DISPLAY_ORDER = "displayOrder";
Walter Jangf2cad222016-07-14 19:49:06 +000080 private static final String KEY_CUSTOM_CONTACTS_FILTER = "customContactsFilter";
James Laskey1e2102f2016-09-19 10:09:08 -070081 private static final String KEY_IMPORT = "import";
82 private static final String KEY_EXPORT = "export";
Wenyi Wanga0313442016-05-16 11:55:19 -070083 private static final String KEY_MY_INFO = "myInfo";
84 private static final String KEY_SORT_ORDER = "sortOrder";
85
86 private static final int LOADER_PROFILE = 0;
87
88 /**
89 * Callbacks for hosts of the {@link DisplayOptionsPreferenceFragment}.
90 */
91 public interface ProfileListener {
92 /**
93 * Invoked after profile has been loaded.
94 */
95 void onProfileLoaded(Cursor data);
96 }
97
98 /**
99 * The projections that are used to obtain user profile
100 */
101 public static class ProfileQuery {
102 /**
103 * Not instantiable.
104 */
105 private ProfileQuery() {}
106
107 private static final String[] PROFILE_PROJECTION_PRIMARY = new String[] {
108 Contacts._ID, // 0
109 Contacts.DISPLAY_NAME_PRIMARY, // 1
110 Contacts.IS_USER_PROFILE, // 2
111 };
112
113 private static final String[] PROFILE_PROJECTION_ALTERNATIVE = new String[] {
114 Contacts._ID, // 0
115 Contacts.DISPLAY_NAME_ALTERNATIVE, // 1
116 Contacts.IS_USER_PROFILE, // 2
117 };
118
119 public static final int CONTACT_ID = 0;
120 public static final int CONTACT_DISPLAY_NAME = 1;
121 public static final int CONTACT_IS_USER_PROFILE = 2;
122 }
123
124 private String mNewLocalProfileExtra;
Wenyi Wang13874012016-05-27 15:23:53 -0700125 private boolean mAreContactsAvailable;
126
127 private boolean mHasProfile;
128 private long mProfileContactId;
Wenyi Wanga0313442016-05-16 11:55:19 -0700129
130 private Preference mMyInfoPreference;
131
132 private ProfileListener mListener;
133
Marcus Hagerott819214d2016-09-29 14:58:27 -0700134 private ViewGroup mRootView;
135 private SaveServiceResultListener mSaveServiceListener;
136
Wenyi Wanga0313442016-05-16 11:55:19 -0700137 private final LoaderManager.LoaderCallbacks<Cursor> mProfileLoaderListener =
138 new LoaderManager.LoaderCallbacks<Cursor>() {
139
140 @Override
141 public CursorLoader onCreateLoader(int id, Bundle args) {
142 final CursorLoader loader = createCursorLoader(getContext());
143 loader.setUri(Profile.CONTENT_URI);
144 loader.setProjection(getProjection(getContext()));
145 return loader;
146 }
147
148 @Override
149 public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
150 if (mListener != null) {
151 mListener.onProfileLoaded(data);
152 }
153 }
154
155 public void onLoaderReset(Loader<Cursor> loader) {
156 }
157 };
158
159 public static DisplayOptionsPreferenceFragment newInstance(String newLocalProfileExtra,
Walter Jang0396cf72016-09-21 13:23:29 -0700160 boolean areContactsAvailable) {
Wenyi Wanga0313442016-05-16 11:55:19 -0700161 final DisplayOptionsPreferenceFragment fragment = new DisplayOptionsPreferenceFragment();
162 final Bundle args = new Bundle();
163 args.putString(ARG_NEW_LOCAL_PROFILE, newLocalProfileExtra);
Wenyi Wang13874012016-05-27 15:23:53 -0700164 args.putBoolean(ARG_CONTACTS_AVAILABLE, areContactsAvailable);
Wenyi Wanga0313442016-05-16 11:55:19 -0700165 fragment.setArguments(args);
166 return fragment;
167 }
168
Yorke Leeb3d841a2014-07-10 11:38:55 -0700169 @Override
Wenyi Wang13874012016-05-27 15:23:53 -0700170 public void onAttach(Activity activity) {
171 super.onAttach(activity);
172 try {
173 mListener = (ProfileListener) activity;
174 } catch (ClassCastException e) {
175 throw new ClassCastException(activity.toString() + " must implement ProfileListener");
176 }
177 }
178
179 @Override
Marcus Hagerott819214d2016-09-29 14:58:27 -0700180 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
181 // Wrap the preference view in a FrameLayout so we can show a snackbar
182 mRootView = new FrameLayout(getActivity());
183 final View list = super.onCreateView(inflater, mRootView, savedInstanceState);
184 mRootView.addView(list);
185 return mRootView;
186 }
187
188 @Override
189 public void onViewCreated(View view, Bundle savedInstanceState) {
190 super.onViewCreated(view, savedInstanceState);
191
192 mSaveServiceListener = new SaveServiceResultListener();
193 LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
194 mSaveServiceListener,
Marcus Hagerott95246bb2016-11-11 10:56:09 -0800195 new IntentFilter(SimImportService.BROADCAST_SIM_IMPORT_COMPLETE));
Marcus Hagerott819214d2016-09-29 14:58:27 -0700196 }
197
198 @Override
Yorke Leeb3d841a2014-07-10 11:38:55 -0700199 public void onCreate(Bundle savedInstanceState) {
200 super.onCreate(savedInstanceState);
201
202 // Load the preferences from an XML resource
203 addPreferencesFromResource(R.xml.preference_display_options);
Tingting Wangc939ae32015-09-01 16:45:08 -0700204
Wenyi Wanga0313442016-05-16 11:55:19 -0700205 final Bundle args = getArguments();
206 mNewLocalProfileExtra = args.getString(ARG_NEW_LOCAL_PROFILE);
Wenyi Wang13874012016-05-27 15:23:53 -0700207 mAreContactsAvailable = args.getBoolean(ARG_CONTACTS_AVAILABLE);
Wenyi Wanga0313442016-05-16 11:55:19 -0700208
James Laskey1e2102f2016-09-19 10:09:08 -0700209 removeUnsupportedPreferences();
James Laskey1e2102f2016-09-19 10:09:08 -0700210
Wenyi Wanga0313442016-05-16 11:55:19 -0700211 mMyInfoPreference = findPreference(KEY_MY_INFO);
Tingting Wang940f0152016-06-30 13:15:49 -0700212
213 final Preference accountsPreference = findPreference(KEY_ACCOUNTS);
214 accountsPreference.setOnPreferenceClickListener(this);
215
James Laskey1e2102f2016-09-19 10:09:08 -0700216 final Preference importPreference = findPreference(KEY_IMPORT);
217 importPreference.setOnPreferenceClickListener(this);
218
219 final Preference exportPreference = findPreference(KEY_EXPORT);
220 if (exportPreference != null) {
221 exportPreference.setOnPreferenceClickListener(this);
222 }
Wenyi Wanga0313442016-05-16 11:55:19 -0700223
Tingting Wangf5b12582016-06-30 18:27:22 -0700224 final Preference blockedNumbersPreference = findPreference(KEY_BLOCKED_NUMBERS);
225 if (blockedNumbersPreference != null) {
226 blockedNumbersPreference.setOnPreferenceClickListener(this);
227 }
228
Wenyi Wanga0313442016-05-16 11:55:19 -0700229 final Preference aboutPreference = findPreference(KEY_ABOUT);
James Laskeyff9a19d2016-11-15 13:36:34 -0800230 if (aboutPreference != null) {
231 aboutPreference.setOnPreferenceClickListener(this);
232 }
Walter Jangf2cad222016-07-14 19:49:06 +0000233
234 final Preference customFilterPreference = findPreference(KEY_CUSTOM_CONTACTS_FILTER);
235 if (customFilterPreference != null) {
236 customFilterPreference.setOnPreferenceClickListener(this);
Walter Jang362b7332016-07-18 18:26:07 -0700237 setCustomContactsFilterSummary();
Walter Jangf2cad222016-07-14 19:49:06 +0000238 }
Yorke Leeb3d841a2014-07-10 11:38:55 -0700239 }
Wenyi Wang9342fbb2015-11-17 19:36:35 -0800240
Wenyi Wanga0313442016-05-16 11:55:19 -0700241 @Override
242 public void onActivityCreated(Bundle savedInstanceState) {
243 super.onActivityCreated(savedInstanceState);
244 getLoaderManager().restartLoader(LOADER_PROFILE, null, mProfileLoaderListener);
245 }
246
Marcus Hagerott819214d2016-09-29 14:58:27 -0700247 @Override
248 public void onDestroyView() {
249 super.onDestroyView();
250 LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mSaveServiceListener);
251 mRootView = null;
252 }
253
Wenyi Wang13874012016-05-27 15:23:53 -0700254 public void updateMyInfoPreference(boolean hasProfile, String displayName, long contactId) {
Wenyi Wang912c5df2016-06-10 13:44:42 -0700255 final CharSequence summary = hasProfile ? displayName : getString(R.string.set_up_profile);
Wenyi Wanga0313442016-05-16 11:55:19 -0700256 mMyInfoPreference.setSummary(summary);
Wenyi Wang13874012016-05-27 15:23:53 -0700257 mHasProfile = hasProfile;
258 mProfileContactId = contactId;
259 mMyInfoPreference.setOnPreferenceClickListener(this);
Wenyi Wanga0313442016-05-16 11:55:19 -0700260 }
261
Walter Jang5665f362016-01-20 21:44:10 +0000262 private void removeUnsupportedPreferences() {
Wenyi Wangb297ad02016-04-17 12:53:46 -0700263 // Disable sort order for CJK locales where it is not supported
Wenyi Wang2882a5a2016-05-13 19:54:45 +0000264 final Resources resources = getResources();
Walter Jang5665f362016-01-20 21:44:10 +0000265 if (!resources.getBoolean(R.bool.config_sort_order_user_changeable)) {
Wenyi Wanga0313442016-05-16 11:55:19 -0700266 getPreferenceScreen().removePreference(findPreference(KEY_SORT_ORDER));
Walter Jang5665f362016-01-20 21:44:10 +0000267 }
268
James Laskeyff9a19d2016-11-15 13:36:34 -0800269 if (HelpUtils.isHelpAndFeedbackAvailable()) {
270 getPreferenceScreen().removePreference(findPreference(KEY_ABOUT));
271 }
272
Walter Jang5665f362016-01-20 21:44:10 +0000273 // Disable display order for CJK locales as well
274 if (!resources.getBoolean(R.bool.config_display_order_user_changeable)) {
Wenyi Wanga0313442016-05-16 11:55:19 -0700275 getPreferenceScreen().removePreference(findPreference(KEY_DISPLAY_ORDER));
Walter Jang5665f362016-01-20 21:44:10 +0000276 }
277
Walter Jang5928e702016-10-31 16:08:37 -0700278 // Remove the default account and custom view settings there aren't any writable accounts
Walter Jang5665f362016-01-20 21:44:10 +0000279 final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(getContext());
280 final List<AccountWithDataSet> accounts = accountTypeManager.getAccounts(
281 /* contactWritableOnly */ true);
282 if (accounts.isEmpty()) {
Tingting Wang940f0152016-06-30 13:15:49 -0700283 getPreferenceScreen().removePreference(findPreference(KEY_DEFAULT_ACCOUNT));
Walter Jang5928e702016-10-31 16:08:37 -0700284 getPreferenceScreen().removePreference(findPreference(KEY_CUSTOM_CONTACTS_FILTER));
Walter Jang5665f362016-01-20 21:44:10 +0000285 }
Tingting Wangf5b12582016-06-30 18:27:22 -0700286
287 final boolean isPhone = TelephonyManagerCompat.isVoiceCapable(
288 (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE));
289 final boolean showBlockedNumbers = isPhone && ContactsUtils.FLAG_N_FEATURE
Wenyi Wangae5c3a02016-06-27 12:43:31 -0700290 && BlockedNumberContract.canCurrentUserBlockNumbers(getContext());
Tingting Wangf5b12582016-06-30 18:27:22 -0700291 if (!showBlockedNumbers) {
292 getPreferenceScreen().removePreference(findPreference(KEY_BLOCKED_NUMBERS));
293 }
James Laskey1e2102f2016-09-19 10:09:08 -0700294
295 if (!mAreContactsAvailable) {
296 getPreferenceScreen().removePreference(findPreference(KEY_EXPORT));
297 }
Tingting Wang918f0b22016-02-09 15:06:24 -0800298 }
Walter Jang5665f362016-01-20 21:44:10 +0000299
Wenyi Wang9342fbb2015-11-17 19:36:35 -0800300 @Override
301 public Context getContext() {
302 return getActivity();
303 }
Wenyi Wanga0313442016-05-16 11:55:19 -0700304
305 private CursorLoader createCursorLoader(Context context) {
306 return new CursorLoader(context) {
307 @Override
308 protected Cursor onLoadInBackground() {
309 try {
310 return super.onLoadInBackground();
311 } catch (RuntimeException e) {
312 return null;
313 }
314 }
315 };
316 }
317
318 private String[] getProjection(Context context) {
319 final ContactsPreferences contactsPrefs = new ContactsPreferences(context);
320 final int displayOrder = contactsPrefs.getDisplayOrder();
321 if (displayOrder == ContactsPreferences.DISPLAY_ORDER_PRIMARY) {
322 return ProfileQuery.PROFILE_PROJECTION_PRIMARY;
323 }
324 return ProfileQuery.PROFILE_PROJECTION_ALTERNATIVE;
325 }
326
Wenyi Wang13874012016-05-27 15:23:53 -0700327 @Override
328 public boolean onPreferenceClick(Preference p) {
329 final String prefKey = p.getKey();
330
331 if (KEY_ABOUT.equals(prefKey)) {
332 ((ContactsPreferenceActivity) getActivity()).showAboutFragment();
333 return true;
James Laskey1e2102f2016-09-19 10:09:08 -0700334 } else if (KEY_IMPORT.equals(prefKey)) {
Marcus Hagerott02f5dba2016-10-18 12:34:57 -0700335 ImportDialogFragment.show(getFragmentManager());
Wenyi Wang13874012016-05-27 15:23:53 -0700336 return true;
James Laskey1e2102f2016-09-19 10:09:08 -0700337 } else if (KEY_EXPORT.equals(prefKey)) {
338 ExportDialogFragment.show(getFragmentManager(), ContactsPreferenceActivity.class,
339 ExportDialogFragment.EXPORT_MODE_ALL_CONTACTS);
340 return true;
Walter Jang0396cf72016-09-21 13:23:29 -0700341 } else if (KEY_MY_INFO.equals(prefKey)) {
Wenyi Wang13874012016-05-27 15:23:53 -0700342 if (mHasProfile) {
343 final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, mProfileContactId);
Walter Jang0396cf72016-09-21 13:23:29 -0700344 ImplicitIntentsUtil.startQuickContact(getActivity(), uri, ScreenType.ME_CONTACT);
Wenyi Wang13874012016-05-27 15:23:53 -0700345 } else {
Walter Jang0396cf72016-09-21 13:23:29 -0700346 final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
Wenyi Wang13874012016-05-27 15:23:53 -0700347 intent.putExtra(mNewLocalProfileExtra, true);
Walter Jang0396cf72016-09-21 13:23:29 -0700348 ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);
Wenyi Wang13874012016-05-27 15:23:53 -0700349 }
Wenyi Wang13874012016-05-27 15:23:53 -0700350 return true;
Tingting Wang940f0152016-06-30 13:15:49 -0700351 } else if (KEY_ACCOUNTS.equals(prefKey)) {
Walter Jang8be77012016-07-07 21:05:34 -0700352 ImplicitIntentsUtil.startActivityOutsideApp(getContext(),
353 ImplicitIntentsUtil.getIntentForAddingAccount());
Tingting Wang940f0152016-06-30 13:15:49 -0700354 return true;
Tingting Wangf5b12582016-06-30 18:27:22 -0700355 } else if (KEY_BLOCKED_NUMBERS.equals(prefKey)) {
356 final Intent intent = TelecomManagerUtil.createManageBlockedNumbersIntent(
357 (TelecomManager) getContext().getSystemService(Context.TELECOM_SERVICE));
358 startActivity(intent);
359 return true;
Walter Jangf2cad222016-07-14 19:49:06 +0000360 } else if (KEY_CUSTOM_CONTACTS_FILTER.equals(prefKey)) {
361 final ContactListFilter filter =
362 ContactListFilterController.getInstance(getContext()).getFilter();
363 AccountFilterUtil.startAccountFilterActivityForResult(
364 this, REQUEST_CODE_CUSTOM_CONTACTS_FILTER, filter);
Wenyi Wang13874012016-05-27 15:23:53 -0700365 }
366 return false;
Wenyi Wanga0313442016-05-16 11:55:19 -0700367 }
Walter Jangf2cad222016-07-14 19:49:06 +0000368
369 @Override
370 public void onActivityResult(int requestCode, int resultCode, Intent data) {
371 if (requestCode == REQUEST_CODE_CUSTOM_CONTACTS_FILTER
372 && resultCode == Activity.RESULT_OK) {
373 AccountFilterUtil.handleAccountFilterResult(
374 ContactListFilterController.getInstance(getContext()), resultCode, data);
Walter Jang362b7332016-07-18 18:26:07 -0700375 setCustomContactsFilterSummary();
Walter Jangf2cad222016-07-14 19:49:06 +0000376 } else {
377 super.onActivityResult(requestCode, resultCode, data);
378 }
379 }
Walter Jang362b7332016-07-18 18:26:07 -0700380
381 private void setCustomContactsFilterSummary() {
382 final Preference customFilterPreference = findPreference(KEY_CUSTOM_CONTACTS_FILTER);
383 if (customFilterPreference != null) {
384 final ContactListFilter filter =
Walter Jang398bca92016-08-02 14:37:57 -0700385 ContactListFilterController.getInstance(getContext()).getPersistedFilter();
Walter Jang362b7332016-07-18 18:26:07 -0700386 if (filter != null) {
387 if (filter.filterType == ContactListFilter.FILTER_TYPE_DEFAULT ||
388 filter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS) {
389 customFilterPreference.setSummary(R.string.list_filter_all_accounts);
390 } else if (filter.filterType == ContactListFilter.FILTER_TYPE_CUSTOM) {
Wenyi Wang2b1aa122016-07-19 19:31:07 -0700391 customFilterPreference.setSummary(R.string.listCustomView);
Walter Jang362b7332016-07-18 18:26:07 -0700392 } else {
393 customFilterPreference.setSummary(null);
394 }
395 }
396 }
397 }
Marcus Hagerott819214d2016-09-29 14:58:27 -0700398
399 private class SaveServiceResultListener extends BroadcastReceiver {
400 @Override
401 public void onReceive(Context context, Intent intent) {
402 final long now = System.currentTimeMillis();
403 final long opStart = intent.getLongExtra(
Marcus Hagerott95246bb2016-11-11 10:56:09 -0800404 SimImportService.EXTRA_OPERATION_REQUESTED_AT_TIME, now);
Marcus Hagerott819214d2016-09-29 14:58:27 -0700405
406 // If it's been over 30 seconds the user is likely in a different context so suppress
407 // the toast message.
408 if (now - opStart > 30*1000) return;
409
Marcus Hagerott95246bb2016-11-11 10:56:09 -0800410 final int code = intent.getIntExtra(SimImportService.EXTRA_RESULT_CODE,
411 SimImportService.RESULT_UNKNOWN);
412 final int count = intent.getIntExtra(SimImportService.EXTRA_RESULT_COUNT, -1);
413 if (code == SimImportService.RESULT_SUCCESS && count > 0) {
Marcus Hagerott819214d2016-09-29 14:58:27 -0700414 Snackbar.make(mRootView, getResources().getQuantityString(
415 R.plurals.sim_import_success_toast_fmt, count, count),
416 Snackbar.LENGTH_LONG).show();
Marcus Hagerott95246bb2016-11-11 10:56:09 -0800417 } else if (code == SimImportService.RESULT_FAILURE) {
Marcus Hagerott819214d2016-09-29 14:58:27 -0700418 Snackbar.make(mRootView, R.string.sim_import_failed_toast,
419 Snackbar.LENGTH_LONG).show();
420 }
421 }
422 }
Yorke Leeb3d841a2014-07-10 11:38:55 -0700423}
424