Hardware key disable support
Change-Id: I42f8b3b9423e218eb612bb8ff57baa58280392e6 Signed-off-by: SagarMakhar <sagarmakhar@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
BIN
res/drawable/activities_icon.png
Normal file
BIN
res/drawable/activities_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
4
res/drawable/fab_accent.xml
Normal file
4
res/drawable/fab_accent.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||
<solid android:color="?android:attr/colorAccent" />
|
||||
</shape>
|
||||
70
res/layout/custom_action_item.xml
Normal file
70
res/layout/custom_action_item.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2006 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.
|
||||
-->
|
||||
|
||||
<!-- Layout for a Preference in a PreferenceActivity. The
|
||||
Preference is able to place a specific widget for its particular
|
||||
type in the "widget_frame" layout. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/widget_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="12dip"
|
||||
android:padding="2dp"
|
||||
android:maxWidth="36dip"
|
||||
android:maxHeight="36dip"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dip"
|
||||
android:layout_marginEnd="6dip"
|
||||
android:layout_marginTop="6dip"
|
||||
android:layout_marginBottom="6dip"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal" />
|
||||
|
||||
<TextView android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Body1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLines="2" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -596,4 +596,8 @@
|
||||
<string name="button_backlight_on_touch_only_title">Button backlight touch</string>
|
||||
<string name="button_backlight_on_touch_only_summary">Button backlight will only appear when buttons are pressed rather than on all the time. Timeout still impacts this feature.</string>
|
||||
|
||||
<!-- Hardware keys -->
|
||||
<string name="hardware_keys_category">Hardware navigation buttons</string>
|
||||
<string name="hardware_keys_disable_title">Disable hardware buttons</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
android:title="@string/button_title"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
||||
|
||||
<PreferenceCategory android:key="hardware_keys"
|
||||
android:title="@string/hardware_keys_category">
|
||||
|
||||
<SwitchPreference android:key="hardware_keys_disable"
|
||||
android:title="@string/hardware_keys_disable_title" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="volume_category"
|
||||
android:title="@string/volume_category">
|
||||
|
||||
@@ -36,8 +36,6 @@ import androidx.preference.SwitchPreference;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Toast;
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
import com.cherish.settings.preferences.SecureSettingSwitchPreference;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -59,10 +57,12 @@ import android.provider.SearchIndexableResource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
public class ButtonSettings extends ActionFragment implements OnPreferenceChangeListener {
|
||||
|
||||
private static final String HWKEY_DISABLE = "hardware_keys_disable";
|
||||
|
||||
// category keys
|
||||
private static final String CATEGORY_HWKEY = "hardware_keys";
|
||||
private static final String CATEGORY_BACK = "back_key";
|
||||
private static final String CATEGORY_HOME = "home_key";
|
||||
private static final String CATEGORY_MENU = "menu_key";
|
||||
@@ -87,6 +87,7 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
|
||||
private static final String TORCH_POWER_BUTTON_GESTURE = "torch_power_button_gesture";
|
||||
|
||||
private SwitchPreference mHwKeyDisable;
|
||||
private ListPreference mTorchPowerButton;
|
||||
private CustomSeekBarPreference mButtonTimoutBar;
|
||||
private CustomSeekBarPreference mManualButtonBrightness;
|
||||
@@ -100,6 +101,22 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
final Resources res = getResources();
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
|
||||
final boolean needsNavbar = ActionUtils.hasNavbarByDefault(getActivity());
|
||||
final PreferenceCategory hwkeyCat = (PreferenceCategory) prefScreen
|
||||
.findPreference(CATEGORY_HWKEY);
|
||||
int keysDisabled = 0;
|
||||
if (!needsNavbar) {
|
||||
mHwKeyDisable = (SwitchPreference) findPreference(HWKEY_DISABLE);
|
||||
keysDisabled = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.HARDWARE_KEYS_DISABLE, 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
mHwKeyDisable.setChecked(keysDisabled != 0);
|
||||
mHwKeyDisable.setOnPreferenceChangeListener(this);
|
||||
} else {
|
||||
prefScreen.removePreference(hwkeyCat);
|
||||
}
|
||||
|
||||
// bits for hardware keys present on device
|
||||
final int deviceKeys = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_deviceHardwareKeys);
|
||||
@@ -143,8 +160,11 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
// let super know we can load ActionPreferences
|
||||
onPreferenceScreenLoaded(ActionConstants.getDefaults(ActionConstants.HWKEYS));
|
||||
|
||||
// screen off torch
|
||||
|
||||
// load preferences first
|
||||
setActionPreferencesEnabled(keysDisabled == 0);
|
||||
|
||||
// screen off torch
|
||||
mTorchPowerButton = (ListPreference) findPreference(TORCH_POWER_BUTTON_GESTURE);
|
||||
int mTorchPowerButtonValue = Settings.System.getInt(resolver,
|
||||
Settings.System.TORCH_POWER_BUTTON_GESTURE, 0);
|
||||
@@ -189,6 +209,11 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
Settings.System.putInt(resolver, Settings.System.TORCH_POWER_BUTTON_GESTURE,
|
||||
mTorchPowerButtonValue);
|
||||
return true;
|
||||
} else if (preference == mHwKeyDisable) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putInt(getContentResolver(), Settings.System.HARDWARE_KEYS_DISABLE,
|
||||
value ? 1 : 0);
|
||||
setActionPreferencesEnabled(!value);
|
||||
} else if (preference == mButtonTimoutBar) {
|
||||
int buttonTimeout = (Integer) newValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
@@ -216,7 +241,26 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.cherish_settings_button);
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.cherish_settings_button;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user