2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.android.settings;
18 import java.util.ArrayList;
19 import java.util.List;
21 import android.content.Context;
22 import android.content.res.Resources;
23 import android.os.Bundle;
24 import android.provider.Settings;
25 import android.provider.Settings.SettingNotFoundException;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.widget.Switch;
31 import com.android.settings.search.BaseSearchIndexProvider;
32 import com.android.settings.search.Indexable;
33 import com.android.settings.search.SearchIndexableRaw;
34 import com.android.settings.widget.SwitchBar;
37 * Screen pinning settings.
39 public class ScreenPinningSettings extends SettingsPreferenceFragment
40 implements SwitchBar.OnSwitchChangeListener, Indexable {
42 private SwitchBar mSwitchBar;
45 public void onActivityCreated(Bundle savedInstanceState) {
46 super.onActivityCreated(savedInstanceState);
48 final SettingsActivity activity = (SettingsActivity) getActivity();
50 mSwitchBar = activity.getSwitchBar();
51 mSwitchBar.addOnSwitchChangeListener(this);
53 mSwitchBar.setChecked(isLockToAppEnabled());
57 public void onDestroyView() {
58 super.onDestroyView();
60 mSwitchBar.removeOnSwitchChangeListener(this);
65 public View onCreateView(LayoutInflater inflater, ViewGroup container,
66 Bundle savedInstanceState) {
67 return inflater.inflate(R.layout.screen_pinning_instructions, null);
70 private boolean isLockToAppEnabled() {
72 return Settings.System.getInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED)
74 } catch (SettingNotFoundException e) {
79 private void setLockToAppEnabled(boolean isEnabled) {
80 Settings.System.putInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED,
85 * Listens to the state change of the lock-to-app master switch.
88 public void onSwitchChanged(Switch switchView, boolean isChecked) {
89 setLockToAppEnabled(isChecked);
95 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
96 new BaseSearchIndexProvider() {
98 public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
99 final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
101 final Resources res = context.getResources();
103 // Add fragment title
104 SearchIndexableRaw data = new SearchIndexableRaw(context);
105 data.title = res.getString(R.string.screen_pinning_title);
106 data.screenTitle = res.getString(R.string.screen_pinning_title);
109 // Screen pinning description.
110 data = new SearchIndexableRaw(context);
111 data.title = res.getString(R.string.screen_pinning_description);
112 data.screenTitle = res.getString(R.string.screen_pinning_title);