1 /* 2 * Copyright (C) 2015 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 17 package com.android.settings.display; 18 19 import android.annotation.Nullable; 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 import android.content.res.Configuration; 23 import android.os.Bundle; 24 25 import com.android.settings.R; 26 import com.android.settings.search.BaseSearchIndexProvider; 27 import com.android.settingslib.display.DisplayDensityUtils; 28 import com.android.settingslib.search.SearchIndexable; 29 30 /** 31 * Preference fragment used to control screen zoom. 32 */ 33 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 34 public class ScreenZoomSettings extends PreviewSeekBarPreferenceFragment { 35 36 private int mDefaultDensity; 37 private int[] mValues; 38 private DisplayDensityUtils mDensity; 39 40 @Override getActivityLayoutResId()41 protected int getActivityLayoutResId() { 42 return R.layout.screen_zoom_activity; 43 } 44 45 @Override getPreviewSampleResIds()46 protected int[] getPreviewSampleResIds() { 47 return getContext().getResources().getBoolean( 48 R.bool.config_enable_extra_screen_zoom_preview) 49 ? new int[]{ 50 R.layout.screen_zoom_preview_1, 51 R.layout.screen_zoom_preview_2, 52 R.layout.screen_zoom_preview_settings} 53 : new int[]{R.layout.screen_zoom_preview_1}; 54 } 55 56 @Override onCreate(@ullable Bundle savedInstanceState)57 public void onCreate(@Nullable Bundle savedInstanceState) { 58 super.onCreate(savedInstanceState); 59 60 mDensity = new DisplayDensityUtils(getContext()); 61 62 final int initialIndex = mDensity.getCurrentIndexForDefaultDisplay(); 63 if (initialIndex < 0) { 64 // Failed to obtain default density, which means we failed to 65 // connect to the window manager service. Just use the current 66 // density and don't let the user change anything. 67 final int densityDpi = getResources().getDisplayMetrics().densityDpi; 68 mValues = new int[]{densityDpi}; 69 mEntries = new String[]{getString(DisplayDensityUtils.SUMMARY_DEFAULT)}; 70 mInitialIndex = 0; 71 mDefaultDensity = densityDpi; 72 } else { 73 mValues = mDensity.getDefaultDisplayDensityValues(); 74 mEntries = mDensity.getDefaultDisplayDensityEntries(); 75 mInitialIndex = initialIndex; 76 mDefaultDensity = mDensity.getDefaultDensityForDefaultDisplay(); 77 } 78 79 getActivity().setTitle(R.string.screen_zoom_title); 80 } 81 82 @Override createConfig(Configuration origConfig, int index)83 protected Configuration createConfig(Configuration origConfig, int index) { 84 // Populate the sample layouts. 85 final Configuration config = new Configuration(origConfig); 86 config.densityDpi = mValues[index]; 87 return config; 88 } 89 90 /** 91 * Persists the selected density and sends a configuration change. 92 */ 93 @Override commit()94 protected void commit() { 95 final int densityDpi = mValues[mCurrentIndex]; 96 if (densityDpi == mDefaultDensity) { 97 mDensity.clearForcedDisplayDensity(); 98 } else { 99 mDensity.setForcedDisplayDensity(densityDpi); 100 } 101 } 102 103 @Override getHelpResource()104 public int getHelpResource() { 105 return R.string.help_url_display_size; 106 } 107 108 @Override getMetricsCategory()109 public int getMetricsCategory() { 110 return SettingsEnums.DISPLAY_SCREEN_ZOOM; 111 } 112 113 /** Index provider used to expose this fragment in search. */ 114 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 115 new BaseSearchIndexProvider() { 116 @Override 117 protected boolean isPageSearchEnabled(Context context) { 118 return false; 119 } 120 }; 121 } 122