Refactor CaptionAppearanceFragment to improve maintainability (3/n)

Root cause: There is a bunch of different logic of preferences in CaptionAppearanceFragment. It’s hard to implement new features and hard to maintain and hard to be testable.
Solution: Move out color and edge preference logic of CaptionAppearanceFragment 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: I8ed80b445a0d376a7e9dda87feda82420a78a9da
This commit is contained in:
menghanli
2022-07-11 13:01:46 +08:00
parent 2675dbf54a
commit 16fbfe4e14
22 changed files with 1769 additions and 161 deletions

View File

@@ -28,6 +28,7 @@ import android.content.Context;
import android.provider.Settings;
import android.view.View;
import android.view.accessibility.CaptioningManager;
import android.view.accessibility.CaptioningManager.CaptionStyle;
import androidx.test.core.app.ApplicationProvider;
@@ -129,4 +130,44 @@ public class CaptionHelperTest {
Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, OFF) == ON;
assertThat(isCaptionEnabled).isFalse();
}
@Test
public void setBackgroundColor_shouldReturnSpecificColor() {
mCaptionHelper.setBackgroundColor(0xFFFF0000);
final int backgroundColor = mCaptionHelper.getBackgroundColor();
assertThat(backgroundColor).isEqualTo(0xFFFF0000);
}
@Test
public void setForegroundColor_shouldReturnSpecificColor() {
mCaptionHelper.setForegroundColor(0xFFFF0000);
final int foregroundColor = mCaptionHelper.getForegroundColor();
assertThat(foregroundColor).isEqualTo(0xFFFF0000);
}
@Test
public void setWindowColor_shouldReturnSpecificColor() {
mCaptionHelper.setWindowColor(0xFFFF0000);
final int windowColor = mCaptionHelper.getWindowColor();
assertThat(windowColor).isEqualTo(0xFFFF0000);
}
@Test
public void setEdgeColor_shouldReturnSpecificColor() {
mCaptionHelper.setEdgeColor(0xFFFF0000);
final int edgeColor = mCaptionHelper.getEdgeColor();
assertThat(edgeColor).isEqualTo(0xFFFF0000);
}
@Test
public void setEdgeType_shouldReturnSpecificType() {
mCaptionHelper.setEdgeType(CaptionStyle.EDGE_TYPE_OUTLINE);
final int edgeType = mCaptionHelper.getEdgeType();
assertThat(edgeType).isEqualTo(CaptionStyle.EDGE_TYPE_OUTLINE);
}
}