summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/ScreenPinningSettings.java
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2014-07-18 09:55:41 -0400
committerJason Monk <jmonk@google.com>2014-07-21 09:01:43 -0400
commit27d7ea56f3f02ea7efaf1e57b5d6758ddb56c353 (patch)
tree7fd4d4b268089ad64b2fc4a30d96d68cd722f589 /src/com/android/settings/ScreenPinningSettings.java
parentd7bdf17aba66b0bd4530773401d54252cf6b180c (diff)
downloadpackages_apps_Settings-27d7ea56f3f02ea7efaf1e57b5d6758ddb56c353.zip
packages_apps_Settings-27d7ea56f3f02ea7efaf1e57b5d6758ddb56c353.tar.gz
packages_apps_Settings-27d7ea56f3f02ea7efaf1e57b5d6758ddb56c353.tar.bz2
Add Screen pinning back to settings
Adds a basic screen for screen pinning (previously lock-to-app) to settings that describes the feature and allows it to be turned on and off. Bug: 16378448 Depends on Ide333463f86310eacb7a1d8b6dc7b1aea8722713 for Settings constant Change-Id: Id3ef8471794aa01de20efeb947bed95c50d6b954
Diffstat (limited to 'src/com/android/settings/ScreenPinningSettings.java')
-rw-r--r--src/com/android/settings/ScreenPinningSettings.java118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/com/android/settings/ScreenPinningSettings.java b/src/com/android/settings/ScreenPinningSettings.java
new file mode 100644
index 0000000..ada5b17
--- /dev/null
+++ b/src/com/android/settings/ScreenPinningSettings.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2014 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.settings;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Switch;
+
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settings.search.SearchIndexableRaw;
+import com.android.settings.widget.SwitchBar;
+
+/**
+ * Screen pinning settings.
+ */
+public class ScreenPinningSettings extends SettingsPreferenceFragment
+ implements SwitchBar.OnSwitchChangeListener, Indexable {
+
+ private SwitchBar mSwitchBar;
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ final SettingsActivity activity = (SettingsActivity) getActivity();
+
+ mSwitchBar = activity.getSwitchBar();
+ mSwitchBar.addOnSwitchChangeListener(this);
+ mSwitchBar.show();
+ mSwitchBar.setChecked(isLockToAppEnabled());
+ }
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+
+ mSwitchBar.removeOnSwitchChangeListener(this);
+ mSwitchBar.hide();
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.screen_pinning_instructions, null);
+ }
+
+ private boolean isLockToAppEnabled() {
+ try {
+ return Settings.System.getInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED)
+ != 0;
+ } catch (SettingNotFoundException e) {
+ return false;
+ }
+ }
+
+ private void setLockToAppEnabled(boolean isEnabled) {
+ Settings.System.putInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED,
+ isEnabled ? 1 : 0);
+ }
+
+ /**
+ * Listens to the state change of the lock-to-app master switch.
+ */
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ setLockToAppEnabled(isChecked);
+ }
+
+ /**
+ * For search
+ */
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
+ final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
+
+ final Resources res = context.getResources();
+
+ // Add fragment title
+ SearchIndexableRaw data = new SearchIndexableRaw(context);
+ data.title = res.getString(R.string.screen_pinning_title);
+ data.screenTitle = res.getString(R.string.screen_pinning_title);
+ result.add(data);
+
+ // Screen pinning description.
+ data = new SearchIndexableRaw(context);
+ data.title = res.getString(R.string.screen_pinning_description);
+ data.screenTitle = res.getString(R.string.screen_pinning_title);
+ result.add(data);
+
+ return result;
+ }
+ };
+}