Remove car-ui-provider.
Package has been deprecated. Remove it.
Bug: 33210228
Test: Built & booted. Verified apps still work.
Change-Id: I18b1aecb0a28dcae354dbc6f48c6e837d3923d0f
diff --git a/car-ui-provider/Android.mk b/car-ui-provider/Android.mk
deleted file mode 100644
index f63674a..0000000
--- a/car-ui-provider/Android.mk
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2015 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.
-#
-#
-
-#disble build in PDK, should add prebuilts/fullsdk to make this work
-ifneq ($(TARGET_BUILD_PDK),true)
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_CERTIFICATE := platform
-LOCAL_MODULE_TAGS := optional
-LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := CarUiProvider
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_DEX_PREOPT := nostripping
-
-include packages/services/Car/car-support-lib/car-support.mk
-
-include $(BUILD_PACKAGE)
-
-endif #TARGET_BUILD_PDK
diff --git a/car-ui-provider/AndroidManifest.xml b/car-ui-provider/AndroidManifest.xml
deleted file mode 100644
index ffbdfed..0000000
--- a/car-ui-provider/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 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.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
- package="android.car.ui.provider" >
- <uses-sdk android:minSdkVersion="23"
- android:targetSdkVersion="23" />
- <application android:label="@string/app_name" />
-</manifest>
diff --git a/car-ui-provider/res/drawable-hdpi/ic_google.png b/car-ui-provider/res/drawable-hdpi/ic_google.png
deleted file mode 100644
index 6e79734..0000000
--- a/car-ui-provider/res/drawable-hdpi/ic_google.png
+++ /dev/null
Binary files differ
diff --git a/car-ui-provider/res/drawable-hdpi/ic_googleg.png b/car-ui-provider/res/drawable-hdpi/ic_googleg.png
deleted file mode 100644
index 0d4158f..0000000
--- a/car-ui-provider/res/drawable-hdpi/ic_googleg.png
+++ /dev/null
Binary files differ
diff --git a/car-ui-provider/res/drawable-mdpi/ic_google.png b/car-ui-provider/res/drawable-mdpi/ic_google.png
deleted file mode 100644
index b00365a..0000000
--- a/car-ui-provider/res/drawable-mdpi/ic_google.png
+++ /dev/null
Binary files differ
diff --git a/car-ui-provider/res/drawable-mdpi/ic_googleg.png b/car-ui-provider/res/drawable-mdpi/ic_googleg.png
deleted file mode 100644
index 4871a0f..0000000
--- a/car-ui-provider/res/drawable-mdpi/ic_googleg.png
+++ /dev/null
Binary files differ
diff --git a/car-ui-provider/res/drawable-xhdpi/ic_google.png b/car-ui-provider/res/drawable-xhdpi/ic_google.png
deleted file mode 100644
index db17d6f..0000000
--- a/car-ui-provider/res/drawable-xhdpi/ic_google.png
+++ /dev/null
Binary files differ
diff --git a/car-ui-provider/res/drawable-xhdpi/ic_googleg.png b/car-ui-provider/res/drawable-xhdpi/ic_googleg.png
deleted file mode 100644
index addab88..0000000
--- a/car-ui-provider/res/drawable-xhdpi/ic_googleg.png
+++ /dev/null
Binary files differ
diff --git a/car-ui-provider/res/drawable-xxhdpi/ic_google.png b/car-ui-provider/res/drawable-xxhdpi/ic_google.png
deleted file mode 100644
index a27a8bc..0000000
--- a/car-ui-provider/res/drawable-xxhdpi/ic_google.png
+++ /dev/null
Binary files differ
diff --git a/car-ui-provider/res/drawable-xxhdpi/ic_googleg.png b/car-ui-provider/res/drawable-xxhdpi/ic_googleg.png
deleted file mode 100644
index 0e89bbb..0000000
--- a/car-ui-provider/res/drawable-xxhdpi/ic_googleg.png
+++ /dev/null
Binary files differ
diff --git a/car-ui-provider/res/layout/car_activity.xml b/car-ui-provider/res/layout/car_activity.xml
deleted file mode 100644
index 041afd3..0000000
--- a/car-ui-provider/res/layout/car_activity.xml
+++ /dev/null
@@ -1,192 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 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.
--->
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_height="match_parent"
- android:layout_width="match_parent">
-
- <ImageView
- android:id="@+id/background"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="centerCrop" />
-
- <android.car.ui.provider.CarDrawerLayout
- android:id="@+id/drawer_container"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
-
- <FrameLayout
- android:id="@+id/container"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
-
- <FrameLayout
- android:id="@+id/drawer"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="left"
- android:layout_marginEnd="96dp"
- android:background="@color/car_card"
- android:paddingTop="@dimen/lens_header_height" >
-
- <android.car.ui.provider.PagedListView
- android:id="@+id/list_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- />
-
- <ProgressBar
- android:id="@+id/progress"
- android:layout_width="48dp"
- android:layout_height="48dp"
- android:layout_gravity="center"
- android:indeterminate="true" />
-
- <android.support.v7.widget.CardView
- android:id="@+id/truncated_list_card"
- android:layout_width="match_parent"
- android:layout_height="@dimen/car_list_truncated_list_card_height"
- android:layout_gravity="bottom"
- android:layout_marginLeft="@dimen/car_list_truncated_list_padding"
- android:layout_marginRight="@dimen/car_list_truncated_list_padding"
- android:layout_marginBottom="@dimen/car_list_truncated_list_padding"
- android:visibility="gone"
- app:cardBackgroundColor="@color/car_blue_grey_800"
- app:cardCornerRadius="@dimen/car_card_view_corner_radius"
- app:cardElevation="@dimen/car_card_view_elevation" >
-
- <TextView
- style="@style/CarTruncatedList"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/car_list_truncated_list_icon_padding"
- android:drawablePadding="@dimen/car_list_truncated_list_drawable_padding"
- android:gravity="center_vertical"
- android:drawableLeft="@drawable/ic_remove_circle"
- android:text="@string/truncated_list" />
-
- </android.support.v7.widget.CardView>
- </FrameLayout>
- </android.car.ui.provider.CarDrawerLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="@dimen/lens_header_height">
-
- <FrameLayout
- android:layout_width="@dimen/car_drawer_button_container_width"
- android:layout_height="match_parent">
-
- <ImageView
- android:id="@+id/car_drawer_button"
- android:layout_width="@dimen/car_drawer_header_menu_button_size"
- android:layout_height="@dimen/car_drawer_header_menu_button_size"
- android:background="@drawable/car_header_button_background"
- android:focusable="false"
- android:scaleType="center"
- android:layout_gravity="center" />
- </FrameLayout>
-
- <FrameLayout
- android:id="@+id/car_drawer_title_container"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1" >
- <TextView
- android:id="@+id/car_drawer_title"
- style="@style/CarTitle.Light"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:ellipsize="end"
- android:focusable="false"
- android:gravity="center_vertical"
- android:singleLine="true"
- />
- </FrameLayout>
- <android.support.v7.widget.CardView
- android:id="@+id/car_search_box"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_marginBottom="16dp"
- android:layout_marginTop="16dp"
- android:gravity="center_vertical"
- app:cardBackgroundColor="@android:color/transparent" >
-
- <FrameLayout
- android:id="@+id/car_search_box_contents"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:animateLayoutChanges="false">
-
- <FrameLayout
- android:id="@+id/car_search_box_search_logo_container"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingStart="16dp" >
-
- <ImageView
- android:id="@+id/car_search_box_search_logo"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="start|center_vertical"
- android:paddingTop="6dp" />
- </FrameLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
-
- <ImageView
- android:id="@+id/car_search_box_super_logo"
- android:layout_width="@dimen/car_list_item_icon_size_small"
- android:layout_height="@dimen/car_list_item_icon_size_small"
- android:layout_gravity="center_vertical"
- android:layout_marginStart="24dp"
- android:scaleType="center" />
- <!--
- Use a 0x0 drawable for textSelectHandle; null drawable crashes, so does
- transparent color. Also set textCursorDrawable to null because this forces
- Android to render a cursor using the text color instead of not rendering
- one at all. See
- http://stackoverflow.com/questions/21397977/android-edit-text-cursor-is-not-visible
- -->
-
- <android.support.car.input.CarRestrictedEditText
- android:id="@+id/car_search_box_edit_text"
- style="@style/CarTitle.Dark"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:gravity="center_vertical"
- android:imeOptions="actionSearch"
- android:paddingEnd="16dp"
- android:paddingStart="36dp"
- android:singleLine="true"
- android:textCursorDrawable="@null"
- android:textSelectHandle="@drawable/car_empty" />
-
- <FrameLayout
- android:id="@+id/car_search_box_end_view"
- android:layout_width="wrap_content"
- android:layout_height="match_parent" />
- </LinearLayout>
- </FrameLayout>
- </android.support.v7.widget.CardView>
- </LinearLayout>
-
-</FrameLayout>
diff --git a/car-ui-provider/res/layout/car_paged_recycler_view.xml b/car-ui-provider/res/layout/car_paged_recycler_view.xml
deleted file mode 100644
index a0f9537..0000000
--- a/car-ui-provider/res/layout/car_paged_recycler_view.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-<!-- Cloned from car ui lib for use in CarUiProvider. Must be kept in sync. -->
-<merge xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.car.ui.provider.MaxWidthLayout
- android:id="@+id/max_width_layout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginStart="@dimen/car_drawer_button_container_width">
- <android.car.ui.provider.CarRecyclerView
- android:id="@+id/recycler_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center_horizontal"
- android:clipChildren="false"/>
- </android.car.ui.provider.MaxWidthLayout>
- <!-- The scroll bar should be drawn ontop of the centered recycler view-->
- <FrameLayout
- android:layout_width="@dimen/car_drawer_button_container_width"
- android:layout_height="match_parent">
- <android.car.ui.provider.PagedScrollBarView
- android:id="@+id/paged_scroll_view"
- android:layout_width="@dimen/car_paged_list_view_pagination_width"
- android:layout_height="match_parent"
- android:paddingBottom="16dp"
- android:paddingTop="16dp"
- android:layout_gravity="center_horizontal"
- android:visibility="invisible"/>
- </FrameLayout>
-</merge>
\ No newline at end of file
diff --git a/car-ui-provider/res/values-h480dp/dimens.xml b/car-ui-provider/res/values-h480dp/dimens.xml
deleted file mode 100644
index 44d9df6..0000000
--- a/car-ui-provider/res/values-h480dp/dimens.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-<resources>
- <dimen name="lens_header_height">112dp</dimen>
-</resources>
diff --git a/car-ui-provider/res/values-h600dp/dimens.xml b/car-ui-provider/res/values-h600dp/dimens.xml
deleted file mode 100644
index c972bad..0000000
--- a/car-ui-provider/res/values-h600dp/dimens.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-<resources>
- <dimen name="car_drawer_header_height">192dp</dimen>
- <dimen name="car_drawer_header_menu_button_size">152dp</dimen>
- <dimen name="car_drawer_button_margin_right">12dp</dimen>
- <dimen name="lens_header_height">148dp</dimen>
-</resources>
diff --git a/car-ui-provider/res/values/dimens.xml b/car-ui-provider/res/values/dimens.xml
deleted file mode 100644
index 378e6f8..0000000
--- a/car-ui-provider/res/values/dimens.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-<resources>
- <dimen name="car_drawer_header_menu_button_size">96dp</dimen>
-
- <!-- The top margin before the start of content in an application. -->
- <dimen name="lens_header_height">72dp</dimen>
-</resources>
diff --git a/car-ui-provider/res/values/strings.xml b/car-ui-provider/res/values/strings.xml
deleted file mode 100644
index c6a70d7..0000000
--- a/car-ui-provider/res/values/strings.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 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.
--->
-<resources>
- <string name="app_name">CarUiProvider</string>
-</resources>
\ No newline at end of file
diff --git a/car-ui-provider/src/android/car/ui/provider/CarDrawerLayout.java b/car-ui-provider/src/android/car/ui/provider/CarDrawerLayout.java
deleted file mode 100644
index 5e70420..0000000
--- a/car-ui-provider/src/android/car/ui/provider/CarDrawerLayout.java
+++ /dev/null
@@ -1,1466 +0,0 @@
-/*
- * Copyright (C) 2015 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 android.car.ui.provider;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.support.annotation.NonNull;
-import android.support.car.ui.CarUiResourceLoader;
-import android.support.car.ui.QuantumInterpolator;
-import android.support.car.ui.R;
-import android.support.car.ui.ReversibleInterpolator;
-import android.support.v4.view.GravityCompat;
-import android.support.v4.view.MotionEventCompat;
-import android.support.v4.view.ViewCompat;
-import android.support.v4.view.ViewGroupCompat;
-import android.support.v4.widget.ViewDragHelper;
-import android.util.AttributeSet;
-import android.view.Gravity;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.FrameLayout;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Acts as a top-level container for window content that allows for
- * interactive "drawer" views to be pulled out from the edge of the window.
- *
- * <p>Drawer positioning and layout is controlled using the <code>android:layout_gravity</code>
- * attribute on child views corresponding to which side of the view you want the drawer
- * to emerge from: left or right. (Or start/end on platform versions that support layout direction.)
- * </p>
- *
- * <p> To use CarDrawerLayout, add your drawer view as the first view in the CarDrawerLayout
- * element and set the <code>layout_gravity</code> appropriately. Drawers commonly use
- * <code>match_parent</code> for height with a fixed width. Add the content views as sibling views
- * after the drawer view.</p>
- *
- * <p>{@link DrawerListener} can be used to monitor the state and motion of drawer views.
- * Avoid performing expensive operations such as layout during animation as it can cause
- * stuttering; try to perform expensive operations during the {@link #STATE_IDLE} state.
- * {@link SimpleDrawerListener} offers default/no-op implementations of each callback method.</p>
- */
-public class CarDrawerLayout extends ViewGroup {
- /**
- * Indicates that any drawers are in an idle, settled state. No animation is in progress.
- */
- public static final int STATE_IDLE = ViewDragHelper.STATE_IDLE;
-
- /**
- * The drawer is unlocked.
- */
- public static final int LOCK_MODE_UNLOCKED = 0;
-
- /**
- * The drawer is locked closed. The user may not open it, though
- * the app may open it programmatically.
- */
- public static final int LOCK_MODE_LOCKED_CLOSED = 1;
-
- /**
- * The drawer is locked open. The user may not close it, though the app
- * may close it programmatically.
- */
- public static final int LOCK_MODE_LOCKED_OPEN = 2;
-
- private static final float MAX_SCRIM_ALPHA = 0.8f;
-
- private static final boolean SCRIM_ENABLED = true;
-
- private static final boolean SHADOW_ENABLED = true;
-
- /**
- * Minimum velocity that will be detected as a fling
- */
- private static final int MIN_FLING_VELOCITY = 400; // dips per second
-
- /**
- * Experimental feature.
- */
- private static final boolean ALLOW_EDGE_LOCK = false;
-
- private static final boolean EDGE_DRAG_ENABLED = false;
-
- private static final boolean CHILDREN_DISALLOW_INTERCEPT = true;
-
- private static final float TOUCH_SLOP_SENSITIVITY = 1.f;
-
- private static final int[] LAYOUT_ATTRS = new int[] {
- android.R.attr.layout_gravity
- };
-
- public static final int DEFAULT_SCRIM_COLOR = 0xff262626;
-
- private int mScrimColor = DEFAULT_SCRIM_COLOR;
- private final Paint mScrimPaint = new Paint();
- private final Paint mEdgeHighlightPaint = new Paint();
-
- private final ViewDragHelper mDragger;
-
- private final Runnable mInvalidateRunnable = new Runnable() {
- @Override
- public void run() {
- requestLayout();
- invalidate();
- }
- };
-
- // view faders who will be given different colors as the drawer opens
- private final Set<ViewFaderHolder> mViewFaders;
- private final ReversibleInterpolator mViewFaderInterpolator;
- private final ReversibleInterpolator mDrawerFadeInterpolator;
- private final Handler mHandler = new Handler();
-
- private int mEndingViewColor;
- private int mStartingViewColor;
- private int mDrawerState;
- private boolean mInLayout;
- /** Whether we have done a layout yet. Used to initialize some view-related state. */
- private boolean mFirstLayout = true;
- private boolean mHasInflated;
- private int mLockModeLeft;
- private int mLockModeRight;
- private boolean mChildrenCanceledTouch;
- private DrawerListener mDrawerListener;
- private DrawerControllerListener mDrawerControllerListener;
- private Drawable mShadow;
- private View mDrawerView;
- private View mContentView;
- private boolean mNeedsFocus;
- /** Whether or not the drawer started open for the current gesture */
- private boolean mStartedOpen;
- private boolean mHasWheel;
-
- /**
- * Listener for monitoring events about drawers.
- */
- public interface DrawerListener {
- /**
- * Called when a drawer's position changes.
- * @param drawerView The child view that was moved
- * @param slideOffset The new offset of this drawer within its range, from 0-1
- */
- void onDrawerSlide(View drawerView, float slideOffset);
-
- /**
- * Called when a drawer has settled in a completely open state.
- * The drawer is interactive at this point.
- *
- * @param drawerView Drawer view that is now open
- */
- void onDrawerOpened(View drawerView);
-
- /**
- * Called when a drawer has settled in a completely closed state.
- *
- * @param drawerView Drawer view that is now closed
- */
- void onDrawerClosed(View drawerView);
-
- /**
- * Called when a drawer is starting to open.
- *
- * @param drawerView Drawer view that is opening
- */
- void onDrawerOpening(View drawerView);
-
- /**
- * Called when a drawer is starting to close.
- *
- * @param drawerView Drawer view that is closing
- */
- void onDrawerClosing(View drawerView);
-
- /**
- * Called when the drawer motion state changes. The new state will
- * be one of {@link #STATE_IDLE}, {@link #STATE_DRAGGING} or {@link #STATE_SETTLING}.
- *
- * @param newState The new drawer motion state
- */
- void onDrawerStateChanged(int newState);
- }
-
- /**
- * Used to execute when the drawer needs to handle state that the underlying views would like
- * to handle in a specific way.
- */
- public interface DrawerControllerListener {
- void onBack();
- boolean onScroll();
- }
-
- /**
- * Stub/no-op implementations of all methods of {@link DrawerListener}.
- * Override this if you only care about a few of the available callback methods.
- */
- public static abstract class SimpleDrawerListener implements DrawerListener {
- @Override
- public void onDrawerSlide(View drawerView, float slideOffset) {
- }
-
- @Override
- public void onDrawerOpened(View drawerView) {
- }
-
- @Override
- public void onDrawerClosed(View drawerView) {
- }
-
- @Override
- public void onDrawerOpening(View drawerView) {
- }
-
- @Override
- public void onDrawerClosing(View drawerView) {
- }
-
- @Override
- public void onDrawerStateChanged(int newState) {
- }
- }
-
- /**
- * Sets the color of (or tints) a view (or views).
- */
- public interface ViewFader {
- void setColor(int color);
- }
-
- public CarDrawerLayout(Context context) {
- this(context, null);
- }
-
- public CarDrawerLayout(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public CarDrawerLayout(final Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- mViewFaders = new HashSet<>();
- mEndingViewColor = getResources().getColor(R.color.car_tint);
-
- mEdgeHighlightPaint.setColor(getResources().getColor(android.R.color.black));
-
- final float density = getResources().getDisplayMetrics().density;
- final float minVel = MIN_FLING_VELOCITY * density;
-
- ViewDragCallback viewDragCallback = new ViewDragCallback();
- mDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, viewDragCallback);
- mDragger.setMinVelocity(minVel);
- viewDragCallback.setDragger(mDragger);
-
- ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
-
- if (SHADOW_ENABLED) {
- setDrawerShadow(CarUiResourceLoader.getDrawable(context, "drawer_shadow"));
- }
-
- Resources.Theme theme = context.getTheme();
- TypedArray ta = theme.obtainStyledAttributes(new int[] {
- android.R.attr.colorPrimaryDark
- });
- setScrimColor(ta.getColor(0, context.getResources().getColor(R.color.car_grey_900)));
-
- mViewFaderInterpolator = new ReversibleInterpolator(
- new QuantumInterpolator(QuantumInterpolator.FAST_OUT_SLOW_IN, 0.25f, 0.25f, 0.5f),
- new QuantumInterpolator(QuantumInterpolator.FAST_OUT_SLOW_IN, 0.43f, 0.14f, 0.43f)
- );
- mDrawerFadeInterpolator = new ReversibleInterpolator(
- new QuantumInterpolator(QuantumInterpolator.FAST_OUT_SLOW_IN, 0.625f, 0.25f, 0.125f),
- new QuantumInterpolator(QuantumInterpolator.FAST_OUT_LINEAR_IN, 0.58f, 0.14f, 0.28f)
- );
-
- mHasWheel = CarUiResourceLoader.getBoolean(context, "has_wheel", false);
- }
-
- @Override
- public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
- int action = keyEvent.getAction();
- int keyCode = keyEvent.getKeyCode();
- final View drawerView = findDrawerView();
- if (drawerView != null && getDrawerLockMode(drawerView) == LOCK_MODE_UNLOCKED) {
- if (isDrawerOpen()) {
- if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
- || keyCode == KeyEvent.KEYCODE_SOFT_RIGHT) {
- closeDrawer();
- return true;
- } else if (keyCode == KeyEvent.KEYCODE_BACK
- && action == KeyEvent.ACTION_UP
- && mDrawerControllerListener != null) {
- mDrawerControllerListener.onBack();
- return true;
- } else {
- return drawerView.dispatchKeyEvent(keyEvent);
- }
- }
- }
-
- return mContentView.dispatchKeyEvent(keyEvent);
- }
-
- @Override
- public boolean dispatchGenericMotionEvent(MotionEvent ev) {
- final View drawerView = findDrawerView();
- if (drawerView != null
- && ev.getAction() == MotionEvent.ACTION_SCROLL
- && mDrawerControllerListener != null
- && mDrawerControllerListener.onScroll()) {
- return true;
- }
- return super.dispatchGenericMotionEvent(ev);
- }
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- mHasInflated = true;
- setAutoDayNightMode();
-
- setOnGenericMotionListener(new OnGenericMotionListener() {
- @Override
- public boolean onGenericMotion(View view, MotionEvent event) {
- if (getChildCount() == 0) {
- return false;
- }
- if (isDrawerOpen()) {
- View drawerView = findDrawerView();
- ViewGroup viewGroup = (ViewGroup) ((FrameLayout) drawerView).getChildAt(0);
- return viewGroup.getChildAt(0).onGenericMotionEvent(event);
- }
- View contentView = findContentView();
- ViewGroup viewGroup = (ViewGroup) ((FrameLayout) contentView).getChildAt(0);
- return viewGroup.getChildAt(0).onGenericMotionEvent(event);
- }
- });
- }
-
- /**
- * Set a simple drawable used for the left or right shadow.
- * The drawable provided must have a nonzero intrinsic width.
- *
- * @param shadowDrawable Shadow drawable to use at the edge of a drawer
- */
- public void setDrawerShadow(Drawable shadowDrawable) {
- mShadow = shadowDrawable;
- invalidate();
- }
-
-
-
- /**
- * Set a color to use for the scrim that obscures primary content while a drawer is open.
- *
- * @param color Color to use in 0xAARRGGBB format.
- */
- public void setScrimColor(int color) {
- mScrimColor = color;
- invalidate();
- }
-
- /**
- * Set a listener to be notified of drawer events.
- *
- * @param listener Listener to notify when drawer events occur
- * @see DrawerListener
- */
- public void setDrawerListener(DrawerListener listener) {
- mDrawerListener = listener;
- }
-
- public void setDrawerControllerListener(DrawerControllerListener listener) {
- mDrawerControllerListener = listener;
- }
-
- /**
- * Enable or disable interaction with all drawers.
- *
- * <p>This allows the application to restrict the user's ability to open or close
- * any drawer within this layout. DrawerLayout will still respond to calls to
- * {@link #openDrawer()}, {@link #closeDrawer()} and friends if a drawer is locked.</p>
- *
- * <p>Locking drawers open or closed will implicitly open or close
- * any drawers as appropriate.</p>
- *
- * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
- * {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
- */
- public void setDrawerLockMode(int lockMode) {
- LayoutParams lp = (LayoutParams) findDrawerView().getLayoutParams();
- setDrawerLockMode(lockMode, lp.gravity);
- }
-
- /**
- * Enable or disable interaction with the given drawer.
- *
- * <p>This allows the application to restrict the user's ability to open or close
- * the given drawer. DrawerLayout will still respond to calls to {@link #openDrawer()},
- * {@link #closeDrawer()} and friends if a drawer is locked.</p>
- *
- * <p>Locking a drawer open or closed will implicitly open or close
- * that drawer as appropriate.</p>
- *
- * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
- * {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
- * @param edgeGravity Gravity.LEFT, RIGHT, START or END.
- * Expresses which drawer to change the mode for.
- *
- * @see #LOCK_MODE_UNLOCKED
- * @see #LOCK_MODE_LOCKED_CLOSED
- * @see #LOCK_MODE_LOCKED_OPEN
- */
- public void setDrawerLockMode(int lockMode, int edgeGravity) {
- final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity,
- ViewCompat.getLayoutDirection(this));
- if (absGravity == Gravity.LEFT) {
- mLockModeLeft = lockMode;
- } else if (absGravity == Gravity.RIGHT) {
- mLockModeRight = lockMode;
- }
- if (lockMode != LOCK_MODE_UNLOCKED) {
- // Cancel interaction in progress
- mDragger.cancel();
- }
- switch (lockMode) {
- case LOCK_MODE_LOCKED_OPEN:
- openDrawer();
- break;
- case LOCK_MODE_LOCKED_CLOSED:
- closeDrawer();
- break;
- // default: do nothing
- }
- }
-
- /**
- * All view faders will be light when the drawer is open and fade to dark and it closes.
- * NOTE: this will clear any existing view faders.
- */
- public void setLightMode() {
- mStartingViewColor = getResources().getColor(R.color.car_title_light);
- mEndingViewColor = getResources().getColor(R.color.car_tint);
- updateViewFaders();
- }
-
- /**
- * All view faders will be dark when the drawer is open and stay that way when it closes.
- * NOTE: this will clear any existing view faders.
- */
- public void setDarkMode() {
- mStartingViewColor = getResources().getColor(R.color.car_title_dark);
- mEndingViewColor = getResources().getColor(R.color.car_tint);
- updateViewFaders();
- }
-
- /**
- * All view faders will be dark during the day and light at night.
- * NOTE: this will clear any existing view faders.
- */
- public void setAutoDayNightMode() {
- mStartingViewColor = getResources().getColor(R.color.car_title);
- mEndingViewColor = getResources().getColor(R.color.car_tint);
- updateViewFaders();
- }
-
- private void resetViewFaders() {
- mViewFaders.clear();
- }
-
- /**
- * Check the lock mode of the given drawer view.
- *
- * @param drawerView Drawer view to check lock mode
- * @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or
- * {@link #LOCK_MODE_LOCKED_OPEN}.
- */
- public int getDrawerLockMode(View drawerView) {
- final int absGravity = getDrawerViewAbsoluteGravity(drawerView);
- if (absGravity == Gravity.LEFT) {
- return mLockModeLeft;
- } else if (absGravity == Gravity.RIGHT) {
- return mLockModeRight;
- }
- return LOCK_MODE_UNLOCKED;
- }
-
- /**
- * Resolve the shared state of all drawers from the component ViewDragHelpers.
- * Should be called whenever a ViewDragHelper's state changes.
- */
- private void updateDrawerState(int activeState) {
- View drawerView = findDrawerView();
- if (drawerView != null && activeState == STATE_IDLE) {
- if (onScreen() == 0) {
- dispatchOnDrawerClosed(drawerView);
- } else if (onScreen() == 1) {
- dispatchOnDrawerOpened(drawerView);
- }
- }
-
- if (mDragger.getViewDragState() != mDrawerState) {
- mDrawerState = mDragger.getViewDragState();
-
- if (mDrawerListener != null) {
- mDrawerListener.onDrawerStateChanged(mDragger.getViewDragState());
- }
- }
- }
-
- private void dispatchOnDrawerClosed(View drawerView) {
- final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
- if (lp.knownOpen) {
- lp.knownOpen = false;
- if (mDrawerListener != null) {
- mDrawerListener.onDrawerClosed(drawerView);
- }
- }
- }
-
- private void dispatchOnDrawerOpened(View drawerView) {
- final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
- if (!lp.knownOpen) {
- lp.knownOpen = true;
- if (mDrawerListener != null) {
- mDrawerListener.onDrawerOpened(drawerView);
- }
- }
- }
-
- private void dispatchOnDrawerSlide(View drawerView, float slideOffset) {
- if (mDrawerListener != null) {
- mDrawerListener.onDrawerSlide(drawerView, slideOffset);
- }
- }
-
- private void dispatchOnDrawerOpening(View drawerView) {
- if (mDrawerListener != null) {
- mDrawerListener.onDrawerOpening(drawerView);
- }
- }
-
- private void dispatchOnDrawerClosing(View drawerView) {
- if (mDrawerListener != null) {
- mDrawerListener.onDrawerClosing(drawerView);
- }
- }
-
- private void setDrawerViewOffset(View drawerView, float slideOffset) {
- if (slideOffset == onScreen()) {
- return;
- }
-
- LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
- lp.onScreen = slideOffset;
- dispatchOnDrawerSlide(drawerView, slideOffset);
- }
-
- private float onScreen() {
- return ((LayoutParams) findDrawerView().getLayoutParams()).onScreen;
- }
-
- /**
- * @return the absolute gravity of the child drawerView, resolved according
- * to the current layout direction
- */
- private int getDrawerViewAbsoluteGravity(View drawerView) {
- final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
- return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
- }
-
- private boolean checkDrawerViewAbsoluteGravity(View drawerView, int checkFor) {
- final int absGravity = getDrawerViewAbsoluteGravity(drawerView);
- return (absGravity & checkFor) == checkFor;
- }
-
- /**
- * @return the drawer view
- */
- private View findDrawerView() {
- if (mDrawerView != null) {
- return mDrawerView;
- }
-
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- final View child = getChildAt(i);
- final int childAbsGravity = getDrawerViewAbsoluteGravity(child);
- if (childAbsGravity != Gravity.NO_GRAVITY) {
- mDrawerView = child;
- return child;
- }
- }
- throw new IllegalStateException("No drawer view found.");
- }
-
- /**
- * @return the content. NOTE: this is the view with no gravity.
- */
- private View findContentView() {
- if (mContentView != null) {
- return mContentView;
- }
-
- final int childCount = getChildCount();
- for (int i = childCount - 1; i >= 0; --i) {
- final View child = getChildAt(i);
- if (isDrawerView(child)) {
- continue;
- }
- mContentView = child;
- return child;
- }
- throw new IllegalStateException("No content view found.");
- }
-
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- }
-
- @Override
- public boolean requestFocus(int direction, Rect rect) {
- // Optimally we want to check isInTouchMode(), but that value isn't always correct.
- if (mHasWheel) {
- mNeedsFocus = true;
- }
- return super.requestFocus(direction, rect);
- }
-
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- mFirstLayout = true;
- // There needs to be a layout pending if we're not going to animate the drawer until the
- // next layout, so make it so.
- requestLayout();
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int widthMode = MeasureSpec.getMode(widthMeasureSpec);
- int heightMode = MeasureSpec.getMode(heightMeasureSpec);
- int widthSize = MeasureSpec.getSize(widthMeasureSpec);
- int heightSize = MeasureSpec.getSize(heightMeasureSpec);
-
- if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) {
- if (isInEditMode()) {
- // Don't crash the layout editor. Consume all of the space if specified
- // or pick a magic number from thin air otherwise.
- // TODO Better communication with tools of this bogus state.
- // It will crash on a real device.
- if (widthMode == MeasureSpec.UNSPECIFIED) {
- widthSize = 300;
- }
- else if (heightMode == MeasureSpec.UNSPECIFIED) {
- heightSize = 300;
- }
- } else {
- throw new IllegalArgumentException(
- "DrawerLayout must be measured with MeasureSpec.EXACTLY.");
- }
- }
-
- setMeasuredDimension(widthSize, heightSize);
-
- View view = findContentView();
- LayoutParams lp = ((LayoutParams) view.getLayoutParams());
- // Content views get measured at exactly the layout's size.
- final int contentWidthSpec = MeasureSpec.makeMeasureSpec(
- widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
- final int contentHeightSpec = MeasureSpec.makeMeasureSpec(
- heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
- view.measure(contentWidthSpec, contentHeightSpec);
-
- view = findDrawerView();
- lp = ((LayoutParams) view.getLayoutParams());
- final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec,
- lp.leftMargin + lp.rightMargin,
- lp.width);
- final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec,
- lp.topMargin + lp.bottomMargin,
- lp.height);
- view.measure(drawerWidthSpec, drawerHeightSpec);
- }
-
- @Override
- protected void onLayout(boolean changed, int l, int t, int r, int b) {
- mInLayout = true;
- final int width = r - l;
-
- View contentView = findContentView();
- View drawerView = findDrawerView();
-
- LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
- LayoutParams contentLp = (LayoutParams) contentView.getLayoutParams();
-
- int contentRight = contentLp.getMarginStart() + getWidth();
- contentView.layout(contentRight - contentView.getMeasuredWidth(),
- contentLp.topMargin, contentRight,
- contentLp.topMargin + contentView.getMeasuredHeight());
-
- final int childHeight = drawerView.getMeasuredHeight();
- int onScreen = (int) (drawerView.getWidth() * drawerLp.onScreen);
- int offset;
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
- offset = onScreen - drawerView.getWidth();
- } else {
- offset = width - onScreen;
- }
- drawerView.layout(drawerLp.getMarginStart() + offset, drawerLp.topMargin,
- width - drawerLp.getMarginEnd() + offset,
- childHeight + drawerLp.topMargin);
- updateDrawerAlpha();
- updateViewFaders();
- if (mFirstLayout) {
-
- // TODO(b/15394507): Normally, onMeasure()/onLayout() are called three times when
- // you create CarDrawerLayout, but when you pop it back it's only called once which
- // leaves us in a weird state. This is a pretty ugly hack to fix that.
- mHandler.post(mInvalidateRunnable);
-
- mFirstLayout = false;
- }
-
- if (mNeedsFocus) {
- if (initializeFocus()) {
- mNeedsFocus = false;
- }
- }
-
- mInLayout = false;
- }
-
- private boolean initializeFocus() {
- // Only request focus if the current view that needs focus doesn't already have it. This
- // prevents some nasty bugs where focus ends up snapping to random elements and also saves
- // a bunch of cycles in the average case.
- mDrawerView.setFocusable(false);
- mContentView.setFocusable(false);
- boolean needFocus = !mDrawerView.hasFocus() && !mContentView.hasFocus();
- if (!needFocus) {
- return true;
- }
-
- // Find something in the hierarchy to give focus to.
- List<View> focusables;
- boolean drawerOpen = isDrawerOpen();
- if (drawerOpen) {
- focusables = mDrawerView.getFocusables(FOCUS_DOWN);
- } else {
- focusables = mContentView.getFocusables(FOCUS_DOWN);
- }
-
- // The 2 else cases here are a catch all for when nothing is focusable in view hierarchy.
- // If you don't have anything focusable on screen, key events will not be delivered to
- // the view hierarchy and you end up getting stuck without being able to open / close the
- // drawer or launch gsa.
-
- if (!focusables.isEmpty()) {
- focusables.get(0).requestFocus();
- return true;
- } else if (drawerOpen) {
- mDrawerView.setFocusable(true);
- } else {
- mContentView.setFocusable(true);
- }
- return false;
- }
-
- @Override
- public void requestLayout() {
- if (!mInLayout) {
- super.requestLayout();
- }
- }
-
- @Override
- public void computeScroll() {
- if (mDragger.continueSettling(true)) {
- ViewCompat.postInvalidateOnAnimation(this);
- }
- }
-
- private static boolean hasOpaqueBackground(View v) {
- final Drawable bg = v.getBackground();
- return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
- }
-
- @Override
- protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
- final int height = getHeight();
- final boolean drawingContent = isContentView(child);
- int clipLeft = findContentView().getLeft();
- int clipRight = findContentView().getRight();
- final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
-
- final int restoreCount = canvas.save();
- if (drawingContent) {
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- final View v = getChildAt(i);
- if (v == child || v.getVisibility() != VISIBLE ||
- !hasOpaqueBackground(v) || !isDrawerView(v) ||
- v.getHeight() < height) {
- continue;
- }
-
- if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) {
- final int vright = v.getRight();
- if (vright > clipLeft) {
- clipLeft = vright;
- }
- } else {
- final int vleft = v.getLeft();
- if (vleft < clipRight) {
- clipRight = vleft;
- }
- }
- }
- canvas.clipRect(clipLeft, 0, clipRight, getHeight());
- }
- final boolean result = super.drawChild(canvas, child, drawingTime);
- canvas.restoreToCount(restoreCount);
-
- if (drawingContent) {
- int scrimAlpha = SCRIM_ENABLED ?
- (int) (baseAlpha * Math.max(0, Math.min(1, onScreen())) * MAX_SCRIM_ALPHA) : 0;
-
- if (scrimAlpha > 0) {
- int color = scrimAlpha << 24 | (mScrimColor & 0xffffff);
- mScrimPaint.setColor(color);
-
- canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint);
-
- canvas.drawRect(clipLeft - 1, 0, clipLeft, getHeight(), mEdgeHighlightPaint);
- }
-
- LayoutParams drawerLp = (LayoutParams) findDrawerView().getLayoutParams();
- if (mShadow != null
- && checkDrawerViewAbsoluteGravity(findDrawerView(), Gravity.LEFT)) {
- final int offScreen = (int) ((1 - drawerLp.onScreen) * findDrawerView().getWidth());
- final int drawerRight = getWidth() - drawerLp.getMarginEnd() - offScreen;
- final int shadowWidth = mShadow.getIntrinsicWidth();
- final float alpha =
- Math.max(0, Math.min((float) drawerRight / mDragger.getEdgeSize(), 1.f));
- mShadow.setBounds(drawerRight, child.getTop(),
- drawerRight + shadowWidth, child.getBottom());
- mShadow.setAlpha((int) (255 * alpha * alpha * alpha));
- mShadow.draw(canvas);
- } else if (mShadow != null
- && checkDrawerViewAbsoluteGravity(findDrawerView(),Gravity.RIGHT)) {
- final int onScreen = (int) (findDrawerView().getWidth() * drawerLp.onScreen);
- final int drawerLeft = drawerLp.getMarginStart() + getWidth() - onScreen;
- final int shadowWidth = mShadow.getIntrinsicWidth();
- final float alpha =
- Math.max(0, Math.min((float) onScreen / mDragger.getEdgeSize(), 1.f));
- canvas.save();
- canvas.translate(2 * drawerLeft - shadowWidth, 0);
- canvas.scale(-1.0f, 1.0f);
- mShadow.setBounds(drawerLeft - shadowWidth, child.getTop(),
- drawerLeft, child.getBottom());
- mShadow.setAlpha((int) (255 * alpha * alpha * alpha * alpha));
- mShadow.draw(canvas);
- canvas.restore();
- }
- }
- return result;
- }
-
- private boolean isContentView(View child) {
- return child == findContentView();
- }
-
- private boolean isDrawerView(View child) {
- return child == findDrawerView();
- }
-
- private void updateDrawerAlpha() {
- float alpha;
- if (mStartedOpen) {
- alpha = mDrawerFadeInterpolator.getReverseInterpolation(onScreen());
- } else {
- alpha = mDrawerFadeInterpolator.getForwardInterpolation(onScreen());
- }
- ViewGroup drawerView = (ViewGroup) findDrawerView();
- int drawerChildCount = drawerView.getChildCount();
- for (int i = 0; i < drawerChildCount; i++) {
- drawerView.getChildAt(i).setAlpha(alpha);
- }
- }
-
- /**
- * Add a view fader whose color will be set as the drawer opens and closes.
- */
- public void addViewFader(ViewFader viewFader) {
- addViewFader(viewFader, mStartingViewColor, mEndingViewColor);
- }
-
- public void addViewFader(ViewFader viewFader, int startingColor, int endingColor) {
- mViewFaders.add(new ViewFaderHolder(viewFader, startingColor, endingColor));
- updateViewFaders();
- }
-
- public void removeViewFader(ViewFader viewFader) {
- for (Iterator<ViewFaderHolder> it = mViewFaders.iterator(); it.hasNext(); ) {
- ViewFaderHolder viewFaderHolder = it.next();
- if (viewFaderHolder.viewFader.equals(viewFader)) {
- it.remove();
- }
- }
- }
-
- private void updateViewFaders() {
- if (!mHasInflated) {
- return;
- }
-
- float fadeProgress;
- if (mStartedOpen) {
- fadeProgress = mViewFaderInterpolator.getReverseInterpolation(onScreen());
- } else {
- fadeProgress = mViewFaderInterpolator.getForwardInterpolation(onScreen());
- }
- for (Iterator<ViewFaderHolder> it = mViewFaders.iterator(); it.hasNext(); ) {
- ViewFaderHolder viewFaderHolder = it.next();
- int startingColor = viewFaderHolder.startingColor;
- int endingColor = viewFaderHolder.endingColor;
- int alpha = weightedAverage(Color.alpha(startingColor),
- Color.alpha(endingColor), fadeProgress);
- int red = weightedAverage(Color.red(startingColor),
- Color.red(endingColor), fadeProgress);
- int green = weightedAverage(Color.green(startingColor),
- Color.green(endingColor), fadeProgress);
- int blue = weightedAverage(Color.blue(startingColor),
- Color.blue(endingColor), fadeProgress);
- viewFaderHolder.viewFader.setColor(alpha << 24 | red << 16 | green << 8 | blue);
- }
- }
-
- private int weightedAverage(int starting, int ending, float weight) {
- return (int) ((1f - weight) * starting + weight * ending);
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- final int action = MotionEventCompat.getActionMasked(ev);
-
- // "|" used deliberately here; both methods should be invoked.
- final boolean interceptForDrag = mDragger.shouldInterceptTouchEvent(ev);
-
- boolean interceptForTap = false;
-
- switch (action) {
- case MotionEvent.ACTION_DOWN: {
- final float x = ev.getX();
- final float y = ev.getY();
- if (onScreen() > 0 && isContentView(mDragger.findTopChildUnder((int) x, (int) y))) {
- interceptForTap = true;
- }
- mChildrenCanceledTouch = false;
- break;
- }
- case MotionEvent.ACTION_CANCEL:
- case MotionEvent.ACTION_UP: {
- mChildrenCanceledTouch = false;
- }
- }
-
- return interceptForDrag || interceptForTap || mChildrenCanceledTouch;
- }
-
- @Override
- public boolean onTouchEvent(@NonNull MotionEvent ev) {
- mDragger.processTouchEvent(ev);
- final int absGravity = getDrawerViewAbsoluteGravity(findDrawerView());
- final int edge;
- if (absGravity == Gravity.LEFT) {
- edge = ViewDragHelper.EDGE_LEFT;
- } else {
- edge = ViewDragHelper.EDGE_RIGHT;
- }
-
- // don't allow views behind the drawer to be touched
- boolean drawerPartiallyOpen = onScreen() > 0;
- return mDragger.isEdgeTouched(edge) ||
- mDragger.getCapturedView() != null ||
- drawerPartiallyOpen;
- }
-
- @Override
- public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
- if (CHILDREN_DISALLOW_INTERCEPT) {
- // If we have an edge touch we want to skip this and track it for later instead.
- super.requestDisallowInterceptTouchEvent(disallowIntercept);
- }
-
- View drawerView = findDrawerView();
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
- super.requestDisallowInterceptTouchEvent(disallowIntercept);
- }
-
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.RIGHT)) {
- super.requestDisallowInterceptTouchEvent(disallowIntercept);
- }
- }
-
- /**
- * Open the drawer view by animating it into view.
- */
- public void openDrawer() {
- ViewGroup drawerView = (ViewGroup) findDrawerView();
- mStartedOpen = false;
-
- if (hasWindowFocus()) {
- int left;
- LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
- left = drawerLp.getMarginStart();
- } else {
- left = drawerLp.getMarginStart() + getWidth() - drawerView.getWidth();
- }
- mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop());
- dispatchOnDrawerOpening(drawerView);
- } else {
- final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
- lp.onScreen = 1.f;
- dispatchOnDrawerOpened(drawerView);
- }
-
- ViewGroup contentView = (ViewGroup) findContentView();
- contentView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
- drawerView.setDescendantFocusability(ViewGroup. FOCUS_AFTER_DESCENDANTS);
-
- View focusable = drawerView.getChildAt(0);
- if (focusable != null) {
- focusable.requestFocus();
- }
- invalidate();
- }
-
- /**
- * Close the specified drawer view by animating it into view.
- */
- public void closeDrawer() {
- ViewGroup drawerView = (ViewGroup) findDrawerView();
- if (!isDrawerView(drawerView)) {
- throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
- }
- mStartedOpen = true;
-
- // Don't trigger the close drawer animation if drawer is not open.
- if (hasWindowFocus() && isDrawerOpen()) {
- int left;
- LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
- left = drawerLp.getMarginStart() - drawerView.getWidth();
- } else {
- left = drawerLp.getMarginStart() + getWidth();
- }
- mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop());
- dispatchOnDrawerClosing(drawerView);
- } else {
- final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
- lp.onScreen = 0.f;
- dispatchOnDrawerClosed(drawerView);
- }
-
- ViewGroup contentView = (ViewGroup) findContentView();
- drawerView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
- contentView.setDescendantFocusability(ViewGroup. FOCUS_AFTER_DESCENDANTS);
-
- if (!isInTouchMode()) {
- List<View> focusables = contentView.getFocusables(FOCUS_DOWN);
- if (focusables.size() > 0) {
- View candidate = focusables.get(0);
- candidate.requestFocus();
- }
- }
- invalidate();
- }
-
- @Override
- public void addFocusables(@NonNull ArrayList<View> views, int direction, int focusableMode) {
- boolean drawerOpen = isDrawerOpen();
- if (drawerOpen) {
- findDrawerView().addFocusables(views, direction, focusableMode);
- } else {
- findContentView().addFocusables(views, direction, focusableMode);
- }
- }
-
- /**
- * Check if the given drawer view is currently in an open state.
- * To be considered "open" the drawer must have settled into its fully
- * visible state. To check for partial visibility use
- * {@link #isDrawerVisible(android.view.View)}.
- *
- * @return true if the given drawer view is in an open state
- * @see #isDrawerVisible(android.view.View)
- */
- public boolean isDrawerOpen() {
- return ((LayoutParams) findDrawerView().getLayoutParams()).knownOpen;
- }
-
- /**
- * Check if a given drawer view is currently visible on-screen. The drawer
- * may be fully extended or anywhere in between.
- *
- * @param drawer Drawer view to check
- * @return true if the given drawer is visible on-screen
- * @see #isDrawerOpen()
- */
- public boolean isDrawerVisible(View drawer) {
- if (!isDrawerView(drawer)) {
- throw new IllegalArgumentException("View " + drawer + " is not a drawer");
- }
- return onScreen() > 0;
- }
-
- /**
- * Check if a given drawer view is currently visible on-screen. The drawer
- * may be fully extended or anywhere in between.
- * If there is no drawer with the given gravity this method will return false.
- *
- * @return true if the given drawer is visible on-screen
- */
- public boolean isDrawerVisible() {
- final View drawerView = findDrawerView();
- return drawerView != null && isDrawerVisible(drawerView);
- }
-
- @Override
- protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
- return new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT);
- }
-
- @Override
- protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
- return p instanceof LayoutParams
- ? new LayoutParams((LayoutParams) p)
- : p instanceof MarginLayoutParams
- ? new LayoutParams((MarginLayoutParams) p)
- : new LayoutParams(p);
- }
-
- @Override
- protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
- return p instanceof LayoutParams && super.checkLayoutParams(p);
- }
-
- @Override
- public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
- return new LayoutParams(getContext(), attrs);
- }
-
- private boolean hasVisibleDrawer() {
- return findVisibleDrawer() != null;
- }
-
- private View findVisibleDrawer() {
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- final View child = getChildAt(i);
- if (isDrawerView(child) && isDrawerVisible(child)) {
- return child;
- }
- }
- return null;
- }
-
- @Override
- protected void onRestoreInstanceState(Parcelable state) {
- SavedState ss = null;
- if (state.getClass().getClassLoader() != getClass().getClassLoader()) {
- // Class loader mismatch, recreate from parcel.
- Parcel stateParcel = Parcel.obtain();
- state.writeToParcel(stateParcel, 0);
- ss = SavedState.CREATOR.createFromParcel(stateParcel);
- } else {
- ss = (SavedState) state;
- }
- super.onRestoreInstanceState(ss.getSuperState());
-
- if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
- openDrawer();
- }
-
- setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
- setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
- }
-
- @Override
- protected Parcelable onSaveInstanceState() {
- final Parcelable superState = super.onSaveInstanceState();
-
- final SavedState ss = new SavedState(superState);
-
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- final View child = getChildAt(i);
- if (!isDrawerView(child)) {
- continue;
- }
-
- final LayoutParams lp = (LayoutParams) child.getLayoutParams();
- if (lp.knownOpen) {
- ss.openDrawerGravity = lp.gravity;
- // Only one drawer can be open at a time.
- break;
- }
- }
-
- ss.lockModeLeft = mLockModeLeft;
- ss.lockModeRight = mLockModeRight;
-
- return ss;
- }
-
- /**
- * State persisted across instances
- */
- protected static class SavedState extends BaseSavedState {
- int openDrawerGravity = Gravity.NO_GRAVITY;
- int lockModeLeft = LOCK_MODE_UNLOCKED;
- int lockModeRight = LOCK_MODE_UNLOCKED;
-
- public SavedState(Parcel in) {
- super(in);
- openDrawerGravity = in.readInt();
- lockModeLeft = in.readInt();
- lockModeRight = in.readInt();
- }
-
- public SavedState(Parcelable superState) {
- super(superState);
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
- dest.writeInt(openDrawerGravity);
- dest.writeInt(lockModeLeft);
- dest.writeInt(lockModeRight);
- }
-
- @SuppressWarnings("hiding")
- public static final Creator<SavedState> CREATOR =
- new Creator<SavedState>() {
- @Override
- public SavedState createFromParcel(Parcel source) {
- return new SavedState(source);
- }
-
- @Override
- public SavedState[] newArray(int size) {
- return new SavedState[size];
- }
- };
- }
-
- private class ViewDragCallback extends ViewDragHelper.Callback {
- @SuppressWarnings("hiding")
- private ViewDragHelper mDragger;
-
- public void setDragger(ViewDragHelper dragger) {
- mDragger = dragger;
- }
-
- @Override
- public boolean tryCaptureView(View child, int pointerId) {
- CarDrawerLayout.LayoutParams lp = (LayoutParams) findDrawerView().getLayoutParams();
- int edges = EDGE_DRAG_ENABLED ? ViewDragHelper.EDGE_ALL : 0;
- boolean captured = isContentView(child) &&
- getDrawerLockMode(child) == LOCK_MODE_UNLOCKED &&
- (lp.knownOpen || mDragger.isEdgeTouched(edges));
- if (captured && lp.knownOpen) {
- mStartedOpen = true;
- } else if (captured && !lp.knownOpen) {
- mStartedOpen = false;
- }
- // We want dragging starting on the content view to drag the drawer. Therefore when
- // touch events try to capture the content view, we force capture of the drawer view.
- if (captured) {
- mDragger.captureChildView(findDrawerView(), pointerId);
- }
- return false;
- }
-
- @Override
- public void onViewDragStateChanged(int state) {
- updateDrawerState(state);
- }
-
- @Override
- public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
- float offset;
- View drawerView = findDrawerView();
- final int drawerWidth = drawerView.getWidth();
- // This reverses the positioning shown in onLayout.
- if (checkDrawerViewAbsoluteGravity(findDrawerView(), Gravity.LEFT)) {
- offset = (float) (left + drawerWidth) / drawerWidth;
- } else {
- offset = (float) (getWidth() - left) / drawerWidth;
- }
- setDrawerViewOffset(findDrawerView(), offset);
-
- updateDrawerAlpha();
-
- updateViewFaders();
- invalidate();
- }
-
- @Override
- public void onViewReleased(View releasedChild, float xvel, float yvel) {
- final View drawerView = findDrawerView();
- final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
- int left;
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
- // Open the drawer if they are swiping right or if they are not currently moving but
- // have moved the drawer in the current gesture and released the drawer when it was
- // fully open.
- // Close otherwise.
- left = xvel > 0 ? lp.getMarginStart() : lp.getMarginStart() - drawerView.getWidth();
- } else {
- // See comment for left drawer.
- left = xvel < 0 ? lp.getMarginStart() + getWidth() - drawerView.getWidth()
- : lp.getMarginStart() + getWidth();
- }
-
- mDragger.settleCapturedViewAt(left, releasedChild.getTop());
- invalidate();
- }
-
- @Override
- public boolean onEdgeLock(int edgeFlags) {
- if (ALLOW_EDGE_LOCK) {
- if (!isDrawerOpen()) {
- closeDrawer();
- }
- return true;
- }
- return false;
- }
-
- @Override
- public void onEdgeDragStarted(int edgeFlags, int pointerId) {
- View drawerView = findDrawerView();
- if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.RIGHT)) {
- drawerView = null;
- }
- } else {
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
- drawerView = null;
- }
- }
-
- if (drawerView != null && getDrawerLockMode(drawerView) == LOCK_MODE_UNLOCKED) {
- mDragger.captureChildView(drawerView, pointerId);
- }
- }
-
- @Override
- public int getViewHorizontalDragRange(View child) {
- return child.getWidth();
- }
-
- @Override
- public int clampViewPositionHorizontal(View child, int left, int dx) {
- final View drawerView = findDrawerView();
- LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
- if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
- return Math.max(drawerLp.getMarginStart() - drawerView.getWidth(),
- Math.min(left, drawerLp.getMarginStart()));
- } else {
- return Math.max(drawerLp.getMarginStart() + getWidth() - drawerView.getWidth(),
- Math.min(left, drawerLp.getMarginStart() + getWidth()));
- }
- }
-
- @Override
- public int clampViewPositionVertical(View child, int top, int dy) {
- return child.getTop();
- }
- }
-
- public static class LayoutParams extends MarginLayoutParams {
-
- public int gravity = Gravity.NO_GRAVITY;
- float onScreen;
- boolean knownOpen;
-
- public LayoutParams(Context c, AttributeSet attrs) {
- super(c, attrs);
-
- final TypedArray a = c.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
- gravity = a.getInt(0, Gravity.NO_GRAVITY);
- a.recycle();
- }
-
- public LayoutParams(int width, int height) {
- super(width, height);
- }
-
- public LayoutParams(int width, int height, int gravity) {
- this(width, height);
- this.gravity = gravity;
- }
-
- public LayoutParams(LayoutParams source) {
- super(source);
- gravity = source.gravity;
- }
-
- public LayoutParams(ViewGroup.LayoutParams source) {
- super(source);
- }
-
- public LayoutParams(MarginLayoutParams source) {
- super(source);
- }
- }
-
- private static final class ViewFaderHolder {
- public final ViewFader viewFader;
- public final int startingColor;
- public final int endingColor;
-
- public ViewFaderHolder(ViewFader viewFader, int startingColor, int endingColor) {
- this.viewFader = viewFader;
- this.startingColor = startingColor;
- this.endingColor = endingColor;
- }
-
- }
-}
diff --git a/car-ui-provider/src/android/car/ui/provider/CarRecyclerView.java b/car-ui-provider/src/android/car/ui/provider/CarRecyclerView.java
deleted file mode 100644
index 04fcd63..0000000
--- a/car-ui-provider/src/android/car/ui/provider/CarRecyclerView.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2015 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 android.car.ui.provider;
-
-import android.content.Context;
-import android.util.AttributeSet;
-
-/**
- * Clone of {@link android.support.car.ui.CarRecyclerView} to be used by CarUiProvider.
- * Workaround for b/25595320
- */
-public class CarRecyclerView extends android.support.car.ui.CarRecyclerView {
- public CarRecyclerView(Context context) {
- super(context);
- }
-
- public CarRecyclerView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public CarRecyclerView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-}
diff --git a/car-ui-provider/src/android/car/ui/provider/CarUiEntry.java b/car-ui-provider/src/android/car/ui/provider/CarUiEntry.java
deleted file mode 100644
index 3668e03..0000000
--- a/car-ui-provider/src/android/car/ui/provider/CarUiEntry.java
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- * Copyright (C) 2015 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 android.car.ui.provider;
-
-import android.car.app.menu.CarMenuCallbacks;
-import android.car.app.menu.RootMenu;
-import android.car.app.menu.SearchBoxEditListener;
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
-import android.graphics.drawable.BitmapDrawable;
-import android.os.Bundle;
-import android.support.car.input.CarRestrictedEditText;
-import android.support.car.ui.DrawerArrowDrawable;
-import android.support.car.ui.PagedListView;
-import android.support.v7.widget.CardView;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.util.Log;
-import android.view.Gravity;
-import android.view.KeyEvent;
-import android.widget.EditText;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-import android.view.View;
-import android.view.LayoutInflater;
-
-import android.support.car.ui.R;
-
-public class CarUiEntry extends android.car.app.menu.CarUiEntry {
- private static final String TAG = "Embedded_CarUiEntry";
-
- // These values and setSearchBoxMode exist rather than separate methods to make sure exactly the
- // same set of things get set for each mode, just to different values.
- /** The search box is not visible. */
- private static final int SEARCH_BOX_MODE_NONE = 0;
- /** The small search box is shown in the header beneath the microphone button. */
- private static final int SEARCH_BOX_MODE_SMALL = 1;
- /** The whole header between the menu button and the microphone button is taken up by the
- * search box. */
- private static final int SEARCH_BOX_MODE_LARGE = 2;
-
- private View mContentView;
- private ImageView mMenuButton;
- private TextView mTitleView;
- private CardView mTruncatedListCardView;
- private CarDrawerLayout mDrawerLayout;
- private DrawerController mDrawerController;
- private PagedListView mListView;
- private DrawerArrowDrawable mDrawerArrowDrawable;
- private CarRestrictedEditText mCarRestrictedEditText;
- private SearchBoxClickListener mSearchBoxClickListener;
-
- private View mSearchBox;
- private View mSearchBoxContents;
- private View mSearchBoxSearchLogoContainer;
- private ImageView mSearchBoxSearchLogo;
- private ImageView mSearchBoxSuperSearchLogo;
- private FrameLayout mSearchBoxEndView;
- private View mTitleContainer;
- private SearchBoxEditListener mSearchBoxEditListener;
-
- public interface SearchBoxClickListener {
- /**
- * The user clicked the search box while it was in small mode.
- */
- void onClick();
- }
-
- public CarUiEntry(Context providerContext, Context appContext) {
- super(providerContext, appContext);
- }
-
- @Override
- public View getContentView() {
- LayoutInflater inflater = LayoutInflater.from(mUiLibContext);
- mContentView = inflater.inflate(R.layout.car_activity, null);
- mDrawerLayout = (CarDrawerLayout) mContentView.findViewById(R.id.drawer_container);
- adjustDrawer();
- mMenuButton = (ImageView) mContentView.findViewById(R.id.car_drawer_button);
- mTitleView = (TextView) mContentView.findViewById(R.id.car_drawer_title);
- mTruncatedListCardView = (CardView) mContentView.findViewById(R.id.truncated_list_card);
- mDrawerArrowDrawable = new DrawerArrowDrawable(mUiLibContext);
- restoreMenuDrawable();
- mListView = (PagedListView) mContentView.findViewById(R.id.list_view);
- mListView.setOnScrollBarListener(mOnScrollBarListener);
- mMenuButton.setOnClickListener(mMenuListener);
- mDrawerController = new DrawerController(this, mMenuButton,
- mDrawerLayout, mListView, mTruncatedListCardView);
- mTitleContainer = mContentView.findViewById(R.id.car_drawer_title_container);
-
- mSearchBoxEndView = (FrameLayout) mContentView.findViewById(R.id.car_search_box_end_view);
- mSearchBox = mContentView.findViewById(R.id.car_search_box);
- mSearchBoxContents = mContentView.findViewById(R.id.car_search_box_contents);
- mSearchBoxSearchLogoContainer = mContentView.findViewById(
- R.id.car_search_box_search_logo_container);
- mSearchBoxSearchLogoContainer.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (mSearchBoxClickListener != null) {
- mSearchBoxClickListener.onClick();
- }
- }
- });
- mSearchBoxSearchLogo = (ImageView) mContentView.findViewById(
- R.id.car_search_box_search_logo);
- mSearchBoxSearchLogo.setImageDrawable(mUiLibContext.getResources()
- .getDrawable(R.drawable.ic_google));
- mSearchBoxSuperSearchLogo = (ImageView) mContentView.findViewById(
- R.id.car_search_box_super_logo);
- mSearchBoxSuperSearchLogo.setImageDrawable(mUiLibContext.getResources()
- .getDrawable(R.drawable.ic_googleg));
-
- mCarRestrictedEditText = (CarRestrictedEditText) mContentView.findViewById(
- R.id.car_search_box_edit_text);
- mCarRestrictedEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
- if (mSearchBoxEditListener != null) {
- mSearchBoxEditListener.onSearch(mCarRestrictedEditText.getText().toString());
- }
- return false;
- }
- });
- mCarRestrictedEditText.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence text, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence text, int start, int before, int count) {
- }
-
- @Override
- public void afterTextChanged(Editable text) {
- if (mSearchBoxEditListener != null) {
- mSearchBoxEditListener.onEdit(text.toString());
- }
- }
- });
- setSearchBoxMode(SEARCH_BOX_MODE_NONE);
- return mContentView;
- }
-
- private final View.OnClickListener mMenuListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- CarUiEntry.this.mDrawerController.openDrawer();
- }
- };
-
- @Override
- public void setCarMenuCallbacks(CarMenuCallbacks callbacks){
- RootMenu rootMenu = callbacks.getRootMenu(null);
- if (rootMenu != null) {
- mDrawerController.setRootAndCallbacks(
- rootMenu.getId(), callbacks);
- mDrawerController.setDrawerEnabled(true);
- } else {
- hideMenuButton();
- }
- }
-
- @Override
- public int getFragmentContainerId() {
- return R.id.container;
- }
-
- @Override
- public void setBackground(Bitmap bitmap) {
- BitmapDrawable bd = new BitmapDrawable(mUiLibContext.getResources(), bitmap);
- ImageView bg = (ImageView) mContentView.findViewById(R.id.background);
- bg.setBackground(bd);
- }
-
- @Override
- public void hideMenuButton() {
- mMenuButton.setVisibility(View.GONE);
- }
-
- @Override
- public void restoreMenuDrawable() {
- mMenuButton.setImageDrawable(mDrawerArrowDrawable);
- }
-
- public void setMenuButtonBitmap(Bitmap bitmap) {
- mMenuButton.setImageDrawable(new BitmapDrawable(mUiLibContext.getResources(), bitmap));
- }
-
- @Override
- public void setScrimColor(int color) {
- mDrawerLayout.setScrimColor(color);
- }
-
- @Override
- public void setTitle(CharSequence title) {
- mDrawerController.setTitle(title);
- }
-
- @Override
- public void closeDrawer() {
- mDrawerController.closeDrawer();
- }
-
- @Override
- public void openDrawer() {
- mDrawerController.openDrawer();
- }
-
- @Override
- public void showMenu(String id, String title) {
- mDrawerController.showMenu(id, title);
- }
-
-
- @Override
- public void setMenuButtonColor(int color) {
- setViewColor(mMenuButton, color);
- setViewColor(mTitleView, color);
- }
-
- @Override
- public void showTitle() {
- mTitleView.setVisibility(View.VISIBLE);
- }
-
- @Override
- public void hideTitle() {
- mTitleView.setVisibility(View.GONE);
- }
-
- @Override
- public void setLightMode() {
- mDrawerController.setLightMode();
- }
-
- @Override
- public void setDarkMode() {
- mDrawerController.setDarkMode();
- }
-
- @Override
- public void setAutoLightDarkMode() {
- mDrawerController.setAutoLightDarkMode();
- }
-
- @Override
- public void showToast(String msg, long duration) {
- // TODO: add toast support
- }
-
- @Override
- public CharSequence getSearchBoxText() {
- return mCarRestrictedEditText.getText();
- }
-
- @Override
- public EditText startInput(String hint,
- View.OnClickListener searchBoxClickListener) {
- mSearchBoxClickListener = wrapSearchBoxClickListener(searchBoxClickListener);
- setSearchBoxModeLarge(hint);
- return mCarRestrictedEditText;
- }
-
-
- @Override
- public void onRestoreInstanceState(Bundle savedInstanceState) {
- if (mDrawerController != null) {
- mDrawerController.restoreState(savedInstanceState);
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- if (mDrawerController != null) {
- mDrawerController.saveState(outState);
- }
- }
-
- @Override
- public void onStart() {
-
- }
-
- @Override
- public void onResume() {
-
- }
-
- @Override
- public void onPause() {
-
- }
-
- @Override
- public void onStop() {
-
- }
-
- /**
- * Sets the colors of all the parts of the search box (regardless of whether it is currently
- * showing).
- */
- @Override
- public void setSearchBoxColors(int backgroundColor, int searchLogoColor, int textColor,
- int hintTextColor) {
- // set background color of mSearchBox to get rid of the animation artifact in b/23767062
- mSearchBox.setBackgroundColor(backgroundColor);
- mSearchBoxContents.setBackgroundColor(backgroundColor);
- mSearchBoxSearchLogo.setColorFilter(searchLogoColor, PorterDuff.Mode.SRC_IN);
- mCarRestrictedEditText.setTextColor(textColor);
- mCarRestrictedEditText.setHintTextColor(hintTextColor);
- }
-
- /**
- * Sets the view to be displayed at the end of the search box, or null to clear any existing
- * views.
- */
- @Override
- public void setSearchBoxEndView(View endView) {
- if (endView == null) {
- mSearchBoxEndView.removeAllViews();
- } else if (mSearchBoxEndView.getChildCount() == 0) {
- mSearchBoxEndView.addView(endView);
- } else if (mSearchBoxEndView.getChildAt(0) != endView) {
- mSearchBoxEndView.removeViewAt(0);
- mSearchBoxEndView.addView(endView);
- }
- }
-
- @Override
- public void showSearchBox(final View.OnClickListener listener) {
- setSearchBoxMode(SEARCH_BOX_MODE_SMALL);
- mSearchBoxClickListener = wrapSearchBoxClickListener(listener);
- }
-
- @Override
- public void stopInput() {
- setSearchBoxMode(SEARCH_BOX_MODE_NONE);
- }
-
- @Override
- public void setSearchBoxEditListener(SearchBoxEditListener listener) {
- mSearchBoxEditListener = listener;
- }
-
-
- /**
- * Set the progress of the animated {@link DrawerArrowDrawable}.
- * @param progress 0f displays a menu button
- * 1f displays a back button
- * anything in between will be an interpolation of the drawable between
- * back and menu
- */
- public void setMenuProgress(float progress) {
- mDrawerArrowDrawable.setProgress(progress);
- }
-
- private void setSearchBoxModeLarge(String hint) {
- mCarRestrictedEditText.setHint(hint);
- setSearchBoxMode(SEARCH_BOX_MODE_LARGE);
- }
-
- public void setTitleText(CharSequence title) {
- mTitleView.setText(title);
- }
-
- /**
- * Sets all the view visibilities and layout params for a search box mode.
- */
- private void setSearchBoxMode(int searchBoxMode) {
- // Set the visibility and width of the search box, and whether the rest of the header sits
- // beside or beneath the microphone button.
- LinearLayout.LayoutParams searchBoxLayoutParams =
- (LinearLayout.LayoutParams) mSearchBox.getLayoutParams();
- if (searchBoxMode == SEARCH_BOX_MODE_LARGE) {
- int screenWidth = mAppContext.getResources().getDisplayMetrics().widthPixels;
- int searchBoxMargin = mUiLibContext.getResources()
- .getDimensionPixelSize(R.dimen.car_drawer_header_menu_button_size);
- int maxSearchBoxWidth = mUiLibContext.getResources().getDimensionPixelSize(
- R.dimen.car_card_max_width);
- int searchBoxMarginStart = 0;
- int searchBoxMarginEnd = searchBoxMargin;
- // If the width of search bar is larger than max card width, we adjust margin to fix it.
- if (screenWidth - searchBoxMargin * 2 > maxSearchBoxWidth) {
- searchBoxMarginEnd = (screenWidth - maxSearchBoxWidth) / 2;
- searchBoxMarginStart = searchBoxMarginEnd - searchBoxMargin;
- }
- searchBoxLayoutParams.width = 0;
- searchBoxLayoutParams.weight = 1.0f;
- searchBoxLayoutParams.setMarginStart(searchBoxMarginStart);
- searchBoxLayoutParams.setMarginEnd(searchBoxMarginEnd);
- } else if (searchBoxMode == SEARCH_BOX_MODE_SMALL) {
- searchBoxLayoutParams.width = mUiLibContext.getResources().getDimensionPixelSize(
- R.dimen.car_app_layout_search_box_small_width);
- searchBoxLayoutParams.weight = 0.0f;
- searchBoxLayoutParams.setMarginStart(mUiLibContext.getResources()
- .getDimensionPixelOffset(R.dimen.car_app_layout_search_box_small_margin));
- searchBoxLayoutParams.setMarginEnd(mUiLibContext.getResources().getDimensionPixelOffset(
- R.dimen.car_app_layout_search_box_small_margin));
- } else {
- searchBoxLayoutParams.width = mUiLibContext.getResources().getDimensionPixelSize(
- R.dimen.car_app_layout_search_box_small_width);
- searchBoxLayoutParams.weight = 0.0f;
- searchBoxLayoutParams.setMarginStart(mUiLibContext.getResources().getDimensionPixelSize(
- R.dimen.car_drawer_header_menu_button_size));
- searchBoxLayoutParams.setMarginEnd(-searchBoxLayoutParams.width);
- }
- mSearchBox.setLayoutParams(searchBoxLayoutParams);
-
- // Animate the visibility of the contents of the search box - either the Search logo or the
- // edit text is visible (the super logo also is visible when the edit text is visible).
- View searchBoxEditTextContainer = (View) mCarRestrictedEditText.getParent();
- if (searchBoxMode == SEARCH_BOX_MODE_SMALL) {
- if (mSearchBoxSearchLogoContainer.getVisibility() != View.VISIBLE) {
- mSearchBoxSearchLogoContainer.setAlpha(0f);
- mSearchBoxSearchLogoContainer.setVisibility(View.VISIBLE);
- }
- // 300ms delay to stagger the fade in behind the fade out animation.
- mSearchBoxSearchLogoContainer.animate().alpha(1f).setStartDelay(300);
- // Animate the container so it includes the super G logo.
- if (searchBoxEditTextContainer.getVisibility() == View.VISIBLE) {
- searchBoxEditTextContainer.animate().alpha(0f).setStartDelay(0)
- .withEndAction(mSetEditTextGoneRunnable);
- }
- } else if (searchBoxMode == SEARCH_BOX_MODE_LARGE) {
- if (searchBoxEditTextContainer.getVisibility() != View.VISIBLE) {
- searchBoxEditTextContainer.setAlpha(0f);
- searchBoxEditTextContainer.setVisibility(View.VISIBLE);
- }
- searchBoxEditTextContainer.animate().alpha(1f).setStartDelay(300);
- if (mSearchBoxSearchLogoContainer.getVisibility() == View.VISIBLE) {
- mSearchBoxSearchLogoContainer.animate().alpha(0f).setStartDelay(0)
- .withEndAction(mSetSearchBoxLogoGoneRunnable);
- }
- } else {
- searchBoxEditTextContainer.setVisibility(View.GONE);
- }
-
- // Set the visibility of the title and status containers.
- if (searchBoxMode == SEARCH_BOX_MODE_LARGE) {
- mTitleContainer.setVisibility(View.GONE);
- } else {
- mTitleContainer.setVisibility(View.VISIBLE);
- }
- }
-
-
- private final Runnable mSetEditTextGoneRunnable = new Runnable() {
- @Override
- public void run() {
- ((View) mCarRestrictedEditText.getParent()).setVisibility(View.GONE);
- }
- };
-
- private final Runnable mSetSearchBoxLogoGoneRunnable = new Runnable() {
- @Override
- public void run() {
- mSearchBoxSearchLogoContainer.setVisibility(View.GONE);
- }
- };
-
-
- private SearchBoxClickListener wrapSearchBoxClickListener(final View.OnClickListener listener) {
- return new SearchBoxClickListener() {
- @Override
- public void onClick() {
- listener.onClick(null);
- }
- };
- }
-
-
- private static void setViewColor(View view, int color) {
- if (view instanceof TextView) {
- ((TextView) view).setTextColor(color);
- } else if (view instanceof ImageView) {
- ImageView imageView = (ImageView) view;
- PorterDuffColorFilter filter =
- new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
- imageView.setColorFilter(filter);
- } else {
- if (Log.isLoggable(TAG, Log.WARN)) {
- Log.w(TAG, "Setting color is only supported for TextView and ImageView.");
- }
- }
- }
-
- private void adjustDrawer() {
- Resources resources = mUiLibContext.getResources();
- float width = resources.getDisplayMetrics().widthPixels;
- CarDrawerLayout.LayoutParams layoutParams = new CarDrawerLayout.LayoutParams(
- CarDrawerLayout.LayoutParams.MATCH_PARENT,
- CarDrawerLayout.LayoutParams.MATCH_PARENT);
- layoutParams.gravity = Gravity.LEFT;
- // 1. If the screen width is larger than 800dp, the drawer width is kept as 704dp;
- // 2. Else the drawer width is adjusted to keep the margin end of drawer as 96dp.
-
-// if (width > resources.getDimension(R.dimen.car_standard_width)) {
-// layoutParams.setMarginEnd(
-// (int) (width - resources.getDimension(R.dimen.car_drawer_standard_width)));
-// } else {
-// layoutParams.setMarginEnd(
-// (int) resources.getDimension(R.dimen.car_card_margin));
-// }
- // TODO: For UX, need to update max drawer width for the large screen use case. The previous
- // 704dp width no longer works.
- layoutParams.setMarginEnd((int) resources.getDimension(R.dimen.car_card_margin));
- mContentView.findViewById(R.id.drawer).setLayoutParams(layoutParams);
- }
-
- private final PagedListView.OnScrollBarListener mOnScrollBarListener =
- new PagedListView.OnScrollBarListener() {
-
- @Override
- public void onReachBottom() {
- if (mDrawerController.isTruncatedList()) {
- mTruncatedListCardView.setVisibility(View.VISIBLE);
- }
- }
-
- @Override
- public void onLeaveBottom() {
- mTruncatedListCardView.setVisibility(View.GONE);
- }
- };
-}
diff --git a/car-ui-provider/src/android/car/ui/provider/DrawerApiAdapter.java b/car-ui-provider/src/android/car/ui/provider/DrawerApiAdapter.java
deleted file mode 100644
index 894938b..0000000
--- a/car-ui-provider/src/android/car/ui/provider/DrawerApiAdapter.java
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
- * Copyright (C) 2015 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 android.car.ui.provider;
-
-import android.content.Context;
-import android.content.res.ColorStateList;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.SystemProperties;
-import android.support.car.ui.CarListItemViewHolder;
-import android.support.car.ui.PagedListView;
-import android.support.car.ui.R;
-import android.support.v7.widget.RecyclerView;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.CompoundButton;
-import android.widget.ImageView;
-import android.widget.RemoteViews;
-import android.widget.TextView;
-
-import android.support.car.app.menu.CarMenu;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.FLAG_BROWSABLE;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.FLAG_FIRSTITEM;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_EMPTY_PLACEHOLDER;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_FLAGS;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_ID;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_LEFTICON;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_REMOTEVIEWS;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_RIGHTICON;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_RIGHTTEXT;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_TEXT;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_TITLE;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_WIDGET;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_WIDGET_STATE;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.WIDGET_CHECKBOX;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.WIDGET_TEXT_VIEW;
-
-public class DrawerApiAdapter extends RecyclerView.Adapter<CarListItemViewHolder>
- implements PagedListView.ItemCap {
- private static final String TAG = "CAR.UI.ADAPTER";
- private static final String INDEX_OUT_OF_BOUNDS_MESSAGE = "invalid item position";
- private static final String KEY_ID_UNAVAILABLE_CATEGORY = "UNAVAILABLE_CATEGORY";
- private static final String UNLIMITED_MODE_PROPERTY = "android.car.drawer.unlimited";
-
- public interface OnItemSelectedListener {
- void onItemClicked(Bundle item, int position);
- boolean onItemLongClicked(Bundle item);
- }
-
- private final Map<String, Integer> mIdToPosMap = new HashMap<>();
-
- private final Object mItemsLock = new Object();
- private List<Bundle> mItems;
- private boolean mIsCapped;
- private OnItemSelectedListener mListener;
- private int mMaxItems;
- private boolean mUseSmallHolder;
- private boolean mNoLeftIcon;
- private boolean mIsEmptyPlaceholder;
- private int mFirstItemIndex = 0;
-
- private final Handler mHandler = new Handler();
-
- public DrawerApiAdapter() {
- setHasStableIds(true);
- }
-
- @Override
- public int getItemViewType(int position) {
- Bundle item;
- try {
- item = mItems.get(position);
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, INDEX_OUT_OF_BOUNDS_MESSAGE, e);
- return 0;
- }
-
- if (KEY_ID_UNAVAILABLE_CATEGORY.equals(item.getString(KEY_ID))) {
- return R.layout.car_unavailable_category;
- }
-
- if (item.containsKey(KEY_EMPTY_PLACEHOLDER) && item.getBoolean(KEY_EMPTY_PLACEHOLDER)) {
- return R.layout.car_list_item_empty;
- }
-
- int flags = item.getInt(KEY_FLAGS);
- if ((flags & FLAG_BROWSABLE) != 0 || item.containsKey(KEY_RIGHTICON)) {
- return R.layout.car_imageview;
- }
-
- if (!item.containsKey(KEY_WIDGET)) {
- return 0;
- }
-
- switch (item.getInt(KEY_WIDGET)) {
- case WIDGET_CHECKBOX:
- return R.layout.car_menu_checkbox;
- case WIDGET_TEXT_VIEW:
- return R.layout.car_textview;
- default:
- return 0;
- }
- }
-
- @Override
- public CarListItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- LayoutInflater inflater = LayoutInflater.from(parent.getContext());
- View view;
- if (viewType == R.layout.car_unavailable_category ||
- viewType == R.layout.car_list_item_empty) {
- view = inflater.inflate(viewType, parent, false);
- } else {
- view = inflater.inflate(R.layout.car_menu_list_item, parent, false);
- }
- return new CarListItemViewHolder(view, viewType);
- }
-
- @Override
- public void setMaxItems(int maxItems) {
- if (SystemProperties.getBoolean(UNLIMITED_MODE_PROPERTY, false)) {
- mMaxItems = PagedListView.ItemCap.UNLIMITED;
- } else {
- mMaxItems = maxItems;
- }
- }
-
- @Override
- public void onBindViewHolder(final CarListItemViewHolder holder, final int position) {
- if (holder.getItemViewType() == R.layout.car_list_item_empty) {
- onBindEmptyPlaceHolder(holder, position);
- } else if (holder.getItemViewType() == R.layout.car_unavailable_category) {
- onBindUnavailableCategoryView(holder);
- } else {
- onBindNormalView(holder, position);
- if (mIsCapped) {
- // Disable all menu items if it is under unavailable category case.
- // TODO(b/24163545): holder.itemView.setAlpha() doesn't work all the time,
- // which makes some items are gray out, the others are not.
- setHolderStatus(holder, false, 0.3f);
- } else {
- setHolderStatus(holder, true, 1.0f);
- }
- }
-
- holder.itemView.setTag(position);
- holder.itemView.setOnClickListener(mOnClickListener);
- holder.itemView.setOnLongClickListener(mOnLongClickListener);
-
- // Ensure correct day/night mode colors are set and not out of sync.
- setDayNightModeColors(holder);
- }
-
- @Override
- public int getItemCount() {
- synchronized (mItemsLock) {
- if (mItems != null) {
- return mMaxItems != PagedListView.ItemCap.UNLIMITED ?
- Math.min(mItems.size(), mMaxItems) : mItems.size();
- }
- }
- return 0;
- }
-
- @Override
- public long getItemId(int position) {
- synchronized (mItemsLock) {
- if (mItems != null) {
- try {
- return mItems.get(position).getString(KEY_ID).hashCode();
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, "invalid item index", e);
- return RecyclerView.NO_ID;
- }
- }
- }
- return super.getItemId(position);
- }
-
- public synchronized void setItems(List<Bundle> items, boolean isCapped) {
- synchronized (mItemsLock) {
- mItems = items;
- }
- mIsCapped = isCapped;
- mFirstItemIndex = 0;
- if (mItems != null) {
- mIdToPosMap.clear();
- mUseSmallHolder = true;
- mNoLeftIcon = true;
- mIsEmptyPlaceholder = false;
- int index = 0;
- for (Bundle bundle : items) {
- if (bundle.containsKey(KEY_EMPTY_PLACEHOLDER)
- && bundle.getBoolean(KEY_EMPTY_PLACEHOLDER)) {
- mIsEmptyPlaceholder = true;
- if (items.size() != 1) {
- throw new IllegalStateException("Empty placeholder should be the only"
- + "item showing in the menu list!");
- }
- }
-
- if (bundle.containsKey(KEY_TEXT) || bundle.containsKey(KEY_REMOTEVIEWS)) {
- mUseSmallHolder = false;
- }
- if (bundle.containsKey(KEY_LEFTICON)) {
- mNoLeftIcon = false;
- }
- if (bundle.containsKey(KEY_FLAGS) &&
- (bundle.getInt(KEY_FLAGS) & FLAG_FIRSTITEM) != 0) {
- mFirstItemIndex = index;
- }
- mIdToPosMap.put(bundle.getString(KEY_ID), index);
- index++;
- }
- }
- notifyDataSetChanged();
- }
-
- public int getMaxItemsNumber() {
- return mMaxItems;
- }
-
- public void setItemSelectedListener(OnItemSelectedListener listener) {
- mListener = listener;
- }
-
- public int getFirstItemIndex() {
- return mFirstItemIndex;
- }
-
- public boolean isEmptyPlaceholder() {
- return mIsEmptyPlaceholder;
- }
-
- public void onChildChanged(RecyclerView.ViewHolder holder, Bundle bundle) {
- synchronized (mItemsLock) {
- // The holder will be null if the view has not been bound yet
- if (holder != null) {
- int position = holder.getAdapterPosition();
- if (position >= 0 && mItems != null && position < mItems.size()) {
- final Bundle oldBundle;
- try {
- oldBundle = mItems.get(position);
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, INDEX_OUT_OF_BOUNDS_MESSAGE, e);
- return;
- }
- oldBundle.putAll(bundle);
- notifyItemChanged(position);
- }
- } else {
- String id = bundle.getString(KEY_ID);
- int position = mIdToPosMap.get(id);
- if (position >= 0 && mItems != null && position < mItems.size()) {
- final Bundle item;
- try {
- item = mItems.get(position);
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, INDEX_OUT_OF_BOUNDS_MESSAGE, e);
- return;
- }
- if (id.equals(item.getString(KEY_ID))) {
- item.putAll(bundle);
- notifyItemChanged(position);
- }
- }
- }
- }
- }
-
- public void setDayNightModeColors(RecyclerView.ViewHolder viewHolder) {
- CarListItemViewHolder holder = (CarListItemViewHolder) viewHolder;
- Context context = holder.itemView.getContext();
- holder.itemView.setBackgroundResource(R.drawable.car_list_item_background);
- if (holder.getItemViewType() == R.layout.car_unavailable_category) {
- holder.title.setTextAppearance(context, R.style.CarUnavailableCategory);
- if (holder.text != null) {
- holder.text.setTextAppearance(context, R.style.CarUnavailableCategory);
- }
- holder.icon.setImageTintList(ColorStateList
- .valueOf(context.getResources().getColor(R.color.car_unavailable_category)));
- } else {
- holder.title.setTextAppearance(context, R.style.CarBody1);
- if (holder.text != null) {
- holder.text.setTextAppearance(context, R.style.CarBody2);
- }
- if (holder.rightCheckbox != null) {
- holder.rightCheckbox.setButtonTintList(
- ColorStateList.valueOf(context.getResources().getColor(R.color.car_tint)));
- } else if (holder.rightImage != null) {
- Object tag = holder.rightImage.getTag();
- if (tag != null && (int) tag != -1) {
- holder.rightImage.setImageResource((int) tag);
- }
- }
- }
- }
-
- private void onBindEmptyPlaceHolder(final CarListItemViewHolder holder, final int position) {
- maybeSetText(position, KEY_TITLE, holder.title);
- if (!mNoLeftIcon) {
- maybeSetBitmap(position, KEY_LEFTICON, holder.icon);
- holder.iconContainer.setVisibility(View.VISIBLE);
- } else {
- holder.iconContainer.setVisibility(View.GONE);
- }
- }
-
- private void onBindUnavailableCategoryView(final CarListItemViewHolder holder) {
- mNoLeftIcon = false;
- holder.itemView.setEnabled(false);
- }
-
- private void onBindNormalView(final CarListItemViewHolder holder, final int position) {
- maybeSetText(position, KEY_TITLE, holder.title);
- maybeSetText(position, KEY_TEXT, holder.text);
- final Bundle item;
- try {
- item = new Bundle(mItems.get(position));
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, INDEX_OUT_OF_BOUNDS_MESSAGE, e);
- return;
- }
- final int flags = item.getInt(KEY_FLAGS);
- if ((flags & FLAG_BROWSABLE) != 0) {
- // Set the resource id as the tag so we can reload it on day/night mode change.
- // If the tag is -1 or not set, then assume the app will send an updated bitmap
- holder.rightImage.setTag(R.drawable.ic_chevron_right);
- holder.rightImage.setImageResource(R.drawable.ic_chevron_right);
- } else if (holder.rightImage != null) {
- maybeSetBitmap(position, KEY_RIGHTICON, holder.rightImage);
- }
-
- if (holder.rightCheckbox != null) {
- holder.rightCheckbox.setChecked(item.getBoolean(
- KEY_WIDGET_STATE, false));
- holder.rightCheckbox.setOnClickListener(mOnClickListener);
- holder.rightCheckbox.setTag(position);
- }
- if (holder.rightText != null) {
- maybeSetText(position, KEY_RIGHTTEXT, holder.rightText);
- }
- if (!mNoLeftIcon) {
- maybeSetBitmap(position, KEY_LEFTICON, holder.icon);
- holder.iconContainer.setVisibility(View.VISIBLE);
- } else {
- holder.iconContainer.setVisibility(View.GONE);
- }
- if (item.containsKey(KEY_REMOTEVIEWS)) {
- holder.remoteViewsContainer.setVisibility(View.VISIBLE);
- RemoteViews views = item.getParcelable(KEY_REMOTEVIEWS);
- View view = views.apply(holder.remoteViewsContainer.getContext(),
- holder.remoteViewsContainer);
- holder.remoteViewsContainer.removeAllViews();
- holder.remoteViewsContainer.addView(view);
- } else {
- holder.remoteViewsContainer.removeAllViews();
- holder.remoteViewsContainer.setVisibility(View.GONE);
- }
-
- // Set the view holder size
- Resources r = holder.itemView.getResources();
- ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
- params.height = mUseSmallHolder ?
- r.getDimensionPixelSize(R.dimen.car_list_item_height_small) :
- r.getDimensionPixelSize(R.dimen.car_list_item_height);
- holder.itemView.setLayoutParams(params);
-
- // Set Icon size
- params = holder.iconContainer.getLayoutParams();
- params.height = params.width = mUseSmallHolder ?
- r.getDimensionPixelSize(R.dimen.car_list_item_small_icon_size) :
- r.getDimensionPixelSize(R.dimen.car_list_item_icon_size);
-
- }
-
- private void maybeSetText(int position, String key, TextView view) {
- Bundle item;
- try {
- item = mItems.get(position);
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, INDEX_OUT_OF_BOUNDS_MESSAGE, e);
- return;
- }
- if (item.containsKey(key)) {
- view.setText(item.getString(key));
- view.setVisibility(View.VISIBLE);
- } else {
- view.setVisibility(View.GONE);
- }
- }
-
- private void maybeSetBitmap(int position, String key, ImageView view) {
- Bundle item;
- try {
- item = mItems.get(position);
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, INDEX_OUT_OF_BOUNDS_MESSAGE, e);
- return;
- }
- if (item.containsKey(key)) {
- view.setImageBitmap((Bitmap) item.getParcelable(key));
- view.setVisibility(View.VISIBLE);
- view.setTag(-1);
- } else {
- view.setVisibility(View.GONE);
- }
- }
-
- private void setHolderStatus(final CarListItemViewHolder holder,
- boolean isEnabled, float alpha) {
- holder.itemView.setEnabled(isEnabled);
- if (holder.icon != null) {
- holder.icon.setAlpha(alpha);
- }
- if (holder.title != null) {
- holder.title.setAlpha(alpha);
- }
- if (holder.text != null) {
- holder.text.setAlpha(alpha);
- }
- if (holder.rightCheckbox != null) {
- holder.rightCheckbox.setAlpha(alpha);
- }
- if (holder.rightImage != null) {
- holder.rightImage.setAlpha(alpha);
- }
- if (holder.rightText != null) {
- holder.rightText.setAlpha(alpha);
- }
- }
-
- private final View.OnClickListener mOnClickListener = new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- final Bundle item;
- int position = (int) view.getTag();
- try {
- item = mItems.get(position);
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, INDEX_OUT_OF_BOUNDS_MESSAGE, e);
- return;
- }
- View right = view.findViewById(R.id.right_item);
- if (right != null && view != right && right instanceof CompoundButton) {
- ((CompoundButton) right).toggle();
- }
- if (mListener != null) {
- mListener.onItemClicked(item, position);
- }
- }
- };
-
- private final View.OnLongClickListener mOnLongClickListener = new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View view) {
- final Bundle item;
- try {
- item = mItems.get((int) view.getTag());
- } catch (IndexOutOfBoundsException e) {
- Log.w(TAG, INDEX_OUT_OF_BOUNDS_MESSAGE, e);
- return true;
- }
- final String id = item.getString(KEY_ID);
- if (mListener != null) {
- return mListener.onItemLongClicked(item);
- }
- return false;
- }
- };
-}
diff --git a/car-ui-provider/src/android/car/ui/provider/DrawerController.java b/car-ui-provider/src/android/car/ui/provider/DrawerController.java
deleted file mode 100644
index 241224a..0000000
--- a/car-ui-provider/src/android/car/ui/provider/DrawerController.java
+++ /dev/null
@@ -1,664 +0,0 @@
-/*
- * Copyright (C) 2015 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 android.car.ui.provider;
-
-import android.car.app.menu.CarMenuCallbacks;
-import android.content.Context;
-import android.graphics.Canvas;
-import android.os.Bundle;
-import android.support.car.ui.PagedListView;
-import android.support.car.ui.R;
-import android.support.v7.widget.CardView;
-import android.support.v7.widget.RecyclerView;
-import android.text.TextUtils;
-import android.util.Log;
-import android.view.View;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.widget.ProgressBar;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.Stack;
-
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.FLAG_BROWSABLE;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_FLAGS;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_ID;
-import static android.car.app.menu.CarMenuConstants.MenuItemConstants.KEY_TITLE;
-
-/**
- * Controls the drawer for SDK app
- */
-public class DrawerController
- implements CarDrawerLayout.DrawerListener, DrawerApiAdapter.OnItemSelectedListener,
- CarDrawerLayout.DrawerControllerListener {
- private static final String TAG = "CAR.UI.DrawerController";
- // Qualify with full package name to make it less likely there will be a collision
- private static final String KEY_IDS = "android.support.car.ui.drawer.sdk.IDS";
- private static final String KEY_DRAWERSTATE =
- "android.support.car.ui.drawer.sdk.DRAWER_STATE";
- private static final String KEY_TITLES = "android.support.car.ui.drawer.sdk.TITLES";
- private static final String KEY_ROOT = "android.support.car.ui.drawer.sdk.ROOT";
- private static final String KEY_ID_UNAVAILABLE_CATEGORY = "UNAVAILABLE_CATEGORY";
- private static final String KEY_CLICK_STACK =
- "android.support.car.ui.drawer.sdk.CLICK_STACK";
- private static final String KEY_MAX_PAGES =
- "android.support.car.ui.drawer.sdk.MAX_PAGES";
- private static final String KEY_IS_CAPPED =
- "android.support.car.ui.drawer.sdk.IS_CAPPED";
-
- /** Drawer is in Auto dark/light mode */
- private static final int MODE_AUTO = 0;
- /** Drawer is in Light mode */
- private static final int MODE_LIGHT = 1;
- /** Drawer is in Dark mode */
- private static final int MODE_DARK = 2;
-
- private final Stack<String> mSubscriptionIds = new Stack<>();
- private final Stack<CharSequence> mTitles = new Stack<>();
- private final SubscriptionCallbacks mSubscriptionCallbacks = new SubscriptionCallbacks();
- // Named to be consistent with CarDrawerFragment to make copying code easier and less error
- // prone
- private final CarDrawerLayout mContainer;
- private final PagedListView mListView;
-// private final CardView mTruncatedListCardView;
- private final ProgressBar mProgressBar;
- private final Context mContext;
- private final ViewAnimationController mPlvAnimationController;
- private final CardView mTruncatedListCardView;
- private final Stack<Integer> mClickCountStack = new Stack<>();
-
- private CarMenuCallbacks mCarMenuCallbacks;
- private DrawerApiAdapter mAdapter;
- private int mScrimColor = CarDrawerLayout.DEFAULT_SCRIM_COLOR;
- private boolean mIsDrawerOpen;
- private boolean mIsDrawerAnimating;
- private boolean mIsCapped;
- private int mItemsNumber;
- private int mDrawerMode;
- private CharSequence mContentTitle;
- private String mRootId;
- private boolean mRestartedFromDayNightMode;
- private CarUiEntry mUiEntry;
-
- public DrawerController(CarUiEntry uiEntry, View menuButton, CarDrawerLayout drawerLayout,
- PagedListView listView, CardView cardView) {
- //mCarAppLayout = appLayout;
- menuButton.setOnClickListener(mMenuClickListener);
- mContainer = drawerLayout;
- mListView = listView;
- mUiEntry = uiEntry;
- mTruncatedListCardView = cardView;
- mListView.setDefaultItemDecoration(new DrawerMenuListDecoration(mListView.getContext()));
- mProgressBar = (ProgressBar) mContainer.findViewById(R.id.progress);
- mContext = mListView.getContext();
- mPlvAnimationController = new ViewAnimationController(
- mListView, R.anim.car_list_in, R.anim.sdk_list_out, R.anim.car_list_pop_out);
- mRootId = null;
-
- mContainer.setDrawerListener(this);
- mContainer.setDrawerControllerListener(this);
- setAutoLightDarkMode();
- }
-
-
- @Override
- public void onDrawerOpened(View drawerView) {
- mIsDrawerOpen = true;
- mIsDrawerAnimating = false;
- mUiEntry.setMenuProgress(1.0f);
- // This can be null on day/night mode changes
- if (mCarMenuCallbacks != null) {
- mCarMenuCallbacks.onCarMenuOpened();
- }
- }
-
- @Override
- public void onDrawerClosed(View drawerView) {
- mIsDrawerOpen = false;
- mIsDrawerAnimating = false;
- clearMenu();
- mUiEntry.setMenuProgress(0);
- mUiEntry.setTitle(mContentTitle);
- // This can be null on day/night mode changes
- if (mCarMenuCallbacks != null) {
- mCarMenuCallbacks.onCarMenuClosed();
- }
- }
-
- @Override
- public void onDrawerStateChanged(int newState) {
- }
-
- @Override
- public void onDrawerOpening(View drawerView) {
- mIsDrawerAnimating = true;
- // This can be null on day/night mode changes
- if (mCarMenuCallbacks != null) {
- mCarMenuCallbacks.onCarMenuOpening();
- }
- }
-
- @Override
- public void onDrawerSlide(View drawerView, float slideOffset) {
- mUiEntry.setMenuProgress(slideOffset);
- }
-
- @Override
- public void onDrawerClosing(View drawerView) {
- mIsDrawerAnimating = true;
- // This can be null on day/night mode changes
- if (mCarMenuCallbacks != null) {
- mCarMenuCallbacks.onCarMenuClosing();
- }
- }
-
- @Override
- public void onItemClicked(Bundle item, int position) {
- // Don't allow selection while animating
- if (mPlvAnimationController.isAnimating()) {
- return;
- }
- int flags = item.getInt(KEY_FLAGS);
- String id = item.getString(KEY_ID);
-
- // Page number is 0 index, + 1 for the actual click.
- int clicksUsed = mListView.getPage(position) + 1;
- mClickCountStack.push(clicksUsed);
- mListView.setMaxPages(mListView.getMaxPages() - clicksUsed);
- mCarMenuCallbacks.onItemClicked(id);
- if ((flags & FLAG_BROWSABLE) != 0) {
- if (mListView.getMaxPages() == 0) {
- mIsCapped = true;
- }
- CharSequence title = item.getString(KEY_TITLE);
- if (TextUtils.isEmpty(title)) {
- title = mContentTitle;
- }
- mUiEntry.setTitleText(title);
- mTitles.push(title);
- if (!mSubscriptionIds.isEmpty()) {
- mPlvAnimationController.enqueueExitAnimation(mClearAdapterRunnable);
- }
- mProgressBar.setVisibility(View.VISIBLE);
- if (!mSubscriptionIds.isEmpty()) {
- mCarMenuCallbacks.unsubscribe(mSubscriptionIds.peek(), mSubscriptionCallbacks);
- }
- mSubscriptionIds.push(id);
- subscribe(id);
- } else {
- closeDrawer();
- }
- }
-
- @Override
- public boolean onItemLongClicked(Bundle item) {
- return mCarMenuCallbacks.onItemLongClicked(item.getString(KEY_ID));
- }
-
- @Override
- public void onBack() {
- backOrClose();
- }
-
- @Override
- public boolean onScroll() {
- // Consume scroll event if we are animating.
- return mPlvAnimationController.isAnimating();
- }
-
- public void setTitle(CharSequence title) {
- Log.d(TAG, "setTitle in drawer" + title);
- if (!TextUtils.isEmpty(title)) {
- mContentTitle = title;
- mUiEntry.showTitle();
- mUiEntry.setTitleText(title);
- } else {
- mUiEntry.hideTitle();
- }
- }
-
- public void setRootAndCallbacks(String rootId, CarMenuCallbacks callbacks) {
- mAdapter = new DrawerApiAdapter();
- mAdapter.setItemSelectedListener(this);
- mListView.setAdapter(mAdapter);
- mCarMenuCallbacks = callbacks;
- // HACK: Due to the handler, setRootId will be called after onRestoreState.
- // If onRestoreState has been called, the root id will already be set. So nothing to do.
- if (mSubscriptionIds.isEmpty()) {
- setRootId(rootId);
- } else {
- subscribe(mSubscriptionIds.peek());
- openDrawer();
- }
- }
-
- public void saveState(Bundle out) {
- out.putStringArray(KEY_IDS, mSubscriptionIds.toArray(new String[mSubscriptionIds.size()]));
- out.putStringArray(KEY_TITLES, mTitles.toArray(new String[mTitles.size()]));
- out.putString(KEY_ROOT, mRootId);
- out.putBoolean(KEY_DRAWERSTATE, mIsDrawerOpen);
- out.putIntegerArrayList(KEY_CLICK_STACK, new ArrayList<Integer>(mClickCountStack));
- out.putBoolean(KEY_IS_CAPPED, mIsCapped);
- out.putInt(KEY_MAX_PAGES, mListView.getMaxPages());
- }
-
- public void restoreState(Bundle in) {
- if (in != null) {
- // Restore subscribed CarMenu ids
- String[] ids = in.getStringArray(KEY_IDS);
- mSubscriptionIds.clear();
- if (ids != null) {
- mSubscriptionIds.addAll(Arrays.asList(ids));
- }
- // Restore drawer titles if there are any
- String[] titles = in.getStringArray(KEY_TITLES);
- mTitles.clear();
- if (titles != null) {
- mTitles.addAll(Arrays.asList(titles));
- }
- if (!mTitles.isEmpty()) {
- mUiEntry.setTitleText(mTitles.peek());
- }
- mRootId = in.getString(KEY_ROOT);
- mIsDrawerOpen = in.getBoolean(KEY_DRAWERSTATE);
- ArrayList<Integer> clickCount = in.getIntegerArrayList(KEY_CLICK_STACK);
- mClickCountStack.clear();
- if (clickCount != null) {
- mClickCountStack.addAll(clickCount);
- }
- mIsCapped = in.getBoolean(KEY_IS_CAPPED);
- mListView.setMaxPages(in.getInt(KEY_MAX_PAGES));
- if (!mRestartedFromDayNightMode && mIsDrawerOpen) {
- closeDrawer();
- }
- }
- }
-
- public void setScrimColor(int color) {
- mScrimColor = color;
- mContainer.setScrimColor(color);
- updateViewFaders();
- }
-
- public void setAutoLightDarkMode() {
- mDrawerMode = MODE_AUTO;
- mContainer.setAutoDayNightMode();
- updateViewFaders();
- }
-
- public void setLightMode() {
- mDrawerMode = MODE_LIGHT;
- mContainer.setLightMode();
- updateViewFaders();
- }
-
- public void setDarkMode() {
- mDrawerMode = MODE_DARK;
- mContainer.setDarkMode();
- updateViewFaders();
- }
-
- public void openDrawer() {
- // If we have no root, then we can't open the drawer.
- if (mRootId == null) {
- return;
- }
- mContainer.openDrawer();
- }
-
- public void closeDrawer() {
- if (mRootId == null) {
- return;
- }
- mTruncatedListCardView.setVisibility(View.GONE);
- mPlvAnimationController.stopAndClearAnimations();
- mContainer.closeDrawer();
- mUiEntry.setTitle(mContentTitle);
- }
-
- public void setDrawerEnabled(boolean enabled) {
- if (enabled) {
- mContainer.setDrawerLockMode(CarDrawerLayout.LOCK_MODE_UNLOCKED);
- } else {
- mContainer.setDrawerLockMode(CarDrawerLayout.LOCK_MODE_LOCKED_CLOSED);
- }
- }
-
- public void showMenu(String id, String title) {
- // The app wants to show the menu associated with the given id. Create a fake item using the
- // given inputs and then pretend as if the user clicked on the item, so that the drawer
- // will subscribe to that menu id, set the title appropriately, and properly handle the
- // subscription stack.
- Bundle bundle = new Bundle();
- bundle.putString(KEY_ID, id);
- bundle.putString(KEY_TITLE, title);
- bundle.putInt(KEY_FLAGS, FLAG_BROWSABLE);
- onItemClicked(bundle, 0 /* position */);
- }
-
- public void setRootId(String rootId) {
- mRootId = rootId;
- }
-
- public void setRestartedFromDayNightMode(boolean restarted) {
- mRestartedFromDayNightMode = restarted;
- }
-
- public boolean isTruncatedList() {
- int maxItems = mAdapter.getMaxItemsNumber();
- return maxItems != PagedListView.ItemCap.UNLIMITED && mItemsNumber > maxItems;
- }
-
- private void clearMenu() {
- if (!mSubscriptionIds.isEmpty()) {
- mCarMenuCallbacks.unsubscribe(mSubscriptionIds.peek(), mSubscriptionCallbacks);
- mSubscriptionIds.clear();
- mTitles.clear();
- }
- mListView.setVisibility(View.GONE);
- mListView.resetMaxPages();
- mClickCountStack.clear();
- mIsCapped = false;
- }
-
- /**
- * Check if the drawer is inside of a CarAppLayout and add the relevant views if it is,
- * automagically add view faders for the correct views
- */
- private void updateViewFaders() {
- mContainer.removeViewFader(mStatusViewViewFader);
- mContainer.addViewFader(mStatusViewViewFader);
- }
-
- private void subscribe(String id) {
- mProgressBar.setVisibility(View.VISIBLE);
- mCarMenuCallbacks.subscribe(id, mSubscriptionCallbacks);
- }
-
- private final CarDrawerLayout.ViewFader mStatusViewViewFader = new CarDrawerLayout.ViewFader() {
- @Override
- public void setColor(int color) {
- mUiEntry.setMenuButtonColor(color);
- }
- };
-
- private void backOrClose() {
- if (mSubscriptionIds.size() > 1) {
- mPlvAnimationController.enqueueBackAnimation(mClearAdapterRunnable);
- mProgressBar.setVisibility(View.VISIBLE);
- mCarMenuCallbacks.unsubscribe(mSubscriptionIds.pop(),
- mSubscriptionCallbacks);
- subscribe(mSubscriptionIds.peek());
- // Restore the title for this menu level.
- mTitles.pop();
- CharSequence title = mTitles.peek();
- if (TextUtils.isEmpty(title)) {
- title = mContentTitle;
- }
- mUiEntry.setTitleText(title);
- } else {
- closeDrawer();
- }
- }
-
- private final View.OnClickListener mMenuClickListener = new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (mIsDrawerAnimating || mCarMenuCallbacks.onMenuClicked()) {
- return;
- }
- // Check if drawer has root set.
- if (mRootId == null) {
- return;
- }
- mTruncatedListCardView.setVisibility(View.GONE);
- if (mIsDrawerOpen) {
- if (!mClickCountStack.isEmpty()) {
- mListView.setMaxPages(mListView.getMaxPages() + mClickCountStack.pop());
- }
- mIsCapped = false;
- backOrClose();
- } else {
- mSubscriptionIds.push(mRootId);
- mTitles.push(mContentTitle);
- subscribe(mRootId);
- openDrawer();
- }
- }
- };
-
- private final Runnable mClearAdapterRunnable = new Runnable() {
- @Override
- public void run() {
- mListView.setVisibility(View.GONE);
- }
- };
-
- public void updateDayNightMode() {
- mContainer.findViewById(R.id.drawer).setBackgroundColor(
- mContext.getResources().getColor(R.color.car_card));
- mListView.setAutoDayNightMode();
- switch (mDrawerMode) {
- case MODE_AUTO:
- setAutoLightDarkMode();
- break;
- case MODE_LIGHT:
- setLightMode();
- break;
- case MODE_DARK:
- setDarkMode();
- break;
- }
- updateViewFaders();
- RecyclerView rv = mListView.getRecyclerView();
- for (int i = 0; i < mAdapter.getItemCount(); ++i) {
- mAdapter.setDayNightModeColors(rv.findViewHolderForAdapterPosition(i));
- }
- }
-
- private static class ViewAnimationController implements Animation.AnimationListener {
- private final Animation mExitAnim;
- private final Animation mEnterAnim;
- private final Animation mBackAnim;
- private final View mView;
- private final Context mContext;
- private final Queue<Animation> mQueue = new LinkedList<>();
-
- private Runnable mOnEnterAnimStartRunnable;
- private Runnable mOnExitAnimCompleteRunnable;
-
- private Animation mCurrentAnimation;
-
- public ViewAnimationController(View view, int enter, int exit, int back) {
- mView = view;
- mContext = view.getContext();
-
- mEnterAnim = AnimationUtils.loadAnimation(mContext, enter);
- mExitAnim = AnimationUtils.loadAnimation(mContext, exit);
- mBackAnim = AnimationUtils.loadAnimation(mContext, back);
-
- mExitAnim.setAnimationListener(this);
- mEnterAnim.setAnimationListener(this);
- mBackAnim.setAnimationListener(this);
- }
-
- @Override
- public void onAnimationStart(Animation animation) {
- if (animation == mEnterAnim && mOnEnterAnimStartRunnable != null) {
- mOnEnterAnimStartRunnable.run();
- mOnEnterAnimStartRunnable = null;
- }
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- if ((animation == mExitAnim || animation == mBackAnim)
- && mOnExitAnimCompleteRunnable != null) {
- mOnExitAnimCompleteRunnable.run();
- mOnExitAnimCompleteRunnable = null;
- }
- Animation nextAnimation = mQueue.poll();
- if (nextAnimation != null) {
- mCurrentAnimation = animation;
- mView.startAnimation(nextAnimation);
- } else {
- mCurrentAnimation = null;
- }
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
-
- }
-
- public void enqueueEnterAnimation(Runnable r) {
- if (r != null) {
- mOnEnterAnimStartRunnable = r;
- }
- enqueueAnimation(mEnterAnim);
- }
-
- public void enqueueExitAnimation(Runnable r) {
- // If the view isn't visible, don't play the exit animation.
- // It will cause flicker.
- if (mView.getVisibility() != View.VISIBLE) {
- return;
- }
- if (r != null) {
- mOnExitAnimCompleteRunnable = r;
- }
- enqueueAnimation(mExitAnim);
- }
-
- public void enqueueBackAnimation(Runnable r) {
- // If the view isn't visible, don't play the back animation.
- if (mView.getVisibility() != View.VISIBLE) {
- return;
- }
- if (r != null) {
- mOnExitAnimCompleteRunnable = r;
- }
- enqueueAnimation(mBackAnim);
- }
-
- public synchronized void stopAndClearAnimations() {
- if (mExitAnim.hasStarted()) {
- mExitAnim.cancel();
- }
-
- if (mEnterAnim.hasStarted()) {
- mEnterAnim.cancel();
- }
-
- mQueue.clear();
- mCurrentAnimation = null;
- }
-
- public boolean isAnimating() {
- return mCurrentAnimation != null;
- }
-
- private synchronized void enqueueAnimation(final Animation animation) {
- if (mQueue.contains(animation)) {
- return;
- }
- if (mCurrentAnimation != null) {
- mQueue.add(animation);
- } else {
- mCurrentAnimation = animation;
- mView.startAnimation(animation);
- }
- }
- }
-
- private class SubscriptionCallbacks extends android.car.app.menu.SubscriptionCallbacks {
- private final Object mItemLock = new Object();
- private volatile List<Bundle> mItems;
-
- @Override
- public void onChildrenLoaded(String parentId, final List<Bundle> items) {
- if (mSubscriptionIds.isEmpty() || parentId.equals(mSubscriptionIds.peek())) {
- // Add unavailable category explanation at the first item of menu.
- if (mIsCapped) {
- Bundle extra = new Bundle();
- extra.putString(KEY_ID, KEY_ID_UNAVAILABLE_CATEGORY);
- items.add(0, extra);
- }
- mItems = items;
- mItemsNumber = mItems.size();
- mProgressBar.setVisibility(View.GONE);
- mPlvAnimationController.enqueueEnterAnimation(new Runnable() {
- @Override
- public void run() {
- synchronized (mItemLock) {
- mAdapter.setItems(mItems, mIsCapped);
- mListView.setVisibility(View.VISIBLE);
- mItems = null;
- }
- mListView.scrollToPosition(mAdapter.getFirstItemIndex());
- }
- });
- }
- }
-
- @Override
- public void onError(String id) {
- // TODO: do something useful here.
- }
-
- @Override
- public void onChildChanged(String parentId, Bundle bundle) {
- if (!mSubscriptionIds.isEmpty() && parentId.equals(mSubscriptionIds.peek())) {
- // List is still animating, so adapter hasn't been updated. Update the list that
- // needs to be set.
- String id = bundle.getString(KEY_ID);
- synchronized (mItemLock) {
- if (mItems != null) {
- for (Bundle item : mItems) {
- if (item.getString(KEY_ID).equals(id)) {
- item.putAll(bundle);
- break;
- }
- }
- return;
- }
- }
- RecyclerView rv = mListView.getRecyclerView();
- RecyclerView.ViewHolder holder = rv.findViewHolderForItemId(id.hashCode());
- mAdapter.onChildChanged(holder, bundle);
- }
- }
- }
-
- private class DrawerMenuListDecoration extends PagedListView.Decoration {
-
- public DrawerMenuListDecoration(Context context) {
- super(context);
- }
-
- @Override
- public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
- if (mAdapter != null && mAdapter.isEmptyPlaceholder()) {
- return;
- }
- super.onDrawOver(c, parent, state);
- }
- }
-}
diff --git a/car-ui-provider/src/android/car/ui/provider/MaxWidthLayout.java b/car-ui-provider/src/android/car/ui/provider/MaxWidthLayout.java
deleted file mode 100644
index 4311c5a..0000000
--- a/car-ui-provider/src/android/car/ui/provider/MaxWidthLayout.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2015 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 android.car.ui.provider;
-
-import android.content.Context;
-import android.util.AttributeSet;
-
-/**
- * Clone of {@link android.support.car.ui.MaxWidthLayout} to be used by CarUiProvider.
- * Workaround for b/25595320
- */
-public class MaxWidthLayout extends android.support.car.ui.MaxWidthLayout {
- public MaxWidthLayout(Context context) {
- super(context);
- }
-
- public MaxWidthLayout(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public MaxWidthLayout(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
-}
\ No newline at end of file
diff --git a/car-ui-provider/src/android/car/ui/provider/PagedListView.java b/car-ui-provider/src/android/car/ui/provider/PagedListView.java
deleted file mode 100644
index 9648dd6..0000000
--- a/car-ui-provider/src/android/car/ui/provider/PagedListView.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2015 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 android.car.ui.provider;
-
-import android.content.Context;
-import android.util.AttributeSet;
-
-/**
- * Clone of {@link android.support.car.ui.PagedListView} to be used by CarUiProvider.
- * Workaround for b/25595320
- */
-public class PagedListView extends android.support.car.ui.PagedListView {
- public PagedListView(Context context, AttributeSet attrs) {
- this(context, attrs, 0 /*defStyleAttrs*/, 0 /*defStyleRes*/);
- }
-
- public PagedListView(Context context, AttributeSet attrs, int defStyleAttrs) {
- this(context, attrs, defStyleAttrs, 0 /*defStyleRes*/);
- }
-
- public PagedListView(Context context, AttributeSet attrs, int defStyleAttrs, int defStyleRes) {
- super(context, attrs, defStyleAttrs, defStyleRes);
- }
-}
diff --git a/car-ui-provider/src/android/car/ui/provider/PagedScrollBarView.java b/car-ui-provider/src/android/car/ui/provider/PagedScrollBarView.java
deleted file mode 100644
index 91a25ab..0000000
--- a/car-ui-provider/src/android/car/ui/provider/PagedScrollBarView.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2015 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 android.car.ui.provider;
-
-import android.content.Context;
-import android.util.AttributeSet;
-
-/**
- * Clone of {@link android.support.car.ui.PagedScrollBarView} to be used by CarUiProvider.
- * Workaround for b/25595320
- */
-public class PagedScrollBarView extends android.support.car.ui.PagedScrollBarView {
- public PagedScrollBarView(
- Context context, AttributeSet attrs) {
- this(context, attrs, 0 /*defStyleAttrs*/, 0 /*defStyleRes*/);
- }
-
- public PagedScrollBarView(
- Context context, AttributeSet attrs, int defStyleAttrs) {
- this(context, attrs, defStyleAttrs, 0 /*defStyleRes*/);
- }
-
- public PagedScrollBarView(
- Context context, AttributeSet attrs, int defStyleAttrs, int defStyleRes) {
- super(context, attrs, defStyleAttrs, defStyleRes);
- }
-}
diff --git a/car_product/build/car.mk b/car_product/build/car.mk
index 16aa275..1c2e7ee 100644
--- a/car_product/build/car.mk
+++ b/car_product/build/car.mk
@@ -74,7 +74,6 @@
PRODUCT_PACKAGES += \
vehicle_monitor_service \
CarService \
- CarUiProvider \
CarTrustAgentService \
CarDialerApp \
CarRadioApp \