- Ranking API is modified to run the ranking asynchronous to the main thread. Therefore, it can now run in parallel to loading the results from DB which decreases the overall latency. - Ranking API now supports reporting failure from the ranker implementation side. - Settings that are not ranked by the ranker algorithm are now ranked at the end of the list. This is added for dynamic settings (e.g., apps). - Failure handling mechanism is added for cases that ranker catches an exception or it takes a long time to respond. Bug: 37312700 Fixes: 36866337 Fixes: 36867476 Fixes: 36866736 Fixes: 36866838 Test: RunSettingsRoboTests Change-Id: I3a2a97e3a07a8d4afbb090061d92172a27588ee7
66 lines
2.2 KiB
Java
66 lines
2.2 KiB
Java
/*
|
|
* Copyright (C) 2017 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.search;
|
|
|
|
import android.content.Context;
|
|
import android.util.Pair;
|
|
import android.view.View;
|
|
import android.widget.Switch;
|
|
|
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|
import com.android.settings.R;
|
|
|
|
/**
|
|
* ViewHolder for Settings represented as SwitchPreferences.
|
|
*/
|
|
public class InlineSwitchViewHolder extends SearchViewHolder {
|
|
|
|
public final Switch switchView;
|
|
|
|
private final Context mContext;
|
|
|
|
public InlineSwitchViewHolder(View view, Context context) {
|
|
super(view);
|
|
mContext = context;
|
|
switchView = view.findViewById(R.id.switchView);
|
|
}
|
|
|
|
@Override
|
|
public int getClickActionMetricName() {
|
|
return MetricsEvent.ACTION_CLICK_SETTINGS_SEARCH_INLINE_RESULT;
|
|
}
|
|
|
|
@Override
|
|
public void onBind(SearchFragment fragment, final SearchResult result) {
|
|
super.onBind(fragment, result);
|
|
if (mContext == null) {
|
|
return;
|
|
}
|
|
final InlineSwitchPayload payload = (InlineSwitchPayload) result.payload;
|
|
switchView.setChecked(payload.getValue(mContext) == InlineSwitchPayload.TRUE);
|
|
switchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
final Pair<Integer, Object> value = Pair.create(
|
|
MetricsEvent.FIELD_SETTINGS_SEARCH_INLINE_RESULT_VALUE, isChecked
|
|
? 1L : 0L);
|
|
fragment.onSearchResultClicked(this, result, value);
|
|
int newValue = isChecked ? InlineSwitchPayload.TRUE : InlineSwitchPayload.FALSE;
|
|
payload.setValue(mContext, newValue);
|
|
});
|
|
}
|
|
}
|