Merge "Prototyping : Demo Image on color setting" into sc-qpr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7efaff8d0f
Binary file not shown.
Before Width: | Height: | Size: 1.2 MiB |
BIN
res/drawable-nodpi/color_mode_preview1.jpg
Normal file
BIN
res/drawable-nodpi/color_mode_preview1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
BIN
res/drawable-nodpi/color_mode_preview2.jpg
Normal file
BIN
res/drawable-nodpi/color_mode_preview2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
BIN
res/drawable-nodpi/color_mode_preview3.jpg
Normal file
BIN
res/drawable-nodpi/color_mode_preview3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 240 KiB |
29
res/drawable/ic_color_arrow_left_lt.xml
Normal file
29
res/drawable/ic_color_arrow_left_lt.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:pathData="M0,0h24v24h-24z"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M16.41,18.59L15,20L7,12L15,4L16.41,5.41L9.83,12"
|
||||||
|
android:fillColor="?android:attr/colorAccent"
|
||||||
|
android:fillType="evenOdd"/>
|
||||||
|
</vector>
|
29
res/drawable/ic_color_arrow_right_lt.xml
Normal file
29
res/drawable/ic_color_arrow_right_lt.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:pathData="M0,0h24v24h-24z"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M7.59,5.41L9,4L17,12L9,20L7.59,18.59L14.17,12"
|
||||||
|
android:fillColor="?android:attr/colorAccent"
|
||||||
|
android:fillType="evenOdd"/>
|
||||||
|
</vector>
|
27
res/drawable/ic_color_page_indicator_focused.xml
Normal file
27
res/drawable/ic_color_page_indicator_focused.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="6dp"
|
||||||
|
android:height="6dp"
|
||||||
|
android:viewportWidth="6"
|
||||||
|
android:viewportHeight="6">
|
||||||
|
<path
|
||||||
|
android:pathData="M3,0C4.65686,0 6,1.34315 6,3C6,4.65686 4.65685,6 3,6C1.34315,6 0,4.65685 0,3C0,1.34315 1.34315,0 3,0Z"
|
||||||
|
android:fillColor="?android:attr/colorAccent"
|
||||||
|
android:fillType="evenOdd"/>
|
||||||
|
</vector>
|
28
res/drawable/ic_color_page_indicator_unfocused.xml
Normal file
28
res/drawable/ic_color_page_indicator_unfocused.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="6dp"
|
||||||
|
android:height="6dp"
|
||||||
|
android:viewportWidth="6"
|
||||||
|
android:viewportHeight="6">
|
||||||
|
<path
|
||||||
|
android:pathData="M3,0C4.65686,0 6,1.34315 6,3C6,4.65686 4.65685,6 3,6C1.34315,6 0,4.65685 0,3C0,1.34315 1.34315,0 3,0Z"
|
||||||
|
android:fillColor="?android:attr/colorAccent"
|
||||||
|
android:fillAlpha="0.24"
|
||||||
|
android:fillType="evenOdd"/>
|
||||||
|
</vector>
|
@@ -14,16 +14,55 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<ImageView
|
<androidx.viewpager.widget.ViewPager
|
||||||
|
android:id="@+id/viewpager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/color_mode_preview_height"
|
android:layout_height="@dimen/color_mode_preview_height"/>
|
||||||
android:scaleType="centerCrop"
|
|
||||||
android:cropToPadding="true"
|
|
||||||
android:src="@drawable/color_mode_preview"
|
|
||||||
android:contentDescription="@null" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/arrow_previous"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:paddingLeft="24dp"
|
||||||
|
android:layout_gravity="center_vertical|left"
|
||||||
|
android:contentDescription="@string/previous_page_content_description">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:src="@drawable/ic_color_arrow_left_lt"/>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/viewGroup"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:gravity="center"/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/arrow_next"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:paddingRight="24dp"
|
||||||
|
android:layout_gravity="center_vertical|right"
|
||||||
|
android:contentDescription="@string/next_page_content_description">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:src="@drawable/ic_color_arrow_right_lt"/>
|
||||||
|
</FrameLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
39
res/layout/color_mode_view1.xml
Normal file
39
res/layout/color_mode_view1.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:foregroundGravity="center_horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image1"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/color_mode_preview_height"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:cropToPadding="true"
|
||||||
|
android:src="@drawable/color_mode_preview1"
|
||||||
|
android:contentDescription="@null" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
</LinearLayout>
|
39
res/layout/color_mode_view2.xml
Normal file
39
res/layout/color_mode_view2.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:foregroundGravity="center_horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/color_mode_preview_height"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:cropToPadding="true"
|
||||||
|
android:src="@drawable/color_mode_preview2"
|
||||||
|
android:contentDescription="@null" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
</LinearLayout>
|
39
res/layout/color_mode_view3.xml
Normal file
39
res/layout/color_mode_view3.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:foregroundGravity="center_horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image3"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/color_mode_preview_height"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:cropToPadding="true"
|
||||||
|
android:src="@drawable/color_mode_preview3"
|
||||||
|
android:contentDescription="@null" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
</LinearLayout>
|
@@ -13542,6 +13542,15 @@
|
|||||||
<!-- Summary for Game settings entry. [CHAR_LIMIT=NONE] -->
|
<!-- Summary for Game settings entry. [CHAR_LIMIT=NONE] -->
|
||||||
<string name="game_settings_summary">Turn on Game Dashboard shortcut, etc</string>
|
<string name="game_settings_summary">Turn on Game Dashboard shortcut, etc</string>
|
||||||
|
|
||||||
|
<!-- Content description of the previous button to bring user to the previous preview page. -->
|
||||||
|
<string name="previous_page_content_description">Previous</string>
|
||||||
|
|
||||||
|
<!-- Content description of the next button to bring user to the next preview page. -->
|
||||||
|
<string name="next_page_content_description">Next</string>
|
||||||
|
|
||||||
|
<!-- Content description of preview pager in colors preview -->
|
||||||
|
<string name="colors_viewpager_content_description">Color preview</string>
|
||||||
|
|
||||||
<!-- Bluetooth sim card permission alert for notification title [CHAR LIMIT=none] -->
|
<!-- Bluetooth sim card permission alert for notification title [CHAR LIMIT=none] -->
|
||||||
<string name="bluetooth_sim_card_access_notification_title">SIM card access request</string>
|
<string name="bluetooth_sim_card_access_notification_title">SIM card access request</string>
|
||||||
<!-- Bluetooth sim card permission alert for notification content [CHAR LIMIT=none] -->
|
<!-- Bluetooth sim card permission alert for notification content [CHAR LIMIT=none] -->
|
||||||
|
@@ -28,12 +28,18 @@ import android.database.ContentObserver;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.hardware.display.ColorDisplayManager;
|
import android.hardware.display.ColorDisplayManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.viewpager.widget.PagerAdapter;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
@@ -43,6 +49,7 @@ import com.android.settingslib.widget.CandidateInfo;
|
|||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -54,10 +61,25 @@ public class ColorModePreferenceFragment extends RadioButtonPickerFragment {
|
|||||||
|
|
||||||
private static final int COLOR_MODE_FALLBACK = COLOR_MODE_NATURAL;
|
private static final int COLOR_MODE_FALLBACK = COLOR_MODE_NATURAL;
|
||||||
|
|
||||||
|
static final String PAGE_VIEWER_SELECTION_INDEX = "page_viewer_selection_index";
|
||||||
|
|
||||||
|
private static final int DOT_INDICATOR_SIZE = 12;
|
||||||
|
private static final int DOT_INDICATOR_LEFT_PADDING = 6;
|
||||||
|
private static final int DOT_INDICATOR_RIGHT_PADDING = 6;
|
||||||
|
|
||||||
private ContentObserver mContentObserver;
|
private ContentObserver mContentObserver;
|
||||||
private ColorDisplayManager mColorDisplayManager;
|
private ColorDisplayManager mColorDisplayManager;
|
||||||
private Resources mResources;
|
private Resources mResources;
|
||||||
|
|
||||||
|
private View mViewArrowPrevious;
|
||||||
|
private View mViewArrowNext;
|
||||||
|
private ViewPager mViewPager;
|
||||||
|
|
||||||
|
private ArrayList<View> mPageList;
|
||||||
|
|
||||||
|
private ImageView[] mDotIndicators;
|
||||||
|
private View[] mViewPagerImages;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@@ -85,6 +107,16 @@ public class ColorModePreferenceFragment extends RadioButtonPickerFragment {
|
|||||||
false /* notifyForDescendants */, mContentObserver, mUserId);
|
false /* notifyForDescendants */, mContentObserver, mUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
final int selectedPosition = savedInstanceState.getInt(PAGE_VIEWER_SELECTION_INDEX);
|
||||||
|
mViewPager.setCurrentItem(selectedPosition);
|
||||||
|
updateIndicator(selectedPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
if (mContentObserver != null) {
|
if (mContentObserver != null) {
|
||||||
@@ -94,6 +126,12 @@ public class ColorModePreferenceFragment extends RadioButtonPickerFragment {
|
|||||||
super.onDetach();
|
super.onDetach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState){
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putInt(PAGE_VIEWER_SELECTION_INDEX, mViewPager.getCurrentItem());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getPreferenceScreenResId() {
|
protected int getPreferenceScreenResId() {
|
||||||
return R.xml.color_mode_settings;
|
return R.xml.color_mode_settings;
|
||||||
@@ -105,11 +143,69 @@ public class ColorModePreferenceFragment extends RadioButtonPickerFragment {
|
|||||||
screen.addPreference(preview);
|
screen.addPreference(preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public ArrayList<Integer> getViewPagerResource() {
|
||||||
|
return new ArrayList<Integer>(
|
||||||
|
Arrays.asList(
|
||||||
|
R.layout.color_mode_view1,
|
||||||
|
R.layout.color_mode_view2,
|
||||||
|
R.layout.color_mode_view3));
|
||||||
|
}
|
||||||
|
|
||||||
|
void addViewPager(LayoutPreference preview) {
|
||||||
|
final ArrayList<Integer> tmpviewPagerList = getViewPagerResource();
|
||||||
|
mViewPager = preview.findViewById(R.id.viewpager);
|
||||||
|
|
||||||
|
mViewPagerImages = new View[3];
|
||||||
|
for (int idx = 0; idx < tmpviewPagerList.size(); idx++) {
|
||||||
|
mViewPagerImages[idx] =
|
||||||
|
getLayoutInflater().inflate(tmpviewPagerList.get(idx), null /* root */);
|
||||||
|
}
|
||||||
|
|
||||||
|
mPageList = new ArrayList<View>();
|
||||||
|
mPageList.add(mViewPagerImages[0]);
|
||||||
|
mPageList.add(mViewPagerImages[1]);
|
||||||
|
mPageList.add(mViewPagerImages[2]);
|
||||||
|
|
||||||
|
mViewPager.setAdapter(new ColorPagerAdapter(mPageList));
|
||||||
|
|
||||||
|
mViewArrowPrevious = preview.findViewById(R.id.arrow_previous);
|
||||||
|
mViewArrowPrevious.setOnClickListener(v -> {
|
||||||
|
final int previousPos = mViewPager.getCurrentItem() - 1;
|
||||||
|
mViewPager.setCurrentItem(previousPos, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
mViewArrowNext = preview.findViewById(R.id.arrow_next);
|
||||||
|
mViewArrowNext.setOnClickListener(v -> {
|
||||||
|
final int nextPos = mViewPager.getCurrentItem() + 1;
|
||||||
|
mViewPager.setCurrentItem(nextPos, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
mViewPager.addOnPageChangeListener(createPageListener());
|
||||||
|
|
||||||
|
final ViewGroup viewGroup = (ViewGroup) preview.findViewById(R.id.viewGroup);
|
||||||
|
mDotIndicators = new ImageView[mPageList.size()];
|
||||||
|
for (int i = 0; i < mPageList.size(); i++) {
|
||||||
|
final ImageView imageView = new ImageView(getContext());
|
||||||
|
final ViewGroup.MarginLayoutParams lp =
|
||||||
|
new ViewGroup.MarginLayoutParams(DOT_INDICATOR_SIZE, DOT_INDICATOR_SIZE);
|
||||||
|
lp.setMargins(DOT_INDICATOR_LEFT_PADDING, 0, DOT_INDICATOR_RIGHT_PADDING, 0);
|
||||||
|
imageView.setLayoutParams(lp);
|
||||||
|
mDotIndicators[i] = imageView;
|
||||||
|
|
||||||
|
viewGroup.addView(mDotIndicators[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateIndicator(mViewPager.getCurrentItem());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addStaticPreferences(PreferenceScreen screen) {
|
protected void addStaticPreferences(PreferenceScreen screen) {
|
||||||
final LayoutPreference preview = new LayoutPreference(screen.getContext(),
|
final LayoutPreference preview = new LayoutPreference(screen.getContext(),
|
||||||
R.layout.color_mode_preview);
|
R.layout.color_mode_preview);
|
||||||
configureAndInstallPreview(preview, screen);
|
configureAndInstallPreview(preview, screen);
|
||||||
|
|
||||||
|
addViewPager(preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -207,6 +303,88 @@ public class ColorModePreferenceFragment extends RadioButtonPickerFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ViewPager.OnPageChangeListener createPageListener() {
|
||||||
|
return new ViewPager.OnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageScrolled(
|
||||||
|
int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
if (positionOffset != 0) {
|
||||||
|
for (int idx = 0; idx < mPageList.size(); idx++) {
|
||||||
|
mViewPagerImages[idx].setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mViewPagerImages[position].setContentDescription(
|
||||||
|
getContext().getString(R.string.colors_viewpager_content_description));
|
||||||
|
updateIndicator(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateIndicator(int position) {
|
||||||
|
for (int i = 0; i < mPageList.size(); i++) {
|
||||||
|
if (position == i) {
|
||||||
|
mDotIndicators[i].setBackgroundResource(
|
||||||
|
R.drawable.ic_color_page_indicator_focused);
|
||||||
|
|
||||||
|
mViewPagerImages[i].setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
mDotIndicators[i].setBackgroundResource(
|
||||||
|
R.drawable.ic_color_page_indicator_unfocused);
|
||||||
|
|
||||||
|
mViewPagerImages[i].setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (position == 0) {
|
||||||
|
mViewArrowPrevious.setVisibility(View.INVISIBLE);
|
||||||
|
mViewArrowNext.setVisibility(View.VISIBLE);
|
||||||
|
} else if (position == (mPageList.size() - 1)) {
|
||||||
|
mViewArrowPrevious.setVisibility(View.VISIBLE);
|
||||||
|
mViewArrowNext.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
mViewArrowPrevious.setVisibility(View.VISIBLE);
|
||||||
|
mViewArrowNext.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ColorPagerAdapter extends PagerAdapter {
|
||||||
|
private final ArrayList<View> mPageViewList;
|
||||||
|
|
||||||
|
ColorPagerAdapter(ArrayList<View> pageViewList) {
|
||||||
|
mPageViewList = pageViewList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||||
|
if (mPageViewList.get(position) != null) {
|
||||||
|
container.removeView(mPageViewList.get(position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object instantiateItem(ViewGroup container, int position) {
|
||||||
|
container.addView(mPageViewList.get(position));
|
||||||
|
return mPageViewList.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mPageViewList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isViewFromObject(View view, Object object) {
|
||||||
|
return object == view;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider(R.xml.color_mode_settings) {
|
new BaseSearchIndexProvider(R.xml.color_mode_settings) {
|
||||||
|
|
||||||
|
@@ -39,6 +39,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@@ -232,4 +233,15 @@ public class ColorModePreferenceFragmentTest {
|
|||||||
|
|
||||||
verify(mFragment).setColorMode(ColorDisplayManager.COLOR_MODE_AUTOMATIC);
|
verify(mFragment).setColorMode(ColorDisplayManager.COLOR_MODE_AUTOMATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@UiThreadTest
|
||||||
|
public void checkViewPagerTotalCount() throws Throwable {
|
||||||
|
final ArrayList<Integer> viewPagerResList = mFragment.getViewPagerResource();
|
||||||
|
|
||||||
|
assertThat(viewPagerResList.size()).isEqualTo(3);
|
||||||
|
for (int idx = 0; idx < viewPagerResList.size(); idx++) {
|
||||||
|
assertThat(viewPagerResList.get(idx) > 0).isTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user