Based on DUI jhenrique09 edits: make it DUI independent Original commit message: Same robust action library as used on software navigation. Supports single tap, double tap, and long press. As a precautionary measure, single tap back and single tap home are fixed and can not be changed. Camera button actions are not supported at this time. We will bring in wake key support at a later time. Also includes: Change-Id: I29ff38678821ca80db36d49d3b10d8ac29a6b4de DUI: Initial checkin for Oreo [4/7] Signed-off-by: Shubham Singh <coolsks94@gmail.com> Signed-off-by: mhkjahromi <m.h.k.jahromi@gmail.com> Signed-off-by: SagarMakhar <sagarmakhar@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
135 lines
3.5 KiB
Java
135 lines
3.5 KiB
Java
/*
|
|
* Copyright (C) 2015 TeamEos 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.
|
|
*
|
|
* Simple preference class implementing ActionHolder interface to assign
|
|
* actions to buttons. It is ABSOLUTELY IMPERITIVE that the preference
|
|
* key is identical to the target ConfigMap tag in ActionConstants
|
|
*/
|
|
|
|
package com.cherish.settings.preferences;
|
|
|
|
import java.util.Map;
|
|
|
|
import com.android.internal.util.hwkeys.ActionConstants.ConfigMap;
|
|
import com.android.internal.util.hwkeys.ActionConstants.Defaults;
|
|
import com.android.internal.util.hwkeys.ActionHolder;
|
|
import com.android.internal.util.hwkeys.Config.ActionConfig;
|
|
import com.android.internal.util.hwkeys.Config.ButtonConfig;
|
|
|
|
import android.content.Context;
|
|
import androidx.preference.Preference;
|
|
import android.util.AttributeSet;
|
|
|
|
public class ActionPreference extends Preference implements ActionHolder {
|
|
private Defaults mDefaults;
|
|
private ConfigMap mMap;
|
|
private ActionConfig mAction;
|
|
private ActionConfig mDefaultAction;
|
|
|
|
public ActionPreference(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
public ActionPreference(Context context, AttributeSet attrs) {
|
|
this(context, attrs, 0);
|
|
}
|
|
|
|
public ActionPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
this(context, attrs, defStyleAttr, 0);
|
|
}
|
|
|
|
public ActionPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
|
int defStyleRes) {
|
|
super(context, attrs);
|
|
}
|
|
|
|
@Override
|
|
public String getTag() {
|
|
return this.getKey();
|
|
}
|
|
|
|
@Override
|
|
public void setTag(String tag) {
|
|
this.setKey(tag);
|
|
}
|
|
|
|
@Override
|
|
public Defaults getDefaults() {
|
|
return mDefaults;
|
|
}
|
|
|
|
@Override
|
|
public void setDefaults(Defaults defaults) {
|
|
mDefaults = defaults;
|
|
final String tag = this.getKey();
|
|
for (Map.Entry<String, ConfigMap> entry : defaults.getActionMap().entrySet()) {
|
|
if (((String) entry.getKey()).equals(tag)) {
|
|
mMap = entry.getValue();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ConfigMap getConfigMap() {
|
|
return mMap;
|
|
}
|
|
|
|
@Override
|
|
public void setConfigMap(ConfigMap map) {
|
|
mMap = map;
|
|
}
|
|
|
|
@Override
|
|
public ButtonConfig getButtonConfig() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void setButtonConfig(ButtonConfig button) {
|
|
}
|
|
|
|
@Override
|
|
public ActionConfig getActionConfig() {
|
|
return mAction;
|
|
}
|
|
|
|
@Override
|
|
public void setActionConfig(ActionConfig action) {
|
|
mAction = action;
|
|
this.setSummary(action.getLabel());
|
|
}
|
|
|
|
@Override
|
|
public ButtonConfig getDefaultButtonConfig() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void setDefaultButtonConfig(ButtonConfig button) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public ActionConfig getDefaultActionConfig() {
|
|
return mDefaultAction;
|
|
}
|
|
|
|
@Override
|
|
public void setDefaultActionConfig(ActionConfig action) {
|
|
mDefaultAction = action;
|
|
}
|
|
}
|