Root cause: There is a bunch of different logic of preferences in ToggleAutoclickPreferenceFragment. It’s hard to implement new features and hard to maintain and hard to be testable. Solution: Move out logic of ToggleAutoclickPreferenceFragment into controllers to reduce the complexity of the relationship between preference and fragment. Bug: 197695932 Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.accessibility Change-Id: I5db18d5a0c577ad67d15c2d0169a36a67e9f13db
79 lines
2.7 KiB
Java
79 lines
2.7 KiB
Java
/*
|
|
* Copyright (C) 2022 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.accessibility;
|
|
|
|
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
|
|
|
import android.annotation.IntDef;
|
|
import android.annotation.PluralsRes;
|
|
import android.content.res.Resources;
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
/** Provides utility methods related auto click. */
|
|
public final class AutoclickUtils {
|
|
|
|
/** Used for autoclick mode in the preferences editor. */
|
|
static final String KEY_DELAY_MODE = "delay_mode";
|
|
|
|
/** Used for autoclick custom delay in the preferences editor. */
|
|
static final String KEY_CUSTOM_DELAY_VALUE = "custom_delay_value";
|
|
|
|
/** Min allowed autoclick delay value. */
|
|
static final int MIN_AUTOCLICK_DELAY_MS = 200;
|
|
|
|
/** Max allowed autoclick delay value. */
|
|
static final int MAX_AUTOCLICK_DELAY_MS = 1000;
|
|
|
|
/**
|
|
* Allowed autoclick delay values are discrete. This is the difference between two allowed
|
|
* values.
|
|
*/
|
|
static final int AUTOCLICK_DELAY_STEP = 100;
|
|
|
|
@Retention(SOURCE)
|
|
@IntDef({
|
|
Quantity.ONE,
|
|
Quantity.FEW
|
|
})
|
|
private @interface Quantity {
|
|
int ONE = 1;
|
|
int FEW = 3;
|
|
}
|
|
|
|
/**
|
|
* Gets string that should be used for provided autoclick delay.
|
|
*
|
|
* @param resources Resources from which string should be retrieved.
|
|
* @param id The desired resource identifier, as generated by the aapt
|
|
* tool. This integer encodes the package, type, and resource
|
|
* entry. The value 0 is an invalid identifier.
|
|
* @param delayMillis Delay for whose value summary should be retrieved.
|
|
*/
|
|
public static CharSequence getAutoclickDelaySummary(Resources resources,
|
|
@PluralsRes int id, int delayMillis) {
|
|
final int quantity = (delayMillis == 1000) ? Quantity.ONE : Quantity.FEW;
|
|
final float delaySecond = (float) delayMillis / 1000;
|
|
// Only show integer when delay time is 1.
|
|
final String decimalFormat = (delaySecond == 1) ? "%.0f" : "%.1f";
|
|
|
|
return resources.getQuantityString(id, quantity, String.format(decimalFormat, delaySecond));
|
|
}
|
|
|
|
private AutoclickUtils(){}
|
|
}
|